Sn1per has uploaded a new change for review.

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

Change subject: Use unprotect i18n messages
......................................................................

Use unprotect i18n messages

When -unprotect flag is set or when the default value
for protection is 'all', use the unprotect i18n messages
when applicable for edit summary.

Bug: T63312
Change-Id: I2cda1fdd472070e4fd65392df9db2d0eebea41ba
---
M scripts/i18n
M scripts/protect.py
2 files changed, 23 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/84/185784/1

diff --git a/scripts/i18n b/scripts/i18n
index 4892b06..2bee9de 160000
--- a/scripts/i18n
+++ b/scripts/i18n
-Subproject commit 4892b065142a239bb014ce6b754467df7a36196f
+Subproject commit 2bee9de535d3bef24f33f40b1bdf720ecaf337d8
diff --git a/scripts/protect.py b/scripts/protect.py
index fd8b3e7..dcf4c8f 100644
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -165,6 +165,18 @@
     protection_types = site.protection_types()
     if '' in protection_levels:
         protection_levels.add('all')
+    # get the default protection level first so we can use the correct
+    # edit summary if applicable
+    for arg in local_args:
+        if arg.startswith('-unprotect'):
+            default_level = 'all'
+            local_args.remove(arg)
+        elif arg.startswith('-default'):
+            if len(arg) == len('-default'):
+                default_level = 'sysop'
+            else:
+                default_level = arg[len('-default:'):]
+            local_args.remove(arg)
     for arg in local_args:
         if arg == '-always':
             options['always'] = True
@@ -178,13 +190,6 @@
             pywikibot.output('\n\03{lightred}-image option is deprecated. '
                              'Please use -imagelinks instead.\03{default}\n')
             local_args.append('-imagelinks' + arg[7:])
-        elif arg.startswith('-unprotect'):
-            default_level = 'all'
-        elif arg.startswith('-default'):
-            if len(arg) == len('-default'):
-                default_level = None
-            else:
-                default_level = arg[len('-default:'):]
         else:
             is_p_type = False
             if arg.startswith('-'):
@@ -198,19 +203,24 @@
             if not is_p_type:
                 if not genFactory.handleArg(arg):
                     raise ValueError('Unknown parameter "{0}"'.format(arg))
-                found = arg.find(':') + 1
+                found = arg.find(':')
                 if found:
-                    message_properties.update({'cat': arg[found:],
-                                               'page': arg[found:]})
+                    message_properties.update({'cat': arg[found+1:],
+                                               'page': arg[found+1:]})
 
                 if 'summary' not in options:
                     generator_type = arg[1:found] if found > 0 else arg[1:]
                     if generator_type in default_summaries:
                         message_type = default_summaries[generator_type]
                         if message_type == 'simple' or message_properties:
-                            options['summary'] = i18n.twtranslate(
-                                site, 'protect-{0}'.format(message_type),
-                                message_properties)
+                            if default_level == 'all':
+                                options['summary'] = i18n.twtranslate(
+                                    site, 
'protect-unprotect-{0}'.format(message_type),
+                                    message_properties)
+                            else:
+                                options['summary'] = i18n.twtranslate(
+                                    site, 'protect-{0}'.format(message_type),
+                                    message_properties)
 
     generator = genFactory.getCombinedGenerator()
     # We are just protecting pages, so we have no need of using a preloading

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

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

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

Reply via email to