Index: /MediaWiki/trunk/extensions/FCKeditor/FCKeditor.body.php
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/FCKeditor.body.php	(revision 536)
+++ /MediaWiki/trunk/extensions/FCKeditor/FCKeditor.body.php	(revision 537)
@@ -464,5 +464,5 @@
     function stripNoGallery($text) {}
     function stripToc( $text ) {
-        $prefix = '<span class="fck_magic">';
+        $prefix = '<span class="fck_mw_magic">';
         $suffix = '</span>';
         
@@ -480,5 +480,5 @@
     }       
     function replaceVariables( $text, $args = array(), $argsOnly = false ) {
-        return preg_replace("/\{\{([^}]+)\}\}(\}*)/", '<span class="fck_template">{{$1}}$2</span>', $text);
+        return preg_replace("/\{\{([^}]+)\}\}(\}*)/", '<span class="fck_mw_template">{{$1}}$2</span>', $text);
     }
 }
Index: /MediaWiki/trunk/extensions/FCKeditor/fckeditor_config.js
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/fckeditor_config.js	(revision 536)
+++ /MediaWiki/trunk/extensions/FCKeditor/fckeditor_config.js	(revision 537)
@@ -12,5 +12,5 @@
 	['Cut','Copy','Paste',/*'PasteText','PasteWord',*/'-','Print'],
 	['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
-	['SpecialChar','Table','Rule'],
+	['SpecialChar','Table','Image','Rule'],
 	'/',
 	['FontFormat'],
@@ -44,3 +44,13 @@
 FCKConfig.FlashUpload   = false ;
 
-FCKConfig.EditorAreaCSS = FCKConfig.EditorAreaCSS.split( ',' ) ;
+FCKConfig.EditorAreaStyles = '\
+.FCK__MWTemplate \
+{ \
+	border: 1px dotted #00F; \
+	background-position: center center; \
+	background-image: url(' + FCKConfig.PluginsPath + 'mediawiki/images/icon_template.gif); \
+	background-repeat: no-repeat; \
+	width: 20px; \
+	height: 15px; \
+	vertical-align: middle; \
+}' ;
Index: /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/fck_link.html
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/fck_link.html	(revision 537)
+++ /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/fck_link.html	(revision 537)
@@ -0,0 +1,231 @@
+﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!--
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * Link dialog window.
+-->
+<html>
+<head>
+	<title>Link Properties</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+	<meta name="robots" content="noindex, nofollow" />
+	<script type="text/javascript">
+
+var oEditor		= window.parent.InnerDialogLoaded() ;
+var FCK			= oEditor.FCK ;
+var FCKLang		= oEditor.FCKLang ;
+var FCKConfig	= oEditor.FCKConfig ;
+var FCKRegexLib	= oEditor.FCKRegexLib ;
+var FCKTools	= oEditor.FCKTools ;
+
+document.write( '<script src="' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js" type="text/javascript"><\/script>' ) ;
+
+	</script>
+	<script type="text/javascript">
+
+// oLink: The actual selected link in the editor.
+var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
+if ( oLink )
+	FCK.Selection.SelectNode( oLink ) ;
+
+window.onload = function()
+{
+	// Translate the dialog box texts.
+	oEditor.FCKLanguageManager.TranslatePage(document) ;
+
+	// Load the selected link information (if any).
+	LoadSelection() ;
+
+	// Activate the "OK" button.
+	window.parent.SetOkButton( true ) ;
+	window.parent.SetAutoSize( true ) ;
+}
+
+function LoadSelection()
+{
+	if ( !oLink ) return ;
+
+	// Get the actual Link href.
+	var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
+	if ( sHRef == null )
+		sHRef = oLink.getAttribute( 'href' , 2 ) || '' ;
+
+	GetE('txtUrl').value = sHRef ;
+}
+
+var searchTimer ;
+
+//#### Called while the user types the URL.
+function OnUrlChange()
+{
+	var link = GetE('txtUrl').value.Trim() ;
+
+	if ( searchTimer )
+		window.clearTimeout( searchTimer ) ;
+		
+	if ( link.StartsWith( '#' ) )
+	{
+		SetSearchMessage( 'anchor link... no search for it' ) ;
+		return ;
+	} 
+	
+	if ( link.StartsWith( 'mailto:' ) )
+	{
+		SetSearchMessage( 'e-mail link... no search for it' ) ;
+		return ;
+	} 
+	
+	if( /^\w+:\/\//.test( link ) )
+	{
+		SetSearchMessage( 'external link... no search for it' ) ;
+		return ;
+	}
+
+	if ( link.length < 3  )
+	{
+		ClearSearch() ;
+
+		if ( link.length == 0 )
+			SetSearchMessage( 'start typing in the above field' ) ;
+		else
+			SetSearchMessage( 'too short... type more' ) ;
+		return ;
+	}
+	
+	SetSearchMessage( 'stop typing to search' ) ;
+	searchTimer = window.setTimeout( StartSearch, 500 ) ;
+}
+
+function StartSearch()
+{
+	var link = GetE('txtUrl').value.Trim() ;
+
+	if ( link.length < 3  )
+		return ;
+
+	SetSearchMessage( 'searching...' ) ;
+
+	// Make an Ajax search for the pages.
+	oEditor.window.parent.sajax_request_type = 'GET' ;
+	oEditor.window.parent.sajax_do_call( 'wfSajaxSearchArticleFCKeditor', [link], LoadSearchResults ) ;
+}
+
+function LoadSearchResults( result )
+{
+	var results = result.responseText.Trim().split( '\n' ) ;
+	var select = GetE( 'xWikiResults' ) ;
+	
+	ClearSearch() ;
+
+	if ( results.length == 0 || ( results.length == 1 && results[0].length == 0 ) )
+	{
+		SetSearchMessage( 'no articles found' ) ;
+	}
+	else
+	{
+		if ( results.length == 1 )
+			SetSearchMessage( 'one article found' ) ;
+		else
+			SetSearchMessage( results.length + ' articles found' ) ;
+
+		for ( var i = 0 ; i < results.length ; i++ )
+			FCKTools.AddSelectOption( select, results[i], results[i] ) ;
+	}
+}
+
+function ClearSearch()
+{
+	var select = GetE( 'xWikiResults' ) ;
+
+	while ( select.options.length > 0 )
+		select.remove( 0 ) 
+}
+
+function SetSearchMessage( message )
+{
+	GetE('xWikiSearchStatus').innerHTML = message ;
+}
+
+function SetUrl( url )
+{
+	GetE('txtUrl').value = url ;
+}
+
+//#### The OK button was hit.
+function Ok()
+{
+	var sUri = GetE('txtUrl').value ;
+	var sInnerHtml ;
+
+	// If no link is selected, create a new one (it may result in more than one link creation - #220).
+	var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri ) ;
+
+	// If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26)
+	var aHasSelection = ( aLinks.length > 0 ) ;
+	if ( !aHasSelection )
+	{
+		sInnerHtml = sUri;
+
+		var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ;
+		var asLinkPath = oLinkPathRegEx.exec( sUri ) ;
+		if (asLinkPath != null)
+			sInnerHtml = asLinkPath[1];  // use matched path
+		
+		// Create a new (empty) anchor.
+		aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ;
+	}
+
+	oEditor.FCKUndo.SaveUndoStep() ;
+
+	for ( var i = 0 ; i < aLinks.length ; i++ )
+	{
+		oLink = aLinks[i] ;
+
+		if ( aHasSelection )
+			sInnerHtml = oLink.innerHTML ;		// Save the innerHTML (IE changes it if it is like an URL).
+
+		oLink.href = sUri ;
+		SetAttribute( oLink, '_fcksavedurl', sUri ) ;
+
+		oLink.innerHTML = sInnerHtml ;		// Set (or restore) the innerHTML
+
+	}
+
+	// Select the (first) link.
+	oEditor.FCKSelection.SelectNode( aLinks[0] );
+
+	return true ;
+}
+
+	</script>
+</head>
+<body scroll="no" style="overflow: hidden">
+	<div id="divInfo">
+		<div id="divLinkTypeUrl">
+			<span>Link</span><br />
+			<input id="txtUrl" style="width: 100%" type="text" onkeyup="OnUrlChange();" />
+			<br />
+			Automatic search results (<span id="xWikiSearchStatus">start typing in the above field</span>)<br />
+			<select id="xWikiResults" size="10" style="width: 100%; height:150px" onclick="SetUrl( this.value );">
+			</select>
+		</div>
+	</div>
+</body>
+</html>
Index: /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/template.html
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/template.html	(revision 537)
+++ /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/template.html	(revision 537)
@@ -0,0 +1,140 @@
+﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!--
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net
+ * Copyright (C) 2003-2007 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ *
+ * Link dialog window.
+-->
+<html>
+<head>
+	<title>Template Properties</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+	<meta name="robots" content="noindex, nofollow" />
+	<script type="text/javascript">
+
+var oEditor		= window.parent.InnerDialogLoaded() ;
+var FCK			= oEditor.FCK ;
+var FCKLang		= oEditor.FCKLang ;
+var FCKConfig	= oEditor.FCKConfig ;
+var FCKRegexLib	= oEditor.FCKRegexLib ;
+var FCKTools	= oEditor.FCKTools ;
+
+document.write( '<script src="' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js" type="text/javascript"><\/script>' ) ;
+
+	</script>
+	<script type="text/javascript">
+
+// Get the selected flash embed (if available).
+var oFakeImage = FCK.Selection.GetSelectedElement() ;
+var oTemplateSpan ;
+
+if ( oFakeImage )
+{
+	if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fck_mw_template') )
+		oTemplateSpan = FCK.GetRealElement( oFakeImage ) ;
+	else
+		oFakeImage = null ;
+}
+
+window.onload = function()
+{
+	// Translate the dialog box texts.
+	oEditor.FCKLanguageManager.TranslatePage(document) ;
+
+	// Load the selected link information (if any).
+	LoadSelection() ;
+
+	// Activate the "OK" button.
+	window.parent.SetOkButton( true ) ;
+	window.parent.SetAutoSize( true ) ;
+}
+
+function LoadSelection()
+{
+	if ( !oTemplateSpan ) return ;
+
+	GetE('xTemplateRaw').value = oTemplateSpan.innerHTML ;
+}
+
+//#### The OK button was hit.
+function Ok()
+{
+	var sUri = GetE('txtUrl').value ;
+	var sInnerHtml ;
+
+	// If no link is selected, create a new one (it may result in more than one link creation - #220).
+	var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri ) ;
+
+	// If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26)
+	var aHasSelection = ( aLinks.length > 0 ) ;
+	if ( !aHasSelection )
+	{
+		sInnerHtml = sUri;
+
+		var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ;
+		var asLinkPath = oLinkPathRegEx.exec( sUri ) ;
+		if (asLinkPath != null)
+			sInnerHtml = asLinkPath[1];  // use matched path
+		
+		// Create a new (empty) anchor.
+		aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ;
+	}
+
+	oEditor.FCKUndo.SaveUndoStep() ;
+
+	for ( var i = 0 ; i < aLinks.length ; i++ )
+	{
+		oLink = aLinks[i] ;
+
+		if ( aHasSelection )
+			sInnerHtml = oLink.innerHTML ;		// Save the innerHTML (IE changes it if it is like an URL).
+
+		oLink.href = sUri ;
+		SetAttribute( oLink, '_fcksavedurl', sUri ) ;
+
+		oLink.innerHTML = sInnerHtml ;		// Set (or restore) the innerHTML
+
+	}
+
+	// Select the (first) link.
+	oEditor.FCKSelection.SelectNode( aLinks[0] );
+
+	return true ;
+}
+
+	</script>
+</head>
+<body style="overflow: hidden">
+	<div id="divInfo">
+		<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
+			<tr>
+				<td>
+					<span>Template raw definition (from {{ to }})</span><br />
+				</td>
+			</tr>
+			<tr>
+				<td>
+					<textarea id="xTemplateRaw" style="width: 100%; height: 100%; font-family: Monospace"
+						cols="50" rows="10" wrap="off"></textarea>
+				</td>
+			</tr>
+		</table>
+	</div>
+</body>
+</html>
Index: diaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fck_link.html
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fck_link.html	(revision 536)
+++ 	(revision )
@@ -1,231 +1,0 @@
-﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<!--
- * FCKeditor - The text editor for Internet - http://www.fckeditor.net
- * Copyright (C) 2003-2007 Frederico Caldeira Knabben
- *
- * == BEGIN LICENSE ==
- *
- * Licensed under the terms of any of the following licenses at your
- * choice:
- *
- *  - GNU General Public License Version 2 or later (the "GPL")
- *    http://www.gnu.org/licenses/gpl.html
- *
- *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
- *    http://www.gnu.org/licenses/lgpl.html
- *
- *  - Mozilla Public License Version 1.1 or later (the "MPL")
- *    http://www.mozilla.org/MPL/MPL-1.1.html
- *
- * == END LICENSE ==
- *
- * Link dialog window.
--->
-<html>
-<head>
-	<title>Link Properties</title>
-	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-	<meta name="robots" content="noindex, nofollow" />
-	<script type="text/javascript">
-
-var oEditor		= window.parent.InnerDialogLoaded() ;
-var FCK			= oEditor.FCK ;
-var FCKLang		= oEditor.FCKLang ;
-var FCKConfig	= oEditor.FCKConfig ;
-var FCKRegexLib	= oEditor.FCKRegexLib ;
-var FCKTools	= oEditor.FCKTools ;
-
-document.write( '<script src="' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js" type="text/javascript"><\/script>' ) ;
-
-	</script>
-	<script type="text/javascript">
-
-// oLink: The actual selected link in the editor.
-var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
-if ( oLink )
-	FCK.Selection.SelectNode( oLink ) ;
-
-window.onload = function()
-{
-	// Translate the dialog box texts.
-	oEditor.FCKLanguageManager.TranslatePage(document) ;
-
-	// Load the selected link information (if any).
-	LoadSelection() ;
-
-	// Activate the "OK" button.
-	window.parent.SetOkButton( true ) ;
-	window.parent.SetAutoSize( true ) ;
-}
-
-function LoadSelection()
-{
-	if ( !oLink ) return ;
-
-	// Get the actual Link href.
-	var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
-	if ( sHRef == null )
-		sHRef = oLink.getAttribute( 'href' , 2 ) || '' ;
-
-	GetE('txtUrl').value = sHRef ;
-}
-
-var searchTimer ;
-
-//#### Called while the user types the URL.
-function OnUrlChange()
-{
-	var link = GetE('txtUrl').value.Trim() ;
-
-	if ( searchTimer )
-		window.clearTimeout( searchTimer ) ;
-		
-	if ( link.StartsWith( '#' ) )
-	{
-		SetSearchMessage( 'anchor link... no search for it' ) ;
-		return ;
-	} 
-	
-	if ( link.StartsWith( 'mailto:' ) )
-	{
-		SetSearchMessage( 'e-mail link... no search for it' ) ;
-		return ;
-	} 
-	
-	if( /^\w+:\/\//.test( link ) )
-	{
-		SetSearchMessage( 'external link... no search for it' ) ;
-		return ;
-	}
-
-	if ( link.length < 3  )
-	{
-		ClearSearch() ;
-
-		if ( link.length == 0 )
-			SetSearchMessage( 'start typing in the above field' ) ;
-		else
-			SetSearchMessage( 'too short... type more' ) ;
-		return ;
-	}
-	
-	SetSearchMessage( 'stop typing to search' ) ;
-	searchTimer = window.setTimeout( StartSearch, 500 ) ;
-}
-
-function StartSearch()
-{
-	var link = GetE('txtUrl').value.Trim() ;
-
-	if ( link.length < 3  )
-		return ;
-
-	SetSearchMessage( 'searching...' ) ;
-
-	// Make an Ajax search for the pages.
-	oEditor.window.parent.sajax_request_type = 'GET' ;
-	oEditor.window.parent.sajax_do_call( 'wfSajaxSearchArticleFCKeditor', [link], LoadSearchResults ) ;
-}
-
-function LoadSearchResults( result )
-{
-	var results = result.responseText.Trim().split( '\n' ) ;
-	var select = GetE( 'xWikiResults' ) ;
-	
-	ClearSearch() ;
-
-	if ( results.length == 0 || ( results.length == 1 && results[0].length == 0 ) )
-	{
-		SetSearchMessage( 'no articles found' ) ;
-	}
-	else
-	{
-		if ( results.length == 1 )
-			SetSearchMessage( 'one article found' ) ;
-		else
-			SetSearchMessage( results.length + ' articles found' ) ;
-
-		for ( var i = 0 ; i < results.length ; i++ )
-			FCKTools.AddSelectOption( select, results[i], results[i] ) ;
-	}
-}
-
-function ClearSearch()
-{
-	var select = GetE( 'xWikiResults' ) ;
-
-	while ( select.options.length > 0 )
-		select.remove( 0 ) 
-}
-
-function SetSearchMessage( message )
-{
-	GetE('xWikiSearchStatus').innerHTML = message ;
-}
-
-function SetUrl( url )
-{
-	GetE('txtUrl').value = url ;
-}
-
-//#### The OK button was hit.
-function Ok()
-{
-	var sUri = GetE('txtUrl').value ;
-	var sInnerHtml ;
-
-	// If no link is selected, create a new one (it may result in more than one link creation - #220).
-	var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri ) ;
-
-	// If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26)
-	var aHasSelection = ( aLinks.length > 0 ) ;
-	if ( !aHasSelection )
-	{
-		sInnerHtml = sUri;
-
-		var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ;
-		var asLinkPath = oLinkPathRegEx.exec( sUri ) ;
-		if (asLinkPath != null)
-			sInnerHtml = asLinkPath[1];  // use matched path
-		
-		// Create a new (empty) anchor.
-		aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ;
-	}
-
-	oEditor.FCKUndo.SaveUndoStep() ;
-
-	for ( var i = 0 ; i < aLinks.length ; i++ )
-	{
-		oLink = aLinks[i] ;
-
-		if ( aHasSelection )
-			sInnerHtml = oLink.innerHTML ;		// Save the innerHTML (IE changes it if it is like an URL).
-
-		oLink.href = sUri ;
-		SetAttribute( oLink, '_fcksavedurl', sUri ) ;
-
-		oLink.innerHTML = sInnerHtml ;		// Set (or restore) the innerHTML
-
-	}
-
-	// Select the (first) link.
-	oEditor.FCKSelection.SelectNode( aLinks[0] );
-
-	return true ;
-}
-
-	</script>
-</head>
-<body scroll="no" style="overflow: hidden">
-	<div id="divInfo">
-		<div id="divLinkTypeUrl">
-			<span>Link</span><br />
-			<input id="txtUrl" style="width: 100%" type="text" onkeyup="OnUrlChange();" />
-			<br />
-			Automatic search results (<span id="xWikiSearchStatus">start typing in the above field</span>)<br />
-			<select id="xWikiResults" size="10" style="width: 100%; height:150px" onclick="SetUrl( this.value );">
-			</select>
-		</div>
-	</div>
-</body>
-</html>
Index: /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fckplugin.js
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fckplugin.js	(revision 536)
+++ /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fckplugin.js	(revision 537)
@@ -30,5 +30,6 @@
 
 // Override some dialogs.
-FCKCommands.RegisterCommand( 'Link', new FCKDialogCommand( 'Link', FCKLang.DlgLnkWindowTitle, FCKConfig.PluginsPath + 'mediawiki/fck_link.html', 400, 330 ) ) ;
+FCKCommands.RegisterCommand( 'Link', new FCKDialogCommand( 'Link', FCKLang.DlgLnkWindowTitle, FCKConfig.PluginsPath + 'mediawiki/dialogs/fck_link.html', 400, 330 ) ) ;
+FCKCommands.RegisterCommand( 'MW_Template', new FCKDialogCommand( 'MW_Template', 'Template Properties', FCKConfig.PluginsPath + 'mediawiki/dialogs/template.html', 400, 330 ) ) ;
 //FCKCommands.RegisterCommand( 'Image', new FCKDialogCommand( 'Image', FCKLang.DlgImgTitle, FCKConfig.PluginsPath + 'mediawiki/fck_image.html', 450, 400 ) ) ;
 
@@ -116,5 +117,5 @@
 				// fake one (like the Flash placeholder image), so we must get the real one.
 				if ( htmlNode.getAttribute('_fckfakelement') )
-					return this._TransformToWikitext( FCK.GetRealElement( htmlNode ), stringBuilder ) ;
+					return this._AppendNode( FCK.GetRealElement( htmlNode ), stringBuilder ) ;
 
 				// Mozilla insert custom nodes in the DOM.
@@ -276,4 +277,11 @@
 
 							break ;
+						
+						case 'span' :
+							if ( htmlNode.className == 'fck_template' )
+							{
+								stringBuilder.push( htmlNode.innerHTML ) ;
+								return ;
+							}
 
 						default :
@@ -436,3 +444,46 @@
 })() ;
 
-
+// MediaWiki document processor (templates and magic words).
+FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
+{
+	var aSpans = document.getElementsByTagName( 'SPAN' ) ;
+
+	var eSpan ;
+	var i = aSpans.length - 1 ;
+	while ( i >= 0 && ( eSpan = aSpans[i--] ) )
+	{
+		var customAtt = null ;
+		
+		switch ( eSpan.className )
+		{
+			case 'fck_mw_template' :
+			case 'fck_mw_magic' :
+				var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__MWTemplate', eSpan.cloneNode(true) ) ;
+				oImg.setAttribute( '_' + eSpan.className, 'true', 0 ) ;
+
+				eSpan.parentNode.insertBefore( oImg, eSpan ) ;
+				eSpan.parentNode.removeChild( eSpan ) ;
+			break ;
+		}
+	}
+}
+
+// Context menu for templates.
+FCK.ContextMenu.RegisterListener({
+	AddItems : function( contextMenu, tag, tagName )
+	{
+		if ( tagName == 'IMG' )
+		{
+			if ( tag.getAttribute( '_fck_mw_template' ) )
+			{
+				contextMenu.AddSeparator() ;
+				contextMenu.AddItem( 'MW_Template', 'Template Properties' ) ;
+			}
+			if ( tag.getAttribute( '_fck_mw_magic' ) )
+			{
+				contextMenu.AddSeparator() ;
+				contextMenu.AddItem( 'MW_MagicWord', 'Modify Magic Word' ) ;
+			}
+		}
+	}
+}) ;
