jenkins-bot has submitted this change and it was merged.
Change subject: (bug 59223) Page.title(asLink=True) accepts a site object "insite", ......................................................................
(bug 59223) Page.title(asLink=True) accepts a site object "insite",
where the page is to be shown. This forces to format the link with family and site code prefix if the "insite" site is different from Page.site.
The default site is given by -lang and -family option or from user-config.py if the options are omitted.
Change-Id: I145293e30fc155c50d300caa84af13f7b61b02c2 --- M pywikibot/page.py 1 file changed, 14 insertions(+), 5 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index e1e3e4c..2949fa2 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -3,7 +3,7 @@ Objects representing various types of MediaWiki pages. """ # -# (C) Pywikibot team, 2008-2013 +# (C) Pywikibot team, 2008-2014 # # Distributed under the terms of the MIT license. # @@ -128,7 +128,7 @@ def title(self, underscore=False, withNamespace=True, withSection=True, asUrl=False, asLink=False, allowInterwiki=True, forceInterwiki=False, textlink=False, - as_filename=False): + as_filename=False, insite=None): """Return the title of this Page, as a Unicode string.
@param underscore: if true, replace all ' ' characters with '_' @@ -144,17 +144,26 @@ before Category: and Image: links @param as_filename: if true, replace any characters that are unsafe in filenames + @param insite: (only used if asLink is true) a site object where the + title is to be shown. default is the current family/lang given by + -family and -lang option i.e. config.family and config.mylang
""" title = self._link.canonical_title() if withSection and self._link.section: title = title + "#" + self._link.section if asLink: + if insite: + target_code = insite.code + target_family = insite.family.name + else: + target_code = config.mylang + target_family = config.family if forceInterwiki or \ (allowInterwiki and - (self.site.family.name != config.family - or self.site.code != config.mylang)): - if self.site.family.name != config.family \ + (self.site.family.name != target_family + or self.site.code != target_code)): + if self.site.family.name != target_family \ and self.site.family.name != self.site.code: return u'[[%s:%s:%s]]' % (self.site.family.name, self.site.code,
pywikibot-commits@lists.wikimedia.org