jenkins-bot has submitted this change and it was merged. Change subject: Be consistent in generation of last edited times ......................................................................
Be consistent in generation of last edited times Supporting changes: * Add method getLatestTimestamp to MobilePage * Add method getLatestEdit to MobilePage * SpecialMobileEditWatchlist->getLineHtml now takes MobilePage parameter * Any page with last modified links will naturally be enhanced Bug: T100366 Change-Id: Ia168644ba13e25d6f538cb9f105a72f039814845 --- M i18n/en.json M i18n/qqq.json M includes/Resources.php M includes/models/MobilePage.php M includes/skins/SkinMinerva.php M includes/specials/SpecialMobileEditWatchlist.php M resources/mobile.head/init.js M resources/mobile.modifiedBar/time.js M resources/mobile.watchlist/WatchListApi.js 9 files changed, 122 insertions(+), 92 deletions(-) Approvals: Florianschmidtwelzow: Looks good to me, approved jenkins-bot: Verified diff --git a/i18n/en.json b/i18n/en.json index 9a0c928..d8e0055 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -374,7 +374,6 @@ "mobile-frontend-watchlist-filter-other": "Other", "mobile-frontend-watchlist-filter-talk": "Talk", "mobile-frontend-watchlist-login-action": "Log in to see it.", - "mobile-frontend-watchlist-modified": "Modified $1", "mobile-frontend-watchlist-more": "more", "mobile-frontend-watchlist-please-wait": "Please wait, watch action is taking longer than expected.", "mobile-frontend-watchlist-error": "There was a problem watching this page. Please try again.", @@ -423,9 +422,6 @@ "mobile-frontend-donate-button-label": "Donate", "mobile-frontend-meta-data-issues-categories": "About this category", "mobile-frontend-loading-message": "Loading…", - "mobile-frontend-days-ago": "$1 {{PLURAL:$1|day|days}} ago", - "mobile-frontend-months-ago": "$1 {{PLURAL:$1|month|months}} ago", - "mobile-frontend-years-ago": "$1 {{PLURAL:$1|year|years}} ago", "mobile-frontend-console-recruit": "\\o/ Hey! This is open source software and we need volunteers to help us build this thing, make it better and fix any bugs that you might be seeing in this JavaScript console!\n\nYou can find our backlog @ https://phabricator.wikimedia.org/project/view/67/", "mobile-frontend-browse-tags-header": "Tags", "mobile-frontend-panel-ok": "Okay", diff --git a/i18n/qqq.json b/i18n/qqq.json index ad1ad95..3ef1ecf 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -370,7 +370,6 @@ "mobile-frontend-watchlist-filter-other": "Label on filter selector for mobile watchlist: other pages (not talk or content page).\n{{Identical|Other}}. This must be a single word for layout reasons.", "mobile-frontend-watchlist-filter-talk": "Label on filter selector for mobile watchlist: talk pages.\n{{Identical|Talk}}. This must be a single word for layout reasons.", "mobile-frontend-watchlist-login-action": "Call to action that follows {{msg-mw|mobile-frontend-watchlist-purpose}} asking them to login.", - "mobile-frontend-watchlist-modified": "Text saying how long ago a page in watchlist was updated.\n* $1 - output of {{msg-mw|ago}} (e.g. \"15 days ago\", \"7 hours ago\").", "mobile-frontend-watchlist-more": "Label for link that shows more pages of the watchlist a-z view.\n{{Identical|More}}", "mobile-frontend-watchlist-please-wait": "Shows if watch action is taking longer than 500ms.", "mobile-frontend-watchlist-error": "Shows if an error occurred whilst trying to watch the page.", @@ -419,9 +418,6 @@ "mobile-frontend-donate-button-label": "Message for donation button in mobile interface at bottom of page.\n{{Identical|Donate}}", "mobile-frontend-meta-data-issues-categories": "Label to appear in button that opens issue overlay on categories.", "mobile-frontend-loading-message": "Hidden text existing for accessibility reasons for intermediate loaders.\n{{Identical|Loading}}", - "mobile-frontend-days-ago": "Expression of duration of time passed in days.\nParameter:\n* $1 - number of days that have passed.", - "mobile-frontend-months-ago": "Expression of duration of time passed in months.<br /> \nParameter:\n* $1 - number of months that have passed.", - "mobile-frontend-years-ago": "Expression of duration of time passed in years.\nParameter:\n * $1 - number of years that have passed.", "mobile-frontend-console-recruit": "Message that is displayed in the JavaScript console aimed at developers in an attempt to recruit volunteers. The \\o/ emoticon is a man with his arms in the air with the purpose of drawing attention to the message. If this doesn't translate into the destination language feel free to omit it or use something more applicable.", "mobile-frontend-browse-tags-header": "The header of the \"tags\" section of the page, which is part of the Browse experiment.", "mobile-frontend-panel-ok": "Label for button in panel replying in affirmitive.\n{{Identical|OK}}", diff --git a/includes/Resources.php b/includes/Resources.php index 3c0b83f..7299323 100644 --- a/includes/Resources.php +++ b/includes/Resources.php @@ -378,9 +378,6 @@ 'scripts' => array( 'resources/mobile.pagelist.scripts/WatchstarPageList.js', ), - 'messages' => array( - 'mobile-frontend-watchlist-modified' - ) ), 'mobile.watchlist' => $wgMFResourceFileModuleBoilerplate + array( @@ -391,15 +388,6 @@ 'scripts' => array( 'resources/mobile.watchlist/WatchListApi.js', 'resources/mobile.watchlist/WatchList.js', - ), - 'messages' => array( - 'mobile-frontend-watchlist-modified', - 'minutes-ago', - 'seconds-ago', - 'hours-ago', - 'mobile-frontend-months-ago', - 'mobile-frontend-days-ago', - 'mobile-frontend-years-ago', ), ), diff --git a/includes/models/MobilePage.php b/includes/models/MobilePage.php index 86e39f3..577ff69 100644 --- a/includes/models/MobilePage.php +++ b/includes/models/MobilePage.php @@ -44,6 +44,39 @@ } /** + * Retrieve the last time the page content was modified. Do not reflect null edits. + * @return string timestamp representing last edited time. + */ + public function getLatestTimestamp() { + $title = $this->getTitle(); + return Revision::getTimestampFromId( $title, $title->getLatestRevID() ); + } + + /** + * Retrieve the last edit to this page. + * @return array defining edit with keys name, timestamp and gender + */ + public function getLatestEdit() { + $rev = Revision::newFromId( $this->getTitle()->getLatestRevID() ); + $unixTimestamp = wfTimestamp( TS_UNIX, $this->getLatestTimestamp() ); + $edit = array( + 'timestamp' => $unixTimestamp, + 'name' => '', + 'gender' => '', + ); + if ( $rev ) { + $userId = $rev->getUser(); + if ( $userId ) { + $revUser = User::newFromId( $userId ); + $revUser->load( User::READ_NORMAL ); + $edit['name'] = $revUser->getName(); + $edit['gender'] = $revUser->getOption( 'gender' ); + } + } + return $edit; + } + + /** * Get the title of the page * * @return Title diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php index 598ec20..5931cc3 100644 --- a/includes/skins/SkinMinerva.php +++ b/includes/skins/SkinMinerva.php @@ -630,9 +630,8 @@ protected function getHistoryLink( Title $title ) { $user = $this->getUser(); $isMainPage = $title->isMainPage(); - // add last modified timestamp - $revId = $this->getRevisionId(); - $timestamp = Revision::getTimestampFromId( $this->getTitle(), $revId ); + $mp = new MobilePage( $this->getTitle(), false ); + $timestamp = $mp->getLatestTimestamp(); // Main pages tend to include transclusions (see bug 51924) if ( $isMainPage ) { $lastModified = $this->msg( 'mobile-frontend-history' )->plain(); @@ -643,27 +642,15 @@ $this->getLanguage()->userTime( $timestamp, $user ) )->parse(); } - $unixTimestamp = wfTimestamp( TS_UNIX, $timestamp ); $historyUrl = $this->mobileContext->getMobileUrl( $title->getFullURL( 'action=history' ) ); + $edit = $mp->getLatestEdit(); $link = array( - 'data-timestamp' => $isMainPage ? '' : $unixTimestamp, + 'data-timestamp' => $isMainPage ? '' : $edit['timestamp'], 'href' => $historyUrl, 'text' => $lastModified, - 'data-user-name' => '', - 'data-user-gender' => 'unknown', + 'data-user-name' => $edit['name'], + 'data-user-gender' => $edit['gender'], ); - $rev = Revision::newFromId( $this->getRevisionId() ); - if ( $rev ) { - $userId = $rev->getUser(); - if ( $userId ) { - $revUser = User::newFromId( $userId ); - $revUser->load( User::READ_NORMAL ); - $link = array_merge( $link, array( - 'data-user-name' => $revUser->getName(), - 'data-user-gender' => $revUser->getOption( 'gender' ), - ) ); - } - } $link['href'] = SpecialPage::getTitleFor( 'History', $title )->getLocalURL(); return $link; } diff --git a/includes/specials/SpecialMobileEditWatchlist.php b/includes/specials/SpecialMobileEditWatchlist.php index 5a0dd45..eb9011e 100644 --- a/includes/specials/SpecialMobileEditWatchlist.php +++ b/includes/specials/SpecialMobileEditWatchlist.php @@ -31,23 +31,35 @@ /** * Gets the HTML fragment for a watched page. * - * @param Title $title The title of the watched page - * @param int $ts When the page was last touched - * @param string $thumb An HTML fragment for the page's thumbnaiL + * @param MobilePage $mp a definition of the page to be rendered. * @return string */ - public static function getLineHtml( Title $title, $ts, $thumb ) { + protected function getLineHtml( MobilePage $mp ) { + $thumb = $mp->getSmallThumbnailHtml(); + $title = $mp->getTitle(); + if ( !$thumb ) { + $thumb = MobilePage::getPlaceHolderThumbnailHtml( 'list-thumb-none', 'list-thumb-x' ); + } + $timestamp = $mp->getLatestTimestamp(); + $user = $this->getUser(); $titleText = $title->getPrefixedText(); - if ( $ts ) { - $ts = new MWTimestamp( $ts ); - $lastModified = wfMessage( - 'mobile-frontend-watchlist-modified', - $ts->getHumanTimestamp() - )->text(); + if ( $timestamp ) { + $lastModified = $this->msg( + 'mobile-frontend-last-modified-date', + $this->getLanguage()->userDate( $timestamp, $user ), + $this->getLanguage()->userTime( $timestamp, $user ) + )->parse(); + $edit = $mp->getLatestEdit(); + $dataAttrs = array( + 'data-timestamp' => $edit['timestamp'], + 'data-user-name' => $edit['name'], + 'data-user-gender' => $edit['gender'], + ); $className = 'title'; } else { $className = 'title new'; $lastModified = ''; + $dataAttrs = array(); } $html = @@ -59,9 +71,15 @@ Html::openElement( 'a', array( 'href' => $title->getLocalUrl(), 'class' => $className ) ); $html .= $thumb; $html .= - Html::element( 'h3', array(), $titleText ). - Html::element( 'div', array( 'class' => 'info' ), $lastModified ) . - Html::closeElement( 'a' ) . + Html::element( 'h3', array(), $titleText ); + + if ( $lastModified ) { + $html .= Html::openElement( 'div', array( 'class' => 'info' ) ) . + Html::element( 'span', array_merge( $dataAttrs, array( 'class' => 'modified-enhancement' ) ), + $lastModified ) . + Html::closeElement( 'div' ); + } + $html .= Html::closeElement( 'a' ) . Html::closeElement( 'li' ); return $html; @@ -228,12 +246,7 @@ protected function getViewHtml( MobileCollection $collection ) { $html = '<ul class="watchlist content-unstyled page-list thumbs page-summary-list">'; foreach ( $collection as $mobilePage ) { - $thumb = $mobilePage->getSmallThumbnailHtml(); - if ( !$thumb ) { - $thumb = MobilePage::getPlaceHolderThumbnailHtml( 'list-thumb-none', 'list-thumb-x' ); - } - $title = $mobilePage->getTitle(); - $html .= self::getLineHtml( $title, $title->getTouched(), $thumb ); + $html .= $this->getLineHtml( $mobilePage ); } $html .= '</ul>'; return $html; diff --git a/resources/mobile.head/init.js b/resources/mobile.head/init.js index 415682e..cdce107 100644 --- a/resources/mobile.head/init.js +++ b/resources/mobile.head/init.js @@ -14,23 +14,38 @@ * months or years * @ignore */ - function initHistoryLink() { - var delta, - $lastModified = $( '#mw-mf-last-modified' ), - $lastModifiedLink = $lastModified.find( 'a' ), - historyUrl = $lastModifiedLink.attr( 'href' ), - ts = $lastModifiedLink.data( 'timestamp' ), - username = $lastModifiedLink.data( 'user-name' ) || false, - gender = $lastModifiedLink.data( 'user-gender' ); + function initHistoryLink( $lastModifiedLink ) { + var delta, historyUrl, msg, + ts, username, gender; + + $lastModifiedLink = $lastModifiedLink || $( '#mw-mf-last-modified a' ); + historyUrl = $lastModifiedLink.attr( 'href' ); + ts = $lastModifiedLink.data( 'timestamp' ); + username = $lastModifiedLink.data( 'user-name' ) || false; + gender = $lastModifiedLink.data( 'user-gender' ); if ( ts ) { delta = time.getTimeAgoDelta( parseInt( ts, 10 ) ); if ( time.isRecent( delta ) ) { - $lastModified.parent( '.last-modified-bar' ).addClass( 'active' ); + $lastModifiedLink.closest( '.last-modified-bar' ).addClass( 'active' ); } - - $lastModifiedLink.replaceWith( time.getLastModifiedMessage( ts, historyUrl, username, gender ) ); + msg = time.getLastModifiedMessage( ts, username, gender, historyUrl ); + $lastModifiedLink.replaceWith( msg ); } + } + + /** + * 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 + * @ignore + */ + function initModifiedInfo() { + $( '.modified-enhancement' ).each( function () { + initHistoryLink( $( this ) ); + } ); } // bind events @@ -42,6 +57,8 @@ } ); $( function () { + // Update anything else that needs enhancing (e.g. watchlist) + initModifiedInfo(); if ( !$( '#mw-mf-page-left' ).find( '.menu' ).length ) { mainMenu.appendTo( '#mw-mf-page-left' ); } diff --git a/resources/mobile.modifiedBar/time.js b/resources/mobile.modifiedBar/time.js index a93a88e..f82f43a 100644 --- a/resources/mobile.modifiedBar/time.js +++ b/resources/mobile.modifiedBar/time.js @@ -55,13 +55,14 @@ /** * Return a message relating to the last modified relative time. * @param {String} ts timestamp - * @param {String} historyUrl url to the history page for the message - * @returns {String} username of the last user to modify the page - * @returns {String} gender of the last user to modify the page + * @param {String} username of the last user to modify the page + * @param {String} [gender] of the last user to modify the page + * @param {String} [historyUrl] url to the history page for the message, if omitted + * returns plain text string rather than html * @ignore */ - function getLastModifiedMessage( ts, historyUrl, username, gender ) { - var delta, + function getLastModifiedMessage( ts, username, gender, historyUrl ) { + var delta, html, keys = { seconds: 'mobile-frontend-last-modified-with-user-seconds', minutes: 'mobile-frontend-last-modified-with-user-minutes', @@ -83,13 +84,18 @@ ] ); } - args = args.concat( [ historyUrl, + 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.getUrl( 'Special:UserProfile/' + username ) : '' ] ); - return mw.message.apply( this, args ).parse(); + html = mw.message.apply( this, args ).parse(); + if ( historyUrl ) { + return html; + } else { + return $( '<div>' ).html( html ).text(); + } } M.define( 'modules/lastEdited/time', { diff --git a/resources/mobile.watchlist/WatchListApi.js b/resources/mobile.watchlist/WatchListApi.js index 2316c26..fe2e4f3 100644 --- a/resources/mobile.watchlist/WatchListApi.js +++ b/resources/mobile.watchlist/WatchListApi.js @@ -43,12 +43,13 @@ var self = this, params = $.extend( { action: 'query', - prop: 'pageimages|info', + prop: 'pageimages|info|revisions', piprop: 'thumbnail', pithumbsize: mw.config.get( 'wgMFThumbnailSizes' ).tiny, pilimit: this.limit, format: 'json', formatversion: 2, + rvprop: 'timestamp|user', generator: 'watchlistraw', gwrnamespace: '0', gwrlimit: this.limit @@ -109,23 +110,12 @@ // Transform the items to a sensible format return $.map( pages, function ( item ) { - var delta, msgId, thumb, data; + var revision, thumb, data; thumb = item.thumbnail; if ( thumb ) { thumb.isLandscape = thumb.width > thumb.height; - } - - // page may or may not exist. - if ( item.touched ) { - // work out delta in seconds - delta = time.timeAgo( ( new Date() - new Date( item.touched ) ) / 1000 ); - if ( $.inArray( delta.unit, [ 'days', 'months', 'years' ] ) > -1 ) { - msgId = 'mobile-frontend-' + delta.unit + '-ago'; - } else { - msgId = delta.unit + '-ago'; - } } data = { @@ -136,10 +126,14 @@ thumbnail: thumb }; - if ( msgId ) { - data.lastModified = mw.msg( 'mobile-frontend-watchlist-modified', - mw.msg( msgId, delta.value ) ); + // page may or may not exist. + if ( item.revisions && item.revisions[0] ) { + revision = item.revisions[0]; + console.log( revision ); + data.lastModified = time.getLastModifiedMessage( new Date( revision.timestamp ).getTime() / 1000, + revision.user ); } + return data; } ); } -- To view, visit https://gerrit.wikimedia.org/r/234705 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia168644ba13e25d6f538cb9f105a72f039814845 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits