* (bug 4663) Edit toolbar enabled in compatible versions of Safari
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 17 Apr 2006 10:36:21 +0000 (10:36 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 17 Apr 2006 10:36:21 +0000 (10:36 +0000)
* (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.

RELEASE-NOTES
includes/EditPage.php
skins/MonoBook.php
skins/common/wikibits.js

index 00e9e8b..75c3910 100644 (file)
@@ -81,6 +81,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   registrations as well as self-registrations.
 * (bug 4327) Report age of cached data sets in query pages
 * (bug 4662) Fix Safari check in wikibits.js
+* (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)
 
 
 == Compatibility ==
index 102ff66..580d386 100644 (file)
@@ -1528,9 +1528,9 @@ END
                                        'key'   =>      'R'
                                )
                );
-               $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
+               $toolbar = "<div id='toolbar'>\n";
+               $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
 
-               $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
                foreach($toolarray as $tool) {
 
                        $image=$wgStylePath.'/common/images/'.$tool['image'];
@@ -1549,8 +1549,8 @@ END
                        $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
                }
 
-               $toolbar.="document.writeln(\"</div>\");\n";
                $toolbar.="/*]]>*/\n</script>";
+               $toolbar.="\n</div>";
                return $toolbar;
        }
 
index feef467..d4c6638 100644 (file)
@@ -65,7 +65,7 @@ class MonoBookTemplate extends QuickTemplate {
                <!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js"></script>
                <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
                <script type="<?php $this->text('jsmimetype') ?>">var skin = '<?php $this->text('skinname')?>';var stylepath = '<?php $this->text('stylepath')?>';</script>
-               <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js"><!-- wikibits js --></script>
+               <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?1"><!-- wikibits js --></script>
 <?php  if($this->data['jsvarurl'  ]) { ?>
                <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl'  ) ?>"><!-- site js --></script>
 <?php  } ?>
index b065fef..c89d77d 100644 (file)
@@ -315,26 +315,59 @@ function toggleToc() {
        }
 }
 
+mwEditButtons = [];
+mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js
+
 // this function generates the actual toolbar buttons with localized text
 // we use it to avoid creating the toolbar where javascript is not enabled
 function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
        // Don't generate buttons for browsers which don't fully
        // support it.
-       if (!document.selection && !is_gecko) {
+       mwEditButtons[mwEditButtons.length] =
+               {"imageFile": imageFile,
+                "speedTip": speedTip,
+                "tagOpen": tagOpen,
+                "tagClose": tagClose,
+                "sampleText": sampleText};
+}
+
+// this function generates the actual toolbar buttons with localized text
+// we use it to avoid creating the toolbar where javascript is not enabled
+function mwInsertEditButton(parent, item) {
+       var image = document.createElement("img");
+       image.width = 23;
+       image.height = 22;
+       image.src = item.imageFile;
+       image.border = 0;
+       image.alt = item.speedTip;
+       image.title = item.speedTip;
+       image.style.cursor = "pointer";
+       image.onclick = function() {
+               insertTags(item.tagOpen, item.tagClose, item.sampleText);
                return false;
        }
-       imageFile = escapeQuotesHTML(imageFile);
-       speedTip = escapeQuotesHTML(speedTip);
-       tagOpen = escapeQuotes(tagOpen);
-       tagClose = escapeQuotes(tagClose);
-       sampleText = escapeQuotes(sampleText);
-       var mouseOver = "";
+       
+       parent.appendChild(image);
+}
 
-       document.write("<a href=\"javascript:insertTags");
-       document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");
-       document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" alt=\""+speedTip+"\" title=\""+speedTip+"\""+mouseOver+">");
-       document.write("</a>");
-       return;
+function mwSetupToolbar() {
+       var toolbar = document.getElementById('toolbar');
+       if (!toolbar) return false;
+
+       var textbox = document.getElementById('wpTextbox1');
+       if (!textbox) return false;
+       
+       // Don't generate buttons for browsers which don't fully
+       // support it.
+       if (!document.selection && textbox.selectionStart == null)
+               return false;
+       
+       for (var i in mwEditButtons) {
+               mwInsertEditButton(toolbar, mwEditButtons[i]);
+       }
+       for (var i in mwCustomEditButtons) {
+               mwInsertEditButton(toolbar, mwCustomEditButtons[i]);
+       }
 }
 
 function escapeQuotes(text) {
@@ -709,3 +742,4 @@ function allmessagesshow() {
 }
 
 hookEvent("load", allmessagesshow);
+hookEvent("load", mwSetupToolbar);
\ No newline at end of file