r86603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86602‎ | r86603 | r86604 >
Date:08:19, 21 April 2011
Author:diebuche
Status:ok (Comments)
Tags:
Comment:
Move edit.js stuff to mediawiki.action.edit.js, and remove wikibits dependency. Wrap publicly accessible functions inside mw.toolbar & provide legacy shortcuts to those. Make the traditional toolbar use $.fn.textSelection, to reduce code duplication. This fixes Bug 27116, Bug 15705, Bug 11011
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/jquery/jquery.textSelection.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js (modified) (history)
  • /trunk/phase3/skins/common/edit.js (modified) (history)
  • /trunk/phase3/skins/common/shared.css (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/shared.css
@@ -40,7 +40,9 @@
4141 #editform, #toolbar, #wpTextbox1 {
4242 clear: both;
4343 }
44 -
 44+#toolbar img {
 45+ cursor: pointer;
 46+}
4547 div#mw-js-message {
4648 margin: 1em 5%;
4749 padding: 0.5em 2.5%;
Index: trunk/phase3/skins/common/edit.js
@@ -1,3 +1,7 @@
 2+// This file is still referenced from
 3+// tests/selenium/data/SimpleSeleniumTestDB.sql
 4+// includes/specials/SpecialUpload.php
 5+// /extensions/SemanticForms/specials/SF_UploadWindow2.php
26 window.currentFocused = undefined;
37
48 // this function adds a toolbar button to the mwEditButtons list
Index: trunk/phase3/includes/EditPage.php
@@ -373,7 +373,7 @@
374374 $this->preview = true;
375375 }
376376
377 - $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.action.edit' ) );
 377+ $wgOut->addModules( array( 'mediawiki.action.edit' ) );
378378
379379 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
380380 $wgOut->addModules( 'mediawiki.legacy.preview' );
@@ -2410,9 +2410,9 @@
24112411
24122412 $paramList = implode( ',',
24132413 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2414 - $script .= "addButton($paramList);\n";
 2414+ $script .= "mw.toolbar.addButton($paramList);\n";
24152415 }
2416 -
 2416+ $script .= "mw.toolbar.init();\n";
