"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", "
", $a[0]);#sometimes
instead of br
#
|i", "
", $a[0]);#sometimes
instead of br
$r = preg_replace("|
|i", "
", $a[0]);#sometimes
instead of br
$r = preg_replace("|
|i", "
", $a[0]);#sometimes
instead of br
# ]*>/','',$tinymcetext);//Remove the start or
# $tinymcetext = preg_replace('/<\/p>/', '".$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("|
', $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("