Hello
Here is the patch I would like to suggest. It does the expansion if API
is used.
Greetings
Am 12.09.2010 22:36, schrieb Dr. Trigon:
Hello
A question about wikipedia.get and wikipedia._getEditPage:
Would it be possible to add an option 'expandtemplates=False'
and the code:
if expandtemplates: params[u'rvexpandtemplates'] = u''
to enable template expansion on pages when/if requested.
I can also provide a patch if this suggestions is welcome.
Thanks and greetings!
DrTrigon
_______________________________________________
Pywikipedia-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
Index: wikipedia.py
===================================================================
--- wikipedia.py (Revision 8551)
+++ wikipedia.py (Arbeitskopie)
@@ -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.
"""
# NOTE: The following few NoPage exceptions could already be thrown at
@@ -640,7 +642,7 @@
# 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 +671,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 +679,7 @@
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
This method returns the raw wiki text as a unicode string.
"""
@@ -694,6 +697,8 @@
}
if oldid:
params['rvstartid'] = oldid
+ if expandtemplates:
+ params[u'rvexpandtemplates'] = u''
if throttle:
get_throttle()
_______________________________________________
Pywikipedia-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l