Opened 16 years ago

Closed 16 years ago

#1437 closed Bug (fixed)

Patch to properly handle MW Special Tags

Reported by: barns Owned by:
Priority: Normal Milestone:
Component: Project : MediaWiki+FCKeditor Version:
Keywords: HasPatch Cc:

Description

Replace the line breaks in special tags to be sure not to lose them in IE6. Also give the special tags a common class to be able to identify them in fckplugins.js and replace it by an image, like templates.

In FCKeditorParser.body.php:

    private function fck_addToStrtr($text) {
        $key = 'Fckmw'.$this->fck_mw_strtr_span_counter.'fckmw';
        $this->fck_mw_strtr_span_counter++;
        $this->fck_mw_strtr_span[$key] = str_replace(array("\r\n", "\n", "\r"),"fckLR",$text);
        return $key;
    }


function fck_genericTagHook( $str, $argv, $parser ) {
        if (empty($argv)) {
            $ret = "<span class=\"fck_mw_special\" _fck_mw_customtag=\"true\" _fck_mw_tagname=\"".$this->fck_mw_taghook."\">"; //YC
        }
        else {
            $ret = "<span class=\"fck_mw_special\" _fck_mw_customtag=\"true\" _fck_mw_tagname=\"".$this->fck_mw_taghook."\""; //YC

In FCKeditorSajax.body.php:

function wfSajaxSearchSpecialTagFCKeditor($empty)
{
    global $wgParser;

    $ret = "";
    foreach ($wgParser->getTags() as $h) {
        if (!in_array($h, array("pre"))) {
            $ret .= $h ."\n";
        }
    }
    return $ret;
}

In fckplugin.js:

tbButton = new FCKToolbarButton( 'MW_Special', 'Special Tag', 'Insert/Edit Special Tag' ) ;
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_special.gif' ;
FCKToolbarItems.RegisterItem( 'MW_Special', tbButton ) ;

FCKCommands.RegisterCommand( 'MW_Special', new FCKDialogCommand( 'MW_Special', 'Special Tag Properties', FCKConfig.PluginsPath + 'mediawiki/dialogs/special.html', 400, 330 ) ) ; //YC

---------------------------------
// Text Node.
case 3 :
	var parentIsSpecialTag = htmlNode.parentNode.className.IEquals( 'fck_mw_special', 'fck_mw_template' ) ; //YC
	var textValue = htmlNode.nodeValue;
	
	if ( !parentIsSpecialTag ) //YC
	{
		if (!this._IsInPre(htmlNode))
			textValue = textValue.replace( /[\n\t]/g, ' ' ) ; 
	
		textValue = FCKTools.HTMLEncode( textValue ) ;
		textValue = textValue.replace( /\u00A0/g, '&nbsp;' ) ;
		
		if ( !htmlNode.previousSibling ||
			( stringBuilder.length > 0 && stringBuilder[ stringBuilder.length - 1 ].EndsWith( '\n' ) ) )
		{
			textValue = textValue.LTrim() ;
		}

		if ( !htmlNode.nextSibling )
			textValue = textValue.RTrim() ;

		textValue = textValue.replace( / {2,}/g, ' ' ) ;

		if ( this._IsInsideCell )
			textValue = textValue.replace( /\|/g, '&#124;' ) ;
		
	}
	else 
	{
		textValue = FCKTools.HTMLDecode(textValue).replace(/fckLR/g,'\r\n');
	}

---------------------------------
// MediaWiki document processor.
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
{
	// Templates and magic words.
	var aSpans = document.getElementsByTagName( 'SPAN' ) ;

	var eSpan ;
	var i = aSpans.length - 1 ;
	while ( i >= 0 && ( eSpan = aSpans[i--] ) )
	{
		var className = null ;
		switch ( eSpan.className )
		{
			case 'fck_mw_ref' :
				className = 'FCK__MWRef' ;
			case 'fck_mw_references' :
				if ( className == null )
					className = 'FCK__MWReferences' ;
			case 'fck_mw_template' :
				if ( className == null ) //YC
					className = 'FCK__MWTemplate' ; //YC
			case 'fck_mw_magic' :
				if ( className == null )
					className = 'FCK__MWMagicWord' ;
			case 'fck_mw_special' : //YC
				if ( className == null )
					className = 'FCK__MWSpecial' ;
---------------------------------
// 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 Redirect' ) ;
			}
			if ( tag.getAttribute( '_fck_mw_special' ) ) //YC
			{
				contextMenu.AddSeparator() ;
				contextMenu.AddItem( 'MW_Special', 'Special Tag Properties' ) ;
			}

Dialog special.html in attachment.

Attachments (1)

special.html (4.9 KB) - added by barns 16 years ago.
Dialog for special tags

Download all attachments as: .zip

Change History (3)

Changed 16 years ago by barns

Attachment: special.html added

Dialog for special tags

comment:1 Changed 16 years ago by Wojciech Olchawa

Keywords: HasPatch added

comment:2 Changed 16 years ago by Wiktor Walc

Resolution: fixed
Status: newclosed

Fixed with [1834] and [1835]. I did some minor modifications, but it works in the same way.

I can't wait to see more patches like this one ;-) Once again, nice work!

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy