summaryrefslogtreecommitdiffstats
path: root/extensions/TinyMCE_MW2.php
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/TinyMCE_MW2.php')
-rw-r--r--extensions/TinyMCE_MW2.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/extensions/TinyMCE_MW2.php b/extensions/TinyMCE_MW2.php
new file mode 100644
index 0000000..370eb50
--- /dev/null
+++ b/extensions/TinyMCE_MW2.php
@@ -0,0 +1,99 @@
+<?php
+/*
+TinyMCE_MW2.php - MediaWiki extension - version 0.1
+
+Bret McMillan <bretm@redhat.com>
+Copyright 2008, Red Hat, Inc., All rights reserved.
+
+Rewritten from Joseph Socoloski's original tinymce extension;
+moves logic to the tinymce plugin framework
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+
+
+if( !defined( 'MEDIAWIKI' ) ) {
+ die();
+}
+
+$wgExtensionCredits['other'][] = array(
+
+ "name" => "Next-gen TinyMCE MediaWiki extension",
+ "author" => "Bret McMillan <bretm@redhat.com>",
+ "version" => "0.1",
+ "url" => "http://www.redhat.com/",
+ "description" => "Easily implement Moxiecode's TinyMCE into MediaWiki using the plugin framework, extends Joseph Socoloski's original work"
+ );
+
+# REGISTER HOOKS
+$wgHooks['ArticleAfterFetchContent'][] = 'wfCheckBeforeEdit';
+$wgHooks['EditPage::showEditForm:initial'][] = 'wfTinymceAddScript';
+
+function wfTinymceAddScript ($q) {
+
+ global $wgOut, $wgTitle, $wgScriptPath, $wgMyWikiURL;
+ global $wgTempText, $wgTinymceDir, $wgTinymceTheme, $wgExt_valid_elements, $wgUseTinymce;
+
+ $wgTinymceDir = "tinymce";
+ $ns_allowed = true;
+ $ns = $wgTitle->getNamespace();
+
+ if ($ns_allowed && $wgUseTinymce) {
+ # use the more modern example straight from moxiecode
+ $wgOut->addScript("<script language=\"javascript\" type=\"text/javascript\">
+function toggleEditor(id) {
+ if (!tinyMCE.get(id))
+ tinyMCE.execCommand('mceAddControl', false, id);
+ else
+ tinyMCE.execCommand('mceRemoveControl', false, id);
+}
+</script>");
+
+ $wgOut->addScript( "<script language=\"javascript\" type=\"text/javascript\" src=\"$wgScriptPath/extensions/$wgTinymceDir/jscripts/tiny_mce/tiny_mce.js\"></script><script language=\"javascript\" type=\"text/javascript\">tinyMCE.init({
+ mode : \"textareas\",
+ theme : \"advanced\",
+ plugins : \"mediawiki\",
+ entity_encoding : \"named\",
+ remove_linebreaks : false,
+ convert_newlines_to_brs : false,
+ force_p_newlines : true,
+ force_br_newlines : false,
+ inline_styles : true,
+ convert_fonts_to_spans : true,
+ apply_source_formatting : false,
+ document_base_url : \"$wgMyWikiURL\"});</script>" );
+
+ #Since editing add the button
+ $wgOut->addHTML("<p><a href=\"javascript:toggleEditor('wpTextbox1');\" title=\"toggle wysiwyg editor\">Toggle Visual Editor</a></p>");
+ } else {
+ $wgOut->addScript("<script language=\"javascript\" type=\"text/javascript\"></script>" );
+ $wgUseTinymce = true;
+ }
+ return true;
+}
+
+# Check existing article for any tags we don't want TinyMCE parsing...
+function wfCheckBeforeEdit ($q, $text) {
+ global $wgUseTinymce;
+
+ if (preg_match("|&lt;(data.*?)&gt;(.*?)&lt;/data&gt;|is", $text, $a)) {
+ $wgUseTinymce = false;
+ }
+ elseif(preg_match("|<(data.*?)>(.*?)</data>|is", $text, $a)) {
+ $wgUseTinymce = false;}
+ else{$wgUseTinymce = true;}
+ return true;
+}
+
+?>
+