Extension:TagCorrection

What can this extension do?
This extension helps to be able to use MediaWiki+FCKeditor with plugin like syntax highlighting etc. using. The extensions corrects for example &amp;lt;source lang="php"&amp;gt; to &lt;source lang="php"&gt;. So with this extension you can paste code into the WYSIWYG editor.

Changes to LocalSettings.php
add the following code to the end:

Code
Create the file TagCorrection.php in your extensions directory and put the below code into it.

<?php # TagCorrection MediaWiki Extention # Created by Johannes Perl #	# feel free to add additional tags you are using # the key of the array is the search string, the value is the replacement # $wgSimpleTagReplaces = array ('search', 'replacement') # the above code would let the hook replace the string search through the string replacement #register hook to be executed if an article is saved $wgHooks['ArticleSave'][] = 'correctTags'; #regulary expression and replacement $wgRegularyTagReplaces = array(				'/&lt;source lang=\"([a-z\._0-9]{1,})\"&gt;/U' => ' '); #simply char replaces $wgSimpleCharReplaces = array('&quot;' => '"', '&lt;' => '<', '&gt;' => '>', ' ' => chr(13), 									' ' => ' ');	/**	 * replaces tags which are destroyed by the WYSIWYG editor	 */	function correctTags(&$article, &$user, &$text, &$summary, $minor, $watch, $sectionanchor, &$flags)	{				global $wgRegularyTagReplaces;		global $wgSimpleTagReplaces;		global $wgSimpleCharReplaces;		echo $text." \n\n\n\n";		foreach($wgSimpleTagReplaces as $search => $repl)			$text = str_replace($search, $repl, $text);		foreach($wgRegularyTagReplaces as $search => $repl)			$text = preg_replace($search, $repl, $text);		$ready = false;		while(!$ready)		{			$oldtext = $text;			foreach($wgSimpleCharReplaces as $search => $repl)			{				$text = preg_replace('/ ', $text);			}			if($oldtext == $text)				$ready = true;		}		return true;	} ?>

Parameters
If you want to add special regulary expression to be replaced (tags which aren't always the same, like syntax highlighting for different languages), use the array $wgRegularyTagReplaces. If you simply want to replace other tags, which are always the same use the array $wgSimpleTagReplaces. For characters, which are also replaced by the editor with html code, use the array $wgSimpleCharReplaces.

If you want to add a tag to be replaced, simply add it to the corresponding array in the form 'search' => 'replacement'. Be awarethat you have to use a regulary expression for the key of the array wgRegularyTagReplaces.

TODO

 * Convince FckEditor developers to built the functionality into their editor and make this extensions unnecessary.
 * Add more tags.
 * Check my regulary expression if its ok.