jenkins-bot has submitted this change and it was merged.

Change subject: mobileview api should support revisions
......................................................................


mobileview api should support revisions

Change-Id: Ia00d135c9e2850372695cb6ff1a15da2381c6872
---
M i18n/en.json
M i18n/qqq.json
M includes/api/ApiMobileView.php
3 files changed, 30 insertions(+), 13 deletions(-)

Approvals:
  Florianschmidtwelzow: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index f8ae80e..20c22c8 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -385,6 +385,7 @@
        "apihelp-mobileview-param-thumbsize": "Maximum thumbnail dimensions.",
        "apihelp-mobileview-param-thumbwidth": "Maximum thumbnail width.",
        "apihelp-mobileview-param-thumbheight": "Maximum thumbnail height.",
+       "apihelp-mobileview-param-revision": "Request a specific revision.",
        "apihelp-mobileview-example-1": "Get information about section 0 of 
[[Doom metal]]",
        "apihelp-mobileview-example-2": "Get information about section 0 and 
sections containing references of [[Candlemass]]",
        "apihelp-mobileview-example-3": "Get information about sections 1 and 
later and sections containing references of [[Candlemass]]",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 811e616..b5b999f 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -383,6 +383,7 @@
        "apihelp-mobileview-param-thumbsize": 
"{{doc-apihelp-param|mobileview|thumbsize}}",
        "apihelp-mobileview-param-thumbwidth": 
"{{doc-apihelp-param|mobileview|thumbwidth}}",
        "apihelp-mobileview-param-thumbheight": 
"{{doc-apihelp-param|mobileview|thumbheight}}",
+       "apihelp-mobileview-param-revision": 
"{{doc-apihelp-param|mobileview|revision}}",
        "apihelp-mobileview-example-1": "{{doc-apihelp-example|mobileview}}",
        "apihelp-mobileview-example-2": "{{doc-apihelp-example|mobileview}}",
        "apihelp-mobileview-example-3": "{{doc-apihelp-example|mobileview}}",
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index 98eb124..3109670 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -96,8 +96,7 @@
                                'ns' => $namespace,
                        ) );
                }
-
-               $data = $this->getData( $title, $params['noimages'] );
+               $data = $this->getData( $title, $params['noimages'], 
$params['revision'] );
                $plainData = array( 'lastmodified', 'lastmodifiedby', 
'revision',
                        'languagecount', 'hasvariants', 'displaytitle', 'id', 
'contentmodel' );
                foreach ( $plainData as $name ) {
@@ -411,18 +410,17 @@
         * Performs a page parse
         * @param WikiPage $wp
         * @param ParserOptions $parserOptions
-        * @return ParserOutput
+        * @param null|int [$oldid] Revision ID to get the text from, passing 
null or 0 will
+        *   get the current revision (default value)
+        * @return ParserOutput|null
         */
-       protected function getParserOutput( WikiPage $wp, ParserOptions 
$parserOptions ) {
+       protected function getParserOutput( WikiPage $wp, ParserOptions 
$parserOptions, $oldid = null ) {
                $time = microtime( true );
-               $parserOutput = $wp->getParserOutput( $parserOptions );
+               $parserOutput = $wp->getParserOutput( $parserOptions, $oldid );
                $time = microtime( true ) - $time;
-               if ( !$parserOutput ) {
-                       wfDebugLog( 'mobile', "Empty parser output on 
'{$wp->getTitle()->getPrefixedText()}'" .
-                               ": rev {$wp->getId()}, time $time" );
-                       throw new Exception( __METHOD__ . ": PoolCounter didn't 
return parser output" );
+               if ( $parserOutput ) {
+                       $parserOutput->setTOCEnabled( false );
                }
-               $parserOutput->setTOCEnabled( false );
 
                return $parserOutput;
        }
@@ -449,9 +447,11 @@
         * Get data of requested article.
         * @param Title $title
         * @param boolean $noImages
+        * @param null|int [$oldid] Revision ID to get the text from, passing 
null or 0 will
+        *   get the current revision (default value)
         * @return array
         */
-       private function getData( Title $title, $noImages ) {
+       private function getData( Title $title, $noImages, $oldid = null ) {
                $mfConfig = MobileContext::singleton()->getMFConfig();
                $useTidy = $this->getConfig()->get( 'UseTidy' );
                $mfTidyMobileViewSections = $mfConfig->get( 
'MFTidyMobileViewSections' );
@@ -485,6 +485,8 @@
                $latest = $wp->getLatest();
                // Use page_touched so template updates invalidate cache
                $touched = $wp->getTouched();
+
+               $revId = $oldid || $title->getLatestRevID();
                if ( $this->file ) {
                        $key = wfMemcKey( 'mf', 'mobileview', 
self::CACHE_VERSION, $noImages,
                                $touched, $this->noTransform, 
$this->file->getSha1(), $this->variant );
@@ -503,6 +505,7 @@
                                self::CACHE_VERSION,
                                $noImages,
                                $touched,
+                               $revId,
                                $this->noTransform,
                                $parserCacheKey
                        );
@@ -516,7 +519,14 @@
                if ( $this->file ) {
                        $html = $this->getFilePage( $title );
                } else {
-                       $parserOutput = $this->getParserOutput( $wp, 
$parserOptions );
+                       $parserOutput = $this->getParserOutput( $wp, 
$parserOptions, $oldid );
+                       if ( $parserOutput === false ) {
+                               $this->dieUsage(
+                                       "Bad revision id/title combination",
+                                       'invalidparams'
+                               );
+                               return;
+                       }
                        $html = $parserOutput->getText();
                        $cacheExpiry = $parserOutput->getCacheExpiry();
                }
@@ -586,7 +596,7 @@
                } else {
                        $data['lastmodifiedby'] = null;
                }
-               $data['revision'] = $title->getLatestRevID();
+               $data['revision'] = $revId;
 
                if ( isset( $parserOutput ) ) {
                        $languages = $parserOutput->getLanguageLinks();
@@ -807,6 +817,11 @@
                                ApiBase::PARAM_MIN => 0,
                                ApiBase::PARAM_DFLT => 0,
                        ),
+                       'revision' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_MIN => 0,
+                               ApiBase::PARAM_DFLT => 0,
+                       ),
                );
                if ( $this->usePageImages ) {
                        $res['prop'][ApiBase::PARAM_TYPE][] = 'image';

-- 
To view, visit https://gerrit.wikimedia.org/r/275723
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia00d135c9e2850372695cb6ff1a15da2381c6872
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to