r109095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109094‎ | r109095 | r109096 >
Date:00:57, 17 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
split code into its own file and some attempt at cleanup of compat code
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.api.js (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.js (added) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -289,10 +289,19 @@
290290 'remoteExtPath' => 'EducationProgram/resources'
291291 );
292292
 293+$wgResourceModules['ep.core'] = $moduleTemplate + array(
 294+ 'scripts' => array(
 295+ 'ep.js',
 296+ ),
 297+);
 298+
293299 $wgResourceModules['ep.api'] = $moduleTemplate + array(
294300 'scripts' => array(
295301 'ep.api.js',
296302 ),
 303+ 'dependencies' => array(
 304+ 'ep.core',
 305+ ),
297306 );
298307
299308 $wgResourceModules['ep.pager'] = $moduleTemplate + array(
@@ -338,6 +347,7 @@
339348 ),
340349 'dependencies' => array(
341350 'jquery.ui.dialog',
 351+ 'ep.core',
342352 'ep.api',
343353 'mediawiki.jqueryMsg',
344354 'mediawiki.language'
Index: trunk/extensions/EducationProgram/resources/ep.js
@@ -0,0 +1,58 @@
 2+/**
 3+ * JavasSript for the Education Program MediaWiki extension.
 4+ * @see https://www.mediawiki.org/wiki/Extension:Reviews
 5+ *
 6+ * @licence GNU GPL v3 or later
 7+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 8+ */
 9+
 10+window.educationProgram = new( function() {
 11+
 12+ this.compatMode = true;
 13+
 14+ this.msg = function () {
 15+ if ( window.educationProgram.compatMode ) {
 16+ return gM.apply( this, arguments );
 17+ }
 18+ else {
 19+ return mw.msg.apply( this, arguments );
 20+ }
 21+ };
 22+
 23+ this.msge = function () {
 24+ return mw.html.escape( this.msg.apply( this, arguments ) );
 25+ };
 26+
 27+} );
 28+
 29+mw.loader.using( 'mediawiki.language', function() {
 30+ window.educationProgram.compatMode = typeof window.mediaWiki.language.gender === 'undefined';
 31+
 32+ if ( window.educationProgram.compatMode ) {
 33+ mw.language.gender = function( gender, forms ) {
 34+ if ( !forms || forms.length === 0 ) {
 35+ return '';
 36+ }
 37+ forms = mw.language.preConvertPlural( forms, 2 );
 38+ if ( gender === 'male' ) {
 39+ return forms[0];
 40+ }
 41+ if ( gender === 'female' ) {
 42+ return forms[1];
 43+ }
 44+ return ( forms.length === 3 ) ? forms[2] : forms[0];
 45+ };
 46+
 47+ mw.jqueryMsg.htmlEmitter.prototype.gender = function( nodes ) {
 48+ var gender;
 49+ if ( nodes[0] && nodes[0].options instanceof mw.Map ){
 50+ gender = nodes[0].options.get( 'gender' );
 51+ } else {
 52+ gender = nodes[0];
 53+ }
 54+ var forms = nodes.slice(1);
 55+ return this.language.gender( gender, forms );
 56+ };
 57+ }
 58+
 59+} );
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/resources/ep.js
___________________________________________________________________
Added: svn:eol-style
160 + native
Index: trunk/extensions/EducationProgram/resources/ep.api.js
@@ -6,95 +6,63 @@
77 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
88 */
99
10 -window.educationProgram = new( function() {
 10+window.educationProgram.api = new( function() {
1111
12 - // TODO: move to own file
13 - this.msg = function () {
14 - if ( typeof mw.language.gender === 'undefined' ) {
15 - mw.jqueryMsg.htmlEmitter.prototype.gender = function( nodes ) {
16 - var gender;
17 - if ( nodes[0] && nodes[0].options instanceof mw.Map ){
18 - gender = nodes[0].options.get( 'gender' );
19 - } else {
20 - gender = nodes[0];
 12+ this.remove = function( data, callback ) {
 13+ var requestArgs = {
 14+ 'action': 'deleteeducation',
 15+ 'format': 'json',
 16+ 'token': window.mw.user.tokens.get( 'editToken' ),
 17+ 'ids': data.ids.join( '|' ),
 18+ 'type': data.type
 19+ };
 20+
 21+ $.post(
 22+ wgScriptPath + '/api.php',
 23+ requestArgs,
 24+ function( data ) {
 25+ var success = data.hasOwnProperty( 'success' ) && data.success;
 26+
 27+ callback( {
 28+ 'success': success
 29+ } );
 30+ }
 31+ );
 32+ };
 33+
 34+ this.instructor = function( args ) {
 35+ var requestArgs = $.extend( {
 36+ 'action': 'instructor',
 37+ 'format': 'json',
 38+ 'token': window.mw.user.tokens.get( 'editToken' )
 39+ }, args );
 40+
 41+ var deferred = $.Deferred();
 42+
 43+ $.post(
 44+ wgScriptPath + '/api.php',
 45+ requestArgs,
 46+ function( data ) {
 47+ if ( data.hasOwnProperty( 'success' ) && data.success ) {
 48+ deferred.resolve();
2149 }
22 - var forms = nodes.slice(1);
23 - return this.language.gender( gender, forms );
24 - };
25 - }
 50+ else {
 51+ deferred.reject();
 52+ }
 53+ }
 54+ );
2655
27 - if ( typeof mw.language.gender === 'undefined' ) {
28 - return gM.apply( this, arguments );
29 - }
30 - else {
31 - return mw.msg.apply( this, arguments );
32 - }
 56+ return deferred.promise();
3357 };
3458
35 - this.msge = function () {
36 - return mw.html.escape( this.msg.apply( this, arguments ) );
 59+ this.addInstructor = function( args ) {
 60+ args.subaction = 'add';
 61+ return this.instructor( args );
3762 };
3863
39 - this.api = new( function() {
 64+ this.removeInstructor = function( args ) {
 65+ args.subaction = 'remove';
 66+ return this.instructor( args );
 67+ };
4068
41 - this.remove = function( data, callback ) {
42 - var requestArgs = {
43 - 'action': 'deleteeducation',
44 - 'format': 'json',
45 - 'token': window.mw.user.tokens.get( 'editToken' ),
46 - 'ids': data.ids.join( '|' ),
47 - 'type': data.type
48 - };
49 -
50 - $.post(
51 - wgScriptPath + '/api.php',
52 - requestArgs,
53 - function( data ) {
54 - var success = data.hasOwnProperty( 'success' ) && data.success;
55 -
56 - callback( {
57 - 'success': success
58 - } );
59 - }
60 - );
61 - };
62 -
63 - this.instructor = function( args ) {
64 - var requestArgs = $.extend( {
65 - 'action': 'instructor',
66 - 'format': 'json',
67 - 'token': window.mw.user.tokens.get( 'editToken' )
68 - }, args );
69 -
70 - var deferred = $.Deferred();
71 -
72 - $.post(
73 - wgScriptPath + '/api.php',
74 - requestArgs,
75 - function( data ) {
76 - if ( data.hasOwnProperty( 'success' ) && data.success ) {
77 - deferred.resolve();
78 - }
79 - else {
80 - deferred.reject();
81 - }
82 - }
83 - );
84 -
85 - return deferred.promise();
86 - };
87 -
88 - this.addInstructor = function( args ) {
89 - args.subaction = 'add';
90 - return this.instructor( args );
91 - };
92 -
93 - this.removeInstructor = function( args ) {
94 - args.subaction = 'remove';
95 - return this.instructor( args );
96 - };
97 -
98 - } );
99 -
10069 } );
101 -

Status & tagging log