John Vandenberg has uploaded a new change for review.

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

Change subject: Move reflinks stop page checker in Bot
......................................................................

Move reflinks stop page checker in Bot

The 'stop page' checker in reflinks is a basic implementation
that can be improved as scripts are standardised.

This changeset changes the stop page from being a hardcoded page
for each language, to being the user subpage of the logged in bot.

Change-Id: I511bff7a5574402857de12e8b169757a882c3db4
---
M pywikibot/bot.py
M scripts/reflinks.py
2 files changed, 50 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/95/166395/1

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 8fbf9ad..b776c02 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -947,6 +947,49 @@
                 pywikibot.output('\nKeyboardInterrupt during %s bot run...' %
                                  self.__class__.__name__)
 
+    def user_page(self, subpage=None, site=None):
+        if not site:
+            if hasattr(self, 'site'):
+                site = self.site
+            else:
+                raise NotImplementedError('Can not load a Bot.user_page. '
+                                          'Property %s.site not set.'
+                                          % self.__class__.__name__)
+
+        if not site.username():
+            raise pywikibot.NoUsername(u'No username for %s' % site)
+
+        page = pywikibot.User(site, site.username())
+        if subpage:
+            page = page.getUserPage(subpage)
+
+        return page
+
+    def set_stop_page_suffix(self, suffix):
+        self.stop_page = self.user_page(suffix)
+        try:
+            self.stop_page_rev_id = self.stop_page.latestRevision()
+        except pywikibot.NoPage:
+            pywikibot.output(u'The stop page %s does not exist'
+                             % self.stop_page.title(asLink=True))
+            raise
+
+    def stop_page_changed(self):
+        """
+        Check the stop page.
+
+        @return: True if the stop page has been modified
+        @rtype: bool
+        """
+        pywikibot.output('\03{lightgreen}Checking stop page...\03{default}')
+        latest_rev_id = self.stop_page.latestRevision()
+        if latest_rev_id != self.stop_page_rev_id:
+            pywikibot.output(
+                u'[[%s]] has been edited : Someone wants us to stop.'
+                % self.stop_page)
+            return True
+        return False
+
 
 class WikidataBot(Bot):
 
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 477b668..6d56b45 100644
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -77,18 +77,7 @@
 
 
 stopPage = {
-    'fr': u'Utilisateur:DumZiBoT/EditezCettePagePourMeStopper',
-    'da': u'Bruger:DumZiBoT/EditThisPageToStopMe',
-    'de': u'Benutzer:DumZiBoT/EditThisPageToStopMe',
-    'fa': u'کاربر:Amirobot/EditThisPageToStopMe',
-    'it': u'Utente:Marco27Bot/EditThisPageToStopMe',
-    'ko': u'사용자:GrassnBreadRefBot/EditThisPageToStopMe1',
-    'he': u'User:Matanyabot/EditThisPageToStopMe',
-    'hu': u'User:Damibot/EditThisPageToStopMe',
-    'en': u'User:DumZiBoT/EditThisPageToStopMe',
-    'pl': u'Wikipedysta:MastiBot/EditThisPageToStopMe',
-    'ru': u'User:Rubinbot/EditThisPageToStopMe',
-    'zh': u'User:Sz-iwbot',
+    'fr': u'EditezCettePagePourMeStopper',
 }
 
 deadLinkTag = {
@@ -424,8 +413,11 @@
             self.msg = i18n.twtranslate(self.site, 'reflinks-msg', locals())
         else:
             self.msg = self.getOption('summary')
-        self.stopPage = pywikibot.Page(self.site,
-                                       i18n.translate(self.site, stopPage))
+
+        stop_page_suffix = stopPage.get(self.site.code, 'EditThisPageToStopMe')
+        if self.site.username() == 'GrassnBreadRefBot':
+            stop_page_suffix = 'EditThisPageToStopMe1'
+        self.set_stop_page_suffix(stop_page_suffix)
 
         local = i18n.translate(self.site, badtitles)
         if local:
@@ -435,12 +427,6 @@
         self.titleBlackList = re.compile(bad, re.I | re.S | re.X)
         self.norefbot = noreferences.NoReferencesBot(None, verbose=False)
         self.deduplicator = DuplicateReferences()
-        try:
-            self.stopPageRevId = self.stopPage.latestRevision()
-        except pywikibot.NoPage:
-            pywikibot.output(u'The stop page %s does not exist'
-                             % self.stopPage.title(asLink=True))
-            raise
 
         # Regex to grasp content-type meta HTML tag in HTML source
         self.META_CONTENT = re.compile(r'(?i)<meta[^>]*content\-type[^>]*>')
@@ -771,13 +757,7 @@
                 return
 
             if editedpages % 20 == 0:
-                pywikibot.output(
-                    '\03{lightgreen}Checking stop page...\03{default}')
-                actualRev = self.stopPage.latestRevision()
-                if actualRev != self.stopPageRevId:
-                    pywikibot.output(
-                        u'[[%s]] has been edited : Someone wants us to stop.'
-                        % self.stopPage)
+                if self.stop_page_changed():
                     return
 
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I511bff7a5574402857de12e8b169757a882c3db4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to