Index: trunk/extensions/WikiLove/WikiLove.hooks.php |
— | — | @@ -56,6 +56,11 @@ |
57 | 57 | if ( !is_null( $title ) ) { |
58 | 58 | $out->addModules( 'ext.wikiLove.icon' ); |
59 | 59 | $out->addModules( 'ext.wikiLove.init' ); |
| 60 | + $out->addInlineScript( |
| 61 | + 'jQuery( document ).ready( function() { |
| 62 | + jQuery.wikiLove.setUsername( ' . FormatJson::encode( $title->getText() ) . ' ); |
| 63 | + } );' |
| 64 | + ); |
60 | 65 | } |
61 | 66 | return true; |
62 | 67 | } |
— | — | @@ -130,10 +135,15 @@ |
131 | 136 | } |
132 | 137 | |
133 | 138 | $ns = $title->getNamespace(); |
134 | | - if ( $ns == NS_USER_TALK && $title->quickUserCan( 'edit' ) ) { |
135 | | - return $title; |
| 139 | + // return quickly if we're in the wrong namespace anyway |
| 140 | + if ( $ns != NS_USER && $ns != NS_USER_TALK ) return null; |
| 141 | + |
| 142 | + $baseTitle = Title::newFromText( $title->getBaseText(), $ns ); |
| 143 | + |
| 144 | + if ( $ns == NS_USER_TALK && $baseTitle->quickUserCan( 'edit' ) ) { |
| 145 | + return $baseTitle; |
136 | 146 | } elseif ( $ns == NS_USER ) { |
137 | | - $talk = $title->getTalkPage(); |
| 147 | + $talk = $baseTitle->getTalkPage(); |
138 | 148 | if ( $talk->quickUserCan( 'edit' ) ) { |
139 | 149 | return $talk; |
140 | 150 | } |
Index: trunk/extensions/WikiLove/WikiLove.api.php |
— | — | @@ -98,7 +98,6 @@ |
99 | 99 | ), |
100 | 100 | 'message' => array( |
101 | 101 | ApiBase::PARAM_TYPE => 'string', |
102 | | - ApiBase::PARAM_REQUIRED => true, |
103 | 102 | ), |
104 | 103 | 'token' => array( |
105 | 104 | ApiBase::PARAM_TYPE => 'string', |
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -8,7 +8,8 @@ |
9 | 9 | currentTypeOrSubtype = null, // content of the current (sub)type (i.e. an object with title, descr, text, etc.) |
10 | 10 | previewData = null, // data of the currently previewed thing is set here |
11 | 11 | emailable = false, |
12 | | - gallery = {}; |
| 12 | + gallery = {}, |
| 13 | + username = ''; |
13 | 14 | |
14 | 15 | return { |
15 | 16 | optionsHook: function() { return {}; }, // hook that can be overridden by the user to modify options |
— | — | @@ -138,7 +139,7 @@ |
139 | 140 | currentTypeId = newTypeId; |
140 | 141 | currentSubtypeId = null; // reset the subtype id |
141 | 142 | |
142 | | - $( '#mw-wikilove-types a' ).removeClass( 'selected' ); |
| 143 | + $( '#mw-wikilove-types' ).find( 'a' ).removeClass( 'selected' ); |
143 | 144 | $( this ).addClass( 'selected' ); // highlight the new type in the menu |
144 | 145 | |
145 | 146 | if( typeof options.types[currentTypeId].subtypes == 'object' ) { |
— | — | @@ -207,51 +208,34 @@ |
208 | 209 | } |
209 | 210 | |
210 | 211 | // show or hide header label and textbox depending on whether a predefined header exists |
211 | | - if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 ) { |
212 | | - $( '#mw-wikilove-header-label').show(); |
213 | | - $( '#mw-wikilove-header' ).show(); |
214 | | - } else { |
215 | | - $( '#mw-wikilove-header-label').hide(); |
216 | | - $( '#mw-wikilove-header' ).hide(); |
217 | | - } |
| 212 | + $( '#mw-wikilove-header, #mw-wikilove-header-label' ) |
| 213 | + .toggle( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 ); |
| 214 | + |
| 215 | + // set the new text for the header textbox |
218 | 216 | $( '#mw-wikilove-header' ).val( currentTypeOrSubtype.header || '' ); |
219 | 217 | |
220 | 218 | // show or hide title label and textbox depending on whether a predefined title exists |
221 | | - if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 ) { |
222 | | - $( '#mw-wikilove-title-label').show(); |
223 | | - $( '#mw-wikilove-title' ).show(); |
224 | | - } else { |
225 | | - $( '#mw-wikilove-title-label').hide(); |
226 | | - $( '#mw-wikilove-title' ).hide(); |
227 | | - } |
| 219 | + $( '#mw-wikilove-title, #mw-wikilove-title-label') |
| 220 | + .toggle( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 ); |
| 221 | + |
| 222 | + // set the new text for the title textbox |
228 | 223 | $( '#mw-wikilove-title' ).val( currentTypeOrSubtype.title || '' ); |
229 | 224 | |
230 | 225 | // show or hide image label and textbox depending on whether a predefined image exists |
231 | | - if( $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 ) { |
232 | | - $( '#mw-wikilove-image-label').show(); |
233 | | - $( '#mw-wikilove-image' ).show(); |
234 | | - } else { |
235 | | - $( '#mw-wikilove-image-label').hide(); |
236 | | - $( '#mw-wikilove-image' ).hide(); |
237 | | - } |
| 226 | + $( '#mw-wikilove-image, #mw-wikilove-image-label') |
| 227 | + .toggle( $.inArray( 'image', currentTypeOrSubtype.fields ) >= 0 ); |
| 228 | + |
| 229 | + // set the new text for the image textbox |
238 | 230 | $( '#mw-wikilove-image' ).val( currentTypeOrSubtype.image || '' ); |
239 | 231 | |
240 | | - if( typeof currentTypeOrSubtype.gallery == 'object' ) { |
241 | | - if( currentTypeOrSubtype.gallery.imageList instanceof Array) { |
242 | | - $( '#mw-wikilove-gallery-label' ).show(); |
243 | | - $( '#mw-wikilove-gallery' ).show(); |
244 | | - $.wikiLove.showGallery(); // build gallery from array of images |
245 | | - } else { |
246 | | - // gallery is a category |
247 | | - // not supported right now |
248 | | - $( '#mw-wikilove-gallery-label' ).hide(); |
249 | | - $( '#mw-wikilove-gallery' ).hide(); |
250 | | - //$.wikiLove.makeGallery(); // build gallery from category |
251 | | - } |
| 232 | + if( typeof currentTypeOrSubtype.gallery == 'object' |
| 233 | + && currentTypeOrSubtype.gallery.imageList instanceof Array |
| 234 | + ) { |
| 235 | + $( '#mw-wikilove-gallery, #mw-wikilove-gallery-label' ).show(); |
| 236 | + $.wikiLove.showGallery(); // build gallery from array of images |
252 | 237 | } |
253 | 238 | else { |
254 | | - $( '#mw-wikilove-gallery-label' ).hide(); |
255 | | - $( '#mw-wikilove-gallery' ).hide(); |
| 239 | + $( '#mw-wikilove-gallery, #mw-wikilove-gallery-label' ).hide(); |
256 | 240 | } |
257 | 241 | |
258 | 242 | if( $.inArray( 'notify', currentTypeOrSubtype.fields ) >= 0 && emailable ) { |
— | — | @@ -298,14 +282,14 @@ |
299 | 283 | $.wikiLove.showError( 'wikilove-err-sig' ); return false; |
300 | 284 | } |
301 | 285 | |
302 | | - var text = prepareMsg( |
| 286 | + var text = $.wikiLove.prepareMsg( |
303 | 287 | currentTypeOrSubtype.text || options.defaultText, |
304 | 288 | currentTypeOrSubtype.imageSize, |
305 | 289 | currentTypeOrSubtype.backgroundColor, |
306 | 290 | currentTypeOrSubtype.borderColor |
307 | 291 | ); |
308 | 292 | |
309 | | - doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + text ); |
| 293 | + $.wikiLove.doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + text ); |
310 | 294 | previewData = { |
311 | 295 | 'header': $( '#mw-wikilove-header' ).val(), |
312 | 296 | 'text': text, |
— | — | @@ -315,7 +299,7 @@ |
316 | 300 | }; |
317 | 301 | |
318 | 302 | if ( $( '#mw-wikilove-notify-checkbox:checked' ).val() && emailable ) { |
319 | | - previewData.email = prepareMsg( currentTypeOrSubtype.email ); |
| 303 | + previewData.email = $.wikiLove.prepareMsg( currentTypeOrSubtype.email ); |
320 | 304 | } |
321 | 305 | }, |
322 | 306 | |
— | — | @@ -347,7 +331,7 @@ |
348 | 332 | msg = msg.replace( '$5', myBackgroundColor ); // replace the background color |
349 | 333 | msg = msg.replace( '$6', myBorderColor ); // replace the border color |
350 | 334 | |
351 | | - msg = msg.replace( '$7', wgTitle ); // replace the username we're sending to |
| 335 | + msg = msg.replace( '$7', username ); // replace the username we're sending to |
352 | 336 | |
353 | 337 | return msg; |
354 | 338 | }, |
— | — | @@ -358,7 +342,7 @@ |
359 | 343 | doPreview: function( wikitext ) { |
360 | 344 | $( '#mw-wikilove-preview-spinner' ).fadeIn( 200 ); |
361 | 345 | $.ajax({ |
362 | | - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?', |
| 346 | + url: mw.util.wikiScript( 'api' ), |
363 | 347 | data: { |
364 | 348 | 'action': 'parse', |
365 | 349 | 'format': 'json', |
— | — | @@ -416,7 +400,7 @@ |
417 | 401 | } |
418 | 402 | |
419 | 403 | $.ajax({ |
420 | | - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?', |
| 404 | + url: mw.util.wikiScript( 'api' ), |
421 | 405 | data: sendData, |
422 | 406 | dataType: 'json', |
423 | 407 | type: 'POST', |
— | — | @@ -472,7 +456,7 @@ |
473 | 457 | |
474 | 458 | var index = 0; |
475 | 459 | $.ajax({ |
476 | | - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php', |
| 460 | + url: mw.util.wikiScript( 'api' ), |
477 | 461 | data: { |
478 | 462 | 'action' : 'query', |
479 | 463 | 'format' : 'json', |
— | — | @@ -517,14 +501,21 @@ |
518 | 502 | }, |
519 | 503 | |
520 | 504 | /* |
521 | | - * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog. |
522 | | - */ |
| 505 | + * Init function which is called upon page load. Binds the WikiLove icon to opening the dialog. |
| 506 | + */ |
523 | 507 | init: function() { |
524 | 508 | options = $.wikiLove.optionsHook(); |
525 | | - $( '#ca-wikilove a' ).click( function( e ) { |
| 509 | + $( '#ca-wikilove' ).find( 'a' ).click( function( e ) { |
526 | 510 | $.wikiLove.openDialog(); |
527 | 511 | e.preventDefault(); |
528 | 512 | }); |
| 513 | + }, |
| 514 | + |
| 515 | + /* |
| 516 | + * Public function to set the username by finding the base title server-side. |
| 517 | + */ |
| 518 | + setUsername: function( name ) { |
| 519 | + username = name; |
529 | 520 | } |
530 | 521 | |
531 | 522 | /* |
— | — | @@ -544,7 +535,7 @@ |
545 | 536 | $( '#mw-wikilove-gallery-spinner' ).fadeIn( 200 ); |
546 | 537 | |
547 | 538 | $.ajax({ |
548 | | - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php', |
| 539 | + url: mw.util.wikiScript( 'api' ), |
549 | 540 | data: { |
550 | 541 | 'action' : 'query', |
551 | 542 | 'format' : 'json', |