r86942 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86941‎ | r86942 | r86943 >
Date:10:08, 26 April 2011
Author:diebuche
Status:resolved (Comments)
Tags:
Comment:
Followup to r86603 per Bug 28681 : Create public array mw.toolbar.buttons. User scripts can modify it, until it's written to the DOM on doc.ready
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js
@@ -4,7 +4,13 @@
55
66 mw.toolbar = {
77 $toolbar : $( '#toolbar' ),
8 - addButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
 8+ buttons : [],
 9+ // If you want to add buttons, use
 10+ // mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText );
 11+ addButton : function() {
 12+ this.buttons.push( [].slice.call( arguments ) );
 13+ },
 14+ insertButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
915 var image = $('<img>', {
1016 width : 23,
1117 height : 23,
@@ -29,18 +35,21 @@
3036 currentFocused.textSelection(
3137 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
3238 );
33 - return;
3439 }
3540 },
3641 init : function() {
3742 // Legacy
38 - // Print out buttons from mwCustomEditButtons
39 - // If you want to add buttons, use
40 - // $( document ).ready( function () { mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) } );
41 - var c;
42 - for ( var i = 0; i < window.mwCustomEditButtons.length; i++ ) {
43 - c = window.mwCustomEditButtons[i];
44 - mw.toolbar.addButton( c.imageFile, c.speedTip, c.tagOpen, c.tagClose, c.sampleText, c.imageId, c.selectText );
 43+ // Merge buttons from mwCustomEditButtons
 44+ var buttons = [].concat( this.buttons, window.mwCustomEditButtons );
 45+ for ( var i = 0; i < buttons.length; i++ ) {
 46+ if ( buttons[i] instanceof Array ) {
 47+ // Passes our button array as arguments
 48+ mw.toolbar.insertButton.apply( this, buttons[i] );
 49+ } else {
 50+ // Legacy mwCustomEditButtons is an object
 51+ var c = buttons[i];
 52+ mw.toolbar.insertButton( c.imageFile, c.speedTip, c.tagOpen, c.tagClose, c.sampleText, c.imageId, c.selectText );
 53+ }
4554 }
4655 return true;
4756 }
@@ -72,7 +81,10 @@
7382 }
7483 };
7584 scrollEditBox();
76 -
 85+
 86+ // Create button bar
 87+ mw.toolbar.init();
 88+
7789 $( '#wpSummary, #wpTextbox1' ).focus( function() {
7890 currentFocused = $(this);
7991 });
Index: trunk/phase3/includes/EditPage.php
@@ -2414,9 +2414,8 @@
24152415 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
24162416 $script .= "mw.toolbar.addButton($paramList);\n";
24172417 }
2418 - $script .= "mw.toolbar.init();\n";
24192418 $wgOut->addScript( Html::inlineScript(
2420 - "if ( window.mediaWiki ) { jQuery(function(){{$script}}); }"
 2419+ "if ( window.mediaWiki ) {{$script}}"
24212420 ) );
24222421
24232422 $toolbar .= "\n</div>";

Follow-up revisions

RevisionCommit summaryAuthorDate
r90083Followup to r86942 per CR comments: instanceof Array -> $.isArray (safer, mor...brion20:55, 14 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86603Move edit.js stuff to mediawiki.action.edit.js, and remove wikibits dependenc...diebuche08:19, 21 April 2011

Comments

#Comment by Krinkle (talk | contribs)   03:34, 29 May 2011
+				if ( buttons[i] instanceof Array ) {

This doesn't work cross-browser, use $.isArray instead. The rest looks OK.

#Comment by Brion VIBBER (talk | contribs)   20:56, 14 June 2011

Fixed in r90083.

Status & tagging log