jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Eliminate api fixmes from PageApi
......................................................................
Hygiene: 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, 71 insertions(+), 27 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
Jdlrobson: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index af63560..2bafab6 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -4,7 +4,7 @@
/**
* Increment this when changing the format of cached data
*/
- const CACHE_VERSION = 5;
+ const CACHE_VERSION = 6;
private $followRedirects, $noHeadings, $mainPage, $noTransform,
$variant, $offset, $maxlen;
@@ -69,6 +69,16 @@
if ( isset( $prop['lastmodified'] ) ) {
$this->getResult()->addValue( null,
$this->getModuleName(),
array( 'lastmodified' => $data['lastmodified'] )
+ );
+ }
+ if ( isset( $prop['lastmodifiedby'] ) ) {
+ $this->getResult()->addValue( null,
$this->getModuleName(),
+ array( 'lastmodifiedby' =>
$data['lastmodifiedby'] )
+ );
+ }
+ if ( isset( $prop['id'] ) ) {
+ $this->getResult()->addValue( null,
$this->getModuleName(),
+ array( 'id' => $data['id'] )
);
}
$result = array();
@@ -244,7 +254,6 @@
'sections' => array(),
'text' => array( $html ),
'refsections' => array(),
- 'lastmodified' => $wp->getTimestamp(),
);
} else {
wfProfileIn( __METHOD__ . '-sections' );
@@ -276,9 +285,19 @@
}
$data['text'][] = $chunk;
}
- $data['lastmodified'] = $wp->getTimestamp();
-
wfProfileOut( __METHOD__ . '-sections' );
+ }
+
+ $data['lastmodified'] = wfTimestamp( TS_ISO_8601,
$wp->getTimestamp() );
+
+ // Page id
+ $data['id'] = $wp->getId();
+ $user = User::newFromId( $wp->getUser() );
+ if( !$user->isAnon() ) {
+ $data['lastmodifiedby'] = array(
+ 'name' => $wp->getUserText(),
+ 'gender' => $user->getOption( 'gender' ),
+ );
}
// Don't store small pages to decrease cache size requirements
if ( strlen( $html ) >= $wgMFMinCachedPageSize ) {
@@ -315,10 +334,12 @@
ApiBase::PARAM_DFLT =>
'text|sections|normalizedtitle',
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => array(
+ 'id',
'text',
'sections',
'normalizedtitle',
'lastmodified',
+ 'lastmodifiedby',
)
),
'sectionprop' => array(
@@ -356,6 +377,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. "
@@ -366,6 +388,7 @@
' sections - information about all
sections on page',
' normalizedtitle - normalized page title',
' lastmodified - MW timestamp for when the
page was last modified, e.g. "20130730174438"',
+ ' lastmodifiedby - information about the user
who modified the page last',
),
'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..ee503ec 100644
--- a/javascripts/common/PageApi.js
+++ b/javascripts/common/PageApi.js
@@ -40,7 +40,7 @@
* @return {jQuery.Deferred} with parameter page data that can
be passed to a Page view
*/
getPage: function( title, endpoint, leadOnly ) {
- var options = endpoint ? { url: endpoint, dataType:
'jsonp' } : {}, page;
+ var options = endpoint ? { url: endpoint, dataType:
'jsonp' } : {}, page, timestamp;
if ( !this.cache[title] ) {
page = this.cache[title] = $.Deferred();
@@ -49,13 +49,13 @@
page: title,
variant: mw.config.get(
'wgPreferredVariant' ),
redirect: 'yes',
- prop: 'sections|text',
+ prop:
'id|sections|text|lastmodified|lastmodifiedby',
noheadings: 'yes',
noimages: mw.config.get(
'wgImagesDisabled', false ) ? 1 : undefined,
sectionprop: 'level|line|anchor',
sections: leadOnly ? 0 : 'all'
}, options ).done( function( resp ) {
- var sections;
+ var sections, lastModified, resolveObj;
if ( resp.error ||
!resp.mobileview.sections ) {
page.reject( resp );
@@ -64,22 +64,27 @@
page.reject( { error: { code:
'lqt' } } );
} else {
sections = transformSections(
resp.mobileview.sections );
- page.resolve( {
+ // Assume the timestamp is in
the form TS_ISO_8601 and we don't care about old browsers
+ // change to seconds to be
consistent with PHP
+ timestamp = new Date(
resp.mobileview.lastmodified ).getTime() / 1000;
+ lastModified =
resp.mobileview.lastmodifiedby;
+ resolveObj = {
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
- } );
+ lastModifiedTimestamp:
timestamp
+ };
+ // Add non-anonymous user
information
+ if ( lastModified ) {
+ $.extend( resolveObj, {
+
lastModifiedUserName: lastModified.name,
+
lastModifiedUserGender: lastModified.gender
+ } );
+ }
+ page.resolve( resolveObj );
}
} ).fail( $.proxy( page, 'reject' ) );
}
diff --git a/tests/javascripts/common/test_PageApi.js
b/tests/javascripts/common/test_PageApi.js
index af7c981..4500c82 100644
--- a/tests/javascripts/common/test_PageApi.js
+++ b/tests/javascripts/common/test_PageApi.js
@@ -10,6 +10,12 @@
QUnit.test( '#getPage (h1s)', 1, function( assert ) {
sinon.stub( PageApi.prototype, 'get' ).returns(
$.Deferred().resolve( {
"mobileview": {
+ "id": -1,
+ "lastmodifiedby": {
+ "name": "bob",
+ "gender": "unknown"
+ },
+ "lastmodified": "2013-10-28T18:49:56Z",
"sections":[
{"id":0,"text":""},
{"level":"1","line":"1","anchor":"1","id":1,"text":"<p>Text of 1\n</p>"},
@@ -20,13 +26,11 @@
} ) );
pageApi.getPage( 'Test' ).done( function( resp ) {
- // FIXME: Hack to reset this since it is variable at
the moment
- resp.lastModifiedTimestamp = '';
assert.deepEqual( resp, {
historyUrl: mw.util.wikiGetlink( 'Test', {
action: 'history' } ),
- lastModifiedUserName: '',
+ lastModifiedUserName: 'bob',
lastModifiedUserGender: 'unknown',
- lastModifiedTimestamp: '',
+ lastModifiedTimestamp: 1382986196,
title: 'Test',
id: -1,
isMainPage: false,
@@ -55,6 +59,12 @@
QUnit.test( '#getPage', 2, function( assert ) {
sinon.stub( PageApi.prototype, 'get' ).returns(
$.Deferred().resolve( {
"mobileview": {
+ "id": -1,
+ "lastmodifiedby": {
+ "name": "Melissa",
+ "gender": "female"
+ },
+ "lastmodified": "2013-10-28T18:49:56Z",
"sections": [
{ "id": 0, "text": "lead content" },
{
@@ -91,13 +101,11 @@
} ) );
pageApi.getPage( 'Test' ).done( function( resp ) {
- // FIXME: Hack to reset this since it is variable at
the moment
- resp.lastModifiedTimestamp = '';
assert.deepEqual( resp, {
historyUrl: mw.util.wikiGetlink( 'Test', {
action: 'history' } ),
- lastModifiedUserName: '',
- lastModifiedUserGender: 'unknown',
- lastModifiedTimestamp: '',
+ lastModifiedUserName: 'Melissa',
+ lastModifiedUserGender: 'female',
+ lastModifiedTimestamp: 1382986196,
title: 'Test',
id: -1,
isMainPage: false,
@@ -242,6 +250,14 @@
QUnit.test( '#getPage (html headings get stripped)', 1, function(
assert ) {
sinon.stub( PageApi.prototype, 'get' ).returns(
$.Deferred().resolve( {
"mobileview": {
+ "id": -1,
+ "lastmodifiedby": {
+ "user": {
+ "name": "",
+ "gender": "unknown"
+ },
+ "timestamp": "1383071742"
+ },
"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: merged
Gerrit-Change-Id: Ie02e7bf37ebcf750b472064379caab97f95a38db
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Robmoen <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Robmoen <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits