[MediaWiki-commits] [Gerrit] fix lookup of family in config.usernames and config.sysopnames - change (pywikibot/core)

2014-07-24 Thread Russell Blau (Code Review)
Russell Blau has submitted this change and it was merged.

Change subject: fix lookup of family in config.usernames and config.sysopnames
..


fix lookup of family in config.usernames and config.sysopnames

using fam.name instead of the string representation for Family objects

bug: 68440
Change-Id: I5eb9d2b39768b047290ac8c14e0201114630daed
---
M pywikibot/__init__.py
1 file changed, 2 insertions(+), 0 deletions(-)

Approvals:
  Russell Blau: Verified; Looks good to me, approved



diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 07a40ac..de518b8 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -463,6 +463,8 @@
 # Fallback to config defaults
 code = code or config.mylang
 fam = fam or config.family
+if hasattr(fam, 'name'):
+fam = fam.name
 interface = interface or config.site_interface
 
 user = user or config.usernames[fam].get(code, None) \

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5eb9d2b39768b047290ac8c14e0201114630daed
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa ricordisa...@openmailbox.org
Gerrit-Reviewer: Ladsgroup ladsgr...@gmail.com
Gerrit-Reviewer: Merlijn van Deen valhall...@arctus.nl
Gerrit-Reviewer: Russell Blau russb...@imapmail.org
Gerrit-Reviewer: jenkins-bot 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] (bug 66403) enable redirect.py follows section links - change (pywikibot/core)

2014-07-15 Thread Russell Blau (Code Review)
Russell Blau has submitted this change and it was merged.

Change subject: (bug 66403) enable redirect.py follows section links
..


(bug 66403) enable redirect.py follows section links

site.getredirtarget() didn't take into account sections and also
page.getRedirectTarget() didn't find the section. This is a
breaking change againts compat behaviour and causes redirect.py
to fail. This patch looks for the section in the redirect target.

Additional improvements:
- normalize title by api result
- title encoding for Exception messages

Change-Id: I4b6d7f32fc1ec79eb962fa8d21d283b4fe783fbf
---
M pywikibot/site.py
1 file changed, 15 insertions(+), 6 deletions(-)

Approvals:
  Russell Blau: Verified; Looks good to me, approved



diff --git a/pywikibot/site.py b/pywikibot/site.py
index 971edc5..203bd7b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1438,17 +1438,26 @@
 if query not in result or redirects not in result[query]:
 raise RuntimeError(
 getredirtarget: No 'redirects' found for page %s.
-% title)
-redirmap = dict((item['from'], item['to'])
+% title.encode(self.encoding()))
+redirmap = dict((item['from'],
+ {'title': item['to'],
+  'section': u'#' + item['tofragment']
+  if 'tofragment' in item and item['tofragment']
+  else ''})
 for item in result['query']['redirects'])
+if 'normalized' in result['query']:
+for item in result['query']['normalized']:
+if item['from'] == title:
+title = item['to']
+break
 if title not in redirmap:
 raise RuntimeError(
 getredirtarget: 'redirects' contains no key for page %s.
-% title)
-target_title = redirmap[title]
+% title.encode(self.encoding()))
+target_title = u'%(title)s%(section)s' % redirmap[title]
 if target_title == title or pages not in result['query']:
 # no pages element indicates a circular redirect
-raise pywikibot.CircularRedirect(redirmap[title])
+raise pywikibot.CircularRedirect(target_title)
 pagedata = list(result['query']['pages'].values())[0]
 # there should be only one value in 'pages', and it is the target
 if self.sametitle(pagedata['title'], target_title):
@@ -1542,7 +1551,7 @@
 raise Error(
 utoken: Query on page %s returned data on page [[%s]]
 % (page.title(withSection=False, asLink=True),
-item['title']))
+   item['title']))
 api.update_page(page, item)
 pywikibot.debug(unicode(item), _logger)
 return item[tokentype + token]

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4b6d7f32fc1ec79eb962fa8d21d283b4fe783fbf
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt i...@gno.de
Gerrit-Reviewer: Alex S.H. Lin ale...@mail2000.com.tw
Gerrit-Reviewer: John Vandenberg jay...@gmail.com
Gerrit-Reviewer: Ladsgroup ladsgr...@gmail.com
Gerrit-Reviewer: Legoktm legoktm.wikipe...@gmail.com
Gerrit-Reviewer: Merlijn van Deen valhall...@arctus.nl
Gerrit-Reviewer: Ricordisamoa ricordisa...@openmailbox.org
Gerrit-Reviewer: Russell Blau russb...@imapmail.org
Gerrit-Reviewer: Xqt i...@gno.de
Gerrit-Reviewer: jenkins-bot 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Code style improvement - change (pywikibot/core)

2014-05-09 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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

Change subject: Code style improvement
..

Code style improvement

