r13689 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13688‎ | r13689 | r13690 >
Date:10:36, 17 April 2006
Author:brion
Status:old
Tags:
Comment:
* (bug 4663) Edit toolbar enabled in compatible versions of Safari
* (bug 5572) Edit toolbar enabled in compatible versions of Konqueror (3.5+)
* (bug 5235) Edit toolbar tooltips no longer show JavaScript junk in Opera
* Edit toolbar now works in pure XHTML mode (application/xhtml+xml)

The edit toolbar buttons are now created with DOM functions rather than
document.writeln(). This makes it compatible with viewing in XML mode in
strict browsers like Firefox, and additionally allows testing if the
textarea supports the 'selectionStart' property so recent versions of
Safari and Konqueror can get the toolbar automatically enabled.

Information for the toolbar items is stored in globals mwEditButtons and
mwCustomEditButtons; this latter allows MediaWiki:Common.js or similar
to quickly and easily add custom items such as the redirect button currently
on en.wikipedia.org.

Switching from a javascript: link to a straight image with an onclick
handler removes the unsightly javascript url gunk from Opera's tooltip.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -315,26 +315,59 @@
316316 }
317317 }
318318
 319+mwEditButtons = [];
 320+mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js
 321+
319322 // this function generates the actual toolbar buttons with localized text
320323 // we use it to avoid creating the toolbar where javascript is not enabled
321324 function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
322325 // Don't generate buttons for browsers which don't fully
323326 // support it.
324 - if (!document.selection && !is_gecko) {
 327+ mwEditButtons[mwEditButtons.length] =
 328+ {"imageFile": imageFile,
 329+ "speedTip": speedTip,
 330+ "tagOpen": tagOpen,
 331+ "tagClose": tagClose,
 332+ "sampleText": sampleText};
 333+}
 334+
 335+// this function generates the actual toolbar buttons with localized text
 336+// we use it to avoid creating the toolbar where javascript is not enabled
 337+function mwInsertEditButton(parent, item) {
 338+ var image = document.createElement("img");
 339+ image.width = 23;
 340+ image.height = 22;
 341+ image.src = item.imageFile;
 342+ image.border = 0;
 343+ image.alt = item.speedTip;
 344+ image.title = item.speedTip;
 345+ image.style.cursor = "pointer";
 346+ image.onclick = function() {
 347+ insertTags(item.tagOpen, item.tagClose, item.sampleText);
325348 return false;
326349 }
327 - imageFile = escapeQuotesHTML(imageFile);
328 - speedTip = escapeQuotesHTML(speedTip);
329 - tagOpen = escapeQuotes(tagOpen);
330 - tagClose = escapeQuotes(tagClose);
331 - sampleText = escapeQuotes(sampleText);
332 - var mouseOver = "";
 350+
 351+ parent.appendChild(image);
 352+}
333353
334 - document.write("<a href=\"javascript:insertTags");
335 - document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");
336 - document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" alt=\""+speedTip+"\" title=\""+speedTip+"\""+mouseOver+">");
337 - document.write("</a>");
338 - return;
 354+function mwSetupToolbar() {
 355+ var toolbar = document.getElementById('toolbar');
 356+ if (!toolbar) return false;
 357+
 358+ var textbox = document.getElementById('wpTextbox1');
 359+ if (!textbox) return false;
 360+
 361+ // Don't generate buttons for browsers which don't fully
 362+ // support it.
 363+ if (!document.selection && textbox.selectionStart == null)
 364+ return false;
 365+
 366+ for (var i in mwEditButtons) {
 367+ mwInsertEditButton(toolbar, mwEditButtons[i]);
 368+ }
 369+ for (var i in mwCustomEditButtons) {
 370+ mwInsertEditButton(toolbar, mwCustomEditButtons[i]);
 371+ }
339372 }
340373
341374 function escapeQuotes(text) {
@@ -709,3 +742,4 @@
710743 }
711744
712745 hookEvent("load", allmessagesshow);
 746+hookEvent("load", mwSetupToolbar);
\ No newline at end of file
Index: trunk/phase3/skins/MonoBook.php
@@ -65,7 +65,7 @@
6666 <!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js"></script>
6767 <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
6868 <script type="<?php $this->text('jsmimetype') ?>">var skin = '<?php $this->text('skinname')?>';var stylepath = '<?php $this->text('stylepath')?>';</script>
69 - <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js"><!-- wikibits js --></script>
 69+ <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?1"><!-- wikibits js --></script>
7070 <?php if($this->data['jsvarurl' ]) { ?>
7171 <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl' ) ?>"><!-- site js --></script>
7272 <?php } ?>
Index: trunk/phase3/includes/EditPage.php
@@ -1528,9 +1528,9 @@
15291529 'key' => 'R'
15301530 )
15311531 );
1532 - $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
 1532+ $toolbar = "<div id='toolbar'>\n";
 1533+ $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
15331534
1534 - $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
15351535 foreach($toolarray as $tool) {
15361536
15371537 $image=$wgStylePath.'/common/images/'.$tool['image'];
@@ -1549,8 +1549,8 @@
15501550 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
15511551 }
15521552
1553 - $toolbar.="document.writeln(\"</div>\");\n";
15541553 $toolbar.="/*]]>*/\n</script>";
 1554+ $toolbar.="\n</div>";
15551555 return $toolbar;
15561556 }
15571557
Index: trunk/phase3/RELEASE-NOTES
@@ -81,6 +81,10 @@
8282 registrations as well as self-registrations.
8383 * (bug 4327) Report age of cached data sets in query pages
8484 * (bug 4662) Fix Safari check in wikibits.js
 85+* (bug 4663) Edit toolbar enabled in compatible versions of Safari
 86+* (bug 5572) Edit toolbar enabled in compatible versions of Konqueror (3.5+)
 87+* (bug 5235) Edit toolbar tooltips no longer show JavaScript junk in Opera
 88+* Edit toolbar now works in pure XHTML mode (application/xhtml+xml)
8589
8690
8791 == Compatibility ==

Follow-up revisions

RevisionCommit summaryAuthorDate
r69856Fix the function comments. This used to be right until r13689....platonides23:21, 24 July 2010
r69858Update function comments to r13689. This time on trunk.platonides23:30, 24 July 2010

Status & tagging log