jenkins-bot has submitted this change and it was merged. Change subject: More misc JS fixes ......................................................................
More misc JS fixes * Remove some variables used only once * Use mw.util.getUrl * Check .length to see whether jQuery matched any elements Change-Id: I14d104fd696a8f41b885a1fe1101f62b381e4f9f --- M modules/lastmodified.js 1 file changed, 20 insertions(+), 50 deletions(-) Approvals: Jforrester: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/lastmodified.js b/modules/lastmodified.js index ed577c3..e7e702e 100644 --- a/modules/lastmodified.js +++ b/modules/lastmodified.js @@ -23,46 +23,21 @@ * * This is the primary function for this script. */ -function render () { +$( function () { + var historyLink = getArticleHistoryLink(), + currentSkin = mw.config.get( 'skin' ), + html = ''; - // Get the last-modified-timestamp value - var lastModifiedTimestamp = getMetaLastModifiedTimestamp(); - - // Get the last-modified-range value - var displayRange = getMetaRange(); - - // Get the current timestamp and remove the milliseconds - var nowStamp = getUtcTimeStamp(); - - // Get the difference in the time from when it was last edited. - var modifiedDifference = nowStamp - lastModifiedTimestamp; - - // Get the last modified text - var lastModifiedText = getLastModifiedText( modifiedDifference, displayRange ); - - // Get the article history link - var historyLink = getArticleHistoryLink(); - - // Get the current skin - var currentSkin = mw.config.get( 'skin' ); - - // Get the proper styling (skin-dependent) - var divStyle = getDivStyle( currentSkin ); - - // Get the HTML property to append to (skin-dependent) - var htmlProperty = getHtmlProperty( currentSkin ); - - // Construct the HTML - var html = ''; - html += '<div style="' + divStyle + '" id="mwe-lastmodified">'; + html += '<div style="' + getDivStyle( currentSkin ) + '" id="mwe-lastmodified">'; html += '<a href="' + historyLink + '" title="' + mw.message( 'lastmodified-title-tag' ).escaped() + '">'; - html += lastModifiedText; + html += getLastModifiedText( getUtcTimeStamp() - getMetaLastModifiedTimestamp(), getMetaRange() ); html += '</a>'; html += '</div>'; - // Insert the HTML into the web page - $( htmlProperty ).append( html ); -} + // Insert the HTML into the web page, based on skin + $( getHtmlProperty( currentSkin ) ).append( html ); +} ); + /** * Get the UTC Timestamp without microseconds * @@ -70,7 +45,7 @@ */ function getUtcTimeStamp () { return parseInt( new Date().getTime() / 1000 ); -} +}; /** * Get the article history link @@ -78,8 +53,8 @@ * @return {string} Return the article title */ function getArticleHistoryLink () { - return mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + '&action=history'; -} + return mw.util.getUrl( mw.config.get( 'wgPageName' ), { action: 'history' } ); +}; /** * Get the value from the meta tag: last-modified-timestamp @@ -91,12 +66,12 @@ var metaTag = $( "meta[name=last-modified-timestamp]" ); // If the tag was found, parse the value - if ( metaTag ) { + if ( metaTag.length ) { return parseInt( metaTag.attr( 'content' ) ); } return 0; -} +}; /** * Get the modified text. This takes advantage of internationalization. @@ -160,7 +135,7 @@ } return message; -} +}; /** * Get the value from the meta tag: last-modified-range @@ -172,12 +147,12 @@ var metaTag = $( 'meta[name=last-modified-range]' ); // If the tag was found, parse the value - if ( metaTag ) { + if ( metaTag.length ) { return parseInt( metaTag.attr( 'content' ) ); } return 0; -} +}; /** * Get the proper div style tag information depending on the skin @@ -190,7 +165,7 @@ } else { return "float: right; font-size: 0.5em;"; } -} +}; /** * Get the HTML property to append to depending on the skin @@ -203,11 +178,6 @@ } else { return '#firstHeading'; } -} - -/** - * Display the last modified link on the page. - */ -$( render ); +}; }() ); -- To view, visit https://gerrit.wikimedia.org/r/170114 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I14d104fd696a8f41b885a1fe1101f62b381e4f9f Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/LastModified Gerrit-Branch: master Gerrit-Owner: Alex Monk <kren...@wikimedia.org> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits