allwiki首页  
天下维客 你可以修改的网络知识库
首页最近更改优秀条目专题展示电脑科技词典软件学习网络知识电脑安全明星时尚天下百科
 

FCKeditor/extension

天下维客,你可以修改的网络知识库

Jump to: navigation, search

<?php

/* 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" => "fckeditor extension",
       "author" => "Mafs",
       "version" => "fck/mw-extension May 2006",
       "url" => "http://meta.wikimedia.org/wiki/FCKeditor",
       "description" => "integrating the fckeditor"
);


  1. REGISTER HOOKS

$wgHooks['ParserBeforeStrip'][] = 'wfFCKeditorBypassParserCut'; $wgHooks['ParserAfterTidy'][] = 'wfFCKeditorBypassParserPaste'; $wgHooks['ArticleAfterFetchContent'][] = 'wfFCKeditorCheck'; $wgHooks['EditPage::showEditForm:initial'][] = 'wfFCKeditorAddFCKScript';


function wfFCKeditorAddFCKScript ($q) {

       global $wgOut, $wgTitle, $wgScriptPath;
       global $wgFCKexcludedNamespaces, $wgFCKUseEditor, $wgFCKEditorToolbarSet; 
       global $wgFCKEditorDir, $wgFCKEditorHeight;
       $ns_allowed = true;
       $ns = $wgTitle->getNamespace();
       if (in_array($ns, $wgFCKexcludedNamespaces)) $ns_allowed = false;
       
       if ($ns_allowed and $wgFCKUseEditor) {
               $wgOut->addScript( "<script type=\"text/javascript\" src=\"$wgScriptPath/$wgFCKEditorDir/fckeditor.js\"></script>\n" );
               
               $wgOut->addScript("<script type=\"text/javascript\"> function onLoadFCK () { var oFCKeditor = new FCKeditor('wpTextbox1') ; oFCKeditor.BasePath = \"$wgScriptPath/$wgFCKEditorDir/\" ; if (document.getElementById(\"wpTextbox1\")) {oFCKeditor.Height = \"$wgFCKEditorHeight\" ; oFCKeditor.ToolbarSet = \"$wgFCKEditorToolbarSet\" ; oFCKeditor.ReplaceTextarea() ; var oDiv=document.getElementById(\"toolbar\"); oDiv.style.cssText = 'display: none;'; }} addOnloadHook(onLoadFCK); </script>\n");
       }

}

function wfFCKeditorCheck ($q, $text) {

       global $wgFCKUseEditor, $wgFCKEditorToken;
       
       if (preg_match("/$wgFCKEditorToken/i", $text, $a)) {
               $wgFCKUseEditor = true;
       }

}


function wfFCKeditorBypassParserCut ($q, $text) {

       global $wgFCKexcludedNamespaces, $wgFCKUseEditor, $wgTitle;
       global $wgFCKBypassText, $wgFCKEditorToken;
       
       $ns_allowed = true;
       $ns = $wgTitle->getNamespace();
       
       if (in_array($ns, $wgFCKexcludedNamespaces)) $ns_allowed = false;
       
       if ($ns_allowed and $wgFCKUseEditor) {
               
               $wgFCKBypassText = $text;
               $text = "";
       }

}


function wfFCKeditorBypassParserPaste ($q, $text) {

       global $wgOut, $wgTitle, $wgParser;
       global $wgFCKexcludedNamespaces, $wgFCKEditorHeight, $wgFCKEditorToolbarSet, $wgFCKUseEditor;
       global $wgFCKBypassText, $wgFCKEditorToken, $wgFCKEditorAllow_a_tags, $wgFCKEditorAllow_img_tags;
       
       $List   = array();
       
       $ns_allowed = true;
       $ns = $wgTitle->getNamespace();
       if (in_array($ns, $wgFCKexcludedNamespaces)) $ns_allowed = false;
       
       if ($ns_allowed and $wgFCKUseEditor) {
       
               $fcktext = $wgFCKBypassText; 
       
               $fcktext = $q->replaceVariables($fcktext);
               
               if ($wgFCKEditorAllow_a_tags) {
                       $i = 0;
                       $ta = md5("aopen");
                       while (preg_match("|(<a.*?>)|i", $fcktext, $a)) {
                               $j = $ta."_".md5($i);
                               $List[$j]["content"] = $a[0];
                               $List[$j]["index"] = $j;
                               $fcktext = str_replace($a[0], $j, $fcktext);
                               $i++;
                       }
                       $i = 0;
                       $ta = md5("aclose");
                       while (preg_match("|(</a>)|i", $fcktext, $a)) {
                               $j = $ta."_".md5($i);
                               $List[$j]["content"] = $a[0];
                               $List[$j]["index"] = $j;
                               $fcktext = str_replace($a[0], $j, $fcktext);
                               $i++;
                       }
               }
               if ($wgFCKEditorAllow_img_tags) {
                       $i = 0;
                       $timg = md5("img");
                       while (preg_match("|(<img[^>]*?/>)|i", $fcktext, $a)) {
                               $j = $timg."_".md5($i);
                               $List[$j]["content"] = $a[0];
                               $List[$j]["index"] = $j;
                               $fcktext = str_replace($a[0], $j, $fcktext);
                               $i++;
                       }
               }
       
               $tagList = array("pre", "math", "gallery", "nowiki", "html");
               foreach($tagList as $tag) {
                       $fcktext = preg_replace("|<$tag>|i", "<$tag>", $fcktext);
                       $fcktext = preg_replace("|</$tag>|i", "</$tag>", $fcktext);
               }
               foreach($q->mTagHooks as $tag) {
                       $fcktext = preg_replace("|<($tag.*?)>|i", "<\\1>", $fcktext);
                       $fcktext = preg_replace("|</$tag>|i", "</$tag>", $fcktext);
               }
       
               $x =& $state;
               $fcktext = $q->strip($fcktext, $x);
               
               $fcktext = preg_replace("/<\/?tbody>/i","", $fcktext);
               $fcktext = preg_replace("/$wgFCKEditorToken/i","", $fcktext);       
       
               $fcktext = Sanitizer::removeHTMLtags( $fcktext, array( &$q, 'attributeStripCallback' ) );
               
               $fcktext = $wgParser->replaceInternalLinks( $fcktext );
               $fcktext = $wgParser->replaceExternalLinks( $fcktext );
       
               # replaceInternalLinks may sometimes leave behind
               # absolute URLs, which have to be masked to hide them from replaceExternalLinks
               $fcktext = str_replace($wgParser->mUniqPrefix."NOPARSE", "", $fcktext);
               
               $fcktext = $wgParser->doMagicLinks( $fcktext );
               $fcktext = $wgParser->formatHeadings( $fcktext );
       
               $wgParser->replaceLinkHolders( $fcktext );
       
               $fcktext = $q->unstripNoWiki( $fcktext, $state );
               $fcktext = $q->unstrip($fcktext, $state);
       
               foreach($List as $item) {
                       $fcktext = str_replace($item["index"], $item["content"], $fcktext);
                       $i++;
               }
       
               $text = $fcktext;
       }

}

?>

Personal tools
工具
金银币拍卖 金币拍卖预展  金银币网店 熊猫金银币 生肖金银币