Index: trunk/extensions/WikiLove/WikiLove.php |
— | — | @@ -86,14 +86,19 @@ |
87 | 87 | 'wikilove-type-makeyourown', |
88 | 88 | ); |
89 | 89 | |
90 | | -// resources |
91 | | -// it is much better to have a chain like: startup -> default -> local -> init, |
92 | | -// but because of this bug that isn't possible right now: https://bugzilla.wikimedia.org/29608 |
| 90 | +// Because of bug 29608 we can't make a dependancy on a wiki module yet |
| 91 | +// For now using 'using' to load the wiki module from within init. |
93 | 92 | $wgResourceModules += array( |
94 | 93 | 'ext.wikiLove.icon' => $extWikiLoveTpl + array( |
95 | 94 | 'styles' => 'ext.wikiLove.icon.css', |
96 | 95 | 'position' => 'top', |
97 | 96 | ), |
| 97 | + 'ext.wikiLove.defaultOptions' => $extWikiLoveTpl + array( |
| 98 | + 'scripts' => array( |
| 99 | + 'ext.wikiLove.defaultOptions.js', |
| 100 | + ), |
| 101 | + 'messages' => $wgWikiLoveOptionMessages, |
| 102 | + ), |
98 | 103 | 'ext.wikiLove.startup' => $extWikiLoveTpl + array( |
99 | 104 | 'scripts' => array( |
100 | 105 | 'ext.wikiLove.core.js', |
— | — | @@ -136,6 +141,7 @@ |
137 | 142 | 'wikilove-err-send-api', |
138 | 143 | ), |
139 | 144 | 'dependencies' => array( |
| 145 | + 'ext.wikiLove.defaultOptions', |
140 | 146 | 'jquery.ui.dialog', |
141 | 147 | 'jquery.ui.button', |
142 | 148 | 'jquery.localize', |
— | — | @@ -144,17 +150,14 @@ |
145 | 151 | ), |
146 | 152 | 'ext.wikiLove.local' => array( |
147 | 153 | 'class' => 'WikiLoveLocal', |
148 | | - /* for information only, this is actually in the class! |
149 | | - 'messages' => $wgWikiLoveOptionMessages, |
150 | | - 'dependencies' => 'ext.wikiLove.startup' |
151 | | - */ |
152 | 154 | ), |
153 | | - 'ext.wikiLove.defaultOptions' => $extWikiLoveTpl + array( |
| 155 | + 'ext.wikiLove.init' => $extWikiLoveTpl + array( |
154 | 156 | 'scripts' => array( |
155 | | - 'ext.wikiLove.defaultOptions.js', |
| 157 | + 'ext.wikiLove.init.js', |
156 | 158 | ), |
157 | | - 'messages' => $wgWikiLoveOptionMessages, |
158 | | - 'dependencies' => 'ext.wikiLove.startup' |
| 159 | + 'dependencies' => array( |
| 160 | + 'ext.wikiLove.startup', |
| 161 | + ), |
159 | 162 | ), |
160 | 163 | 'jquery.elastic' => array( |
161 | 164 | 'localBasePath' => dirname( __FILE__ ) . '/modules/jquery.elastic', |
Index: trunk/extensions/WikiLove/WikiLove.hooks.php |
— | — | @@ -59,18 +59,7 @@ |
60 | 60 | |
61 | 61 | $title = self::getUserTalkPage( $skin->getTitle() ); |
62 | 62 | if ( !is_null( $title ) ) { |
63 | | - $out->addModules( 'ext.wikiLove.icon' ); |
64 | | - |
65 | | - // it is much better to have a chain like: startup -> default -> local -> init, |
66 | | - // but because of this bug that isn't possible right now: https://bugzilla.wikimedia.org/29608 |
67 | | - $optionsTitle = Title::newFromText( "MediaWiki:WikiLove.js" ); |
68 | | - if( $optionsTitle->exists() && $optionsTitle->isCssOrJsPage() ) { |
69 | | - $out->addModules( 'ext.wikiLove.local' ); |
70 | | - } |
71 | | - else { |
72 | | - $out->addModules( 'ext.wikiLove.defaultOptions' ); |
73 | | - } |
74 | | - |
| 63 | + $out->addModules( array( 'ext.wikiLove.icon', 'ext.wikiLove.init' ) ); |
75 | 64 | self::$recipient = $title->getBaseText(); |
76 | 65 | } |
77 | 66 | return true; |
Index: trunk/extensions/WikiLove/WikiLove.local.php |
— | — | @@ -9,12 +9,6 @@ |
10 | 10 | ); |
11 | 11 | } |
12 | 12 | |
13 | | - public function getDependencies() { |
14 | | - return array( |
15 | | - 'ext.wikiLove.startup', |
16 | | - ); |
17 | | - } |
18 | | - |
19 | 13 | public function getMessages() { |
20 | 14 | global $wgWikiLoveOptionMessages; |
21 | 15 | return $wgWikiLoveOptionMessages; |
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | ( function( $ ) { |
3 | | -$.wikiLoveOptions = function() { return { |
| 3 | +$.wikiLoveOptions = { |
4 | 4 | defaultText: '{| style="background-color: $5; border: 1px solid $6;"\n\ |
5 | 5 | |rowspan="2" style="vertical-align: middle; padding: 5px;" | [[$3|$4]]\n\ |
6 | 6 | |style="font-size: x-large; padding: 3px; height: 1.5em;" | \'\'\'$2\'\'\'\n\ |
— | — | @@ -388,10 +388,6 @@ |
389 | 389 | icon: mw.config.get( 'wgExtensionAssetsPath' ) + '/WikiLove/modules/ext.wikiLove/images/icons/wikilove-icon-create.png' |
390 | 390 | } |
391 | 391 | } |
392 | | -}; }; |
| 392 | +}; |
393 | 393 | |
394 | | -if( typeof $.wikiLove != 'undefined' ) $.wikiLove.init(); // this is required when copying this file to MediaWiki:WikiLove.js |
395 | | -// because of https://bugzilla.wikimedia.org/29608 ; please leave it here as it does no harm being executed in defaultOptions.js |
396 | | -// and it may be confusing if it is required to uncomment it when copying this to MediaWiki:WikiLove.js |
397 | | - |
398 | 394 | } )( jQuery ); |
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js |
— | — | @@ -0,0 +1 @@ |
| 2 | +mw.loader.using( 'ext.wikiLove.local', jQuery.wikiLove.init ); |
Property changes on: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.init.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 3 | + native |
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | ( function( $ ) { |
3 | | -$.wikiLove = (function(){ |
4 | 3 | |
5 | 4 | var options = {}, // options modifiable by the user |
6 | 5 | $dialog = null, // dialog jQuery object |
— | — | @@ -9,8 +8,8 @@ |
10 | 9 | rememberData = null, // input data to remember when switching types or subtypes |
11 | 10 | emailable = false, |
12 | 11 | gallery = {}; |
13 | | - |
14 | | -return { |
| 12 | + |
| 13 | +$.wikiLove = { |
15 | 14 | /* |
16 | 15 | * Opens the dialog and builds it if necessary. |
17 | 16 | */ |
— | — | @@ -85,7 +84,7 @@ |
86 | 85 | <span class="mw-wikilove-note" id="mw-wikilove-image-note"><html:msg key="wikilove-image-example"/></span>\ |
87 | 86 | <input type="text" class="text" id="mw-wikilove-image"/>\ |
88 | 87 | <div id="mw-wikilove-commons-text">\ |
89 | | - ' + mw.msg( 'wikilove-commons-text', '<a href="' + mw.msg( 'wikilove-commons-url' ) +'" target="_blank">' + mw.msg( 'wikilove-commons-link' ) +'</a>' ) + '\ |
| 88 | + ' + mw.msg( 'wikilove-commons-text', '<a href="' + mw.msg( 'wikilove-commons-url' ) + '" target="_blank">' + mw.msg( 'wikilove-commons-link' ) +'</a>' ) + '\ |
90 | 89 | </div>\ |
91 | 90 | <label for="mw-wikilove-message" id="mw-wikilove-message-label"><html:msg key="wikilove-enter-message"/></label>\ |
92 | 91 | <span class="mw-wikilove-note" id="mw-wikilove-message-note"><html:msg key="wikilove-omit-sig"/></span>\ |
— | — | @@ -119,12 +118,21 @@ |
120 | 119 | resizable: false |
121 | 120 | }); |
122 | 121 | |
123 | | - if ( skin == 'vector' ) { |
124 | | - $( '#mw-wikilove-button-preview' ).button( { label: mw.msg( 'wikilove-button-preview' ), icons: { primary:'ui-icon-search' } } ); |
| 122 | + if ( mw.config.get( 'skin' ) == 'vector' ) { |
| 123 | + $( '#mw-wikilove-button-preview' ).button( { |
| 124 | + label: mw.msg( 'wikilove-button-preview' ), |
| 125 | + icons: { |
| 126 | + primary:'ui-icon-search' |
| 127 | + } |
| 128 | + } ); |
125 | 129 | } else { |
126 | | - $( '#mw-wikilove-button-preview' ).button( { label: mw.msg( 'wikilove-button-preview' ) } ); |
| 130 | + $( '#mw-wikilove-button-preview' ).button( { |
| 131 | + label: mw.msg( 'wikilove-button-preview' ) |
| 132 | + } ); |
127 | 133 | } |
128 | | - $( '#mw-wikilove-button-send' ).button( { label: mw.msg( 'wikilove-button-send' ) } ); |
| 134 | + $( '#mw-wikilove-button-send' ).button( { |
| 135 | + label: mw.msg( 'wikilove-button-send' ) |
| 136 | + } ); |
129 | 137 | $( '#mw-wikilove-add-details' ).hide(); |
130 | 138 | $( '#mw-wikilove-preview' ).hide(); |
131 | 139 | $( '#mw-wikilove-types' ).replaceWith( $typeList ); |
— | — | @@ -135,7 +143,9 @@ |
136 | 144 | $( '#mw-wikilove-send-form' ).click( $.wikiLove.submitSend ); |
137 | 145 | $( '#mw-wikilove-message' ).elastic(); // have the message textarea grow automatically |
138 | 146 | |
139 | | - if ( mw.config.get( 'wikilove-anon' ) === 0 ) $( '#mw-wikilove-anon-warning' ).hide(); |
| 147 | + if ( mw.config.get( 'wikilove-anon' ) === 0 ) { |
| 148 | + $( '#mw-wikilove-anon-warning' ).hide(); |
| 149 | + } |
140 | 150 | |
141 | 151 | // When the image changes, we want to reset the preview and error message. |
142 | 152 | $( '#mw-wikilove-image' ).change( function() { |
— | — | @@ -220,31 +230,31 @@ |
221 | 231 | * Remember data the user entered if it is different from the default. |
222 | 232 | */ |
223 | 233 | rememberInputData: function() { |
224 | | - if( rememberData === null) { |
| 234 | + if ( rememberData === null) { |
225 | 235 | rememberData = { |
226 | | - 'header' : '', |
227 | | - 'title' : '', |
228 | | - 'message': '', |
229 | | - 'image' : '', |
| 236 | + header : '', |
| 237 | + title : '', |
| 238 | + message: '', |
| 239 | + image : '' |
230 | 240 | }; |
231 | 241 | } |
232 | | - if( currentTypeOrSubtype !== null ) { |
233 | | - if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && |
| 242 | + if ( currentTypeOrSubtype !== null ) { |
| 243 | + if ( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && |
234 | 244 | ( !currentTypeOrSubtype.header || $( '#mw-wikilove-header' ).val() != currentTypeOrSubtype.header ) ) |
235 | 245 | { |
236 | 246 | rememberData.header = $( '#mw-wikilove-header' ).val(); |
237 | 247 | } |
238 | | - if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 && |
| 248 | + if ( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 && |
239 | 249 | ( !currentTypeOrSubtype.title || $( '#mw-wikilove-title' ).val() != currentTypeOrSubtype.title ) ) |
240 | 250 | { |
241 | 251 | rememberData.title = $( '#mw-wikilove-title' ).val(); |
242 | 252 | } |
243 | | - if( $.inArray( 'message', currentTypeOrSubtype.fields ) >= 0 && |
| 253 | + if ( $.inArray( 'message', currentTypeOrSubtype.fields ) >= 0 && |
244 | 254 | ( !currentTypeOrSubtype.message || $( '#mw-wikilove-message' ).val() != currentTypeOrSubtype.message ) ) |
245 | 255 | { |
246 | 256 | rememberData.message = $( '#mw-wikilove-message' ).val(); |
247 | 257 | } |
248 | | - if( typeof currentTypeOrSubtype.gallery == 'undefined' && $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 && |
| 258 | + if ( currentTypeOrSubtype.gallery === undefined && $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 && |
249 | 259 | ( !currentTypeOrSubtype.image || $( '#mw-wikilove-image' ).val() != currentTypeOrSubtype.image ) ) |
250 | 260 | { |
251 | 261 | rememberData.image = $( '#mw-wikilove-image' ).val(); |
— | — | @@ -263,7 +273,7 @@ |
264 | 274 | 'header' : ( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 ? rememberData.header : '' ), |
265 | 275 | 'title' : ( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 ? rememberData.title : '' ), |
266 | 276 | 'message': ( $.inArray( 'message', currentTypeOrSubtype.fields ) >= 0 ? rememberData.message : '' ), |
267 | | - 'image' : ( $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 ? rememberData.image : '' ), |
| 277 | + 'image' : ( $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 ? rememberData.image : '' ) |
268 | 278 | }; |
269 | 279 | |
270 | 280 | // only show the description if it exists for this type or subtype |
— | — | @@ -328,12 +338,12 @@ |
329 | 339 | $( '#mw-wikilove-dialog' ).find( '.mw-wikilove-error' ).remove(); |
330 | 340 | |
331 | 341 | // Check for a header if it is required |
332 | | - if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-header' ).val().length <= 0 ) { |
| 342 | + if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-header' ).val().length === 0 ) { |
333 | 343 | $.wikiLove.showAddDetailsError( 'wikilove-err-header' ); return false; |
334 | 344 | } |
335 | 345 | |
336 | 346 | // Check for a title if it is required, and otherwise use the header text |
337 | | - if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-title' ).val().length <= 0 ) { |
| 347 | + if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-title' ).val().length === 0 ) { |
338 | 348 | $( '#mw-wikilove-title' ).val( $( '#mw-wikilove-header' ).val() ); |
339 | 349 | } |
340 | 350 | |
— | — | @@ -347,7 +357,7 @@ |
348 | 358 | // Split image validation depending on whether or not it is a gallery |
349 | 359 | if ( typeof currentTypeOrSubtype.gallery == 'undefined' ) { // not a gallery |
350 | 360 | if ( $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 ) { // asks for an image |
351 | | - if ( $( '#mw-wikilove-image' ).val().length <= 0 ) { // no image entered |
| 361 | + if ( $( '#mw-wikilove-image' ).val().length === 0 ) { // no image entered |
352 | 362 | // Give them the default image and continue with preview. |
353 | 363 | $( '#mw-wikilove-image' ).val( options.defaultImage ); |
354 | 364 | $.wikiLove.submitPreview(); |
— | — | @@ -388,7 +398,7 @@ |
389 | 399 | $.wikiLove.submitPreview(); |
390 | 400 | } |
391 | 401 | } else { // a gallery |
392 | | - if ( $( '#mw-wikilove-image' ).val().length <= 0 ) { // no image selected |
| 402 | + if ( $( '#mw-wikilove-image' ).val().length === 0 ) { // no image selected |
393 | 403 | // Display an error telling them to select an image. |
394 | 404 | $.wikiLove.showAddDetailsError( 'wikilove-err-image' ); return false; |
395 | 405 | } else { // image was selected |
— | — | @@ -441,7 +451,11 @@ |
442 | 452 | * Adds a "File:" prefix if there isn't already a media namespace prefix. |
443 | 453 | */ |
444 | 454 | addFilePrefix: function( filename ) { |
445 | | - if ( filename.indexOf( 'File:' ) !== 0 && filename.indexOf( 'Image:' ) !== 0 && filename.indexOf( wgFormattedNamespaces[6] + ':' ) !== 0 ) { |
| 455 | + // Can't use mw.Title in 1.17 |
| 456 | + var prefix = filename.split( ':' )[0] || '', |
| 457 | + normalized = $.trim( prefix ).toLowerCase().replace( /\s/g, '_' ); |
| 458 | + // wgNamespaceIds is missing 'file' in 1.17 on non-English wikis |
| 459 | + if ( mw.config.get( 'wgNamespaceIds' )[normalized] !== 6 && normalized !== 'file' ) { |
446 | 460 | filename = 'File:' + filename; |
447 | 461 | } |
448 | 462 | return filename; |
— | — | @@ -509,12 +523,12 @@ |
510 | 524 | $( '#mw-wikilove-dialog' ).find( '.mw-wikilove-error' ).remove(); |
511 | 525 | |
512 | 526 | // Check for a header if it is required |
513 | | - if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-header' ).val().length <= 0 ) { |
| 527 | + if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-header' ).val().length === 0 ) { |
514 | 528 | $.wikiLove.showAddDetailsError( 'wikilove-err-header' ); return false; |
515 | 529 | } |
516 | 530 | |
517 | 531 | // Check for a title if it is required, and otherwise use the header text |
518 | | - if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-title' ).val().length <= 0 ) { |
| 532 | + if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-title' ).val().length === 0 ) { |
519 | 533 | $( '#mw-wikilove-title' ).val( $( '#mw-wikilove-header' ).val() ); |
520 | 534 | } |
521 | 535 | |
— | — | @@ -689,13 +703,13 @@ |
690 | 704 | * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog. |
691 | 705 | */ |
692 | 706 | init: function() { |
693 | | - if( typeof $.wikiLoveOptions == 'function' ) options = $.wikiLoveOptions(); |
694 | | - |
| 707 | + options = $.wikiLoveOptions; |
| 708 | + |
695 | 709 | var $wikiLoveLink = $( '#ca-wikilove' ).find( 'a' ); |
696 | 710 | $wikiLoveLink.unbind( 'click' ); |
697 | 711 | $wikiLoveLink.click( function( e ) { |
| 712 | + e.preventDefault(); |
698 | 713 | $.wikiLove.openDialog(); |
699 | | - e.preventDefault(); |
700 | 714 | }); |
701 | 715 | } |
702 | 716 | |
— | — | @@ -782,7 +796,7 @@ |
783 | 797 | } |
784 | 798 | } |
785 | 799 | } |
786 | | - if( gallery.length <= 0 ) { |
| 800 | + if( gallery.length === 0 ) { |
787 | 801 | $( '#mw-wikilove-gallery' ).hide(); |
788 | 802 | $( '#mw-wikilove-gallery-label' ).hide(); |
789 | 803 | } |
— | — | @@ -794,7 +808,6 @@ |
795 | 809 | */ |
796 | 810 | }; |
797 | 811 | |
798 | | -}()); |
799 | 812 | |
800 | 813 | $( document ).ready( $.wikiLove.init ); |
801 | 814 | } ) ( jQuery ); |