From a6fc8f799b26e65648c7027ce2bb804d37893890 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 17 Apr 2006 10:36:21 +0000 Subject: [PATCH] * (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. --- RELEASE-NOTES | 4 +++ includes/EditPage.php | 6 ++--- skins/MonoBook.php | 2 +- skins/common/wikibits.js | 58 +++++++++++++++++++++++++++++++--------- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 00e9e8b961..75c3910b13 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/EditPage.php b/includes/EditPage.php index 102ff66d2d..580d38692b 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1528,9 +1528,9 @@ END 'key' => 'R' ) ); - $toolbar =""; + $toolbar.="\n"; return $toolbar; } diff --git a/skins/MonoBook.php b/skins/MonoBook.php index feef467499..d4c6638519 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -65,7 +65,7 @@ class MonoBookTemplate extends QuickTemplate { - + data['jsvarurl' ]) { ?> diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index b065fef99e..c89d77dd85 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -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(""); - document.write("\""+speedTip+"\""); - document.write(""); - 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 -- 2.20.1