2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Main MediaWiki integration plugin.
23
* Wikitext syntax reference:
24
* http://meta.wikimedia.org/wiki/Help:Wikitext_examples
25
* http://meta.wikimedia.org/wiki/Help:Advanced_editing
28
* http://meta.wikimedia.org/wiki/Meta:Sandbox
31
// Rename the "Source" buttom to "Wikitext".
32
FCKToolbarItems.RegisterItem( 'Source', new FCKToolbarButton( 'Source', 'Wikitext', null, FCK_TOOLBARITEM_ICONTEXT, true, true, 1 ) ) ;
34
// Register our toolbar buttons.
35
var tbButton = new FCKToolbarButton( 'MW_Template', 'Template', FCKLang.wikiBtnTemplate || 'Insert/Edit Template') ;
36
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_template.gif' ;
37
FCKToolbarItems.RegisterItem( 'MW_Template', tbButton ) ;
40
tbButton = new FCKToolbarButton( 'MW_Ref', 'Ref', FCKLang.wikiBtnReference || 'Insert/Edit Reference' ) ;
41
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_ref.gif' ;
42
FCKToolbarItems.RegisterItem( 'MW_Ref', tbButton ) ;
43
if ( !FCKConfig.showreferences ) { //hack to disable MW_Ref button
44
tbButton.Create = function() {return 0;}
45
tbButton.Disable = function() {return 0;}
46
tbButton.RefreshState = function() {return 0;}
50
var FCKReferences = function( ) { } ;
51
FCKReferences.prototype.GetState = function() { return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED) } ;
52
FCKCommands.RegisterCommand( 'MW_References', new FCKReferences() ) ;
53
tbButton = new FCKToolbarButton( 'MW_References', 'References', FCKLang.wikiBtnReferences || 'Insert <references /> tag', FCK_TOOLBARITEM_ICONTEXT,true, true, 1 );
54
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_ref.gif' ;
55
if ( !FCKConfig.showreferences ) { //hack to disable MW_References button
56
tbButton.Create = function() {return 0;}
57
tbButton.Disable = function() {return 0;}
58
tbButton.RefreshState = function() {return 0;}
61
FCKReferences.prototype.Execute = function()
63
if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
66
FCKUndo.SaveUndoStep() ;
68
var e = FCK.EditorDocument.createElement( 'span' ) ;
69
e.setAttribute("_fck_mw_customtag", "true");
70
e.setAttribute("_fck_mw_tagname", "references");
71
e.className = "fck_mw_references";
73
oFakeImage = FCK.InsertElement( FCKDocumentProcessor_CreateFakeImage( 'FCK__MWReferences', e ) ) ;
75
FCKToolbarItems.RegisterItem( 'MW_References', tbButton ) ;
78
var FCKSignature = function( ) {} ;
79
FCKSignature.prototype.GetState = function() { return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED) } ;
80
FCKCommands.RegisterCommand( 'MW_Signature', new FCKSignature() ) ;
81
tbButton = new FCKToolbarButton( 'MW_Signature', 'Signature', FCKLang.wikiBtnSignature || 'Insert signature', FCK_TOOLBARITEM_ONLYICON,true, true, 1 );
82
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_signature.gif' ;
84
FCKSignature.prototype.Execute = function()
86
if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
89
FCKUndo.SaveUndoStep() ;
90
var e = FCK.EditorDocument.createElement( 'span' ) ;
91
e.className = "fck_mw_signature";
93
oFakeImage = FCK.InsertElement( FCKDocumentProcessor_CreateFakeImage( 'FCK__MWSignature', e ) ) ;
95
FCKToolbarItems.RegisterItem( 'MW_Signature', tbButton ) ;
97
tbButton = new FCKToolbarButton( 'MW_Math', 'Formula', FCKLang.wikiBtnFormula || 'Insert/Edit Formula' ) ;
98
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_math.gif' ;
99
FCKToolbarItems.RegisterItem( 'MW_Math', tbButton ) ;
101
tbButton = new FCKToolbarButton( 'MW_Source', 'Source', FCKLang.wikiBtnSourceCode || 'Insert/Edit Source Code' ) ;
102
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_source.gif' ;
103
FCKToolbarItems.RegisterItem( 'MW_Source', tbButton ) ;
104
if ( !FCKConfig.showsource ) { //hack to disable MW_Source button
105
tbButton.Create = function() {return 0;}
106
tbButton.Disable = function() {return 0;}
107
tbButton.RefreshState = function() {return 0;}
110
tbButton = new FCKToolbarButton( 'MW_Special', 'Special Tag', FCKLang.wikiBtnSpecial || 'Insert/Edit Special Tag' ) ;
111
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_special.gif' ;
112
FCKToolbarItems.RegisterItem( 'MW_Special', tbButton ) ;
114
tbButton = new FCKToolbarButton( 'MW_Category', 'Categories', FCKLang.wikiBtnCategories || 'Insert/Edit categories' ) ;
115
tbButton.IconPath = FCKConfig.PluginsPath + 'mediawiki/images/tb_icon_category.gif' ;
116
FCKToolbarItems.RegisterItem( 'MW_Category', tbButton ) ;
118
// Override some dialogs.
119
FCKCommands.RegisterCommand( 'MW_Template', new FCKDialogCommand( 'MW_Template', ( FCKLang.wikiCmdTemplate || 'Template Properties' ), FCKConfig.PluginsPath + 'mediawiki/dialogs/template.html', 400, 330 ) ) ;
120
FCKCommands.RegisterCommand( 'MW_Ref', new FCKDialogCommand( 'MW_Ref', ( FCKLang.wikiCmdReference || 'Reference Properties' ), FCKConfig.PluginsPath + 'mediawiki/dialogs/ref.html', 400, 250 ) ) ;
121
FCKCommands.RegisterCommand( 'MW_Math', new FCKDialogCommand( 'MW_Math', ( FCKLang.wikiCmdFormula || 'Formula' ), FCKConfig.PluginsPath + 'mediawiki/dialogs/math.html', 400, 300 ) ) ;
122
FCKCommands.RegisterCommand( 'MW_Special', new FCKDialogCommand( 'MW_Special', ( FCKLang.wikiCmdSpecial || 'Special Tag Properties' ), FCKConfig.PluginsPath + 'mediawiki/dialogs/special.html', 400, 330 ) ) ;
123
FCKCommands.RegisterCommand( 'MW_Source', new FCKDialogCommand( 'MW_Source', ( FCKLang.wikiCmdSourceCode || 'Source Code Properties' ), FCKConfig.PluginsPath + 'mediawiki/dialogs/source.html', 720, 380 ) ) ;
124
FCKCommands.RegisterCommand( 'Link', new FCKDialogCommand( 'Link', FCKLang.DlgLnkWindowTitle, FCKConfig.PluginsPath + 'mediawiki/dialogs/link.html', 400, 250 ) ) ;
125
FCKCommands.RegisterCommand( 'MW_Category', new FCKDialogCommand( 'MW_Category', ( FCKLang.wikiCmdCategories || 'Categories' ), FCKConfig.PluginsPath + 'mediawiki/dialogs/category.html', 400, 500 ) ) ;
126
FCKCommands.RegisterCommand( 'Image', new FCKDialogCommand( 'Image', FCKLang.DlgImgTitle, FCKConfig.PluginsPath + 'mediawiki/dialogs/image.html', 450, 300 ) ) ;
128
FCKToolbarItems.OldGetItem = FCKToolbarItems.GetItem;
130
FCKToolbarItems.GetItem = function( itemName )
132
var oItem = FCKToolbarItems.LoadedItems[ itemName ] ;
139
case 'Bold' : oItem = new FCKToolbarButton( 'Bold' , FCKLang.Bold, null, null, true, true, 20 ) ; break ;
140
case 'Italic' : oItem = new FCKToolbarButton( 'Italic' , FCKLang.Italic, null, null, true, true, 21 ) ; break ;
141
case 'Underline' : oItem = new FCKToolbarButton( 'Underline' , FCKLang.Underline, null, null, true, true, 22 ) ; break ;
142
case 'StrikeThrough': oItem = new FCKToolbarButton( 'StrikeThrough' , FCKLang.StrikeThrough, null, null, true, true, 23 ) ; break ;
143
case 'Link' : oItem = new FCKToolbarButton( 'Link' , FCKLang.InsertLinkLbl, FCKLang.InsertLink, null, true, true, 34 ) ; break ;
146
return FCKToolbarItems.OldGetItem( itemName );
149
FCKToolbarItems.LoadedItems[ itemName ] = oItem ;
154
FCKToolbarButton.prototype.Click = function()
156
var oToolbarButton = this._ToolbarButton || this ;
158
// for some buttons, do something else instead...
160
if ( oToolbarButton.SourceView && (FCK_EDITMODE_SOURCE == FCK.EditMode) )
162
if ( !window.parent.popup )
163
var oDoc = window.parent;
165
var oDoc = window.parent.popup;
167
switch (oToolbarButton.CommandName)
169
case 'Bold' : oDoc.FCKeditorInsertTags ('\'\'\'', '\'\'\'', 'Bold text', document) ; CMode = true ; break ;
170
case 'Italic' : oDoc.FCKeditorInsertTags ('\'\'', '\'\'', 'Italic text', document) ; CMode = true ; break ;
171
case 'Underline' : oDoc.FCKeditorInsertTags ('<u>', '</u>', 'Underlined text', document) ; CMode = true ; break ;
172
case 'StrikeThrough': oDoc.FCKeditorInsertTags ('<strike>', '</strike>', 'Strikethrough text', document) ; CMode = true ; break ;
173
case 'Link' : oDoc.FCKeditorInsertTags ('[[', ']]', 'Internal link', document) ; CMode = true ; break ;
178
FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( oToolbarButton.CommandName ).Execute() ;
181
// MediaWiki Wikitext Data Processor implementation.
188
* Returns a string representing the HTML format of "data". The returned
189
* value will be loaded in the editor.
190
* The HTML must be from <html> to </html>, eventually including
192
* @param {String} data The data to be converted in the
193
* DataProcessor specific format.
195
ConvertToHtml : function( data )
197
// Call the original code.
198
return FCKDataProcessor.prototype.ConvertToHtml.call( this, data ) ;
202
* Converts a DOM (sub-)tree to a string in the data format.
203
* @param {Object} rootNode The node that contains the DOM tree to be
204
* converted to the data format.
205
* @param {Boolean} excludeRoot Indicates that the root node must not
206
* be included in the conversion, only its children.
207
* @param {Boolean} format Indicates that the data must be formatted
208
* for human reading. Not all Data Processors may provide it.
210
ConvertToDataFormat : function( rootNode, excludeRoot, ignoreIfEmptyParagraph, format )
212
// rootNode is <body>.
214
// Normalize the document for text node processing (except IE - #1586).
215
if ( !FCKBrowserInfo.IsIE )
216
rootNode.normalize() ;
218
var stringBuilder = new Array() ;
219
this._AppendNode( rootNode, stringBuilder, '' ) ;
220
return stringBuilder.join( '' ).RTrim().replace(/^\n*/, "") ;
224
* Makes any necessary changes to a piece of HTML for insertion in the
225
* editor selection position.
226
* @param {String} html The HTML to be fixed.
228
FixHtml : function( html )
233
// Collection of element definitions:
236
// 2 : Ignore children
239
b : [ "'''", "'''" ],
240
strong : [ "'''", "'''" ],
244
h1 : [ '\n= ', ' =\n' ],
245
h2 : [ '\n== ', ' ==\n' ],
246
h3 : [ '\n=== ', ' ===\n' ],
247
h4 : [ '\n==== ', ' ====\n' ],
248
h5 : [ '\n===== ', ' =====\n' ],
249
h6 : [ '\n====== ', ' ======\n' ],
250
br : [ '<br>', null, true ],
251
hr : [ '\n----\n', null, true ]
254
// This function is based on FCKXHtml._AppendNode.
255
_AppendNode : function( htmlNode, stringBuilder, prefix )
260
switch ( htmlNode.nodeType )
265
// Here we found an element that is not the real element, but a
266
// fake one (like the Flash placeholder image), so we must get the real one.
267
if ( htmlNode.getAttribute('_fckfakelement') && !htmlNode.getAttribute( '_fck_mw_math' ) )
268
return this._AppendNode( FCK.GetRealElement( htmlNode ), stringBuilder ) ;
270
// Mozilla insert custom nodes in the DOM.
271
if ( FCKBrowserInfo.IsGecko && htmlNode.hasAttribute('_moz_editor_bogus_node') )
274
// This is for elements that are instrumental to FCKeditor and
275
// must be removed from the final HTML.
276
if ( htmlNode.getAttribute('_fcktemp') )
279
// Get the element name.
280
var sNodeName = htmlNode.tagName.toLowerCase() ;
282
if ( FCKBrowserInfo.IsIE )
284
// IE doens't include the scope name in the nodeName. So, add the namespace.
285
if ( htmlNode.scopeName && htmlNode.scopeName != 'HTML' && htmlNode.scopeName != 'FCK' )
286
sNodeName = htmlNode.scopeName.toLowerCase() + ':' + sNodeName ;
290
if ( sNodeName.StartsWith( 'fck:' ) )
291
sNodeName = sNodeName.Remove( 0,4 ) ;
294
// Check if the node name is valid, otherwise ignore this tag.
295
// If the nodeName starts with a slash, it is a orphan closing tag.
296
// On some strange cases, the nodeName is empty, even if the node exists.
297
if ( !FCKRegexLib.ElementName.test( sNodeName ) )
300
if ( sNodeName == 'br' && ( this._inPre || this._inLSpace ) )
302
stringBuilder.push( "\n" ) ;
303
if ( this._inLSpace )
304
stringBuilder.push( " " ) ;
308
// Remove the <br> if it is a bogus node.
309
if ( sNodeName == 'br' && htmlNode.getAttribute( 'type', 2 ) == '_moz' )
312
// The already processed nodes must be marked to avoid then to be duplicated (bad formatted HTML).
313
// So here, the "mark" is checked... if the element is Ok, then mark it.
314
if ( htmlNode._fckxhtmljob && htmlNode._fckxhtmljob == FCKXHtml.CurrentJobNum )
317
var basicElement = this._BasicElements[ sNodeName ] ;
320
var basic0 = basicElement[0];
321
var basic1 = basicElement[1];
323
if ( ( basicElement[0] == "''" || basicElement[0] == "'''" ) && stringBuilder.length > 2 )
325
var pr1 = stringBuilder[stringBuilder.length-1];
326
var pr2 = stringBuilder[stringBuilder.length-2];
328
if ( pr1 + pr2 == "'''''") {
329
if ( basicElement[0] == "''")
334
if ( basicElement[0] == "'''")
343
stringBuilder.push( basic0 ) ;
345
var len = stringBuilder.length ;
347
if ( !basicElement[2] )
349
this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
350
// only empty element inside, remove it to avoid quotes
351
if ( ( stringBuilder.length == len || (stringBuilder.length == len + 1 && !stringBuilder[len].length) )
352
&& basicElement[0] && basicElement[0].charAt(0) == "'")
361
stringBuilder.push( basic1 ) ;
369
var isFirstLevel = !htmlNode.parentNode.nodeName.IEquals( 'ul', 'ol', 'li', 'dl', 'dt', 'dd' ) ;
371
this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
373
if ( isFirstLevel && stringBuilder[ stringBuilder.length - 1 ] != "\n" ) {
374
stringBuilder.push( '\n' ) ;
381
if( stringBuilder.length > 1)
383
var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ;
384
if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*")
385
stringBuilder.push( '\n' + prefix ) ;
388
var parent = htmlNode.parentNode ;
393
if ( parent.nodeName.toLowerCase() == 'ul' )
398
else if ( parent.nodeName.toLowerCase() == 'ol' )
403
else if ( parent.nodeName.toLowerCase() != 'li' )
406
parent = parent.parentNode ;
409
stringBuilder.push( listType ) ;
410
this._AppendChildNodes( htmlNode, stringBuilder, prefix + listType ) ;
417
// Get the actual Link href.
418
var href = htmlNode.getAttribute( '_fcksavedurl' ) ;
419
var hrefType = htmlNode.getAttribute( '_fck_mw_type' ) || '' ;
422
href = htmlNode.getAttribute( 'href' , 2 ) || '' ;
424
var isWikiUrl = true ;
426
if ( hrefType == "media" )
427
stringBuilder.push( '[[Media:' ) ;
428
else if ( htmlNode.className == "extiw" )
430
stringBuilder.push( '[[' ) ;
431
var isWikiUrl = true;
435
var isWikiUrl = !( href.StartsWith( 'mailto:' ) || /^\w+:\/\//.test( href ) ) ;
436
stringBuilder.push( isWikiUrl ? '[[' : '[' ) ;
439
if (htmlNode.getAttribute( '_fcknotitle' ) && htmlNode.getAttribute( '_fcknotitle' ) == "true")
441
var testHref = FCKConfig.ProtectedSource.Revert( href, 0 ) ;
442
var testInner = FCKConfig.ProtectedSource.Revert( htmlNode.innerHTML, 0 ) ;
443
if ( href.toLowerCase().StartsWith( 'category:' ) )
444
testInner = 'Category:' + testInner ;
445
if ( testHref.toLowerCase().StartsWith( 'rtecolon' ) )
446
testHref = testHref.replace( /rtecolon/, ":" ) ;
447
testInner = testInner.replace( /&/, "&" ) ;
448
if ( testInner == testHref )
451
if (href.toLowerCase().StartsWith( 'rtecolon' )) //change 'rtecolon=' => ':' in links
453
stringBuilder.push(':');
454
href = href.substring(8);
456
stringBuilder.push( href ) ;
457
if ( pipeline && htmlNode.innerHTML != '[n]' && (!isWikiUrl || href != htmlNode.innerHTML || !href.toLowerCase().StartsWith("category:")))
459
stringBuilder.push( isWikiUrl? '|' : ' ' ) ;
460
this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
462
stringBuilder.push( isWikiUrl ? ']]' : ']' ) ;
468
this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
469
var isFirstLevel = !htmlNode.parentNode.nodeName.IEquals( 'ul', 'ol', 'li', 'dl', 'dd', 'dt' ) ;
470
if ( isFirstLevel && stringBuilder[ stringBuilder.length - 1 ] != "\n" )
471
stringBuilder.push( '\n') ;
477
if( stringBuilder.length > 1)
479
var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ;
480
if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*" )
481
stringBuilder.push( '\n' + prefix ) ;
483
stringBuilder.push( ';' ) ;
484
this._AppendChildNodes( htmlNode, stringBuilder, prefix + ";") ;
490
if( stringBuilder.length > 1)
492
var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ;
493
if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*" )
494
stringBuilder.push( '\n' + prefix ) ;
496
stringBuilder.push( ':' ) ;
497
this._AppendChildNodes( htmlNode, stringBuilder, prefix + ":" ) ;
503
var attribs = this._GetAttributesStr( htmlNode ) ;
505
stringBuilder.push( '\n{|' ) ;
506
if ( attribs.length > 0 )
507
stringBuilder.push( attribs ) ;
508
stringBuilder.push( '\n' ) ;
510
if ( htmlNode.caption && htmlNode.caption.innerHTML.length > 0 )
512
stringBuilder.push( '|+ ' ) ;
513
this._AppendChildNodes( htmlNode.caption, stringBuilder, prefix ) ;
514
stringBuilder.push( '\n' ) ;
517
for ( var r = 0 ; r < htmlNode.rows.length ; r++ )
519
attribs = this._GetAttributesStr( htmlNode.rows[r] ) ;
521
stringBuilder.push( '|-' ) ;
522
if ( attribs.length > 0 )
523
stringBuilder.push( attribs ) ;
524
stringBuilder.push( '\n' ) ;
526
for ( var c = 0 ; c < htmlNode.rows[r].cells.length ; c++ )
528
attribs = this._GetAttributesStr( htmlNode.rows[r].cells[c] ) ;
530
if ( htmlNode.rows[r].cells[c].tagName.toLowerCase() == "th" )
531
stringBuilder.push( '!' ) ;
533
stringBuilder.push( '|' ) ;
535
if ( attribs.length > 0 )
536
stringBuilder.push( attribs + ' |' ) ;
538
stringBuilder.push( ' ' ) ;
540
this._IsInsideCell = true ;
541
this._AppendChildNodes( htmlNode.rows[r].cells[c], stringBuilder, prefix ) ;
542
this._IsInsideCell = false ;
544
stringBuilder.push( '\n' ) ;
548
stringBuilder.push( '|}\n' ) ;
554
var formula = htmlNode.getAttribute( '_fck_mw_math' ) ;
556
if ( formula && formula.length > 0 )
558
stringBuilder.push( '<math>' ) ;
559
stringBuilder.push( formula ) ;
560
stringBuilder.push( '</math>' ) ;
564
var imgName = htmlNode.getAttribute( '_fck_mw_filename' ) ;
565
var imgCaption = htmlNode.getAttribute( 'alt' ) || '' ;
566
var imgType = htmlNode.getAttribute( '_fck_mw_type' ) || '' ;
567
var imgLocation = htmlNode.getAttribute( '_fck_mw_location' ) || '' ;
568
var imgWidth = htmlNode.getAttribute( '_fck_mw_width' ) || '' ;
569
var imgHeight = htmlNode.getAttribute( '_fck_mw_height' ) || '' ;
570
var imgStyleWidth = ( parseInt(htmlNode.style.width) || '' ) + '' ;
571
var imgStyleHeight = ( parseInt(htmlNode.style.height) || '' ) + '' ;
572
var imgRealWidth = ( htmlNode.getAttribute( 'width' ) || '' ) + '' ;
573
var imgRealHeight = ( htmlNode.getAttribute( 'height' ) || '' ) + '' ;
575
stringBuilder.push( '[[Image:' ) ;
576
stringBuilder.push( imgName ) ;
578
if ( imgStyleWidth.length > 0 )
579
imgWidth = imgStyleWidth ;
580
else if ( imgWidth.length > 0 && imgRealWidth.length > 0 )
581
imgWidth = imgRealWidth ;
583
if ( imgStyleHeight.length > 0 )
584
imgHeight = imgStyleHeight ;
585
else if ( imgHeight.length > 0 && imgRealHeight.length > 0 )
586
imgHeight = imgRealHeight ;
588
if ( imgType.length > 0 )
589
stringBuilder.push( '|' + imgType ) ;
591
if ( imgLocation.length > 0 )
592
stringBuilder.push( '|' + imgLocation ) ;
594
if ( imgWidth.length > 0 )
596
stringBuilder.push( '|' + imgWidth ) ;
598
if ( imgHeight.length > 0 )
599
stringBuilder.push( 'x' + imgHeight ) ;
601
stringBuilder.push( 'px' ) ;
604
if ( imgCaption.length > 0 )
605
stringBuilder.push( '|' + imgCaption ) ;
607
stringBuilder.push( ']]' ) ;
612
switch ( htmlNode.className )
614
case 'fck_mw_source' :
615
var refLang = htmlNode.getAttribute( 'lang' ) ;
617
stringBuilder.push( '<source' ) ;
618
stringBuilder.push( ' lang="' + refLang + '"' ) ;
619
stringBuilder.push( '>' ) ;
620
stringBuilder.push( FCKTools.HTMLDecode(htmlNode.innerHTML).replace(/fckLR/g,'\r\n') ) ;
621
stringBuilder.push( '</source>' ) ;
625
var refName = htmlNode.getAttribute( 'name' ) ;
627
stringBuilder.push( '<ref' ) ;
629
if ( refName && refName.length > 0 )
630
stringBuilder.push( ' name="' + refName + '"' ) ;
632
if ( htmlNode.innerHTML.length == 0 )
633
stringBuilder.push( ' />' ) ;
636
stringBuilder.push( '>' ) ;
637
stringBuilder.push( htmlNode.innerHTML ) ;
638
stringBuilder.push( '</ref>' ) ;
642
case 'fck_mw_references' :
643
stringBuilder.push( '<references />' ) ;
646
case 'fck_mw_signature' :
647
stringBuilder.push( FCKConfig.WikiSignature ) ;
650
case 'fck_mw_template' :
651
stringBuilder.push( FCKTools.HTMLDecode(htmlNode.innerHTML).replace(/fckLR/g,'\r\n') ) ;
654
case 'fck_mw_magic' :
655
stringBuilder.push( htmlNode.innerHTML ) ;
658
case 'fck_mw_nowiki' :
659
sNodeName = 'nowiki' ;
666
case 'fck_mw_includeonly' :
667
sNodeName = 'includeonly' ;
670
case 'fck_mw_noinclude' :
671
sNodeName = 'noinclude' ;
674
case 'fck_mw_gallery' :
675
sNodeName = 'gallery' ;
678
case 'fck_mw_onlyinclude' :
679
sNodeName = 'onlyinclude' ;
684
// Change the node name and fell in the "default" case.
685
if ( htmlNode.getAttribute( '_fck_mw_customtag' ) )
686
sNodeName = htmlNode.getAttribute( '_fck_mw_tagname' ) ;
689
var attribs = this._GetAttributesStr( htmlNode ) ;
691
if ( htmlNode.className == "_fck_mw_lspace")
693
stringBuilder.push( "\n " ) ;
694
this._inLSpace = true ;
695
this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
696
this._inLSpace = false ;
697
var len = stringBuilder.length ;
699
var tail = stringBuilder[len-2] + stringBuilder[len-1];
701
tail = stringBuilder[len-3] + tail ;
703
if (tail.EndsWith("\n ")) {
704
stringBuilder[len-1] = stringBuilder[len-1].replace(/ $/, "");
706
else if ( !tail.EndsWith("\n") ) {
707
stringBuilder.push( "\n" ) ;
713
stringBuilder.push( '<' ) ;
714
stringBuilder.push( sNodeName ) ;
716
if ( attribs.length > 0 )
717
stringBuilder.push( attribs ) ;
718
if(htmlNode.innerHTML == "")
719
stringBuilder.push( ' />' ) ;
722
stringBuilder.push( '>' ) ;
724
this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
725
this._inPre = false ;
727
stringBuilder.push( '<\/' ) ;
728
stringBuilder.push( sNodeName ) ;
729
stringBuilder.push( '>' ) ;
735
var attribs = this._GetAttributesStr( htmlNode ) ;
737
stringBuilder.push( '<' ) ;
738
stringBuilder.push( sNodeName ) ;
740
if ( attribs.length > 0 )
741
stringBuilder.push( attribs ) ;
743
stringBuilder.push( '>' ) ;
744
this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
745
stringBuilder.push( '<\/' ) ;
746
stringBuilder.push( sNodeName ) ;
747
stringBuilder.push( '>' ) ;
752
htmlNode._fckxhtmljob = FCKXHtml.CurrentJobNum ;
758
var parentIsSpecialTag = htmlNode.parentNode.getAttribute( '_fck_mw_customtag' ) ;
759
var textValue = htmlNode.nodeValue;
760
if ( !parentIsSpecialTag )
762
if ( FCKBrowserInfo.IsIE && this._inLSpace ) {
763
textValue = textValue.replace( /\r/g, "\r " ) ;
764
if (textValue.EndsWith( "\r " )) {
765
textValue = textValue.replace( /\r $/, "\r" );
768
if ( !FCKBrowserInfo.IsIE && this._inLSpace ) {
769
textValue = textValue.replace( /\n(?! )/g, "\n " ) ;
772
if (!this._inLSpace && !this._inPre) {
773
textValue = textValue.replace( /[\n\t]/g, ' ' ) ;
776
textValue = FCKTools.HTMLEncode( textValue ) ;
777
textValue = textValue.replace( /\u00A0/g, ' ' ) ;
779
if ( ( !htmlNode.previousSibling ||
780
( stringBuilder.length > 0 && stringBuilder[ stringBuilder.length - 1 ].EndsWith( '\n' ) ) ) && !this._inLSpace && !this._inPre )
782
textValue = textValue.LTrim() ;
785
if ( !htmlNode.nextSibling && !this._inLSpace && !this._inPre && (!htmlNode.parentNode || !htmlNode.parentNode.nextSibling))
786
textValue = textValue.RTrim() ;
788
if (!this._inLSpace && !this._inPre)
789
textValue = textValue.replace( / {2,}/g, ' ' ) ;
791
if ( this._inLSpace && textValue.length == 1 && textValue.charCodeAt(0) == 13 )
792
textValue = textValue + " " ;
794
if ( !this._inLSpace && !this._inPre && textValue == " " ) {
795
var len = stringBuilder.length;
797
var tail = stringBuilder[len-2] + stringBuilder[len-1];
798
if ( tail.toString().EndsWith( "\n" ) )
803
if ( this._IsInsideCell ) {
804
var result, linkPattern = new RegExp( "\\[\\[.*?\\]\\]", "g" ) ;
805
while( result = linkPattern.exec( textValue ) ) {
806
textValue = textValue.replace( result, result.toString().replace( /\|/g, "<!--LINK_PIPE-->" ) ) ;
808
textValue = textValue.replace( /\|/g, '|' ) ;
809
textValue = textValue.replace( /<!--LINK_PIPE-->/g, '|' ) ;
814
textValue = FCKTools.HTMLDecode(textValue).replace(/fckLR/g,'\r\n');
817
stringBuilder.push( textValue ) ;
822
// IE catches the <!DOTYPE ... > as a comment, but it has no
823
// innerHTML, so we can catch it, and ignore it.
824
if ( FCKBrowserInfo.IsIE && !htmlNode.innerHTML )
827
stringBuilder.push( "<!--" ) ;
829
try { stringBuilder.push( htmlNode.nodeValue ) ; }
830
catch (e) { /* Do nothing... probably this is a wrong format comment. */ }
832
stringBuilder.push( "-->" ) ;
837
_AppendChildNodes : function( htmlNode, stringBuilder, listPrefix )
839
var child = htmlNode.firstChild ;
843
this._AppendNode( child, stringBuilder, listPrefix ) ;
844
child = child.nextSibling ;
848
_GetAttributesStr : function( htmlNode )
851
var aAttributes = htmlNode.attributes ;
853
for ( var n = 0 ; n < aAttributes.length ; n++ )
855
var oAttribute = aAttributes[n] ;
857
if ( oAttribute.specified )
859
var sAttName = oAttribute.nodeName.toLowerCase() ;
862
// Ignore any attribute starting with "_fck".
863
if ( sAttName.StartsWith( '_fck' ) )
865
// There is a bug in Mozilla that returns '_moz_xxx' attributes as specified.
866
else if ( sAttName.indexOf( '_moz' ) == 0 )
868
// For "class", nodeValue must be used.
869
else if ( sAttName == 'class' )
871
// Get the class, removing any fckXXX we can have there.
872
sAttValue = oAttribute.nodeValue.replace( /(^|\s*)fck\S+/, '' ).Trim() ;
874
if ( sAttValue.length == 0 )
877
else if ( sAttName == 'style' && FCKBrowserInfo.IsIE ) {
878
sAttValue = htmlNode.style.cssText.toLowerCase() ;
880
// XHTML doens't support attribute minimization like "CHECKED". It must be trasformed to cheched="checked".
881
else if ( oAttribute.nodeValue === true )
882
sAttValue = sAttName ;
884
sAttValue = htmlNode.getAttribute( sAttName, 2 ) ; // We must use getAttribute to get it exactly as it is defined.
887
if ( sAttName.StartsWith( '{{' ) && sAttName.EndsWith( '}}' ) ) {
888
attStr += ' ' + sAttName ;
891
attStr += ' ' + sAttName + '="' + String(sAttValue).replace( '"', '"' ) + '"' ;
899
// Here we change the SwitchEditMode function to make the Ajax call when
900
// switching from Wikitext.
903
if (window.parent.showFCKEditor & (2|4)) //if popup or toggle link
905
var original_ULF = FCK.UpdateLinkedField ;
906
FCK.UpdateLinkedField = function(){
907
if (window.parent.showFCKEditor & 1) //only if editor is up-to-date
909
original_ULF.apply();
913
var original = FCK.SwitchEditMode ;
914
window.parent.oFCKeditor.ready = true;
915
FCK.SwitchEditMode = function()
917
var args = arguments ;
918
window.parent.oFCKeditor.ready = false;
919
var loadHTMLFromAjax = function( result )
921
FCK.EditingArea.Textarea.value = result.responseText ;
922
original.apply( FCK, args ) ;
923
window.parent.oFCKeditor.ready = true;
925
var edittools_markup = parent.document.getElementById ('editpage-specialchars') ;
927
if ( FCK.EditMode == FCK_EDITMODE_SOURCE )
929
// Hide the textarea to avoid seeing the code change.
930
FCK.EditingArea.Textarea.style.visibility = 'hidden' ;
931
var loading = document.createElement( 'span' ) ;
932
loading.innerHTML = ' '+ (FCKLang.wikiLoadingWikitext || 'Loading Wikitext. Please wait...' )+' ';
933
loading.style.position = 'absolute' ;
934
loading.style.left = '5px' ;
935
// loading.style.backgroundColor = '#ff0000' ;
936
FCK.EditingArea.Textarea.parentNode.appendChild( loading, FCK.EditingArea.Textarea ) ;
937
// if we have a standard Edittools div, hide the one containing wikimarkup
938
if (edittools_markup) {
939
edittools_markup.style.display = 'none' ;
942
// Use Ajax to transform the Wikitext to HTML.
943
if( window.parent.popup ){
944
window.parent.popup.parent.FCK_sajax( 'wfSajaxWikiToHTML', [FCK.EditingArea.Textarea.value], loadHTMLFromAjax ) ;
947
window.parent.FCK_sajax( 'wfSajaxWikiToHTML', [FCK.EditingArea.Textarea.value], loadHTMLFromAjax ) ;
951
original.apply( FCK, args ) ;
952
if (edittools_markup) {
953
edittools_markup.style.display = '' ;
955
window.parent.oFCKeditor.ready = true;
960
// MediaWiki document processor.
961
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
963
// #1011: change signatures to SPAN elements
964
var aTextNodes = document.getElementsByTagName( '*' ) ;
966
var signatureRegExp = new RegExp( FCKConfig.WikiSignature.replace( /([*:.*?();|$])/g, "\\$1" ), "i" );
967
while (element = aTextNodes[i++])
969
var nodes = element.childNodes ;
971
while ( node = nodes[j++] )
973
if ( node.nodeType == 3 )
977
while ( aSignatures = node.nodeValue.match( signatureRegExp ) )
979
index = node.nodeValue.indexOf( aSignatures[0] ) ;
982
var e = FCK.EditorDocument.createElement( 'span' ) ;
983
e.className = "fck_mw_signature";
984
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__MWSignature', e ) ;
986
var substr1 = FCK.EditorDocument.createTextNode( node.nodeValue.substring(0, index) ) ;
987
var substr2 = FCK.EditorDocument.createTextNode( node.nodeValue.substring(index + aSignatures[0].length) ) ;
989
node.parentNode.insertBefore( substr1, node ) ;
990
node.parentNode.insertBefore( oFakeImage, node ) ;
991
node.parentNode.insertBefore( substr2, node ) ;
993
node.parentNode.removeChild( node ) ;
995
node.nodeValue = '' ;
1002
// Templates and magic words.
1003
var aSpans = document.getElementsByTagName( 'SPAN' ) ;
1006
var i = aSpans.length - 1 ;
1007
while ( i >= 0 && ( eSpan = aSpans[i--] ) )
1009
var className = null ;
1010
switch ( eSpan.className )
1012
case 'fck_mw_source' :
1013
className = 'FCK__MWSource' ;
1015
if (className == null)
1016
className = 'FCK__MWRef' ;
1017
case 'fck_mw_references' :
1018
if ( className == null )
1019
className = 'FCK__MWReferences' ;
1020
case 'fck_mw_template' :
1021
if ( className == null ) //YC
1022
className = 'FCK__MWTemplate' ; //YC
1023
case 'fck_mw_magic' :
1024
if ( className == null )
1025
className = 'FCK__MWMagicWord' ;
1026
case 'fck_mw_magic' :
1027
if ( className == null )
1028
className = 'FCK__MWMagicWord' ;
1029
case 'fck_mw_special' : //YC
1030
if ( className == null )
1031
className = 'FCK__MWSpecial' ;
1032
case 'fck_mw_nowiki' :
1033
if ( className == null )
1034
className = 'FCK__MWNowiki' ;
1035
case 'fck_mw_html' :
1036
if ( className == null )
1037
className = 'FCK__MWHtml' ;
1038
case 'fck_mw_includeonly' :
1039
if ( className == null )
1040
className = 'FCK__MWIncludeonly' ;
1041
case 'fck_mw_gallery' :
1042
if ( className == null )
1043
className = 'FCK__MWGallery' ;
1044
case 'fck_mw_noinclude' :
1045
if ( className == null )
1046
className = 'FCK__MWNoinclude' ;
1047
case 'fck_mw_onlyinclude' :
1048
if ( className == null )
1049
className = 'FCK__MWOnlyinclude' ;
1051
var oImg = FCKDocumentProcessor_CreateFakeImage( className, eSpan.cloneNode(true) ) ;
1052
oImg.setAttribute( '_' + eSpan.className, 'true', 0 ) ;
1054
eSpan.parentNode.insertBefore( oImg, eSpan ) ;
1055
eSpan.parentNode.removeChild( eSpan ) ;
1060
// Math tags without Tex.
1061
var aImgs = document.getElementsByTagName( 'IMG' ) ;
1063
i = aImgs.length - 1 ;
1064
while ( i >= 0 && ( eImg = aImgs[i--] ) )
1066
var className = null ;
1067
switch ( eImg.className )
1069
case 'FCK__MWMath' :
1070
eImg.src = FCKConfig.PluginsPath + 'mediawiki/images/icon_math.gif' ;
1075
// InterWiki / InterLanguage links
1076
var aHrefs = document.getElementsByTagName( 'A' ) ;
1078
var i = aHrefs.length - 1 ;
1079
while ( i >= 0 && ( a = aHrefs[i--] ) )
1081
if (a.className == 'extiw')
1084
a.setAttribute( '_fcksavedurl', a.href ) ;
1088
if (a.href.toLowerCase().StartsWith( 'rtecolon' ))
1090
a.href = ":" + a.href.substring(8);
1091
if (a.innerHTML.toLowerCase().StartsWith( 'rtecolon' ))
1093
a.innerHTML = a.innerHTML.substring(8);
1100
// Context menu for templates.
1101
FCK.ContextMenu.RegisterListener({
1102
AddItems : function( contextMenu, tag, tagName )
1104
if ( tagName == 'IMG' )
1106
if ( tag.getAttribute( '_fck_mw_template' ) )
1108
contextMenu.AddSeparator() ;
1109
contextMenu.AddItem( 'MW_Template', FCKLang.wikiMnuTemplate || 'Template Properties' ) ;
1111
if ( tag.getAttribute( '_fck_mw_magic' ) )
1113
contextMenu.AddSeparator() ;
1114
contextMenu.AddItem( 'MW_MagicWord', FCKLang.wikiMnuMagicWord || 'Modify Magic Word' ) ;
1116
if ( tag.getAttribute( '_fck_mw_ref' ) )
1118
contextMenu.AddSeparator() ;
1119
contextMenu.AddItem( 'MW_Ref', FCKLang.wikiMnuReference || 'Reference Properties' ) ;
1121
if ( tag.getAttribute( '_fck_mw_html' ) )
1123
contextMenu.AddSeparator() ;
1124
contextMenu.AddItem( 'MW_Special', 'Edit HTML code' ) ;
1126
if ( tag.getAttribute( '_fck_mw_source' ) )
1128
contextMenu.AddSeparator() ;
1129
contextMenu.AddItem( 'MW_Source', FCKLang.wikiMnuSourceCode || 'Source Code Properties' ) ;
1131
if ( tag.getAttribute( '_fck_mw_math' ) )
1133
contextMenu.AddSeparator() ;
1134
contextMenu.AddItem( 'MW_Math', FCKLang.wikiMnuFormula || 'Edit Formula' ) ;
1136
if ( tag.getAttribute( '_fck_mw_special' ) || tag.getAttribute( '_fck_mw_nowiki' ) || tag.getAttribute( '_fck_mw_includeonly' ) || tag.getAttribute( '_fck_mw_noinclude' ) || tag.getAttribute( '_fck_mw_onlyinclude' ) || tag.getAttribute( '_fck_mw_gallery' )) //YC
1138
contextMenu.AddSeparator() ;
1139
contextMenu.AddItem( 'MW_Special', FCKLang.wikiMnuSpecial || 'Special Tag Properties' ) ;