Index: /MediaWiki/trunk/extensions/FCKeditor/fckeditor_config.js
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/fckeditor_config.js	(revision 552)
+++ /MediaWiki/trunk/extensions/FCKeditor/fckeditor_config.js	(revision 553)
@@ -13,4 +13,5 @@
 	['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
 	['SpecialChar','Table','Image','Rule'],
+	['MW_Template'],
 	'/',
 	['FontFormat'],
Index: diaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/fck_link.html
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/fck_link.html	(revision 552)
+++ 	(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/dialogs/link.html
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/link.html	(revision 553)
+++ /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/link.html	(revision 553)
@@ -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 552)
+++ /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/dialogs/template.html	(revision 553)
@@ -70,5 +70,5 @@
 	if ( !oTemplateSpan ) return ;
 
-	GetE('xTemplateRaw').value = oTemplateSpan.innerHTML ;
+	GetE('xTemplateRaw').value = FCKTools.HTMLDecode( oTemplateSpan.innerHTML ).replace( /&quot;/g, '"' ) ;
 }
 
@@ -76,43 +76,26 @@
 function Ok()
 {
-	var sUri = GetE('txtUrl').value ;
-	var sInnerHtml ;
+	if ( !oTemplateSpan )
+	{
+		oTemplateSpan = FCK.EditorDocument.createElement( 'SPAN' ) ;
+		oTemplateSpan.className = 'fck_mw_template' ;
+	}
+	
+	var templateData = FCKTools.HTMLEncode( GetE('xTemplateRaw').value ).Trim().replace( /"/g, '&quot;' ) ;
+	
+	if ( !( /^{{[\s\S]+}}$/.test( templateData ) ) )
+	{
+		alert( 'Templates must start with {{ and end with }}. Please check it.' ) ;
+		return false ;
+	}
+	
+	oTemplateSpan.innerHTML = templateData ;
 
-	// 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 )
+	if ( !oFakeImage )
 	{
-		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' ) ] ;
+		oFakeImage	= oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__MWTemplate', oTemplateSpan ) ;
+		oFakeImage.setAttribute( '_fck_mw_template', 'true', 0 ) ;
+		oFakeImage	= FCK.InsertElement( oFakeImage ) ;
 	}
-
-	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 ;
Index: /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fckplugin.js
===================================================================
--- /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fckplugin.js	(revision 552)
+++ /MediaWiki/trunk/extensions/FCKeditor/plugins/mediawiki/fckplugin.js	(revision 553)
@@ -29,8 +29,13 @@
 FCKToolbarItems.RegisterItem( 'Source', new FCKToolbarButton( 'Source', 'Wikitext', null, FCK_TOOLBARITEM_ICONTEXT, true, true, 1 ) ) ;
 
+// Register our toolbar buttons.
+var tbButton = new FCKToolbarButton( 'MW_Template', 'Template', 'Insert/Edit Template' ) ;
+tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_template.gif' ;
+FCKToolbarItems.RegisterItem( 'MW_Template', tbButton ) ;
+
 // Override some dialogs.
-FCKCommands.RegisterCommand( 'Link', new FCKDialogCommand( 'Link', FCKLang.DlgLnkWindowTitle, FCKConfig.PluginsPath + 'mediawiki/dialogs/fck_link.html', 400, 330 ) ) ;
+FCKCommands.RegisterCommand( 'Link', new FCKDialogCommand( 'Link', FCKLang.DlgLnkWindowTitle, FCKConfig.PluginsPath + 'mediawiki/dialogs/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 ) ) ;
+//FCKCommands.RegisterCommand( 'Image', new FCKDialogCommand( 'Image', FCKLang.DlgImgTitle, FCKConfig.PluginsPath + 'mediawiki/image.html', 450, 400 ) ) ;
 
 // MediaWiki Wikitext Data Processor implementation.
@@ -279,8 +284,10 @@
 						
 						case 'span' :
-							if ( htmlNode.className == 'fck_mw_template' )
+							switch ( htmlNode.className )
 							{
-								stringBuilder.push( htmlNode.innerHTML ) ;
-								return ;
+								case 'fck_mw_template' :
+								case 'fck_mw_magic' :
+									stringBuilder.push( htmlNode.innerHTML ) ;
+									return ;
 							}
 
@@ -303,16 +310,5 @@
 				}
 
-//				var oNode = this._CreateNode( sNodeName ) ;
-
-				// Add all attributes.
-//				FCKXHtml._AppendAttributes( xmlNode, htmlNode, oNode, sNodeName ) ;
-
 				htmlNode._fckxhtmljob = FCKXHtml.CurrentJobNum ;
-
-				// Tag specific processing.
-//				var oTagProcessor = FCKXHtml.TagProcessors[ sNodeName ] ;
-
-//				if ( oTagProcessor )
-//					oNode = oTagProcessor( oNode, htmlNode, xmlNode ) ;
 				return ;
 
