22
22
#include " wikisite.hpp"
23
23
#include " wikiutil.hpp"
24
24
#include " wikiuser.hpp"
25
+ #include < QRegularExpression>
25
26
#include < QUrl>
26
27
27
28
using namespace Huggle ;
@@ -205,7 +206,7 @@ void Message::processNextStep()
205
206
this ->Error = MessageError_ArticleExist;
206
207
} else
207
208
{
208
- this ->Fail (_l (" error-unknown-code" ,ec));
209
+ this ->Fail (_l (" error-unknown-code" , ec));
209
210
this ->Error = MessageError_Unknown;
210
211
}
211
212
return ;
@@ -319,17 +320,15 @@ void Message::processSend()
319
320
if (this ->SectionKeep )
320
321
{
321
322
this ->Text = this ->appendText (this ->Text , this ->originalUnmodifiedPageText , this ->Title );
322
- } else
323
- {
323
+ } else {
324
324
// original page needs to be included in new value
325
325
if (!this ->originalUnmodifiedPageText .isEmpty ())
326
326
this ->Text = this ->originalUnmodifiedPageText + " \n\n " + this ->Text ;
327
327
}
328
328
this ->query ->Parameters = " title=" + QUrl::toPercentEncoding (User->GetTalk ()) + " &summary=" + QUrl::toPercentEncoding (summary)
329
329
+ " &text=" + QUrl::toPercentEncoding (this ->Text ) + parameters
330
330
+ " &token=" + QUrl::toPercentEncoding (this ->User ->GetSite ()->GetProjectConfig ()->Token_Csrf );
331
- }else
332
- {
331
+ } else {
333
332
this ->query ->Parameters = " title=" + QUrl::toPercentEncoding (User->GetTalk ()) + " §ion=new§iontitle="
334
333
+ QUrl::toPercentEncoding (this ->Title ) + " &summary=" + QUrl::toPercentEncoding (summary)
335
334
+ " &text=" + QUrl::toPercentEncoding (this ->Text ) + parameters + " &token="
@@ -357,8 +356,7 @@ void Message::processTalkPageRetrieval()
357
356
this ->originalUnmodifiedPageText = page->Value ;
358
357
this ->previousTalkPageRetrieved = true ;
359
358
return ;
360
- } else
361
- {
359
+ } else {
362
360
if (!missing)
363
361
{
364
362
Huggle::Syslog::HuggleLogs->DebugLog (this ->query ->Result ->Data );
@@ -375,12 +373,10 @@ QString Message::appendText(QString text, QString original_text, QString section
375
373
// there is nothing to insert this to
376
374
return original_text += " \n\n " + text + " \n\n " ;
377
375
}
378
- # ifdef QT6_BUILD
376
+
379
377
QRegularExpression regex (" \\ s*==\\ s*" + QRegularExpression::escape (section_name) + " \\ s*==" );
380
- #else
381
- QRegExp regex (" \\ s*==\\ s*" + QRegExp::escape (section_name) + " \\ s*==" );
382
- #endif
383
- if (!original_text.contains (regex))
378
+ QRegularExpressionMatch regex_match;
379
+ if (!original_text.contains (regex, ®ex_match))
384
380
{
385
381
// there is no section to append to
386
382
if (!original_text.isEmpty ())
@@ -390,32 +386,20 @@ QString Message::appendText(QString text, QString original_text, QString section
390
386
original_text += " == " + section_name + " ==\n\n " + text;
391
387
return original_text;
392
388
}
393
- #ifdef QT6_BUILD
394
- QRegularExpression header (" \\ s*==.*==\\ s*" );
395
- #else
396
- QRegExp header (" \\ s*==.*==\\ s*" );
397
- #endif
398
- int start_of_desired_section = original_text.lastIndexOf (regex);
389
+
399
390
// we need to check if there is any other section after this one
391
+ int start_of_desired_section = original_text.lastIndexOf (regex) + regex_match.capturedView ().length ();
400
392
QString section = original_text.mid (start_of_desired_section);
401
- if (section.contains (" \n " ))
402
- {
403
- // cut the header text
404
- int Diff = section.indexOf (" \n " ) + 1 ;
405
- start_of_desired_section += Diff;
406
- section = section.mid (Diff);
407
- }
393
+ QRegularExpression next_header (" \\ s*==.*==\\ s*" );
408
394
int start_point = start_of_desired_section;
409
- if (section.contains (header ))
395
+ if (section.contains (next_header ))
410
396
{
411
397
// yes there is some other section, so we need to know where it is, so that we know where current
412
398
// section ends (we want to append text to bottom of current section)
413
- start_point += section.indexOf (header);
414
- } else
415
- {
399
+ start_point += section.indexOf (next_header);
400
+ } else {
416
401
start_point += section.length ();
417
402
}
418
403
// write the text exactly after the start point, but leave some space after it
419
- original_text = original_text.insert (start_point, " \n\n " + text + " \n " );
420
- return original_text;
404
+ return original_text.insert (start_point, " \n\n " + text + " \n " );
421
405
}
0 commit comments