Robmoen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/91532


Change subject: Eliminate api fixmes from PageApi
......................................................................

Eliminate api fixmes from PageApi

* revise lastmodified property returned by api
** mobile view api now returns last modified by username and gender
* PageApi -> use data returned from mobileview api, removed fixmes
* revise qunit tests to reflect changes

Change-Id: Ie02e7bf37ebcf750b472064379caab97f95a38db
---
M includes/api/ApiMobileView.php
M javascripts/common/PageApi.js
M tests/javascripts/common/test_PageApi.js
3 files changed, 48 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/32/91532/1

diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index c58573e..fa1b498 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -71,6 +71,11 @@
                                array( 'lastmodified' => $data['lastmodified'] )
                        );
                }
+               if ( isset( $prop['id'] ) ) {
+                       $this->getResult()->addValue( null, 
$this->getModuleName(),
+                               array( 'id' => $data['id'] )
+                       );
+               }
                $result = array();
                $missingSections = array();
                $requestedSections = isset( $params['sections'] )
@@ -241,7 +246,6 @@
                                'sections' => array(),
                                'text' => array( $html ),
                                'refsections' => array(),
-                               'lastmodified' => $wp->getTimestamp(),
                        );
                } else {
                        wfProfileIn( __METHOD__ . '-sections' );
@@ -273,10 +277,18 @@
                                }
                                $data['text'][] = $chunk;
                        }
-                       $data['lastmodified'] = $wp->getTimestamp();
-
                        wfProfileOut( __METHOD__ . '-sections' );
                }
