From d55c81c97b6545e59a36a49c5695b216491c2a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Tue, 30 Aug 2016 18:05:51 +0200 Subject: [PATCH] Set article status when worked on talkpage To detect whole redfam status after run over all articles Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=89 FS#89] --- bots/markpages.py | 56 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/bots/markpages.py b/bots/markpages.py index aa9597c..7548294 100644 --- a/bots/markpages.py +++ b/bots/markpages.py @@ -129,7 +129,9 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() self.current_wikicode = mwparser.parse( self.current_page.text ) # Add notice - self.add_disc_notice_template() + # Returns True if added + # None if already present + add_ret = self.add_disc_notice_template() # Convert wikicode back to string to save self.new_text = str( self.current_wikicode ) @@ -142,8 +144,24 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() if not summary[:len("Bot:")] == "Bot:": summary = "Bot: " + summary.strip() - # Save - self.put_current( self.new_text, summary=summary ) + # will return True if saved + # False if not saved because of errors + # None if change was not accepted by user + save_ret = self.put_current( self.new_text ) + + # Status + if add_ret is None or add_ret and save_ret: + self.current_page.redfam.article_add_status( + "marked", + title=self.current_page.title(withNamespace=False)) + elif save_ret is None: + self.current_page.redfam.article_add_status( + "note_rej", + title=self.current_page.title(withNamespace=False)) + else: + self.current_page.redfam.article_add_status( + "sav_err", + title=self.current_page.title(withNamespace=False)) def add_disc_notice_template( self ): """ @@ -157,7 +175,7 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() # Check if it is already present in wikicode if self.disc_notice_present(): - return False + return # Find the right place to insert notice template # Therfore we need the first section (if there is one) @@ -211,3 +229,33 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() # If nothing is found, loop will run till its end else: return False + + # We need to overrite this since orginal from pywikibot.bot.CurrentPageBot + # does not return result of self._save_page + def put_current(self, new_text, ignore_save_related_errors=None, + ignore_server_errors=None, **kwargs): + """ + Call L{Bot.userPut} but use the current page. + + It compares the new_text to the current page text. + + @param new_text: The new text + @type new_text: basestring + @param ignore_save_related_errors: Ignore save related errors and + automatically print a message. If None uses this instances default. + @type ignore_save_related_errors: bool or None + @param ignore_server_errors: Ignore server errors and automatically + print a message. If None uses this instances default. + @type ignore_server_errors: bool or None + @param kwargs: Additional parameters directly given to L{Bot.userPut}. + @type kwargs: dict + """ + if ignore_save_related_errors is None: + ignore_save_related_errors = self.ignore_save_related_errors + if ignore_server_errors is None: + ignore_server_errors = self.ignore_server_errors + return self.userPut( + self.current_page, self.current_page.text, new_text, + ignore_save_related_errors=ignore_save_related_errors, + ignore_server_errors=ignore_server_errors, + **kwargs)