Using if not total:, although technically correct, is confusing
when an integer is expected, and makes code maintenance more difficult.
Replace with if total == 0: which is easier to understand.

Change-Id: I5571600cf180bca7c700f2ada148dbd580b25250
---
M pywikibot/page.py
1 file changed, 8 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/93/132593/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 43111d0..fe54ef6 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1812,7 +1812,7 @@
 yield subcat
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 if recurse:
 for item in subcat.subcategories(
@@ -1820,14 +1820,14 @@
 yield item
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 else:
 for subcat in self._subcats:
 yield subcat
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 if recurse:
 for item in subcat.subcategories(
@@ -1835,7 +1835,7 @@
 yield item
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 
 @deprecate_arg(startFrom, startsort)
@@ -1895,7 +1895,7 @@
 yield member
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 if recurse:
 if not isinstance(recurse, bool) and recurse:
@@ -1913,7 +1913,7 @@
 yield article
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 
 def members(self, recurse=False, namespaces=None, step=None, total=None,
@@ -1925,7 +1925,7 @@
 yield member
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 if recurse:
 if not isinstance(recurse, bool) and recurse:
@@ -1937,7 +1937,7 @@
 yield article
 if total is not None:
 total -= 1
-if not total:
+if total == 0:
 return
 
 def isEmptyCategory(self):

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5571600cf180bca7c700f2ada148dbd580b25250
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Add Page.protection() method to core - change (pywikibot/core)

2014-05-08 Thread Russell Blau (Code Review)
Russell Blau has submitted this change and it was merged.

Change subject: Add Page.protection() method to core
..


Add Page.protection() method to core

This is similar to compat but returns a clearer dictionary from
corresponding site method.

Change-Id: I2427d5a9a62f38a4e64dfbf54577c57e2e8a07cc
---
M pywikibot/page.py
1 file changed, 4 insertions(+), 0 deletions(-)

Approvals:
  Russell Blau: Verified; Looks good to me, approved



diff --git a/pywikibot/page.py b/pywikibot/page.py
index 25e9046..76309f1 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -745,6 +745,10 @@
 content=content
 )
 
+def protection(self):
+Returns a dictionary reflecting page protections
+return self.site.page_restrictions(self)
+
 def canBeEdited(self):
 Return bool indicating whether this page can be edited.
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2427d5a9a62f38a4e64dfbf54577c57e2e8a07cc
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt i...@gno.de
Gerrit-Reviewer: Ladsgroup ladsgr...@gmail.com
Gerrit-Reviewer: Legoktm legoktm.wikipe...@gmail.com
Gerrit-Reviewer: Merlijn van Deen valhall...@arctus.nl
Gerrit-Reviewer: Pyfisch pyfi...@gmail.com
Gerrit-Reviewer: Ricordisamoa ricordisa...@live.it
Gerrit-Reviewer: Russell Blau russb...@imapmail.org
Gerrit-Reviewer: jenkins-bot 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Category.subcategories() should yield objects that have the ... - change (pywikibot/core)

2014-05-05 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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

Change subject: Category.subcategories() should yield objects that have the 
same properties, not just the same title, as the objects yielded by 
Category.members()
..

Category.subcategories() should yield objects that have the same properties,
not just the same title, as the objects yielded by Category.members()

Change-Id: I4e31a22393ba1ce3216e0c6a65978fae8ec0c6d4
---
M pywikibot/page.py
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/44/131644/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 25e9046..0fb4826 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1809,7 +1809,7 @@
 for member in self.site.categorymembers(
 self, namespaces=[14], step=step,
 total=total, content=content):
-subcat = Category(self.site, member.title())
+subcat = Category(member)
 self._subcats.append(subcat)
 yield subcat
 if total is not None:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e31a22393ba1ce3216e0c6a65978fae8ec0c6d4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Use subcategories() method instead of this roundabout method... - change (pywikibot/core)

2014-05-05 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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

Change subject: Use subcategories() method instead of this roundabout method 
call.
..

Use subcategories() method instead of this roundabout method call.

Change-Id: Id125dade743028350148dfb00774a2dba3f3b77d
---
M scripts/category_redirect.py
1 file changed, 1 insertion(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/45/131645/1

diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index 7aa1bc6..c60572a 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -264,8 +264,7 @@
 
 # get a list of all members of the category-redirect category
 catpages = dict((c, None)
-for c in self.site.categorymembers(redircat,
-   namespaces=[14]))
+for c in redircat.subcategories())
 
 # check the category pages for redirected categories
 pywikibot.output(u)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id125dade743028350148dfb00774a2dba3f3b77d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Allow category redirects with or without the namespace prefix. - change (pywikibot/core)

2014-02-08 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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

Change subject: Allow category redirects with or without the namespace prefix.
..

Allow category redirects with or without the namespace prefix.

Change-Id: Id258f16186d14eaaf4e1864799bc9277bf954182
---
M pywikibot/page.py
1 file changed, 11 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/12/112312/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index b75bbc3..972a061 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -483,7 +483,6 @@
 
 def isCategoryRedirect(self):
 Return True if this is a category redirect page, False otherwise.
-
 if not self.isCategory():
 return False
 if not hasattr(self, _catredirect):
@@ -492,8 +491,17 @@
 if template.title(withNamespace=False) in catredirs:
 # Get target (first template argument)
 try:
-self._catredirect = %s:%s % (self.site.namespace(14),
-   args[0].strip())
+cr = args[0].strip()
+if : in cr and cr[ : cr.find(:)] \
+in self.site.namespaces()[14]:
+# {{category redirect|Category:Foo}}
+# target is [[Category:Foo]]
+self._catredirect = cr
+else:
+# {{category redirect|Foo}}
+# target is [[Category:Foo]]
+self._catredirect = %s:%s \
+% (self.site.namespace(14), cr)
 break
 except IndexError:
 pywikibot.warning(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id258f16186d14eaaf4e1864799bc9277bf954182
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Remove obsolete line from docstring (-api flag not used in c... - change (pywikibot/core)

2013-10-18 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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


Change subject: Remove obsolete line from docstring (-api flag not used in 
core).
..

Remove obsolete line from docstring (-api flag not used in core).

Change-Id: I3b802c50ac08a9e229f306572f0e3e74f51dc475
---
M scripts/redirect.py
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/80/90680/1

diff --git a/scripts/redirect.py b/scripts/redirect.py
index 57778ac..233cad9 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -13,7 +13,7 @@
 
 double Fix redirects which point to other redirects
 broken Delete redirects where targets don\'t exist. Requires adminship.
-both   Both of the above. Permitted only with -api. Implies -api.
+both   Both of the above.
 
 and arguments can be:
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3b802c50ac08a9e229f306572f0e3e74f51dc475
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] redirect.py: preserve section anchors when fixing double red... - change (pywikibot/core)

2013-10-18 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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


Change subject: redirect.py: preserve section anchors when fixing double 
redirects.
..

redirect.py: preserve section anchors when fixing double redirects.

Change-Id: I13c7602979edda5016b46e808458037b425d4187
---
M scripts/redirect.py
1 file changed, 9 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/81/90681/1

diff --git a/scripts/redirect.py b/scripts/redirect.py
index 233cad9..2d8e485 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -561,9 +561,17 @@
 except pywikibot.BadTitle:
 pywikibot.output(uBad Title Error)
 break
+oldlink = self.site.redirectRegex().search(oldText).group(1)
+if # in oldlink and targetPage.section() is None:
+sectionlink = oldlink[oldlink.index(#): ]
+targetlink = pywikibot.Page(self.site,
+targetPage.title() + sectionlink
+).title(asLink=True, textlink=True)
+else:
+targetlink = targetPage.title(asLink=True, textlink=True)
 text = self.site.redirectRegex().sub(
 '#%s %s' % (self.site.redirect(True),
-targetPage.title(asLink=True, textlink=True)),
+targetlink),
 oldText)
 if redir.title() == targetPage.title() or text == oldText:
 pywikibot.output(uNote: Nothing left to do on %s

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I13c7602979edda5016b46e808458037b425d4187
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Use the API to retrieve redirects to the category redirect t... - change (pywikibot/core)

2013-09-20 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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


Change subject: Use the API to retrieve redirects to the category redirect 
template (this time with caching)
..

Use the API to retrieve redirects to the category redirect template
(this time with caching)

Change-Id: I7af283b3b7a18bd713627cb5f1d8667773e3f3c6
---
M pywikibot/families/wikipedia_family.py
M pywikibot/family.py
2 files changed, 24 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/03/85203/1

diff --git a/pywikibot/families/wikipedia_family.py 
b/pywikibot/families/wikipedia_family.py
index 9e57685..d35d4e9 100644
--- a/pywikibot/families/wikipedia_family.py
+++ b/pywikibot/families/wikipedia_family.py
@@ -54,11 +54,7 @@
 'arz': (u'تحويل تصنيف',),
 'cs': (u'Zastaralá kategorie',),
 'da': (u'Kategoriomdirigering',),
-'en': (u'Category redirect',
-   u'Category Redirect',
-   uCategoryredirect,
-   u'Catredirect',
-   u'Cat redirect',),
+'en': (u'Category redirect',),
 'es': (u'Categoría redirigida',),
 'eu': (u'Kategoria redirect',),
 'fa': (u'رده بهتر',
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 88eb3d3..291f523 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -545,7 +545,6 @@
 }
 
 # A list of category redirect template names in different languages
-# Note: It *is* necessary to list template redirects here
 self.category_redirect_templates = {
 '_default': []
 }
@@ -750,15 +749,34 @@
 % {'language_code': code})
 
 def category_redirects(self, code, fallback=_default):
-if code in self.category_redirect_templates:
-return self.category_redirect_templates[code]
-elif fallback:
-return self.category_redirect_templates[fallback]
+if not hasattr(self, _catredirtemplates) or code not in 
self._catredirtemplates:
+self.get_cr_templates(code, fallback)
+if code in self._catredirtemplates:
+return self._catredirtemplates[code]
 else:
 raise KeyError(
 ERROR: title for category redirect template in language '%s' unknown
 % code)
 
+def get_cr_templates(self, code, fallback):
+if not hasattr(self, _catredirtemplates):
+self._catredirtemplates={}
+if code in self.category_redirect_templates:
+cr_template = self.category_redirect_templates[code][0]
+else:
+cr_template = self.category_redirect_templates[fallback][0]
+# start with list of category redirect templates from family file
+cr_page = pywikibot.Page(pywikibot.Site(code, self),
+ Template: + cr_template)
+cr_list = list(self.category_redirect_templates[code])
+# retrieve all redirects to primary template from API,
+# add any that are not already on the list
+for t in cr_page.backlinks(filterRedirects=True, namespaces=10):
+newtitle = t.title(withNamespace=False)
+if newtitle not in cr_list:
+cr_list.append(newtitle)
+self._catredirtemplates[code] = cr_list
+
 def disambig(self, code, fallback='_default'):
 if code in self.disambiguationTemplates:
 return self.disambiguationTemplates[code]

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7af283b3b7a18bd713627cb5f1d8667773e3f3c6
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Use API to retrieve all current redirects to the primary cat... - change (pywikibot/core)

2013-09-05 Thread Russell Blau (Code Review)
Russell Blau has uploaded a new change for review.

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


Change subject: Use API to retrieve all current redirects to the primary 
category-redirect template, instead of having to maintain a list of all such 
redirects in the family file.
..

Use API to retrieve all current redirects to the primary category-redirect
template, instead of having to maintain a list of all such redirects in
the family file.

Change-Id: I54ab3ff585236416249d9e31457cd852a1b54408
---
M pywikibot/families/wikipedia_family.py
M pywikibot/family.py
M scripts/i18n
3 files changed, 15 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/54/83054/1

diff --git a/pywikibot/families/wikipedia_family.py 
b/pywikibot/families/wikipedia_family.py
index 9624a92..3a36369 100644
--- a/pywikibot/families/wikipedia_family.py
+++ b/pywikibot/families/wikipedia_family.py
@@ -54,11 +54,7 @@
 'arz': (u'تحويل تصنيف',),
 'cs': (u'Zastaralá kategorie',),
 'da': (u'Kategoriomdirigering',),
-'en': (u'Category redirect',
-   u'Category Redirect',
-   uCategoryredirect,
-   u'Catredirect',
-   u'Cat redirect',),
+'en': (u'Category redirect',),
 'es': (u'Categoría redirigida',),
 'eu': (u'Kategoria redirect',),
 'fa': (u'رده بهتر',
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 88eb3d3..f421399 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -751,13 +751,24 @@
 
 def category_redirects(self, code, fallback=_default):
 if code in self.category_redirect_templates:
-return self.category_redirect_templates[code]
+cr_template = self.category_redirect_templates[code][0]
 elif fallback:
-return self.category_redirect_templates[fallback]
+cr_template = self.category_redirect_templates[fallback][0]
 else:
 raise KeyError(
 ERROR: title for category redirect template in language '%s' unknown
 % code)
+# start with list of category redirect templates from family file
+cr_page = pywikibot.Page(pywikibot.Site(code, self),
+ Template: + cr_template)
+cr_list = list(self.category_redirect_templates[code])
+# retrieve all redirects to primary template from API,
+# add any that are not already on the list
+for t in cr_page.backlinks(filterRedirects=True, namespaces=10):
+newtitle = t.title(withNamespace=False)
+if newtitle not in cr_list:
+cr_list.append(newtitle)
+return cr_list
 
 def disambig(self, code, fallback='_default'):
 if code in self.disambiguationTemplates:
@@ -769,6 +780,7 @@
 ERROR: title for disambig template in language %s unknown
 % code)
 
+
 # Methods
 def protocol(self, code):
 
diff --git a/scripts/i18n b/scripts/i18n
index 0dcc4d6..9199b7d 16
--- a/scripts/i18n
+++ b/scripts/i18n
-Subproject commit 0dcc4d63546b038f61e4a5901fda756d0938ea3a
+Subproject commit 9199b7d0d5b5cc987c9089972d401e9ccba0f99a

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I54ab3ff585236416249d9e31457cd852a1b54408
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Russell Blau russb...@imapmail.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits