r88787 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88786‎ | r88787 | r88788 >
Date:13:48, 25 May 2011
Author:janpaul123
Status:ok
Tags:
Comment:
Rewrite of module structure per comments by Krinkle
Modified paths:
  • /trunk/extensions/WikiLove/WikiLove.hooks.php (modified) (history)
  • /trunk/extensions/WikiLove/WikiLove.local.php (added) (history)
  • /trunk/extensions/WikiLove/WikiLove.php (modified) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js (modified) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js (added) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/WikiLove.php
@@ -56,6 +56,7 @@
5757 // add autoload classes
5858 $wgAutoloadClasses['WikiLoveApi'] = $dir . 'WikiLove.api.php';
5959 $wgAutoloadClasses['WikiLoveHooks'] = $dir . 'WikiLove.hooks.php';
 60+$wgAutoloadClasses['WikiLoveLocal'] = $dir . 'WikiLove.local.php';
6061
6162 // i18n messages
6263 $wgExtensionMessagesFiles['WikiLove'] = $dir . 'WikiLove.i18n.php';
@@ -81,7 +82,7 @@
8283 'styles' => 'ext.wikiLove.icon.css',
8384 'position' => 'top',
8485 ),
85 - 'ext.wikiLove' => $extWikiLoveTpl + array(
 86+ 'ext.wikiLove.startup' => $extWikiLoveTpl + array(
8687 'scripts' => array(
8788 'ext.wikiLove.core.js',
8889 'ext.wikiLove.defaultOptions.js',
@@ -119,6 +120,20 @@
120121 'jquery.localize',
121122 ),
122123 ),
 124+ 'ext.wikiLove.local' => array(
 125+ 'class' => 'WikiLoveLocal',
 126+ /* for information only, this is actually in the class!
 127+ 'dependencies' => array(
 128+ 'ext.wikiLove.startup',
 129+ ),
 130+ */
 131+ ),
 132+ 'ext.wikiLove.init' => $extWikiLoveTpl + array(
 133+ 'scripts' => 'ext.wikiLove.init.js',
 134+ 'dependencies' => array(
 135+ 'ext.wikiLove.local',
 136+ ),
 137+ ),
123138 'jquery.elastic' => array(
124139 'localBasePath' => dirname( __FILE__ ) . '/modules/jquery.elastic',
125140 'remoteExtPath' => 'WikiLove/modules/jquery.elastic',
Index: trunk/extensions/WikiLove/WikiLove.hooks.php
@@ -55,7 +55,7 @@
5656 $title = self::getUserTalkPage( $skin->getTitle() );
5757 if ( !is_null( $title ) ) {
5858 $out->addModules( 'ext.wikiLove.icon' );
59 - $out->addModules( 'ext.wikiLove' );
 59+ $out->addModules( 'ext.wikiLove.init' );
6060 }
6161 return true;
6262 }
Index: trunk/extensions/WikiLove/WikiLove.local.php
@@ -0,0 +1,17 @@
 2+<?php
 3+/*
 4+ * Custom ResourceLoader module that loads a custom WikiLove.js per-wiki.
 5+ */
 6+class WikiLoveLocal extends ResourceLoaderWikiModule {
 7+ protected function getPages( ResourceLoaderContext $context ) {
 8+ return array(
 9+ 'MediaWiki:WikiLove.js' => array( 'type' => 'script' ),
 10+ );
 11+ }
 12+
 13+ public function getDependencies() {
 14+ return array(
 15+ 'ext.wikiLove.startup',
 16+ );
 17+ }
 18+}
Property changes on: trunk/extensions/WikiLove/WikiLove.local.php
___________________________________________________________________
Added: svn:eol-style
119 + native
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js
@@ -1,68 +1,80 @@
2 -$.wikiLove.types = {
3 - // example type, could be removed later (also no i18n)
4 - 'barnstar': {
5 - name: 'Barnstar', // name of the type (appears in the types menu)
6 - select: 'Select a barnstar:', // subtype select label
7 - subtypes: { // some different subtypes
8 - // note that when not using subtypes you should use these subtype options
9 - // for the top-level type
10 - 'original': {
11 - fields: [ 'notify' ], // fields to ask for in form
12 - option: 'Original barnstar', // option listed in the select list
13 - descr: 'This barnstar is given to recognize particularly fine contributions to Wikipedia, to let people know that their hard work is seen and appreciated.', // description
14 - header: 'A barnstar for you!', // header that appears at the top of the talk page post (optional)
15 - title: 'The Original Barnstar', // title that appears inside the award box (optional)
16 - image: 'Original Barnstar Hires.png', // image for the award
17 - mail: 'Hello $7!\n\nI just awarded you a barnstar.' // message to use in email notification; $7 is replaced by the recipient's username
 2+$.wikiLove.optionsHook = function() { return {
 3+ defaultText: '{| style="background-color: $5; border: 1px solid $6;"\n\
 4+|rowspan="2" style="vertical-align: middle; padding: 5px;" | [[Image:$3|$4]]\n\
 5+|style="font-size: x-large; padding: 3px; height: 1.5em;" | \'\'\'$2\'\'\'\n\
 6+|-\n\
 7+|style="vertical-align: middle; padding: 3px;" | $1 ~~~~\n\
 8+|}',
 9+ defaultBackgroundColor: '#fdffe7',
 10+ defaultBorderColor: '#fceb92',
 11+ defaultImageSize: '100px',
 12+
 13+ types: {
 14+ // example type, could be removed later (also no i18n)
 15+ 'barnstar': {
 16+ name: 'Barnstar', // name of the type (appears in the types menu)
 17+ select: 'Select a barnstar:', // subtype select label
 18+ subtypes: { // some different subtypes
 19+ // note that when not using subtypes you should use these subtype options
 20+ // for the top-level type
 21+ 'original': {
 22+ fields: [ 'notify' ], // fields to ask for in form
 23+ option: 'Original barnstar', // option listed in the select list
 24+ descr: 'This barnstar is given to recognize particularly fine contributions to Wikipedia, to let people know that their hard work is seen and appreciated.', // description
 25+ header: 'A barnstar for you!', // header that appears at the top of the talk page post (optional)
 26+ title: 'The Original Barnstar', // title that appears inside the award box (optional)
 27+ image: 'Original Barnstar Hires.png', // image for the award
 28+ mail: 'Hello $7!\n\nI just awarded you a barnstar.' // message to use in email notification; $7 is replaced by the recipient's username
 29+ },
 30+ 'editors': {
 31+ fields: [ 'notify' ],
 32+ option: 'Editor\'s barnstar',
 33+ descr: 'The Editor\'s Barnstar is awarded to individuals who display particularly fine decisions in general editing.',
 34+ header: 'A barnstar for you!',
 35+ title: 'The Editor\'s Barnstar',
 36+ image: 'Editors Barnstar Hires.png',
 37+ mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 38+ },
 39+ 'tireless': {
 40+ fields: [ 'title', 'notify' ],
 41+ option: 'Tireless contributor barnstar',
 42+ descr: 'The Tireless Contributor Barnstar is awarded to especially tireless Wikipedians who contribute an especially large body of work without sacrificing quality.',
 43+ header: 'A barnstar for you!',
 44+ title: 'Tireless contributor barnstar',
 45+ image: 'Tireless Contributor Barnstar Hires.gif',
 46+ mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 47+ }
1848 },
19 - 'editors': {
20 - fields: [ 'notify' ],
21 - option: 'Editor\'s barnstar',
22 - descr: 'The Editor\'s Barnstar is awarded to individuals who display particularly fine decisions in general editing.',
23 - header: 'A barnstar for you!',
24 - title: 'The Editor\'s Barnstar',
25 - image: 'Editors Barnstar Hires.png',
26 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
27 - },
28 - 'tireless': {
29 - fields: [ 'title', 'notify' ],
30 - option: 'Tireless contributor barnstar',
31 - descr: 'The Tireless Contributor Barnstar is awarded to especially tireless Wikipedians who contribute an especially large body of work without sacrificing quality.',
32 - header: 'A barnstar for you!',
33 - title: 'Tireless contributor barnstar',
34 - image: 'Tireless Contributor Barnstar Hires.gif',
35 - mail: 'Hello $7!\n\nI just awarded you a barnstar.'
 49+ icon: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/extensions/WikiLove/images/icons/wikilove-icon-barnstar.png' // icon for left-side menu
 50+ },
 51+ 'puppy': {
 52+ name: 'Puppy',
 53+ fields: [ 'header' ],
 54+ header: 'A puppy for you!',
 55+ text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: both"/>', // custom text
 56+ gallery: {
 57+ // right now we can only query the local wiki (not e.g. commons)
 58+ category: 'Category:Puppies',
 59+ total: 100, // total number of pictures to retrieve, and to randomise
 60+ num: 3, // number of pictures to show from the randomised set
 61+ width: 145 // width of each picture in pixels in the interface (not in the template)
3662 }
3763 },
38 - icon: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/extensions/WikiLove/images/icons/wikilove-icon-barnstar.png' // icon for left-side menu
39 - },
40 - 'puppy': {
41 - name: 'Puppy',
42 - fields: [ 'header' ],
43 - header: 'A puppy for you!',
44 - text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: both"/>', // custom text
45 - gallery: {
46 - // right now we can only query the local wiki (not e.g. commons)
47 - category: 'Category:Puppies',
48 - total: 100, // total number of pictures to retrieve, and to randomise
49 - num: 3, // number of pictures to show from the randomised set
50 - width: 145 // width of each picture in pixels in the interface (not in the template)
 64+ 'kitten': {
 65+ name: 'Kitten',
 66+ fields: [ 'header' ],
 67+ header: 'A kitten for you!',
 68+ text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: both"/>', // $3 is the image filename
 69+ gallery: {
 70+ imageList: ['File:Cucciolo gatto Bibo.jpg','File:Kitten (06) by Ron.jpg','File:Kitten-stare.jpg'],
 71+ width: 145
 72+ }
 73+ },
 74+ // default type, nice to leave this one in place when adding other types
 75+ 'makeyourown': {
 76+ name: mw.msg( 'wikilove-type-makeyourown' ),
 77+ fields: [ 'header', 'title', 'image', 'notify' ],
 78+ imageSize: '150px'
5179 }
52 - },
53 - 'kitten': {
54 - name: 'Kitten',
55 - fields: [ 'header' ],
56 - header: 'A kitten for you!',
57 - text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: both"/>', // $3 is the image filename
58 - gallery: {
59 - imageList: ['File:Cucciolo gatto Bibo.jpg','File:Kitten (06) by Ron.jpg','File:Kitten-stare.jpg'],
60 - width: 145
61 - }
62 - },
63 - // default type, nice to leave this one in place when adding other types
64 - 'makeyourown': {
65 - name: mw.msg( 'wikilove-type-makeyourown' ),
66 - fields: [ 'header', 'title', 'image', 'notify' ],
67 - imageSize: '150px'
6880 }
69 -}
\ No newline at end of file
 81+}; };
\ No newline at end of file
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js
@@ -0,0 +1,13 @@
 2+/*
 3+ * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog.
 4+ */
 5+
 6+$.wikiLove.init = function() {
 7+ $.wikiLove.options = $.wikiLove.optionsHook();
 8+ $( '#ca-wikilove a' ).click( function( e ) {
 9+ $.wikiLove.openDialog();
 10+ e.preventDefault();
 11+ });
 12+}
 13+
 14+$( document ).ready( $.wikiLove.init );
Property changes on: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js
___________________________________________________________________
Added: svn:eol-style
115 + native
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -1,5 +1,7 @@
22 ( function( $ ) { $.wikiLove = {
3 -
 3+
 4+ options: {}, // options modifiable by the user
 5+ optionsHook: function() { return {}; }, // hook that can be overridden by the user to modify options
46 $dialog: null, // dialog jQuery object
57 currentTypeId: null, // id of the currently selected type (e.g. 'barnstar' or 'makeyourown')
68 currentSubtypeId: null, // id of the currently selected subtype (e.g. 'original' or 'special')
@@ -7,43 +9,30 @@
810 previewData: null, // data of the currently previewed thing is set here
911 emailable: false,
1012 gallery: {},
11 - defaultText: '{| style="background-color: $5; border: 1px solid $6;"\n\
12 -|rowspan="2" style="vertical-align: middle; padding: 5px;" | [[Image:$3|$4]]\n\
13 -|style="font-size: x-large; padding: 3px; height: 1.5em;" | \'\'\'$2\'\'\'\n\
14 -|-\n\
15 -|style="vertical-align: middle; padding: 3px;" | $1 ~~~~\n\
16 -|}',
17 - defaultBackgroundColor: '#fdffe7',
18 - defaultBorderColor: '#fceb92',
19 - defaultImageSize: '100px',
2013
2114 /*
2215 * Opens the dialog and builds it if necessary.
2316 */
2417 openDialog: function() {
2518 if ( $.wikiLove.$dialog === null ) {
26 - // Load local configuration
27 - var wikiLoveConfigUrl = wgServer + wgScript + '?' + $.param( { 'title': 'MediaWiki:WikiLove.js', 'action': 'raw', 'ctype': 'text/javascript' } );
28 - mw.loader.load( wikiLoveConfigUrl );
29 -
3019 // Test to see if the 'E-mail this user' link exists
3120 $.wikiLove.emailable = $( '#t-emailuser' ).length ? true : false;
3221
3322 // Build a type list like this:
3423 var $typeList = $( '<ul id="mw-wikilove-types"></ul>' );
35 - for( var typeId in $.wikiLove.types ) {
 24+ for( var typeId in $.wikiLove.options.types ) {
3625 var $button = $( '<a href="#"></a>' );
3726 var $buttonInside = $( '<div class="mw-wikilove-inside"></div>' );
3827
39 - if( typeof $.wikiLove.types[typeId].icon == 'string' ) {
 28+ if( typeof $.wikiLove.options.types[typeId].icon == 'string' ) {
4029 $buttonInside.append( '<div class="mw-wikilove-icon-box"><img src="'
41 - + mw.html.escape( $.wikiLove.types[typeId].icon ) + '"/></div>' );
 30+ + mw.html.escape( $.wikiLove.options.types[typeId].icon ) + '"/></div>' );
4231 }
4332 else {
4433 $buttonInside.addClass( 'mw-wikilove-no-icon' );
4534 }
4635
47 - $buttonInside.append( '<div class="mw-wikilove-link-text">' + $.wikiLove.types[typeId].name + '</div>' );
 36+ $buttonInside.append( '<div class="mw-wikilove-link-text">' + $.wikiLove.options.types[typeId].name + '</div>' );
4837
4938 $button.append( '<div class="mw-wikilove-left-cap"></div>');
5039 $button.append( $buttonInside );
@@ -149,14 +138,14 @@
150139 $( '#mw-wikilove-types a' ).removeClass( 'selected' );
151140 $( this ).addClass( 'selected' ); // highlight the new type in the menu
152141
153 - if( typeof $.wikiLove.types[$.wikiLove.currentTypeId].subtypes == 'object' ) {
 142+ if( typeof $.wikiLove.options.types[$.wikiLove.currentTypeId].subtypes == 'object' ) {
154143 // we're dealing with subtypes here
155144 $.wikiLove.currentTypeOrSubtype = null; // reset the (sub)type object until a subtype is selected
156145 $( '#mw-wikilove-subtype' ).html( '' ); // clear the subtype menu
157146
158 - for( var subtypeId in $.wikiLove.types[$.wikiLove.currentTypeId].subtypes ) {
 147+ for( var subtypeId in $.wikiLove.options.types[$.wikiLove.currentTypeId].subtypes ) {
159148 // add all the subtypes to the menu while setting their subtype ids in jQuery data
160 - var subtype = $.wikiLove.types[$.wikiLove.currentTypeId].subtypes[subtypeId];
 149+ var subtype = $.wikiLove.options.types[$.wikiLove.currentTypeId].subtypes[subtypeId];
161150 $( '#mw-wikilove-subtype' ).append(
162151 $( '<option></option>' ).text( subtype.option ).data( 'subtypeId', subtypeId )
163152 );
@@ -164,13 +153,13 @@
165154 $( '#mw-wikilove-subtype' ).show();
166155
167156 // change and show the subtype label depending on the type
168 - $( '#mw-wikilove-subtype-label' ).text( $.wikiLove.types[$.wikiLove.currentTypeId].select || mw.msg( 'wikilove-select-type' ) );
 157+ $( '#mw-wikilove-subtype-label' ).text( $.wikiLove.options.types[$.wikiLove.currentTypeId].select || mw.msg( 'wikilove-select-type' ) );
169158 $( '#mw-wikilove-subtype-label' ).show();
170159 $.wikiLove.changeSubtype(); // update controls depending on the currently selected (i.e. first) subtype
171160 }
172161 else {
173162 // there are no subtypes, just use this type for the current (sub)type
174 - $.wikiLove.currentTypeOrSubtype = $.wikiLove.types[$.wikiLove.currentTypeId];
 163+ $.wikiLove.currentTypeOrSubtype = $.wikiLove.options.types[$.wikiLove.currentTypeId];
175164 $( '#mw-wikilove-subtype' ).hide();
176165 $( '#mw-wikilove-subtype-label' ).hide();
177166 $.wikiLove.updateAllDetails(); // update controls depending on this type
@@ -190,7 +179,7 @@
191180 var newSubtypeId = $( '#mw-wikilove-subtype option:selected' ).first().data( 'subtypeId' );
192181 if( $.wikiLove.currentSubtypeId != newSubtypeId ) { // only change stuff when a different subtype is selected
193182 $.wikiLove.currentSubtypeId = newSubtypeId;
194 - $.wikiLove.currentTypeOrSubtype = $.wikiLove.types[$.wikiLove.currentTypeId]
 183+ $.wikiLove.currentTypeOrSubtype = $.wikiLove.options.types[$.wikiLove.currentTypeId]
195184 .subtypes[$.wikiLove.currentSubtypeId];
196185 $( '#mw-wikilove-subtype-description' ).html( $.wikiLove.currentTypeOrSubtype.descr );
197186 $.wikiLove.updateAllDetails();
@@ -293,7 +282,7 @@
294283 }
295284
296285 var msg = $.wikiLove.prepareMsg(
297 - $.wikiLove.currentTypeOrSubtype.text || $.wikiLove.defaultText,
 286+ $.wikiLove.currentTypeOrSubtype.text || $.wikiLove.options.defaultText,
298287 $.wikiLove.currentTypeOrSubtype.imageSize,
299288 $.wikiLove.currentTypeOrSubtype.backgroundColor,
300289 $.wikiLove.currentTypeOrSubtype.borderColor
@@ -332,9 +321,9 @@
333322 msg = msg.replace( '$2', $( '#mw-wikilove-title' ).val() ); // replace the title
334323 msg = msg.replace( '$3', $( '#mw-wikilove-image' ).val() ); // replace the image
335324
336 - var myImageSize = imageSize || $.wikiLove.defaultImageSize;
337 - var myBackgroundColor = backgroundColor || $.wikiLove.defaultBackgroundColor;
338 - var myBorderColor = borderColor || $.wikiLove.defaultBorderColor;
 325+ var myImageSize = imageSize || $.wikiLove.options.defaultImageSize;
 326+ var myBackgroundColor = backgroundColor || $.wikiLove.options.defaultBackgroundColor;
 327+ var myBorderColor = borderColor || $.wikiLove.options.defaultBorderColor;
339328
340329 msg = msg.replace( '$4', myImageSize ); // replace the image size
341330 msg = msg.replace( '$5', myBackgroundColor ); // replace the background color
@@ -580,17 +569,7 @@
581570 }
582571 });
583572 },
584 -
585 - /*
586 - * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog.
587 - */
588 - init: function() {
589 - $( '#ca-wikilove a' ).click( function( e ) {
590 - $.wikiLove.openDialog();
591 - e.preventDefault();
592 - });
593 - }
594573 };
595 -
596 -$( document ).ready( $.wikiLove.init );
597574 } ) ( jQuery );
 575+
 576+mw.log( 'core loaded' );
\ No newline at end of file

Status & tagging log