Merlijn van Deen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/243514

Change subject: Changes are wrongly detected in the last langlink
......................................................................

Changes are wrongly detected in the last langlink

This was first detected in cosmetic_changes.py, where pages not needing any
cosmetic changes were still being updated, and the supposed changed was an
unchanged langlink (the last one). Then I realized this also happens in
interwiki.py, but only when changes are supposed to be made to the page.
After checking textlib.py, I noticed that removeLanguageLinks() returns a
stripped version of the text whereas replaceLanguageLinks() does not. So
the actual difference is related to blank space.
This explains why cosmetic_changes.py detects a change and updates the page,
but interwiki.py does not: interwiki.py does not rely in differences in the
final text to make an update, but when it does need to make an update, it
outputs that diff.

This patch strips the text in replaceLanguageLinks() before returning if the
original text is stripped itself.

Conflicts:
        pywikibot/textlib.py

Change-Id: Icd7252be8dbccf3fb04a4b4a465f6b057e3a8e3a
---
M pywikibot/textlib.py
1 file changed, 9 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/14/243514/1

diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index b40aba4..206a86d 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -31,7 +31,11 @@
 
 from pywikibot import config2 as config
 from pywikibot.family import Family
-from pywikibot.tools import OrderedDict
+from pywikibot.tools import (
+    DeprecatedRegex,
+    OrderedDict,
+    issue_deprecation_warning
+)
 
 # cache for replaceExcept to avoid recompile or regexes each call
 _regex_cache = {}
@@ -595,6 +599,9 @@
     cseparator = site.family.category_text_separator
     separatorstripped = separator.strip()
     cseparatorstripped = cseparator.strip()
+    do_not_strip = oldtext.strip() != oldtext
+    if do_not_strip:
+        issue_deprecation_warning('Using unstripped text', 'stripped text', 2)
     if addOnly:
         s2 = oldtext
     else:
@@ -662,7 +669,7 @@
                     newtext = s2.replace(marker, '').strip() + separator + s
     else:
         newtext = s2.replace(marker, '')
-    return newtext
+    return newtext if do_not_strip else newtext.strip()
 
 
 def interwikiFormat(links, insite=None):

-- 
To view, visit https://gerrit.wikimedia.org/r/243514
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd7252be8dbccf3fb04a4b4a465f6b057e3a8e3a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: Merlijn van Deen <valhall...@arctus.nl>
Gerrit-Reviewer: Malafaya <malaf...@clix.pt>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to