http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99522
Revision: 99522
Author: jpostlethwaite
Date: 2011-10-11 18:30:47 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
Adding new extension LastModified.
Added Paths:
-----------
trunk/extensions/LastModified/
trunk/extensions/LastModified/LastModified.alias.php
trunk/extensions/LastModified/LastModified.i18n.php
trunk/extensions/LastModified/LastModified.php
trunk/extensions/LastModified/modules/
trunk/extensions/LastModified/modules/lastmodified.js
Added: trunk/extensions/LastModified/LastModified.alias.php
===================================================================
--- trunk/extensions/LastModified/LastModified.alias.php
(rev 0)
+++ trunk/extensions/LastModified/LastModified.alias.php 2011-10-11
18:30:47 UTC (rev 99522)
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * @author Katie Horn <[email protected]>, Jeremy Postlethwaite
<[email protected]>
+ */
+
+/**
+ * Aliases for Special:LastModified
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$specialPageAliases = array();
+
+/** English (English) */
+$specialPageAliases['en'] = array(
+ 'LastModified' => array( 'LastModified' ),
+);
+
+/**
+ * For backwards compatibility with MediaWiki 1.15 and earlier.
+ */
+$aliases =& $specialPageAliases;
Property changes on: trunk/extensions/LastModified/LastModified.alias.php
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date HeadURL Header Id Revision
Added: svn:eol-style
+ native
Added: trunk/extensions/LastModified/LastModified.i18n.php
===================================================================
--- trunk/extensions/LastModified/LastModified.i18n.php
(rev 0)
+++ trunk/extensions/LastModified/LastModified.i18n.php 2011-10-11 18:30:47 UTC
(rev 99522)
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * @author Katie Horn <[email protected]>, Jeremy Postlethwaite
<[email protected]>
+ */
+
+/**
+ * Internationalisation for LastModified extension
+ */
+
+$messages = array();
+
+/** English
+ * @author Katie Horn, Jeremy Postlethwaite
+ */
+$messages['en'] = array(
+ 'lastmodified-desc' => 'Generates last modified times for articles',
+ 'lastmodified' => 'LastModified',
+ 'lastmodified-seconds' => 'Last updated $1 seconds ago',
+ 'lastmodified-minutes' => 'Last updated $1 minutes ago',
+ 'lastmodified-hours' => 'Last updated $1 hours ago',
+ 'lastmodified-days' => 'Last updated $1 days ago',
+ 'lastmodified-months' => 'Last updated $1 months ago',
+ 'lastmodified-years' => 'Last updated $1 years ago',
+);
Property changes on: trunk/extensions/LastModified/LastModified.i18n.php
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date HeadURL Header Id Revision
Added: svn:eol-style
+ native
Added: trunk/extensions/LastModified/LastModified.php
===================================================================
--- trunk/extensions/LastModified/LastModified.php
(rev 0)
+++ trunk/extensions/LastModified/LastModified.php 2011-10-11 18:30:47 UTC
(rev 99522)
@@ -0,0 +1,84 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * @author Katie Horn <[email protected]>, Jeremy Postlethwaite
<[email protected]>
+ */
+
+# Alert the user that this is not a valid entry point to MediaWiki if they try
to access the special pages file directly.
+if ( !defined( 'MEDIAWIKI' ) ) {
+ echo <<<EOT
+To install this extension, put the following line in LocalSettings.php:
+require_once( "\$IP/extensions/LastModified/LastModified.php" );
+EOT;
+ exit( 1 );
+}
+
+// Extension credits that will show up on Special:Version
+$wgExtensionCredits['specialpage'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'LastModified',
+ 'version' => '1.0',
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:LastModified',
+ 'author' => 'Katie Horn, Jeremy Postlethwaite',
+ 'descriptionmsg' => 'lastmodified-desc',
+);
+
+$dir = dirname( __FILE__ ) . '/';
+
+$wgExtensionMessagesFiles['LastModified'] = $dir . 'LastModified.i18n.php';
+$wgExtensionAliasesFiles['LastModified'] = $dir . 'LastModified.alias.php';
+
+/**
+ * ADDITIONAL MAGICAL GLOBALS
+ */
+
+// Resource modules
+$wgResourceTemplate = array(
+ 'localBasePath' => $dir . 'modules',
+ 'remoteExtPath' => 'LastModified/modules',
+);
+
+$wgResourceModules['last.modified'] = array(
+ 'scripts' => 'lastmodified.js',
+ 'position' => 'top',
+ 'messages' => array(
+ 'lastmodified-seconds',
+ 'lastmodified-hours',
+ 'lastmodified-minutes',
+ 'lastmodified-hours',
+ 'lastmodified-days',
+ 'lastmodified-months',
+ 'lastmodified-years',
+ ),
+) + $wgResourceTemplate;
+
+$wgHooks['BeforePageDisplay'][] = 'fnLastModified';
+
+$wgLastModifiedRange = isset( $wgLastModifiedRange ) ? (integer)
$wgLastModifiedRange : 0;
+
+function fnLastModified() {
+ global $wgOut, $wgResourceModules, $wgArticle, $wgLastModifiedRange;
+
+ if (isset( $wgArticle ) && !empty( $wgArticle ) ){
+ $timestamp = $wgArticle->getTimestamp();
+ $wgOut->addMeta( 'last-edited', wfTimestamp ( TS_UNIX,
$timestamp ) );
+ $wgOut->addMeta( 'last-modified-range', $wgLastModifiedRange );
+ $wgOut->addModules( 'last.modified' );
+ }
+
+ return true;
+}
+
Property changes on: trunk/extensions/LastModified/LastModified.php
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date HeadURL Header Id Revision
Added: svn:eol-style
+ native
Added: trunk/extensions/LastModified/modules/lastmodified.js
===================================================================
--- trunk/extensions/LastModified/modules/lastmodified.js
(rev 0)
+++ trunk/extensions/LastModified/modules/lastmodified.js 2011-10-11
18:30:47 UTC (rev 99522)
@@ -0,0 +1,216 @@
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * @author Katie Horn <[email protected]>, Jeremy Postlethwaite
<[email protected]>
+ */
+
+/**
+ * Run the last modified helper.
+ *
+ * This is the primary function for this script.
+ *
+ */
+function extensionsLastModified() {
+
+ // Get the last-edit value
+ var lastEdited = extensionsLastModifiedGetMetaLastEdited();
+ //console.log( 'lastEdited: ' + lastEdited );
+
+ // Get the last-modified-range value
+ var displayRange = extensionsLastModifiedGetMetaRange();
+ //console.log( 'displayRange: ' + displayRange );
+
+ // Get the current Date object
+ var now = new Date();
+ //console.log( 'now: ' + now );
+
+ // Get the current timestamp and remove the milliseconds
+ var nowStamp = parseInt( now.getTime() / 1000 ) ;
+ //console.log( 'nowStamp: ' + nowStamp );
+
+ // Get the difference in the time from when it was last edited.
+ var modifiedDifference = nowStamp - lastEdited;
+ //console.log( 'modifiedDifference: ' + modifiedDifference );
+
+ // Get the last modified text
+ var lastModifiedText = extensionsLastModifiedGetLastModifiedText(
modifiedDifference, displayRange );
+ //console.log( 'lastModifiedText: ' + lastModifiedText );
+
+ // Insert the text on the web page
+ extensionsLastModifiedInsertHtml( lastModifiedText );
+}
+
+/**
+ * Get the article history link
+ *
+ * @return string Return the article title
+ */
+function extensionsLastModifiedGetArticleHistoryLink() {
+
+ var href = $(location).attr('href');
+
+ var query = '';
+
+ if (href.indexOf('?') == -1) {
+ query += '?';
+ }
+ else {
+ query += '&';
+ }
+
+ query += 'action=history';
+
+ //console.log( 'href: ' + href );
+
+ return href + query;
+}
+
+/**
+ * Get the value from the meta tag: last-edited
+ *
+ * @return integer
+ */
+function extensionsLastModifiedGetMetaLastEdited() {
+
+ // Fetch the meta tag
+ var metaTag = $("meta[name=last-edited]");
+
+ // If the tag was found, parse the value
+ if ( metaTag ) {
+
+ return parseInt( metaTag.attr( 'content' ) );
+ }
+
+ return 0;
+}
+
+/**
+ * Get the modified text. This takes advantage of internationalization.
+ *
+ * @param integer modifiedDifference The difference of time from now
compared to last edited
+ * @param integer displayRange The maximum unit of time to
display for last updated
+ *
+ * displayRange
+ * - 0: default - display: years, months, days, hours, minutes, seconds
+ * - 1: months - display: months, days, hours, minutes, seconds
+ * - 2: days - display: days, hours, minutes, seconds
+ * - 3: hours - display: hours, minutes, seconds
+ * - 4: minutes - display: minutes, seconds
+ * - 5: seconds - display: seconds
+ *
+ * @return string
+ */
+function extensionsLastModifiedGetLastModifiedText( modifiedDifference,
displayRange ) {
+
+ // Message to return
+ var message = '';
+ var lastEdit = modifiedDifference;
+
+ if ( modifiedDifference < 60 ) {
+
+ // seconds
+ message = ( mw.msg( 'lastmodified-seconds', lastEdit ) );
+
+ }
+ else if ( modifiedDifference < 3600 ) {
+
+ // minutes
+ lastEdit = parseInt( modifiedDifference / 60 );
+ message = ( mw.msg( 'lastmodified-minutes', myLastEdit ) );
+
+ }
+ else if ( modifiedDifference < 86400 ) {
+
+ // hours
+ myLastEdit = parseInt( modifiedDifference / 3600 );
+ message = ( mw.msg( 'lastmodified-hours', myLastEdit ) );
+
+ }
+ else if ( modifiedDifference < 2592000 ) {
+
+ // days
+ myLastEdit = parseInt( modifiedDifference / 86400 );
+ message = ( mw.msg( 'lastmodified-days', myLastEdit ) );
+
+ }
+ else if ( modifiedDifference < 31536000 ) {
+
+ // months
+ myLastEdit = parseInt( modifiedDifference / 2592000 );
+ message = ( mw.msg( 'lastmodified-months', myLastEdit ) );
+
+ }
+ else {
+
+ // years
+ myLastEdit = parseInt( modifiedDifference / 31536000 );
+ message = ( mw.msg( 'lastmodified-years', myLastEdit ) );
+
+ }
+
+ return message;
+}
+
+/**
+ * Get the value from the meta tag: last-modified-range
+ *
+ * @return integer
+ */
+function extensionsLastModifiedGetMetaRange() {
+
+ // Fetch the meta tag
+ var metaTag = $("meta[name=last-modified-range]");
+
+ // If the tag was found, parse the value
+ if ( metaTag ) {
+
+ return parseInt( metaTag.attr( 'content' ) );
+ }
+
+ return 0;
+}
+
+/**
+ * Insert the last modified text with jQuery
+ *
+ * @param string lastModifiedText The string of text to display
in the container.
+ */
+function extensionsLastModifiedInsertHtml( lastModifiedText ) {
+
+ //http://en.wikipedia.org/w/index.php?title=San_Francisco&action=history
+
+ // Get the article history link
+ var historyLink = extensionsLastModifiedGetArticleHistoryLink();
+ //console.log( 'historyLink: ' + historyLink );
+
+ var html = '';
+
+ html += '<div style="float: right;" class="lastmodified">';
+ html += '<a href="' + historyLink + '" title="View the revision history
for this article.">';
+ html += lastModifiedText;
+ html += '</a>';
+ html += '</div>';
+
+ $('.mw-content-ltr').prepend( html );
+}
+
+/**
+ * Display the last modified link on the page.
+ *
+ */
+$(document).ready(function(){
+ extensionsLastModified();
+});
+
Property changes on: trunk/extensions/LastModified/modules/lastmodified.js
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date HeadURL Header Id Revision
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs