Skip to content

Commit

Permalink
Add rvslots param when requesting page text (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Nov 4, 2018
1 parent 078a5ec commit 862338a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 16 additions & 5 deletions mwclient/page.py
Expand Up @@ -130,7 +130,7 @@ def edit(self, *args, **kwargs):
category=DeprecationWarning, stacklevel=2)
return self.text(*args, **kwargs)

def text(self, section=None, expandtemplates=False, cache=True):
def text(self, section=None, expandtemplates=False, cache=True, slot='main'):
"""Get the current wikitext of the page, or of a specific section.
If the page does not exist, an empty string is returned. By
Expand All @@ -157,10 +157,13 @@ def text(self, section=None, expandtemplates=False, cache=True):
return self._textcache[key]

revs = self.revisions(prop='content|timestamp', limit=1, section=section,
expandtemplates=expandtemplates)
expandtemplates=expandtemplates, slots=slot)
try:
rev = next(revs)
text = rev['*']
if 'slots' in rev:
text = rev['slots'][slot]
else:
text = rev['*']
self.last_rev_time = rev['timestamp']
except StopIteration:
text = u''
Expand Down Expand Up @@ -439,7 +442,7 @@ def revisions(self, startid=None, endid=None, start=None, end=None,
dir='older', user=None, excludeuser=None, limit=50,
prop='ids|timestamp|flags|comment|user',
expandtemplates=False, section=None,
diffto=None):
diffto=None, slots=None):
"""List revisions of the current page.
API doc: https://www.mediawiki.org/wiki/API:Revisions
Expand All @@ -460,13 +463,21 @@ def revisions(self, startid=None, endid=None, start=None, end=None,
diffto (str): Revision ID to diff each revision to. Use "prev",
"next" and "cur" for the previous, next and current
revision respectively.
slots (str): The content slot (Mediawiki >= 1.32) to retrieve
content from.
Returns:
mwclient.listings.List: Revision iterator
"""
kwargs = dict(mwclient.listing.List.generate_kwargs('rv', startid=startid, endid=endid,
start=start, end=end, user=user,
excludeuser=excludeuser, diffto=diffto))
excludeuser=excludeuser, diffto=diffto,
slots=slots))

if self.site.version[:2] < (1, 32) and 'rvslots' in kwargs:
# https://github.com/mwclient/mwclient/issues/199
del kwargs['rvslots']

kwargs['rvdir'] = dir
kwargs['rvprop'] = prop
if expandtemplates:
Expand Down
4 changes: 3 additions & 1 deletion test/test_page.py
Expand Up @@ -230,6 +230,7 @@ def setUp(self):
self.site.get.return_value = {'query': {'pages': {'1': {'title': title}}}}
self.site.rights = ['read']
self.site.api_limit = 500
self.site.version = (1, 32, 0)

self.page = Page(self.site, title)

Expand Down Expand Up @@ -261,7 +262,8 @@ def test_get_page_text(self):
'rvdir': 'older',
'titles': self.page.page_title,
'rvprop': 'content|timestamp',
'rvlimit': '1'
'rvlimit': '1',
'rvslots': 'main',
}

def test_get_page_text_cached(self):
Expand Down

0 comments on commit 862338a

Please sign in to comment.