http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10337
Revision: 10337 Author: xqt Date: 2012-06-08 22:25:36 +0000 (Fri, 08 Jun 2012) Log Message: ----------- enable cosmetic changes for rewrite branch additional setting cosmetic_changes_deny_script to exclude some scripts from cc changes.
Modified Paths: -------------- branches/rewrite/pywikibot/config2.py branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/config2.py =================================================================== --- branches/rewrite/pywikibot/config2.py 2012-06-08 20:52:06 UTC (rev 10336) +++ branches/rewrite/pywikibot/config2.py 2012-06-08 22:25:36 UTC (rev 10337) @@ -478,12 +478,14 @@ # If you want the bot to also do cosmetic changes when editing a page on a # foreign wiki, set cosmetic_changes_mylang_only to False, but be careful! cosmetic_changes_mylang_only = True + # The dictionary cosmetic_changes_enable should contain a tuple of languages # for each site where you wish to enable in addition to your own langlanguage # (if cosmetic_changes_mylang_only is set) # Please set your dictionary by adding such lines to your user-config.py: # cosmetic_changes_enable['wikipedia'] = ('de', 'en', 'fr') cosmetic_changes_enable = {} + # The dictionary cosmetic_changes_disable should contain a tuple of languages # for each site where you wish to disable cosmetic changes. You may use it with # cosmetic_changes_mylang_only is False, but you can also disable your own @@ -492,6 +494,12 @@ # cosmetic_changes_disable['wikipedia'] = ('de', 'en', 'fr') cosmetic_changes_disable = {}
+# cosmetic_changes_deny_script is a list of scripts for which cosmetic changes +# are disabled. You may add additional scripts by appending script names in +# your user_config.py ("+=" operator is strictly recommended): +# cosmetic_changes_deny_script += ['your_script_name_1', 'your_script_name_2'] +cosmetic_changes_deny_script = ['cosmetic_changes', 'touch'] + ############## FURTHER SETTINGS ##############
### Proxy configuration ###
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2012-06-08 20:52:06 UTC (rev 10336) +++ branches/rewrite/pywikibot/page.py 2012-06-08 22:25:36 UTC (rev 10337) @@ -749,6 +749,8 @@ def _save(self, comment, minor, watchval, botflag, async, callback): err = None link = self.title(asLink=True) + if config.cosmetic_changes: + comment = self._cosmetic_changes_hook(comment) or comment try: done = self.site.editpage(self, summary=comment, minor=minor, watch=watchval, bot=botflag) @@ -771,6 +773,39 @@ if callback: callback(self, err)
+ def _cosmetic_changes_hook(self, comment): + if self.isTalkPage() or \ + pywikibot.calledModuleName() in config.cosmetic_changes_deny_script: + return + family = self.site.family.name + if config.cosmetic_changes_mylang_only: + cc = (family == config.family and \ + self.site.lang == config.mylang) or \ + family in config.cosmetic_changes_enable.keys() and \ + self.site.lang in config.cosmetic_changes_enable[family] + else: + cc = True + cc = cc and not \ + (family in config.cosmetic_changes_disable.keys() and \ + self.site.lang in config.cosmetic_changes_disable[family]) + if not cc: + return + old = self.text + if config.verbose_output: + pywikibot.output(u'Cosmetic changes for %s-%s enabled.' + % (family, self.site.lang)) + from scripts.cosmetic_changes import CosmeticChangesToolkit + from pywikibot import i18n + ccToolkit = CosmeticChangesToolkit(self.site, + redirect=self.isRedirectPage(), + namespace=self.namespace(), + pageTitle=self.title()) + self.text = ccToolkit.change(old) + if comment and \ + old.strip().replace('\r\n', '\n') != self.text.strip().replace('\r\n', '\n'): + comment += i18n.twtranslate(self.site, 'cosmetic_changes-append') + return comment + def put(self, newtext, comment=u'', watchArticle=None, minorEdit=True, botflag=None, force=False, async=False, callback=None): """Save the page with the contents of the first argument as the text.
pywikipedia-svn@lists.wikimedia.org