jenkins-bot has submitted this change and it was merged.
Change subject: Story 1262: Adding user to last modified
......................................................................
Story 1262: Adding user to last modified
A second pass at Kaldari's 1st attempt on this tricky piece
of coding. This one only adds the user profile with JavaScript which
simplifies the i18n messages somewhat. Features the most creative use
of PLURAL evah.
Also breaks out common functionality between lastModified in beta
and stable and ensures they do not run at the same time.
Minimal changes to the skin itself.
Also rename sibling-link class since it no longer always refers to
a link
Change-Id: I0874956d593c02bea38d45eafebbba781dc5ab9a
---
M MobileFrontend.i18n.php
M includes/Resources.php
M includes/skins/MinervaTemplate.php
M includes/skins/SkinMinerva.php
M includes/skins/SkinMobile.php
M includes/skins/SkinMobileAlpha.php
M includes/skins/SkinMobileBeta.php
M javascripts/common/Page.js
M javascripts/common/PageApi.js
A javascripts/modules/lastEdited/lastEdited.js
A javascripts/modules/lastEdited/lastEditedBeta.js
A javascripts/modules/lastEdited/time.js
D javascripts/modules/lastModifiedBeta.js
D javascripts/modules/mf-last-modified.js
M less/common/common.less
M templates/page.html
M tests/javascripts/common/test_PageApi.js
17 files changed, 334 insertions(+), 121 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MobileFrontend.i18n.php b/MobileFrontend.i18n.php
index b8fbe3e..3f2b535 100644
--- a/MobileFrontend.i18n.php
+++ b/MobileFrontend.i18n.php
@@ -84,6 +84,14 @@
'mobile-frontend-last-modified-days' => 'Last modified {{PLURAL:$1|$1
day|$1 days}} ago',
'mobile-frontend-last-modified-months' => 'Last modified {{PLURAL:$1|$1
month|$1 months}} ago',
'mobile-frontend-last-modified-years' => 'Last modified {{PLURAL:$1|$1
year|$1 years}} ago',
+ 'mobile-frontend-last-modified-just-now' => 'Last modified just now',
+ 'mobile-frontend-last-modified-with-user-seconds' => '[$4 Last
{{GENDER:$1|edited}} {{PLURAL:$3|$3 second|$3 seconds}} ago] by {{PLURAL:$5|[$6
$2]|0=an anonymous user}}',
+ 'mobile-frontend-last-modified-with-user-minutes' => '[$4 Last
{{GENDER:$1|edited}} {{PLURAL:$3|$3 minute|$3 minutes}} ago] by
{{PLURAL:$5|[$6 $2]|0=an anonymous user}}.',
+ 'mobile-frontend-last-modified-with-user-hours' => '[$4 Last
{{GENDER:$1|edited}} {{PLURAL:$3|$3 hour|$3 hours}} ago] by {{PLURAL:$5|[$6
$2]|0=an anonymous user}}',
+ 'mobile-frontend-last-modified-with-user-days' => '[$4 Last
{{GENDER:$1|edited}} {{PLURAL:$3|$3 day|$3 days}} ago] by {{PLURAL:$5|[$6
$2]|0=an anonymous user}}',
+ 'mobile-frontend-last-modified-with-user-months' => '[$4 Last
{{GENDER:$1|edited}} {{PLURAL:$3|$3 month|$3 months}} ago] by {{PLURAL:$5|[$6
$2]|0=an anonymous user}}',
+ 'mobile-frontend-last-modified-with-user-years' => '[$4 Last
{{GENDER:$1|edited}} {{PLURAL:$3|$3 year|$3 years}} ago] by {{PLURAL:$5|[$6
$2]|0=an anonymous user}}',
+ 'mobile-frontend-last-modified-with-user-just-now' => '[$3 Last
{{GENDER:$1|edited}}] just now by {{PLURAL:$4|[$5 $2]|0=an anonymous user}}.',
'mobile-frontend-learn-more' => 'Learn more',
// account creation
'mobile-frontend-account-create-submit' => 'Sign up',
@@ -485,6 +493,61 @@
'mobile-frontend-last-modified-years' => 'Text displayed on page to
show how long ago the page was updated. Parameters:
* $1 - number of years
{{Related|Mobile-frontend-last-modified}}',
+ 'mobile-frontend-last-modified-just-now' => 'Text displayed on page to
show that the page was edited within the last few seconds.',
+ 'mobile-frontend-last-modified-with-user-date' => 'Text that displays
the date the page was last modified and who modified it. Parameters:
+* $1 - date
+* $2 - time
+* $3 - link to user profile
+* $4 - gender of user who performed the edit
+* $5 - parameters for link to page history',
+ 'mobile-frontend-last-modified-with-user-seconds' => "Text displayed on
page to show how long ago the page was updated and who updated it. Parameters:
+* $1 - user's gender
+* $2 - username
+* $3 - number of seconds
+* $4 - link to page history
+* $5 - Integer. When 0 the user is anonymous. When 1 the user is named
+* $6 - link to user's profile.",
+ 'mobile-frontend-last-modified-with-user-minutes' => "Text displayed on
page to show how long ago the page was updated and who updated it. Parameters:
+* $1 - user's gender
+* $2 - username
+* $3 - number of minutes
+* $4 - link to page history
+* $5 - Integer. When 0 the user is anonymous. When 1 the user is named
+* $6 - link to user's profile.",
+ 'mobile-frontend-last-modified-with-user-hours' => "Text displayed on
page to show how long ago the page was updated and who updated it. Parameters:
+* $1 - user's gender
+* $2 - username
+* $3 - number of hours
+* $4 - link to page history
+* $5 - Integer. When 0 the user is anonymous. When 1 the user is named
+* $6 - link to user's profile.",
+ 'mobile-frontend-last-modified-with-user-days' => "Text displayed on
page to show how long ago the page was updated and who updated it. Parameters:
+* $1 - user's gender
+* $2 - username
+* $3 - number of days
+* $4 - link to page history
+* $5 - Integer. When 0 the user is anonymous. When 1 the user is named
+* $6 - link to user's profile.",
+ 'mobile-frontend-last-modified-with-user-months' => "Text displayed on
page to show how long ago the page was updated and who updated it. Parameters:
+* $1 - user's gender
+* $2 - username
+* $3 - number of months
+* $4 - link to page history
+* $5 - Integer. When 0 the user is anonymous. When 1 the user is named
+* $6 - link to user's profile.",
+ 'mobile-frontend-last-modified-with-user-years' => "Text displayed on
page to show how long ago the page was updated and who updated it. Parameters:
+* $1 - user's gender
+* $2 - username
+* $3 - number of years
+* $4 - link to page history
+* $5 - Integer. When 0 the user is anonymous. When 1 the user is named
+* $6 - link to user's profile.",
+ 'mobile-frontend-last-modified-with-user-just-now' => "Text displayed
on page to show when a page was very recently updated and who updated it.
Parameters:
+* $1 - user's gender
+* $2 - username
+* $4 - link to page history
+* $5 - Integer. When 0 the user is anonymous. When 1 the user is named
+* $6 - link to user's profile.",
'mobile-frontend-learn-more' => 'A caption of a button or a link
leading to details about a given piece of information.
{{Identical|Learn more}}',
'mobile-frontend-account-create-submit' => 'Text in account creation
submit button.
diff --git a/includes/Resources.php b/includes/Resources.php
index e95f8b7..a2f7947 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -333,7 +333,7 @@
'javascripts/modules/talk/talk.js',
'javascripts/modules/search/pageImages.js',
'javascripts/modules/languages/preferred.js',
- 'javascripts/modules/lastModifiedBeta.js',
+ 'javascripts/modules/lastEdited/lastEditedBeta.js',
'javascripts/modules/keepgoing/keepgoing.js',
'javascripts/modules/tutorials/LeadPhotoTutorialOverlay.js',
'javascripts/modules/tutorials/newbieUploads.js',
@@ -354,6 +354,15 @@
// newbieUploads.js
'mobile-frontend-lead-image-tutorial-summary',
'mobile-frontend-lead-image-tutorial-confirm',
+
+ // LastEditedBeta.js
+ 'mobile-frontend-last-modified-with-user-seconds',
+ 'mobile-frontend-last-modified-with-user-minutes',
+ 'mobile-frontend-last-modified-with-user-hours',
+ 'mobile-frontend-last-modified-with-user-days',
+ 'mobile-frontend-last-modified-with-user-months',
+ 'mobile-frontend-last-modified-with-user-years',
+ 'mobile-frontend-last-modified-with-user-just-now',
),
),
@@ -516,6 +525,17 @@
'mobile-frontend-editor-edit',
// modules/editor/EditorOverlay.js and modules/talk.js
'mobile-frontend-editor-save',
+ // PageApi.js
+ 'mobile-frontend-last-modified-with-user-date',
+ ),
+ ),
+
+ 'mobile.lastEdited.stable' => $wgMFMobileResourceBoilerplate + array(
+ 'dependencies' => array(
+ 'mobile.stable',
+ ),
+ 'scripts' => array(
+ 'javascripts/modules/lastEdited/lastEdited.js',
),
),
@@ -533,7 +553,7 @@
'javascripts/modules/mf-toggle.js',
'javascripts/modules/issues/issues.js',
'javascripts/modules/languages/languages.js',
- 'javascripts/modules/mf-last-modified.js',
+ 'javascripts/modules/lastEdited/time.js',
'javascripts/modules/uploads/lead-photo-init.js',
'javascripts/modules/mainmenutweaks.js',
'javascripts/modules/search/search.js',
@@ -553,7 +573,7 @@
'mobile-frontend-meta-data-issues',
'mobile-frontend-meta-data-issues-header',
- // mf-last-modified.js
+ // lastEdited.js
'mobile-frontend-last-modified-seconds',
'mobile-frontend-last-modified-hours',
'mobile-frontend-last-modified-minutes',
@@ -561,6 +581,7 @@
'mobile-frontend-last-modified-days',
'mobile-frontend-last-modified-months',
'mobile-frontend-last-modified-years',
+ 'mobile-frontend-last-modified-just-now',
// leadphoto.js
'mobile-frontend-photo-upload-disabled',
diff --git a/includes/skins/MinervaTemplate.php
b/includes/skins/MinervaTemplate.php
index 08b5cea..84a522a 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -1,10 +1,17 @@
<?php
class MinervaTemplate extends BaseTemplate {
+ /**
+ * @var Boolean
+ */
+ protected $isSpecialPage;
+
public function getPersonalTools() {
return $this->data['personal_urls'];
}
public function execute() {
+ $title = $this->getSkin()->getTitle();
+ $this->isSpecialPage = $title->isSpecialPage();
$this->getSkin()->prepareData( $this );
wfRunHooks( 'MinervaPreRender', array( $this ) );
$this->render( $this->data );
@@ -74,7 +81,7 @@
}
protected function renderFooter( $data ) {
- if ( !$this->getSkin()->getTitle()->isSpecialPage() ) {
+ if ( !$this->isSpecialPage ) {
?>
<div id="footer">
<?php
@@ -97,6 +104,10 @@
?></ul><?php
}
+ /**
+ * Outputs the 'Last edited' message, e.g. 'Last edited on...'
+ * @param Array $data Data used to build the page
+ */
protected function renderHistoryLink( $data ) {
if ( isset( $data['historyLink'] ) ) {
$historyLink = $data['historyLink'];
@@ -111,11 +122,10 @@
}
protected function renderContentWrapper( $data ) {
- $isSpecialPage = $this->getSkin()->getTitle()->isSpecialPage();
?>
<div id="content_wrapper">
<?php
- if ( !$isSpecialPage ) {
+ if ( !$this->isSpecialPage ) {
echo $data['prebodytext'];
// FIXME: Temporary solution until we
have design
if ( isset(
$data['_old_revision_warning'] ) ) {
@@ -170,7 +180,6 @@
}
protected function render( $data ) { // FIXME: replace with template
engines
- $isSpecialPage = $this->getSkin()->getTitle()->isSpecialPage();
// begin rendering
echo $data[ 'headelement' ];
@@ -190,7 +199,7 @@
<div class="header">
<?php
$this->html( 'menuButton' );
- if ( $isSpecialPage ) {
+ if ( $this->isSpecialPage ) {
echo
$data['specialPageHeader'];
} else {
?>
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 696942f..78449f7 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -186,6 +186,52 @@
);
}
+ /**
+ * Prepare the content for the 'last edited' message, e.g. 'Last edited
on 30 August
+ * 2013, at 23:31'. This message is different for the main page since
main page
+ * content is typically transcuded rather than edited directly.
+ * @param Title $title The Title object of the page being viewed
+ */
+ protected function getHistoryLink( Title $title ) {
+ $user = $this->getUser();
+ $isMainPage = $title->isMainPage();
+ // add last modified timestamp
+ $revId = $this->getRevisionId();
+ $timestamp = Revision::getTimestampFromId( $this->getTitle(),
$revId );
+ // Main pages tend to include transclusions (see bug 51924)
+ if ( $isMainPage ) {
+ $lastModified = wfMessage( 'mobile-frontend-history'
)->plain();
+ } else {
+ $lastModified = wfMessage(
+ 'mobile-frontend-last-modified-date',
+ $this->getLanguage()->userDate( $timestamp,
$user ),
+ $this->getLanguage()->userTime( $timestamp,
$user )
+ )->parse();
+ }
+ $unixTimestamp = wfTimestamp( TS_UNIX, $timestamp );
+ $historyUrl = $this->mobileContext->getMobileUrl(
$title->getFullURL( 'action=history' ) );
+ $link = array(
+ 'id' => 'mw-mf-last-modified',
+ 'data-timestamp' => $isMainPage ? '' : $unixTimestamp,
+ 'href' => $historyUrl,
+ 'text' => $lastModified,
+ );
+ $rev = Revision::newFromId( $this->getRevisionId() );
+ if ( $rev ) {
+ $userId = $rev->getUser();
+ if ( $userId ) {
+ $revUser = User::newFromId( $userId );
+ $link += array(
+ 'data-user-name' => $revUser->getName(),
+ 'data-user-gender' =>
$revUser->getOption( 'gender' ),
+ );
+ } else {
+ $link['data-user-gender'] = 'unknown';
+ }
+ }
+ return $link;
+ }
+
public function prepareData( BaseTemplate $tpl ) {
global $wgMFEnableSiteNotice;
$title = $this->getTitle();
@@ -206,6 +252,11 @@
} else {
$preBodyText = Html::rawElement( 'h1', array( 'id' =>
'section_0' ), $pageHeading );
$tpl->set( 'prebodytext', $preBodyText );
+
+ // If it's a page that exists, add last edited timestamp
+ if ( $this->getWikiPage()->exists() ) {
+ $tpl->set( 'historyLink',
$this->getHistoryLink( $title ) );
+ }
}
// set defaults
@@ -370,6 +421,7 @@
$modules['watch'] = array();
$modules['search'] = array();
+ $modules['stableonly'] = array( 'mobile.lastEdited.stable' );
$title = $this->getTitle();
// modules based on context
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index 0a310ba..1d818c4 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -315,38 +315,13 @@
*/
function prepareTemplatePageContent( QuickTemplate $tpl ) {
$title = $this->getTitle();
- $isSpecialPage = $title->isSpecialPage();
- $isMainPage = $title->isMainPage();
- $user = $this->getUser();
- if ( !$isSpecialPage && $this->getWikiPage()->exists() ) {
-
- // add last modified timestamp
- $revId = $this->getRevisionId();
- $timestamp = Revision::getTimestampFromId(
$this->getTitle(), $revId );
- // Main pages tend to include transclusions (see bug
51924)
- $lastModified = $isMainPage ?
- wfMessage( 'mobile-frontend-history' ) :
- wfMessage( 'mobile-frontend-last-modified-date',
- $this->getLanguage()->userDate(
$timestamp, $user ),
- $this->getLanguage()->userTime(
$timestamp, $user ) )->parse();
-
- $timestamp = wfTimestamp( TS_UNIX, $timestamp );
- $historyUrl = $this->mobileContext->getMobileUrl(
$title->getFullURL( 'action=history' ) );
- $historyLink = array(
- 'id' => 'mw-mf-last-modified',
- 'data-timestamp' => $isMainPage ? '' :
$timestamp,
- 'href' => $historyUrl,
- 'text' => $lastModified,
- 'class' => 'sibling-page',
- );
- $tpl->set( 'historyLink', $historyLink );
- }
+ // If it's a talk page, add a link to the main namespace page
if ( $title->isTalkPage() ) {
$tpl->set( 'subject-page', Linker::link(
$title->getSubjectPage(),
wfMessage( 'mobile-frontend-talk-back-to-page',
$title->getText() ),
- array( 'class' => 'sibling-page' )
+ array( 'class' => 'return-link' )
) );
}
}
diff --git a/includes/skins/SkinMobileAlpha.php
b/includes/skins/SkinMobileAlpha.php
index a3392f8..fd80b5e 100644
--- a/includes/skins/SkinMobileAlpha.php
+++ b/includes/skins/SkinMobileAlpha.php
@@ -41,16 +41,6 @@
public function prepareData( BaseTemplate $tpl ) {
parent::prepareData( $tpl );
$this->prepareTalkLabel( $tpl );
- $this->prepareHistoryLink( $tpl );
- }
-
- protected function prepareHistoryLink( BaseTemplate $tpl ) {
- $revId = $this->getRevisionId();
- if ( isset( $tpl->data['historyLink'] ) ) {
- $h = $tpl->data['historyLink'];
- $h['href'] = SpecialPage::getTitleFor( 'MobileDiff',
$revId )->getLocalUrl();
- $tpl->set( 'historyLink', $h );
- }
}
protected function prepareTalkLabel( BaseTemplate $tpl ) {
diff --git a/includes/skins/SkinMobileBeta.php
b/includes/skins/SkinMobileBeta.php
index 888f553..e835ade 100644
--- a/includes/skins/SkinMobileBeta.php
+++ b/includes/skins/SkinMobileBeta.php
@@ -17,6 +17,13 @@
$vars = parent::getSkinConfigVariables();
// force cta on in beta
$vars['wgMFEnablePhotoUploadCTA'] = true;
+ // Kill this when we fix the functionality in PageApi.js
+ $user = $this->getUser();
+ if ( $user->isLoggedIn() ) {
+ $vars['wgMFUserGender'] = $this->getUser()->getOption(
'gender' );
+ } else {
+ $vars['wgMFUserGender'] = 'unknown';
+ }
return $vars;
}
@@ -27,7 +34,8 @@
$modules['beta'][] = 'mobile.notifications.overlay';
}
$modules['beta'][] = 'mobile.geonotahack';
-
+ // turn off stable only modules
+ $modules['stableonly'] = array();
return $modules;
}
diff --git a/javascripts/common/Page.js b/javascripts/common/Page.js
index f0f4e11..8bd1635 100644
--- a/javascripts/common/Page.js
+++ b/javascripts/common/Page.js
@@ -30,9 +30,7 @@
inBetaOrAlpha: mw.config.get( 'wgMFMode' ) !== 'stable',
isMainPage: false,
talkLabel: mw.msg(
'mobile-frontend-talk-overlay-header' ),
- editLabel: mw.msg( 'mobile-frontend-editor-edit' ),
- // FIXME: this is not a useful default and asking for
trouble (only valid on a just edited page)
- lastModifiedTimestamp: ( "" + new Date().getTime()
).substr( 0,10 ) // Default to current timestamp
+ editLabel: mw.msg( 'mobile-frontend-editor-edit' )
},
isMainPage: function() {
diff --git a/javascripts/common/PageApi.js b/javascripts/common/PageApi.js
index 4ee50f8..a7bb1a7 100644
--- a/javascripts/common/PageApi.js
+++ b/javascripts/common/PageApi.js
@@ -70,7 +70,15 @@
id: -1,
lead: sections[0].text,
sections:
sections.slice( 1 ),
- isMainPage:
resp.mobileview.hasOwnProperty( 'mainpage' ) ? true : false
+ 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
} );
}
} ).fail( $.proxy( page, 'reject' ) );
diff --git a/javascripts/modules/lastEdited/lastEdited.js
b/javascripts/modules/lastEdited/lastEdited.js
new file mode 100644
index 0000000..c66c44a
--- /dev/null
+++ b/javascripts/modules/lastEdited/lastEdited.js
@@ -0,0 +1,47 @@
+( function( M, $ ) {
+
+M.assertMode( [ 'stable' ] );
+var module = ( function() {
+ var time = M.require( 'modules/lastEdited/time' );
+
+ /**
+ * Initialisation function for last modified module.
+ *
+ * Enhances #mw-mf-last-modified element
+ * to show a human friendly date in seconds, minutes, hours, days
+ * months or years
+ *
+ */
+ function init() {
+ var $lastModified = $( '#mw-mf-last-modified' ),
+ ts = $lastModified.data( 'timestamp' ),
+ keys = {
+ seconds:
'mobile-frontend-last-modified-seconds',
+ minutes:
'mobile-frontend-last-modified-minutes',
+ hours: 'mobile-frontend-last-modified-hours',
+ days: 'mobile-frontend-last-modified-days',
+ months: 'mobile-frontend-last-modified-months',
+ years: 'mobile-frontend-last-modified-years'
+ },
+ message, delta;
+
+ if ( ts ) {
+ delta = time.getTimeAgoDelta( parseInt( ts, 10 ) );
+ if ( time.isNow( delta ) ) {
+ message = mw.msg(
'mobile-frontend-last-modified-just-now' );
+ } else {
+ message = mw.msg( keys[ delta.unit ],
mw.language.convertNumber( delta.value ) );
+ }
+ $lastModified.text( message );
+ }
+ }
+ M.on( 'page-loaded', init );
+
+ return {
+ init: init
+ };
+}() );
+
+M.define( 'last-modified', module );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/modules/lastEdited/lastEditedBeta.js
b/javascripts/modules/lastEdited/lastEditedBeta.js
new file mode 100644
index 0000000..5242924
--- /dev/null
+++ b/javascripts/modules/lastEdited/lastEditedBeta.js
@@ -0,0 +1,62 @@
+( function( M, $ ) {
+
+M.assertMode( [ 'beta', 'alpha' ] );
+
+var module = ( function() {
+ var time = M.require( 'modules/lastEdited/time' );
+
+ /**
+ * Initialisation function for last modified module.
+ *
+ * Enhances #mw-mf-last-modified element
+ * to show a human friendly date in seconds, minutes, hours, days
+ * months or years
+ *
+ */
+ function init() {
+ var $lastModified = $( '#mw-mf-last-modified' ),
+ historyUrl = $lastModified.attr( 'href' ),
+ ts = $lastModified.data( 'timestamp' ),
+ username = $lastModified.data( 'user-name' ) || false,
+ gender = $lastModified.data( 'user-gender' ),
+ keys = {
+ seconds:
'mobile-frontend-last-modified-with-user-seconds',
+ minutes:
'mobile-frontend-last-modified-with-user-minutes',
+ hours:
'mobile-frontend-last-modified-with-user-hours',
+ days:
'mobile-frontend-last-modified-with-user-days',
+ months:
'mobile-frontend-last-modified-with-user-months',
+ years:
'mobile-frontend-last-modified-with-user-years'
+ },
+ delta, args = [];
+
+ if ( ts ) {
+ delta = time.getTimeAgoDelta( parseInt( ts, 10 ) );
+ if ( time.isNow( delta ) ) {
+ args = args.concat( [
'mobile-frontend-last-modified-with-user-just-now', gender, username ] );
+ } else {
+ args = args.concat( [ keys[ delta.unit ],
gender, username,
+ mw.language.convertNumber(
delta.value ) ] );
+ }
+
+ args = args.concat( [ historyUrl,
+ // Abuse PLURAL support to determine if
the user is anonymous or not
+ mw.language.convertNumber( username ? 1
: 0 ),
+ // I'll abuse of PLURAL support means
we have to pass the relative URL rather than construct it from a wikilink
+ username ? mw.util.wikiGetlink(
'Special:UserProfile/' + username ) : '' ] );
+
+ $( '<div>' ).attr( 'id', 'mw-mf-last-modified' ).
+ html( mw.message.apply( this, args ).parse() ).
+ insertBefore( $lastModified );
+ $lastModified.remove();
+ }
+ }
+ M.on( 'page-loaded', init );
+
+ return {
+ init: init
+ };
+}() );
+
+M.define( 'last-modified-beta', module );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/modules/lastEdited/time.js
b/javascripts/modules/lastEdited/time.js
new file mode 100644
index 0000000..4d40741
--- /dev/null
+++ b/javascripts/modules/lastEdited/time.js
@@ -0,0 +1,28 @@
+( function( M ) {
+ var units = ['seconds', 'minutes', 'hours', 'days', 'months', 'years'],
+ limits = [1, 60, 3600, 86400, 2592000, 31536000];
+
+ function timeAgo( timestampDelta ) {
+ var i = 0;
+ while ( i < limits.length && timestampDelta > limits[i + 1] ) {
+ ++i;
+ }
+ return { value: Math.round( timestampDelta / limits[i] ), unit:
units[i] };
+ }
+
+ function getTimeAgoDelta( timestamp ) {
+ var currentTimestamp = Math.round( new Date().getTime() / 1000
),
+ delta = timeAgo( currentTimestamp - timestamp );
+ return delta;
+ }
+
+ function isNow( delta ) {
+ return delta.unit === 'seconds' && delta.value < 10;
+ }
+
+ M.define( 'modules/lastEdited/time', {
+ getTimeAgoDelta: getTimeAgoDelta,
+ isNow: isNow
+ } );
+
+}( mw.mobileFrontend ) );
diff --git a/javascripts/modules/lastModifiedBeta.js
b/javascripts/modules/lastModifiedBeta.js
deleted file mode 100644
index 347d9de..0000000
--- a/javascripts/modules/lastModifiedBeta.js
+++ /dev/null
@@ -1,11 +0,0 @@
-( function( M ) {
- var schema = M.require( 'loggingSchemas/MobileWebClickTracking' );
-
- function addClickTracking() {
- schema.hijackLink( '#mw-mf-last-modified', 'page-history' );
- }
-
- M.on( 'page-loaded', addClickTracking );
- addClickTracking();
-
-}( mw.mobileFrontend ) );
diff --git a/javascripts/modules/mf-last-modified.js
b/javascripts/modules/mf-last-modified.js
deleted file mode 100644
index 5b49414..0000000
--- a/javascripts/modules/mf-last-modified.js
+++ /dev/null
@@ -1,54 +0,0 @@
-( function( M, $ ) {
-
-var module = ( function() {
- var units = ['seconds', 'minutes', 'hours', 'days', 'months', 'years'],
- limits = [1, 60, 3600, 86400, 2592000, 31536000];
-
- function timeAgo( timestampDelta ) {
- var i = 0;
- while ( i < limits.length && timestampDelta > limits[i + 1] ) {
- ++i;
- }
- return { value: Math.round( timestampDelta / limits[i] ), unit:
units[i] };
- }
-
- /**
- * Initialisation function for last modified module.
- *
- * Enhances #mw-mf-last-modified element
- * to show a human friendly date in seconds, minutes, hours, days
- * months or years
- *
- */
- function init() {
- var $lastModified = $( '#mw-mf-last-modified' ),
- ts = $lastModified.data( 'timestamp' ),
- keys = {
- seconds:
'mobile-frontend-last-modified-seconds',
- minutes:
'mobile-frontend-last-modified-minutes',
- hours: 'mobile-frontend-last-modified-hours',
- days: 'mobile-frontend-last-modified-days',
- months: 'mobile-frontend-last-modified-months',
- years: 'mobile-frontend-last-modified-years'
- },
- message, pageTimestamp, currentTimestamp, delta;
-
- if ( ts ) {
- pageTimestamp = parseInt( ts, 10 );
- currentTimestamp = Math.round( new Date().getTime() /
1000 );
- delta = timeAgo( currentTimestamp - pageTimestamp );
- message = mw.msg( keys[ delta.unit ],
mw.language.convertNumber( delta.value ) );
- $lastModified.text( message );
- }
- }
- M.on( 'page-loaded', init );
-
- return {
- timeAgo: timeAgo,
- init: init
- };
-}() );
-
-M.define( 'last-modified', module );
-
-}( mw.mobileFrontend, jQuery ) );
diff --git a/less/common/common.less b/less/common/common.less
index 4b310b0..add18ec 100644
--- a/less/common/common.less
+++ b/less/common/common.less
@@ -132,11 +132,6 @@
border: 1px solid #ccc;
}
-.sibling-page {
- display: block;
- font-size: .9em;
- margin-top: 1.5em;
-}
/* Plainlinks - this can be used to switch
* off special external link styling */
@@ -205,6 +200,14 @@
div.magnify {
display: none;
}
+
+ // Generic class name needed
+ .return-link,
+ #mw-mf-last-modified {
+ display: block;
+ font-size: .9em;
+ margin-top: 1.5em;
+ }
}
.jsonly {
diff --git a/templates/page.html b/templates/page.html
index fcda429..3355113 100644
--- a/templates/page.html
+++ b/templates/page.html
@@ -19,5 +19,7 @@
{{#inBetaOrAlpha}}<div id="page-secondary-actions">{{/inBetaOrAlpha}}
<div class="section" id="mw-mf-language-section"></div>
{{#inBetaOrAlpha}}</div>{{/inBetaOrAlpha}}
- <a href="{{historyUrl}}" id="mw-mf-last-modified"
data-timestamp="{{lastModifiedTimestamp}}"></a>
+ <a href="{{historyUrl}}" id="mw-mf-last-modified"
data-timestamp="{{lastModifiedTimestamp}}"
+ data-user-name="{{lastModifiedUserName}}"
data-user-gender="{{lastModifiedUserGender}}"
+ ></a>
</div>
diff --git a/tests/javascripts/common/test_PageApi.js
b/tests/javascripts/common/test_PageApi.js
index a28f30d..af7c981 100644
--- a/tests/javascripts/common/test_PageApi.js
+++ b/tests/javascripts/common/test_PageApi.js
@@ -20,7 +20,13 @@
} ) );
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: '',
title: 'Test',
id: -1,
isMainPage: false,
@@ -85,7 +91,13 @@
} ) );
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: '',
title: 'Test',
id: -1,
isMainPage: false,
--
To view, visit https://gerrit.wikimedia.org/r/90443
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0874956d593c02bea38d45eafebbba781dc5ab9a
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Kaldari <[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