Skip to content

Commit

Permalink
Merge pull request #119 from huggle/parser_fix
Browse files Browse the repository at this point in the history
Parser fix
  • Loading branch information
benapetr committed Nov 15, 2014
2 parents 10c3b72 + 24b9d22 commit 15af67c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
39 changes: 18 additions & 21 deletions huggle/huggleparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,14 @@ QString HuggleParser::GetKeyFromValue(QString item)
return item;
}

static int DateMark(QString page)
static int DateMark(QString page, WikiSite *site)
{
QStringList marks;
marks << "(UTC)" << "(CET)" << "(CEST)";
int m = 0;
int position = 0;
QString mark = "";
while (m < marks.count())
while (m < site->GetProjectConfig()->Parser_Date_Suffix.count())
{
QString m_ = marks.at(m);
QString m_ = site->GetProjectConfig()->Parser_Date_Suffix.at(m);
if (page.contains(m_))
{
int mp = page.lastIndexOf(m_);
Expand Down Expand Up @@ -275,7 +273,7 @@ byte_ht HuggleParser::GetLevel(QString page, QDate bt, WikiSite *site)
page = "";
while (CurrentIndex < sections.count())
{
int dp = DateMark(sections.at(CurrentIndex));
int dp = DateMark(sections.at(CurrentIndex), site);
// we need to find a date in this section
if (!dp)
{
Expand All @@ -285,25 +283,17 @@ byte_ht HuggleParser::GetLevel(QString page, QDate bt, WikiSite *site)
}
QString section = sections.at(CurrentIndex);
section = section.mid(0, dp).trimmed();
if (!section.contains(","))
if (!section.contains(site->GetProjectConfig()->Parser_Date_Prefix))
{
// this is some borked date let's remove it
CurrentIndex++;
continue;
}
QString time = section.mid(section.lastIndexOf(","));
if (time.length() < 2)
{
// what the fuck
HUGGLE_DEBUG("Negative position: " + time, 1);
CurrentIndex++;
continue;
}
// we remove the comma
time = time.mid(2);
QString time = section.mid(section.lastIndexOf(site->GetProjectConfig()->Parser_Date_Prefix) + site->GetProjectConfig()->Parser_Date_Prefix.length());
// now we need this uberhack so that we can get a month name from localized version
// let's hope that month is a word in a middle of string
QString month_name = time;
time = time.trimmed();
QString month_name = "";
QStringList parts_time = time.split(' ');
if (parts_time.count() < 3)
{
Expand All @@ -316,16 +306,23 @@ byte_ht HuggleParser::GetLevel(QString page, QDate bt, WikiSite *site)
// e.g. dewiki's days end with dot
if(day.endsWith('.'))
day = day.mid(0, day.length() - 1);
month_name = parts_time.at(1);
// on some wikis months have spaces in name
int i = 1;
while (i < parts_time.count() - 1)
{
month_name += parts_time.at(i) + " ";
i++;
}
month_name = month_name.trimmed();
byte_ht month = HuggleParser::GetIDOfMonth(month_name);

// let's create a new time string from converted one, just to make sure it will be parsed properly
if (month > 0)
{
time = day + " " + QString::number(month) + " " + parts_time.at(2);
time = day + " " + QString::number(month) + " " + parts_time.last();
} else
{
time = day + " " + parts_time.at(1); + " " + parts_time.at(2);
time = day + " " + parts_time.at(1); + " " + parts_time.last();
}
QDate date = QDate::fromString(time, "d M yyyy");
if (!date.isValid())
Expand Down
8 changes: 7 additions & 1 deletion huggle/projectconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ ProjectConfiguration::ProjectConfiguration(QString project_name)
<< "October"
<< "November"
<< "December";

this->Parser_Date_Suffix << "(CET)" << "(UTC)" << "(CEST)";

// defaults
this->ProtectReason = "Persistent [[WP:VAND|vandalism]]";
this->BlockExpiryOptions.append("indefinite");
Expand All @@ -53,7 +56,7 @@ bool ProjectConfiguration::Parse(QString config, QString *reason)
{
Version version(HuggleParser::ConfigurationParse("min-version", config, "3.0.0"));
Version huggle_version(HUGGLE_VERSION);
if (&huggle_version < &version)
if (huggle_version < version)
{
if (reason)
*reason = "your huggle is too old, " + this->ProjectName + " supports only " + version.ToString() + " or newer.";
Expand All @@ -66,6 +69,9 @@ bool ProjectConfiguration::Parse(QString config, QString *reason)
this->AIVExtend = SafeBool(HuggleParser::ConfigurationParse("aiv-extend", config));
this->ReportAIV = HuggleParser::ConfigurationParse("aiv", config);
this->ReportSt = HuggleParser::ConfigurationParse("aiv-section", config).toInt();
// we use these to understand which format they use on a wiki for dates
this->Parser_Date_Suffix = HuggleParser::ConfigurationParse_QL("parser-date-suffix", config, this->Parser_Date_Suffix, true);
this->Parser_Date_Prefix = HuggleParser::ConfigurationParse("parser-date-prefix", config, this->Parser_Date_Prefix);
this->IPVTemplateReport = HuggleParser::ConfigurationParse("aiv-ip", config, "User $1: $2$3 ~~~~");
this->RUTemplateReport = HuggleParser::ConfigurationParse("aiv-user", config, "User $1: $2$3 ~~~~");
this->ReportDefaultReason = HuggleParser::ConfigurationParse("vandal-report-reason", config, "Persistent vandalism and/or "\
Expand Down
2 changes: 2 additions & 0 deletions huggle/projectconfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ namespace Huggle
QStringList Assisted;
QStringList Templates;
QStringList IgnorePatterns;
QString Parser_Date_Prefix = ",";
QStringList Parser_Date_Suffix;
int TalkPageWarningScore = -800;
bool GlobalRequired = true;
// Tagging
Expand Down

0 comments on commit 15af67c

Please sign in to comment.