r82308 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82307‎ | r82308 | r82309 >
Date:23:05, 16 February 2011
Author:mah
Status:resolved (Comments)
Tags:
Comment:
(Bug #27447) Added option to toolbar-item to switch off text-selection

Carsten Nielsen explains:

A client of mine was a bit annoyed by the editor:
Every time he inserted - lets say - an image, the default contents of the
image-fields "thumbs|width|caption...." were automatically marked/selected. So
with a tip on the keyboard all "helping" text was gone.

I added an option to the toolbar-items to optional deactivate this behaviour.
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/skins/common/edit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/edit.js
@@ -1,7 +1,7 @@
22 window.currentFocused = undefined;
33
44 // this function adds a toolbar button to the mwEditButtons list
5 -window.addButton = function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId ) {
 5+window.addButton = function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
66 // Don't generate buttons for browsers which don't fully
77 // support it.
88 mwEditButtons.push({
@@ -10,7 +10,8 @@
1111 'speedTip': speedTip,
1212 'tagOpen': tagOpen,
1313 'tagClose': tagClose,
14 - 'sampleText': sampleText
 14+ 'sampleText': sampleText,
 15+ 'selectText': selectText
1516 });
1617 };
1718
@@ -29,7 +30,7 @@
3031 image.title = item.speedTip;
3132 image.style.cursor = 'pointer';
3233 image.onclick = function() {
33 - insertTags( item.tagOpen, item.tagClose, item.sampleText );
 34+ insertTags( item.tagOpen, item.tagClose, item.sampleText, item.selectText );
3435 // click tracking
3536 if ( ( typeof $ != 'undefined' ) && ( typeof $.trackAction != 'undefined' ) ) {
3637 $.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, "-") );
@@ -77,7 +78,7 @@
7879
7980 // apply tagOpen/tagClose to selection in textarea,
8081 // use sampleText instead of selection if there is none
81 -window.insertTags = function( tagOpen, tagClose, sampleText ) {
 82+window.insertTags = function( tagOpen, tagClose, sampleText, selectText) {
8283 if ( typeof $ != 'undefined' && typeof $.fn.textSelection != 'undefined' && currentFocused &&
8384 ( currentFocused.nodeName.toLowerCase() == 'iframe' || currentFocused.id == 'wpTextbox1' ) ) {
8485 $( '#wpTextbox1' ).textSelection(
@@ -109,15 +110,17 @@
110111 // insert tags
111112 checkSelectedText();
112113 range.text = tagOpen + selText + tagClose;
113 - // mark sample text as selected
114 - if ( isSample && range.moveStart ) {
115 - if ( window.opera ) {
116 - tagClose = tagClose.replace(/\n/g,'');
 114+ // mark sample text as selected if not switched off by option
 115+ if ( selectText !== false ) {
 116+ if ( isSample && range.moveStart ) {
 117+ if ( window.opera ) {
 118+ tagClose = tagClose.replace(/\n/g,'');
 119+ }
 120+ range.moveStart('character', - tagClose.length - selText.length);
 121+ range.moveEnd('character', - tagClose.length);
117122 }
118 - range.moveStart('character', - tagClose.length - selText.length);
119 - range.moveEnd('character', - tagClose.length);
 123+ range.select();
120124 }
121 - range.select();
122125 // restore window scroll position
123126 if ( document.documentElement && document.documentElement.scrollTop ) {
124127 document.documentElement.scrollTop = winScroll;
@@ -139,7 +142,7 @@
140143 + tagOpen + selText + tagClose
141144 + txtarea.value.substring(endPos, txtarea.value.length);
142145 // set new selection
143 - if ( isSample ) {
 146+ if ( isSample && ( selectText !== false )) {
144147 txtarea.selectionStart = startPos + tagOpen.length;
145148 txtarea.selectionEnd = startPos + tagOpen.length + selText.length;
146149 } else {
Index: trunk/phase3/includes/EditPage.php
@@ -2387,6 +2387,7 @@
23882388 $close = $tool['close'],
23892389 $sample = $tool['sample'],
23902390 $cssId = $tool['id'],
 2391+ $select = $tool['select'],
23912392 );
23922393
23932394 $paramList = implode( ',',

Sign-offs

UserFlagDate
Krinkleinspected00:21, 2 March 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r82328Rv part of r82308 that causes warningsnikerabbit10:12, 17 February 2011
r82343Followup bug #27447 and r82308 and r82328 with patch supplied by...mah18:41, 17 February 2011

Comments

#Comment by Reedy (talk | contribs)   23:31, 16 February 2011

Notice: Undefined index: select in /home/reedy/mediawiki/trunk/phase3/includes/EditPage.php on line 2390

Status & tagging log