"TinyMCE MW extension", "author" => "Joseph P. Socoloski III", "version" => "0.5.4", "url" => "http://www.mediawiki.org/wiki/Extension:TinyMCE_MW", "description" => "Easily implement Moxiecode's TinyMCE into MediaWiki" ); # REGISTER HOOKS $wgHooks['ParserBeforeStrip'][] = 'wfTinymceParserCut'; $wgHooks['ParserAfterTidy'][] = 'wfTinymceParserPaste'; $wgHooks['ArticleAfterFetchContent'][] = 'wfCheckBeforeEdit'; $wgHooks['EditPage::showEditForm:initial'][] = 'wfTinymceAddScript'; ##Process the raw wikidb code before any internal processing is applied function wfTinymceParserCut ($q, $text) { global $wgTitle; global $wgTempText, $wgUseTinymce; $ns_allowed = true; $ns = $wgTitle->getNamespace(); #if (in_array($ns, $wgexcludedNamespaces)) $ns_allowed = false; $wgTempText = $text;#get text #$text = ""; return true; } ##Process the wgTempText code (wikitext and html) and reformat it into html friendly $text function wfTinymceParserPaste ($q, $text) { global $wgOut, $wgTitle, $wgParser; global $wgTempText, $wgTinymceToken, $wgUseTinymce; $List = array(); $ns_allowed = true; $ns = $wgTitle->getNamespace(); # TinyMCE can NOT be enabled for any pages that have data tags if ($ns_allowed and $wgUseTinymce) { $tinymcetext = $wgTempText; ## EXTENSION TAGS | ADD HERE ## #Custom tags may ONLY be entered in the regular editor NOT the HTML Source editor #Allow_inputbox_tags while (preg_match("|<inputbox>(.*?)</inputbox>|is", $tinymcetext, $a)) { $r = preg_replace("| |i", "", $a[0]);#erase all the whitespace $r = preg_replace("|

|i", "
", $a[0]);#sometimes

instead of br $r = preg_replace("||i", "\n", $r); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext);#htmlentities() } #Allow_repeat_tags while (preg_match("|<repeat.*?>(.*?)</repeat>|is", $tinymcetext, $a)) { $r = preg_replace("| |i", "", $a[0]);#erase all the whitespace $r = preg_replace("|

|i", "
", $a[0]);#sometimes

instead of br # $r = preg_replace("||i", "\n", $r); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext);#htmlentities() } #Allow_categorytree_tags while (preg_match("|<categorytree.*?>(.*?)</categorytree>|is", $tinymcetext, $a)) { $r = preg_replace("| |i", "", $a[0]);#erase all the whitespace $r = preg_replace("|

|i", "
", $a[0]);#sometimes

instead of br $r = preg_replace("||i", "\n", $r); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext);#htmlentities() } #Allow_includeonlyx_tags while (preg_match("|<includeonly>(.*?)</includeonly>|is", $tinymcetext, $a)) { $r = preg_replace("| |i", "", $a[0]);#erase all the whitespace $r = preg_replace("|

|i", "
", $a[0]);#sometimes

instead of br $r = preg_replace("||i", "\n", $r); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext);#htmlentities() } #Allow_repeat_tags while (preg_match("|<sql2wiki.*?>(.*?)</sql2wiki>|is", $tinymcetext, $a)) { $r = preg_replace("| |i", "", $a[0]);#erase all the whitespace $r = preg_replace("|

|i", "
", $a[0]);#sometimes

instead of br # $r = preg_replace("||i", "\n", $r); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext);#htmlentities() } ## EXTENSION TAGS END ## #Allow_a_tags $i = 0; $ta = md5("aopen"); while (preg_match("|()|i", $tinymcetext, $a)) { $j = $ta."_".md5($i); $List[$j]["content"] = $a[0]; $List[$j]["index"] = $j; $tinymcetext = str_replace($a[0], $j, $tinymcetext); $i++; } $i = 0; $ta = md5("aclose"); while (preg_match("|()|i", $tinymcetext, $a)) { $j = $ta."_".md5($i); $List[$j]["content"] = $a[0]; $List[$j]["index"] = $j; $tinymcetext = str_replace($a[0], $j, $tinymcetext); $i++; } #Allow_img_tags $i = 0; $timg = md5("img"); while (preg_match("|(]*?/>)|i", $tinymcetext, $a)) { $j = $timg."_".md5($i); $List[$j]["content"] = $a[0]; $List[$j]["index"] = $j; $tinymcetext = str_replace($a[0], $j, $tinymcetext); $i++; } ## MEDIAWIKI WIKITEXT HANDLING ## #'''''bold and italic''''' while (preg_match("|'''''.*?'''''|is", $tinymcetext, $a)) { $value = implode(",", $a); $value = str_replace("'''''", "", $value); $r = preg_replace("|'''''.*?'''''|is", "".$value."", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } #'''bold''' while (preg_match("|'''.*?'''|is", $tinymcetext, $a)) { $value = implode(",", $a); $value = str_replace("'''", "", $value); $r = preg_replace("|'''.*?'''|is", "".$value."", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } #''italic'' while (preg_match("|''.*?''|is", $tinymcetext, $a)) { $value = implode(",", $a); $value = str_replace("''", "", $value); $r = preg_replace("|''.*?''|is", "".$value."", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } #=====level 4===== while (preg_match("|=====.*?=====|is", $tinymcetext, $a)) { $value = implode(",", $a); $value = str_replace("=====", "", $value); $r = preg_replace("|=====.*?=====|is", "