+               // Page id
+               $data['id'] = $wp->getId();
+               // Last modified
+               $data['lastmodified'] = array(
+                       'user' => array(
+                               'name' => $wp->getUserText(),
+                               'gender' => User::newFromId( $wp->getUser() 
)->getOption( 'gender' ),
+                       ),
+                       'time' => $wp->getTimestamp(),
+               );
                // Don't store small pages to decrease cache size requirements
                if ( strlen( $html ) >= $wgMFMinCachedPageSize ) {
                        // store for the same time as original parser output
@@ -312,6 +324,7 @@
                                ApiBase::PARAM_DFLT => 
'text|sections|normalizedtitle',
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_TYPE => array(
+                                       'id',
                                        'text',
                                        'sections',
                                        'normalizedtitle',
@@ -353,6 +366,7 @@
 
        public function getParamDescription() {
                return array(
+                       'id' => 'Id of the page',
                        'page' => 'Title of page to process',
                        'redirect' => 'Whether redirects should be followed',
                        'sections' => "Pipe-separated list of section numbers 
for which to return text or `all' to return for all. "
@@ -362,7 +376,7 @@
                                ' text            - HTML of selected 
section(s)',
                                ' sections        - information about all 
sections on page',
                                ' normalizedtitle - normalized page title',
-                               ' lastmodified    - MW timestamp for when the 
page was last modified, e.g. "20130730174438"',
+                               ' lastmodified    - information about the user 
who modified the page last and when',
                        ),
                        'sectionprop' => 'What information about sections to 
get',
                        'variant' => "Convert content into this language 
variant",
diff --git a/javascripts/common/PageApi.js b/javascripts/common/PageApi.js
index a7bb1a7..2c362b9 100644
--- a/javascripts/common/PageApi.js
+++ b/javascripts/common/PageApi.js
@@ -49,7 +49,7 @@
                                        page: title,
                                        variant: mw.config.get( 
'wgPreferredVariant' ),
                                        redirect: 'yes',
-                                       prop: 'sections|text',
+                                       prop: 'id|sections|text|lastmodified',
                                        noheadings: 'yes',
                                        noimages: mw.config.get( 
'wgImagesDisabled', false ) ? 1 : undefined,
                                        sectionprop: 'level|line|anchor',
@@ -64,21 +64,17 @@
                                                page.reject( { error: { code: 
'lqt' } } );
                                        } else {
                                                sections = transformSections( 
resp.mobileview.sections );
+
                                                page.resolve( {
                                                        title: title,
-                                                       // FIXME [api] should 
return the page id - this is needed to tell if a page is new or not
-                                                       id: -1,
+                                                       id: resp.mobileview.id,
                                                        lead: sections[0].text,
                                                        sections: 
sections.slice( 1 ),
                                                        isMainPage: 
resp.mobileview.hasOwnProperty( 'mainpage' ) ? true : false,
                                                        historyUrl: 
mw.util.wikiGetlink( title, { action: 'history' } ),
-                                                       // FIXME: [API] This is 
incorrect in alpha where lazy loading is possible. Should come from API
-                                                       // Note: In stable/beta 
only time this happens is on an edit so this is accurate there.
-                                                       lastModifiedUserName: 
mw.config.get( 'wgUserName' ),
-                                                       // FIXME: [API] This 
should come from the API
-                                                       lastModifiedUserGender: 
mw.config.get( 'wgMFUserGender' ),
-                                                       // FIXME [API] Only 
valid on a recently edited page (not true in alpha)
-                                                       lastModifiedTimestamp: 
( "" + new Date().getTime() ).substr( 0,10 ) // Default to current timestamp
+                                                       lastModifiedUserName: 
resp.mobileview.lastmodified.user.name,
+                                                       lastModifiedUserGender: 
resp.mobileview.lastmodified.user.gender,
+                                                       lastModifiedTimestamp:  
resp.mobileview.lastmodified.time
                                                } );
                                        }
                                } ).fail( $.proxy( page, 'reject' ) );
diff --git a/tests/javascripts/common/test_PageApi.js 
b/tests/javascripts/common/test_PageApi.js
index af7c981..e57eea6 100644
--- a/tests/javascripts/common/test_PageApi.js
+++ b/tests/javascripts/common/test_PageApi.js
@@ -10,6 +10,14 @@
        QUnit.test( '#getPage (h1s)', 1, function( assert ) {
                sinon.stub( PageApi.prototype, 'get' ).returns( 
$.Deferred().resolve( {
                        "mobileview": {
+                               "id": -1,
+                               "lastmodified": {
+                                       "user": {
+                                               "name": "",
+                                               "gender": "unknown"
+                                       },
+                                       "time": ( "" + new Date().getTime() 
).substr( 0,10 )
+                               },
                                "sections":[
                                        {"id":0,"text":""},
                                        
{"level":"1","line":"1","anchor":"1","id":1,"text":"<p>Text of 1\n</p>"},
@@ -55,6 +63,14 @@
        QUnit.test( '#getPage', 2, function( assert ) {
                sinon.stub( PageApi.prototype, 'get' ).returns( 
$.Deferred().resolve( {
                        "mobileview": {
+                               "id": -1,
+                               "lastmodified": {
+                                       "user": {
+                                               "name": "",
+                                               "gender": "unknown"
+                                       },
+                                       "time": ( "" + new Date().getTime() 
).substr( 0,10 )
+                               },
                                "sections": [
                                        { "id": 0, "text": "lead content" },
                                        {
@@ -242,6 +258,14 @@
        QUnit.test( '#getPage (html headings get stripped)', 1, function( 
assert ) {
                sinon.stub( PageApi.prototype, 'get' ).returns( 
$.Deferred().resolve( {
                        "mobileview": {
+                               "id": -1,
+                               "lastmodified": {
+                                       "user": {
+                                               "name": "",
+                                               "gender": "unknown"
+                                       },
+                                       "time": ( "" + new Date().getTime() 
).substr( 0,10 )
+                               },
                                "sections":[
                                        {"id":0,"text":""},
                                        {"level":"1","line":"<i>html text 
heading</i>","anchor":"1","id":1,"text":"<p>Text of 1\n</p>"}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie02e7bf37ebcf750b472064379caab97f95a38db
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Robmoen <rm...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to