24172417 $wgOut->addScript( Html::inlineScript(
24182418 "if ( window.mediaWiki ) { jQuery(function(){{$script}}); }"
24192419 ) );
Index: trunk/phase3/resources/jquery/jquery.textSelection.js
@@ -62,10 +62,17 @@
6363 isSample = true;
6464 } else if ( options.replace ) {
6565 selText = options.peri;
66 - } else if ( selText.charAt( selText.length - 1 ) == ' ' ) {
67 - // Exclude ending space char
68 - selText = selText.substring(0, selText.length - 1);
69 - options.post += ' ';
 66+ } else {
 67+ while ( selText.charAt( selText.length - 1 ) == ' ' ) {
 68+ // Exclude ending space char
 69+ selText = selText.substring(0, selText.length - 1);
 70+ options.post += ' ';
 71+ }
 72+ while ( selText.charAt( 0 ) == ' ' ) {
 73+ // Exclude prepending space char
 74+ selText = selText.substring(1, selText.length);
 75+ options.pre = ' ' + options.pre;
 76+ }
7077 }
7178 }
7279 var isSample = false;
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js
@@ -1,14 +1,61 @@
2 -/* Note, there is still stuff in skins/common/edit.js that
3 - * has not been jQuery-ized.
4 - */
 2+(function( $ ) {
 3+ // currentFocus is used to determine where to insert tags
 4+ var currentFocused = $( '#wpTextbox1' );
 5+
 6+ mw.toolbar = {
 7+ $toolbar : $( '#toolbar' ),
 8+ addButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
 9+ var image = $('<img>', {
 10+ width : 23,
 11+ height : 23,
 12+ src : imageFile,
 13+ alt : speedTip,
 14+ title : speedTip,
 15+ id : imageId || '',
 16+ 'class': 'mw-toolbar-editbutton'
 17+ } ).click( function() {
 18+ mw.toolbar.insertTags( tagOpen, tagClose, sampleText, selectText );
 19+ return false;
 20+ } );
521
6 -(function( $ ) {
 22+ this.$toolbar.append( image );
 23+ return true;
 24+ },
 25+
 26+ // apply tagOpen/tagClose to selection in textarea,
 27+ // use sampleText instead of selection if there is none
 28+ insertTags : function( tagOpen, tagClose, sampleText, selectText) {
 29+ if ( currentFocused.length ) {
 30+ currentFocused.textSelection(
 31+ 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
 32+ );
 33+ return;
 34+ }
 35+ },
 36+ init : function() {
 37+ // 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 ( 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 );
 45+ }
 46+ return true;
 47+ }
 48+ };
 49+
 50+ //Legacy
 51+ window.addButton = mw.toolbar.addButton;
 52+ window.insertTags = mw.toolbar.insertTags;
 53+
754 //make sure edit summary does not exceed byte limit
855 $( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function( e ) {
956 // first check to see if this is actually a character key
1057 // being pressed.
1158 // Based on key-event info from http://unixpapa.com/js/key.html
12 - // JQuery should also normalize e.which to be consistent cross-browser,
 59+ // jQuery should also normalize e.which to be consistent cross-browser,
1360 // however the same check is still needed regardless of jQuery.
1461
1562 // Note: At the moment, for some older opera versions (~< 10.5)
@@ -33,4 +80,39 @@
3481 e.preventDefault();
3582 }
3683 });
 84+
 85+
 86+ $( document ).ready( function() {
 87+ /**
 88+ * Restore the edit box scroll state following a preview operation,
 89+ * and set up a form submission handler to remember this state
 90+ */
 91+ var scrollEditBox = function() {
 92+ var editBox = document.getElementById( 'wpTextbox1' );
 93+ var scrollTop = document.getElementById( 'wpScrolltop' );
 94+ var $editForm = $( '#editform' );
 95+ if( $editForm.length && editBox && scrollTop ) {
 96+ if( scrollTop.value ) {
 97+ editBox.scrollTop = scrollTop.value;
 98+ }
 99+ $editForm.submit( function() {
 100+ scrollTop.value = editBox.scrollTop;
 101+ });
 102+ }
 103+ };
 104+ scrollEditBox();
 105+
 106+ $( '#wpSummary, #wpTextbox1' ).focus( function() {
 107+ currentFocused = $(this);
 108+ });
 109+
 110+ // HACK: make currentFocused work with the usability iframe
 111+ // With proper focus detection support (HTML 5!) this'll be much cleaner
 112+ var iframe = $( '.wikiEditor-ui-text iframe' );
 113+ if ( iframe.length > 0 ) {
 114+ $( iframe.get( 0 ).contentWindow.document )
 115+ .add( iframe.get( 0 ).contentWindow.document.body ) // for IE
 116+ .focus( function() { currentFocused = iframe; } );
 117+ }
 118+ });
37119 })(jQuery);
Index: trunk/phase3/resources/Resources.php
@@ -412,6 +412,7 @@
413413 ),
414414 'mediawiki.action.edit' => array(
415415 'scripts' => 'resources/mediawiki.action/mediawiki.action.edit.js',
 416+ 'dependencies' => 'jquery.textSelection',
416417 ),
417418 'mediawiki.action.view.rightClickEdit' => array(
418419 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js',

Sign-offs

UserFlagDate
Catropeinspected08:48, 21 April 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r86608Followup to 86603 per CR: Fix var declaration of idiebuche09:03, 21 April 2011
r86942Followup to r86603 per Bug 28681 : Create public array mw.toolbar.buttons. Us...diebuche10:08, 26 April 2011
r91749r86603 : Updating module name of mediawiki.legacy.edit in SemanticForms Exten...diebuche18:58, 8 July 2011
r91750r86603 : Updatin last call to mediawiki.legacy.edit and removing the modulediebuche19:01, 8 July 2011
r101990Fixes Bug #31722 — “ugly old toolbar icons - height inconsistent” —...mah13:21, 4 November 2011

Comments

#Comment by Catrope (talk | contribs)   08:47, 21 April 2011
+			for ( i = 0; i < window.mwCustomEditButtons.length; i++ ) {

i is leaked into the global scope. Use for ( var i = 0; ....

#Comment by Catrope (talk | contribs)   09:53, 25 April 2011

bug 28681 was reported against this rev

#Comment by TheDJ (talk | contribs)   19:21, 22 October 2011

This changes the size of the old edit toolbar images from 23x22 to 23x23. Was there a specific need for that change ?

#Comment by DieBuche (talk | contribs)   21:34, 3 November 2011

Looks like an accident. Could you do a commit, I'm not at home.

#Comment by MarkAHershberger (talk | contribs)   04:34, 9 November 2011

Status & tagging log