http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11310
Revision: 11310 Author: legoktm Date: 2013-03-31 17:04:00 +0000 (Sun, 31 Mar 2013) Log Message: ----------- Proper support for reading/creating claims for commonsMedia
Modified Paths: -------------- branches/rewrite/pywikibot/page.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2013-03-31 16:44:16 UTC (rev 11309) +++ branches/rewrite/pywikibot/page.py 2013-03-31 17:04:00 UTC (rev 11310) @@ -2562,7 +2562,11 @@ if claim.getType() == 'wikibase-item': claim.target = ItemPage(site, 'Q' + str(data['mainsnak']['datavalue']['value']['numeric-id'])) + elif claim.getType() == 'commonsMedia': + claim.target = ImagePage(site.image_repository(), 'File:' + + data['mainsnak']['datavalue']['value']) else: + #This covers string type claim.target = data['mainsnak']['datavalue']['value'] if 'references' in data: for source in data['references']:
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2013-03-31 16:44:16 UTC (rev 11309) +++ branches/rewrite/pywikibot/site.py 2013-03-31 17:04:00 UTC (rev 11310) @@ -3377,6 +3377,8 @@ 'numeric-id': claim.getTarget().getID(numeric=True)}) elif claim.getType() == 'string': params['value'] = '"' + claim.getTarget() + '"' + elif claim.getType() == 'commonsMedia': + params['value'] = '"' + claim.getTarget().title(withNamespace=False) + '"' else: raise NotImplementedError('%s datatype is not supported yet.' % claim.getType()) params['token'] = self.token(item, 'edit') @@ -3412,6 +3414,8 @@ 'numeric-id': claim.getTarget().getID(numeric=True)}) elif claim.getType() == 'string': params['value'] = '"' + claim.getTarget() + '"' + elif claim.getType() == 'commonsMedia': + params['value'] = '"' + claim.getTarget().title(withNamespace=False) + '"' else: raise NotImplementedError('%s datatype is not supported yet.' % claim.getType())
pywikipedia-svn@lists.wikimedia.org