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.
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10336
Revision: 10336
Author: xqt
Date: 2012-06-08 20:52:06 +0000 (Fri, 08 Jun 2012)
Log Message:
-----------
cosmetic_changes_enable/disable dict added
Modified Paths:
--------------
branches/rewrite/pywikibot/config2.py
Modified: branches/rewrite/pywikibot/config2.py
===================================================================
--- branches/rewrite/pywikibot/config2.py 2012-06-08 20:12:23 UTC (rev 10335)
+++ branches/rewrite/pywikibot/config2.py 2012-06-08 20:52:06 UTC (rev 10336)
@@ -478,6 +478,19 @@
# 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
+# language. This also overrides the settings in the cosmetic_changes_enable
+# dictionary. Please set your dict by adding such lines to your user-config.py:
+# cosmetic_changes_disable['wikipedia'] = ('de', 'en', 'fr')
+cosmetic_changes_disable = {}
############## FURTHER SETTINGS ##############
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10334
Revision: 10334
Author: drtrigon
Date: 2012-06-08 17:23:09 +0000 (Fri, 08 Jun 2012)
Log Message:
-----------
new feature; DRTRIGON-122 'matchhead_list' added
Modified Paths:
--------------
trunk/pywikipedia/sum_disc.py
Modified: trunk/pywikipedia/sum_disc.py
===================================================================
--- trunk/pywikipedia/sum_disc.py 2012-06-08 16:33:42 UTC (rev 10333)
+++ trunk/pywikipedia/sum_disc.py 2012-06-08 17:23:09 UTC (rev 10334)
@@ -127,11 +127,11 @@
# list values
# which lists are regex to compile ('backlinks_list' are no regex)
#'regex_compile': [ 'checkedit_list', 'checksign_list', 'ignorepage_list', ],
- #'regex_compile': [ 'checkedit_list', 'ignorepage_list', 'ignorehead_list', ],
- 'regex_compile': [ 'checkedit_list', 'ignorehead_list', ],
+ #'regex_compile': [ 'checkedit_list', 'ignorepage_list', 'ignorehead_list', 'matchhead_list', ],
+ 'regex_compile': [ 'checkedit_list', 'ignorehead_list', 'matchhead_list', ],
# which lists may contain variables to substitute
#'vars_subst': [ 'checkedit_list', 'checksign_list', 'ignorepage_list', 'backlinks_list', 'altsign_list' ],
- 'vars_subst': [ 'checkedit_list', 'ignorepage_list', 'backlinks_list', 'altsign_list' ], # + 'ignorehead_list' ?
+ 'vars_subst': [ 'checkedit_list', 'ignorepage_list', 'backlinks_list', 'altsign_list' ], # + 'ignorehead_list', 'matchhead_list' ?
# which lists should preserve/keep their defaults (instead of getting it overwritten by user settings)
'default_keep': [ 'checkedit_list', 'altsign_list' ],
# which lists should be translated according to site's lang
@@ -199,8 +199,10 @@
# (hidden)
#userResultPage: default is NOT DEFINED - this is a SPECIAL PARAM it is not
# thought to be used explicit, it is defined by the page link (implicit).
- # (not published yet: LIST of HEADs to IGNORE, a LIST)
+ # (not officially published yet: LIST of HEADs to IGNORE, a LIST)
'ignorehead_list': [ u'(.*?) \(erl.\)', ],
+ # (not published yet: LIST of HEADs to PROCESS ONLY, a LIST)
+ 'matchhead_list': [],
# (hidden)
'notify_msg': {
@@ -1478,6 +1480,10 @@
if check.search(wikiline):
skip = True
break
+ for check in self._param['matchhead_list']:
+ if not check.search(wikiline):
+ skip = True
+ break
if skip: continue
# check relevancy of section
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10333
Revision: 10333
Author: xqt
Date: 2012-06-08 16:33:42 +0000 (Fri, 08 Jun 2012)
Log Message:
-----------
do not invoke cosmetic_changes with touch.py
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2012-06-08 14:58:03 UTC (rev 10332)
+++ trunk/pywikipedia/wikipedia.py 2012-06-08 16:33:42 UTC (rev 10333)
@@ -1980,7 +1980,8 @@
self._editrestriction = False
# If no comment is given for the change, use the default
comment = comment or action
- if config.cosmetic_changes and not self.isTalkPage() and not calledModuleName() == 'cosmetic_changes':
+ if config.cosmetic_changes and not self.isTalkPage() and \
+ not calledModuleName() in ('cosmetic_changes', 'touch'):
if config.cosmetic_changes_mylang_only:
cc = (self.site().family.name == config.family and self.site().lang == config.mylang) or \
self.site().family.name in config.cosmetic_changes_enable.keys() and \