jenkins-bot has submitted this change and it was merged.
Change subject: Use 'time' of siprop 'general' for the server time ......................................................................
Use 'time' of siprop 'general' for the server time
Instead of parsing {{CURRENTTIMESTAMP}} this uses 'time' in the siprop 'general'. Because 'time' was only added in 1.16 it'll use old way if required.
Change-Id: Ia91ca4ec6d8b5bcc9d7b888d0c976b4f58a1267d --- M pywikibot/site.py M tests/site_tests.py 2 files changed, 32 insertions(+), 9 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved XZise: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 5e0d28b..77e3b84 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1570,6 +1570,7 @@ concat = msgs['and'] + msgs['word-separator'] return msgs['comma-separator'].join(args[:-2] + [concat.join(args[-2:])])
+ @need_version("1.12") def expand_text(self, text, title=None, includecomments=None): """ Parse the given text for preprocessing and rendering.
@@ -1600,17 +1601,35 @@ return req.submit()['expandtemplates'][key]
def getcurrenttimestamp(self): - """Return server time, {{CURRENTTIMESTAMP}}, as a string. - - Format is 'yyyymmddhhmmss' - """ - return self.expand_text("{{CURRENTTIMESTAMP}}") + Return the server time as a MediaWiki timestamp string. + + It calls L{getcurrenttime} first so it queries the server to get the + current server time. + + @return: the server time + @rtype: str (as 'yyyymmddhhmmss') + """ + return self.getcurrenttime().totimestampformat()
def getcurrenttime(self): - """Return a Timestamp object representing the current server time.""" - ts = self.getcurrenttimestamp() - return pywikibot.Timestamp.fromtimestampformat(ts) + """ + Return a Timestamp object representing the current server time. + + For wikis with a version newer than 1.16 it uses the 'time' property + of the siteinfo 'general'. It'll force a reload before returning the + time. It requests to expand the text '{{CURRENTTIMESTAMP}}' for older + wikis. + + @return the current server time + @rtype: L{Timestamp} + """ + if LV(self.version()) >= LV("1.16"): + return pywikibot.Timestamp.fromISOformat( + self.siteinfo.get('time', force=True)) + else: + return pywikibot.Timestamp.fromtimestampformat( + self.expand_text("{{CURRENTTIMESTAMP}}"))
def getmagicwords(self, word): """Return list of localized "word" magic words for the site.""" diff --git a/tests/site_tests.py b/tests/site_tests.py index 241bcbe..a2b7cb3 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -197,7 +197,11 @@ self.assertTrue(len(mysite.mediawiki_messages(['*'])) > 10) self.assertFalse('*' in mysite.mediawiki_messages(['*']))
- self.assertType(mysite.getcurrenttimestamp(), basestring) + self.assertType(mysite.getcurrenttime(), pywikibot.Timestamp) + ts = mysite.getcurrenttimestamp() + self.assertType(ts, basestring) + self.assertRegexpMatches(ts, r'(19|20)\d\d[0-1]\d[0-3]\d[0-2]\d[0-5]\d[0-5]\d') + self.assertType(mysite.siteinfo, pywikibot.site.Siteinfo) self.assertType(mysite.months_names, list) self.assertEqual(mysite.months_names[4], (u'May', u'May'))
pywikibot-commits@lists.wikimedia.org