[Pywikipedia-l] [Pywikipedia-svn] SVN: [8561] trunk/pywikipedia/wikipedia.py

Dr. Trigon dr.trigon at surfeu.ch
Wed Sep 15 11:37:17 UTC 2010


Thanks a lot!

Am 15.09.2010 13:32, schrieb xqt at svn.wikimedia.org:
> Revision: 8561
> Author:   xqt
> Date:     2010-09-15 11:32:15 +0000 (Wed, 15 Sep 2010)
>
> Log Message:
> -----------
> expandtemplates parameter for Page.get() - Fully resolve templates within page content submitted by DrTrogom. Thanks.
>
> Modified Paths:
> --------------
>      trunk/pywikipedia/wikipedia.py
>
> Modified: trunk/pywikipedia/wikipedia.py
> ===================================================================
> --- trunk/pywikipedia/wikipedia.py	2010-09-15 10:11:05 UTC (rev 8560)
> +++ trunk/pywikipedia/wikipedia.py	2010-09-15 11:32:15 UTC (rev 8561)
> @@ -585,7 +585,7 @@
>           return self.autoFormat()[0] is not None
>
>       def get(self, force=False, get_redirect=False, throttle=True,
> -            sysop=False, change_edit_time=True):
> +            sysop=False, change_edit_time=True, expandtemplates=False):
>           """Return the wiki-text of the page.
>
>           This will retrieve the page from the server if it has not been
> @@ -604,6 +604,8 @@
>           If change_edit_time is False, do not check this version for changes
>           before saving. This should be used only if the page has been loaded
>           previously.
> +        If expandtemplates is True, all templates in the page content are
> +        fully resolved too (if API is used).
>
>           """
>           # NOTE: The following few NoPage exceptions could already be thrown at
> @@ -622,7 +624,7 @@
>           if self.site().isInterwikiLink(self.title()):
>               raise NoPage('%s is not a local page on %s!'
>                            % (self.aslink(), self.site()))
> -        if force:
> +        if force or expandtemplates:
>               # When forcing, we retry the page no matter what. Old exceptions
>               # and contents do not apply any more.
>               for attr in ['_redirarg', '_getexception', '_contents']:
> @@ -640,7 +642,8 @@
>           # Make sure we did try to get the contents once
>           if not hasattr(self, '_contents'):
>               try:
> -                self._contents = self._getEditPage(get_redirect = get_redirect, throttle = throttle, sysop = sysop)
> +                self._contents = self._getEditPage(get_redirect=get_redirect, throttle=throttle, sysop=sysop,
> +                                                   expandtemplates = expandtemplates)
>                   hn = self.section()
>                   if hn:
>                       m = re.search("=+ *%s *=+" % hn, self._contents)
> @@ -669,7 +672,7 @@
>           return self._contents
>
>       def _getEditPage(self, get_redirect=False, throttle=True, sysop=False,
> -                     oldid=None, change_edit_time=True):
> +                     oldid=None, change_edit_time=True, expandtemplates=False):
>           """Get the contents of the Page via API query
>
>           Do not use this directly, use get() instead.
> @@ -677,6 +680,8 @@
>           Arguments:
>               oldid - Retrieve an old revision (by id), not the current one
>               get_redirect  - Get the contents, even if it is a redirect page
> +        expandtemplates - Fully resolve templates within page content
> +                          (if API is used)
>
>           This method returns the raw wiki text as a unicode string.
>           """
> @@ -694,6 +699,8 @@
>           }
>           if oldid:
>               params['rvstartid'] = oldid
> +        if expandtemplates:
> +            params[u'rvexpandtemplates'] = u''
>
>           if throttle:
>               get_throttle()
>
>
>
> _______________________________________________
> Pywikipedia-svn mailing list
> Pywikipedia-svn at lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn




More information about the Pywikipedia-l mailing list