".$value."
", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } #====level 3==== while (preg_match("|====.*?====|is", $tinymcetext, $a)) { $value = implode(",", $a); $value = str_replace("====", "", $value); $r = preg_replace("|====.*?====|is", "

".$value."

", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } #===level 2=== while (preg_match("|===.*?===|is", $tinymcetext, $a)) { $value = implode(",", $a); $value = str_replace("===", "", $value); $r = preg_replace("|===.*?===|is", "

".$value."

", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } #==heading== while (preg_match("|==.*?==|is", $tinymcetext, $a)) { $value = implode(",", $a); $value = str_replace("==", "", $value); $r = preg_replace("|==.*?==|is", "

".$value."

", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } #==heading 1== ## Does not support

tags because "|=.*?=|is" grabs too much #---- horizontal line while (preg_match("|----|is", $tinymcetext, $a)) { $r = preg_replace("|----|is", "
", $a[0]); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } ## MEDIAWIKI WIKITEXT HANDLING END ## $tagList = array("pre", "math", "gallery", "nowiki", "html"); foreach($tagList as $tag) { while (preg_match("|<($tag.*?)>(.*?)</$tag>|is", $tinymcetext, $a)) { $r = preg_replace("||i", "", $a[0]); $r = preg_replace("| |i", " ", $r); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } } foreach($q->mTagHooks as $tag => $func) { while (preg_match("|<($tag.*?)>(.*?)</$tag>|is", $tinymcetext, $a)) { $r = preg_replace("||i", "", $a[0]); $r = preg_replace("| |i", " ", $r); $tinymcetext = str_replace($a[0], html_entity_decode($r), $tinymcetext); } } $state = new StripState; $x =& $state; $tinymcetext = $q->strip($tinymcetext, $x); # optional remove

#$tinymcetext = preg_replace('/]*>/','',$tinymcetext);//Remove the start

or

# $tinymcetext = preg_replace('/<\/p>/', '
', $tinymcetext); // Replace the end #$tinymcetext = preg_replace('/<\/p>/', '\n', $tinymcetext); // Replace the end #$tinymcetext = preg_replace("|
|i", "\n", $tinymcetext); $tinymcetext = preg_replace("/<\/?tbody>/i","", $tinymcetext); $tinymcetext = preg_replace("/$wgTinymceToken/i","", $tinymcetext); $tinymcetext = Sanitizer::removeHTMLtags( $tinymcetext, array( &$q, 'attributeStripCallback' ) ); $tinymcetext = $q->replaceVariables($tinymcetext); $tinymcetext = $q->stripToc( $tinymcetext ); $tinymcetext = $q->replaceInternalLinks( $tinymcetext ); $tinymcetext = $q->replaceExternalLinks( $tinymcetext ); $tinymcetext = str_replace($q->mUniqPrefix."NOPARSE", "", $tinymcetext); $tinymcetext = $q->doMagicLinks( $tinymcetext ); $tinymcetext = $q->formatHeadings( $tinymcetext, true ); $q->replaceLinkHolders( $tinymcetext ); $tinymcetext = $q->unstripNoWiki( $tinymcetext, $state ); $tinymcetext = $q->unstrip($tinymcetext, $state); foreach($List as $item) { $tinymcetext = str_replace($item["index"], $item["content"], $tinymcetext); $i++; } $text = $tinymcetext; } return true; } 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) { # following from http://rorlach.de/mediawiki/index.php/Toggle_TinyMCE $wgOut->addScript(""); if (($wgTinymceTheme == "simple")){ $wgOut->addScript( "" ); } elseif(($wgTinymceTheme == "advanced")) { $wgOut->addScript( "" ); }elseif(($wgTinymceTheme == "msword")) { $wgOut->addScript(""); }else{$wgOut->addScript("**TINYMCE NOT ENABLED: FIX wgTinymceTheme**" );} #Since editing add the button $wgOut->addHTML("

Hide Editor

"); } else{$wgOut->addScript("" ); $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("|<(data.*?)>(.*?)</data>|is", $text, $a)) { $wgUseTinymce = false; } elseif(preg_match("|<(data.*?)>(.*?)|is", $text, $a)) { $wgUseTinymce = false;} else{$wgUseTinymce = true;} return true; } ?>