From 847a09be1190672b9e384ee920ee7b1fc2ede5db Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Sat, 17 Aug 2013 20:21:42 +0200 Subject: [PATCH] Refactor Cite extension JavaScript and make it pass Jshint Moved the scripts and the CSS into the modules folder directly (like almost all other extensions do), added a .jshintrc to not have jenkins shout at this change and minor stuff. After this change Cite will no longer work with anything older than PHP 5.3! Change-Id: I1c87af794f2a9894fb0d82a5bd97bd2182f028e1 --- .jshintignore | 1 + .jshintrc | 34 +++++++++++++++++++ Cite.php | 19 +++++------ SpecialCite.php | 6 ++-- .../ext.cite.js => ext.cite.popups.js} | 7 ++-- modules/{ext.rtlcite => }/ext.rtlcite.css | 0 .../{ext.specialcite => }/ext.specialcite.css | 0 7 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 .jshintignore create mode 100644 .jshintrc rename modules/{ext.cite/ext.cite.js => ext.cite.popups.js} (67%) rename modules/{ext.rtlcite => }/ext.rtlcite.css (100%) rename modules/{ext.specialcite => }/ext.specialcite.css (100%) diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 000000000..df46ab979 --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +modules/jquery.tooltip/jquery.tooltip.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 000000000..4b356f815 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,34 @@ +{ + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "latedef": true, + "newcap": true, + "supernew": true, + "shadow": true, + "noarg": true, + "noempty": true, + "nonew": true, + "quotmark": false, // sometimes double quotes make sense, e.g. "foo's" is better readable than 'foo\'s' + "trailing": true, + "undef": true, + "unused": "vars", // we want to allow unused function parameters + "laxbreak": true, + "laxcomma": false, + "onevar": false, + "bitwise": false, + "forin": false, + "regexp": false, + "strict": true, + "scripturl": true, + + // Environment + "browser": true, + + // Globals + "predef": [ + "jQuery", + "mediaWiki" + ] +} diff --git a/Cite.php b/Cite.php index 0f957659f..99d51638d 100644 --- a/Cite.php +++ b/Cite.php @@ -28,10 +28,10 @@ $wgExtensionCredits['parserhook'][] = array( 'descriptionmsg' => 'cite-desc', 'url' => 'https://www.mediawiki.org/wiki/Extension:Cite/Cite.php' ); -$wgParserTestFiles[] = dirname( __FILE__ ) . "/citeParserTests.txt"; -$wgParserTestFiles[] = dirname( __FILE__ ) . "/citeCatTreeParserTests.txt"; -$wgExtensionMessagesFiles['Cite'] = dirname( __FILE__ ) . "/Cite.i18n.php"; -$wgAutoloadClasses['Cite'] = dirname( __FILE__ ) . "/Cite_body.php"; +$wgParserTestFiles[] = __DIR__ . "/citeParserTests.txt"; +$wgParserTestFiles[] = __DIR__ . "/citeCatTreeParserTests.txt"; +$wgExtensionMessagesFiles['Cite'] = __DIR__ . "/Cite.i18n.php"; +$wgAutoloadClasses['Cite'] = __DIR__ . "/Cite_body.php"; $wgSpecialPageGroups['Cite'] = 'pagetools'; define( 'CITE_DEFAULT_GROUP', '' ); @@ -66,13 +66,12 @@ function wfCite( $parser ) { // Resources $citeResourceTemplate = array( - 'localBasePath' => dirname(__FILE__) . '/modules', + 'localBasePath' => __DIR__ . '/modules', 'remoteExtPath' => 'Cite/modules' ); -$wgResourceModules['ext.cite'] = $citeResourceTemplate + array( - 'styles' => array(), - 'scripts' => 'ext.cite/ext.cite.js', +$wgResourceModules['ext.cite.popups'] = $citeResourceTemplate + array( + 'scripts' => 'ext.cite.popups.js', 'position' => 'bottom', 'dependencies' => array( 'jquery.tooltip', @@ -87,7 +86,7 @@ $wgResourceModules['jquery.tooltip'] = $citeResourceTemplate + array( /* Add RTL fix for the cite elements */ $wgResourceModules['ext.rtlcite'] = $citeResourceTemplate + array( - 'styles' => 'ext.rtlcite/ext.rtlcite.css', + 'styles' => 'ext.rtlcite.css', 'position' => 'top', ); @@ -100,7 +99,7 @@ function wfCiteBeforePageDisplay( $out, &$sk ) { global $wgCiteEnablePopups; if ( $wgCiteEnablePopups ) { - $out->addModules( 'ext.cite' ); + $out->addModules( 'ext.cite.popups' ); } /* RTL support quick-fix module */ diff --git a/SpecialCite.php b/SpecialCite.php index 6d9b81381..5990f5489 100644 --- a/SpecialCite.php +++ b/SpecialCite.php @@ -22,7 +22,7 @@ $wgExtensionCredits['specialpage'][] = array( 'url' => 'https://www.mediawiki.org/wiki/Extension:Cite/Special:Cite.php' ); -$dir = dirname( __FILE__ ) . '/'; +$dir = __DIR__ . '/'; # Internationalisation file $wgExtensionMessagesFiles['SpecialCite'] = $dir . 'SpecialCite.i18n.php'; $wgExtensionMessagesFiles['SpecialCiteAliases'] = $dir . 'SpecialCite.alias.php'; @@ -35,12 +35,12 @@ $wgAutoloadClasses['SpecialCite'] = $dir . 'SpecialCite_body.php'; // Resources $citeResourceTemplate = array( - 'localBasePath' => dirname(__FILE__) . '/modules', + 'localBasePath' => __DIR__ . '/modules', 'remoteExtPath' => 'Cite/modules' ); $wgResourceModules['ext.specialcite'] = $citeResourceTemplate + array( - 'styles' => 'ext.specialcite/ext.specialcite.css', + 'styles' => 'ext.specialcite.css', 'scripts' => array(), 'position' => 'bottom', ); diff --git a/modules/ext.cite/ext.cite.js b/modules/ext.cite.popups.js similarity index 67% rename from modules/ext.cite/ext.cite.js rename to modules/ext.cite.popups.js index dc7328b4d..03529fd34 100644 --- a/modules/ext.cite/ext.cite.js +++ b/modules/ext.cite.popups.js @@ -1,6 +1,8 @@ -( function($) { +( function( $ ) { + 'use strict'; + $( function() { - $('.biblio-cite-link,sup.reference a').tooltip({ + $( '.biblio-cite-link,sup.reference a' ).tooltip( { bodyHandler: function() { return $( '#' + this.hash.substr(1) + ' > .reference-text' ) .html(); @@ -8,5 +10,4 @@ showURL : false } ); } ); - } )( jQuery ); diff --git a/modules/ext.rtlcite/ext.rtlcite.css b/modules/ext.rtlcite.css similarity index 100% rename from modules/ext.rtlcite/ext.rtlcite.css rename to modules/ext.rtlcite.css diff --git a/modules/ext.specialcite/ext.specialcite.css b/modules/ext.specialcite.css similarity index 100% rename from modules/ext.specialcite/ext.specialcite.css rename to modules/ext.specialcite.css