~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to dist/mediawiki-extensions-fckeditor/usr/share/mediawiki-extensions/fckeditor/plugins/mediawiki/fckplugin.js

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 
3
 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
 
4
 *
 
5
 * == BEGIN LICENSE ==
 
6
 *
 
7
 * Licensed under the terms of any of the following licenses at your
 
8
 * choice:
 
9
 *
 
10
 *  - GNU General Public License Version 2 or later (the "GPL")
 
11
 *    http://www.gnu.org/licenses/gpl.html
 
12
 *
 
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 
14
 *    http://www.gnu.org/licenses/lgpl.html
 
15
 *
 
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 
18
 *
 
19
 * == END LICENSE ==
 
20
 *
 
21
 * Main MediaWiki integration plugin.
 
22
 *
 
23
 * Wikitext syntax reference:
 
24
 *      http://meta.wikimedia.org/wiki/Help:Wikitext_examples
 
25
 *      http://meta.wikimedia.org/wiki/Help:Advanced_editing
 
26
 *
 
27
 * MediaWiki Sandbox:
 
28
 *      http://meta.wikimedia.org/wiki/Meta:Sandbox
 
29
 */
 
30
 
 
31
// Rename the "Source" buttom to "Wikitext".
 
32
FCKToolbarItems.RegisterItem( 'Source', new FCKToolbarButton( 'Source', 'Wikitext', null, FCK_TOOLBARITEM_ICONTEXT, true, true, 1 ) ) ;
 
33
 
 
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 ) ;
 
38
 
 
39
//Ref button
 
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;}
 
47
}
 
48
 
 
49
//References button
 
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;}
 
59
}
 
60
 
 
61
FCKReferences.prototype.Execute = function()
 
62
{
 
63
        if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
 
64
                return ;
 
65
 
 
66
        FCKUndo.SaveUndoStep() ;
 
67
 
 
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";
 
72
 
 
73
        oFakeImage = FCK.InsertElement( FCKDocumentProcessor_CreateFakeImage( 'FCK__MWReferences', e ) ) ;
 
74
}
 
75
FCKToolbarItems.RegisterItem( 'MW_References', tbButton ) ;
 
76
 
 
77
//Signature button
 
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' ;
 
83
 
 
84
FCKSignature.prototype.Execute = function()
 
85
{
 
86
        if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
 
87
                return ;
 
88
 
 
89
        FCKUndo.SaveUndoStep() ;
 
90
        var e = FCK.EditorDocument.createElement( 'span' ) ;
 
91
        e.className = "fck_mw_signature";
 
92
 
 
93
        oFakeImage = FCK.InsertElement( FCKDocumentProcessor_CreateFakeImage( 'FCK__MWSignature', e ) ) ;
 
94
}
 
95
FCKToolbarItems.RegisterItem( 'MW_Signature', tbButton ) ;
 
96
 
 
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 ) ;
 
100
 
 
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;}
 
108
}
 
109
 
 
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 ) ;
 
113
 
 
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 ) ;
 
117
 
 
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 ) ) ;
 
127
 
 
128
FCKToolbarItems.OldGetItem = FCKToolbarItems.GetItem;
 
129
 
 
130
FCKToolbarItems.GetItem = function( itemName )
 
131
{
 
132
        var oItem = FCKToolbarItems.LoadedItems[ itemName ] ;
 
133
 
 
134
        if ( oItem )
 
135
                return oItem ;
 
136
 
 
137
        switch ( itemName )
 
138
        {
 
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 ;
 
144
 
 
145
                default:
 
146
                        return FCKToolbarItems.OldGetItem( itemName );
 
147
        }
 
148
 
 
149
        FCKToolbarItems.LoadedItems[ itemName ] = oItem ;
 
150
 
 
151
        return oItem ;
 
152
}
 
153
 
 
154
FCKToolbarButton.prototype.Click = function()
 
155
{
 
156
        var oToolbarButton = this._ToolbarButton || this ;
 
157
 
 
158
        // for some buttons, do something else instead...
 
159
        var CMode = false ;
 
160
        if ( oToolbarButton.SourceView && (FCK_EDITMODE_SOURCE == FCK.EditMode) )
 
161
        {
 
162
                if ( !window.parent.popup )
 
163
                        var oDoc = window.parent;
 
164
                else
 
165
                        var oDoc = window.parent.popup;
 
166
 
 
167
                switch (oToolbarButton.CommandName)
 
168
                {
 
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 ;
 
174
                }
 
175
        }
 
176
 
 
177
        if ( !CMode )
 
178
                FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( oToolbarButton.CommandName ).Execute() ;
 
179
}
 
180
 
 
181
// MediaWiki Wikitext Data Processor implementation.
 
182
FCK.DataProcessor =
 
183
{
 
184
        _inPre : false,
 
185
        _inLSpace : false,
 
186
 
 
187
        /*
 
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
 
191
         * the DOCTYPE.
 
192
         *     @param {String} data The data to be converted in the
 
193
         *            DataProcessor specific format.
 
194
         */
 
195
        ConvertToHtml : function( data )
 
196
        {
 
197
                // Call the original code.
 
198
                return FCKDataProcessor.prototype.ConvertToHtml.call( this, data ) ;
 
199
        },
 
200
 
 
201
        /*
 
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.
 
209
         */
 
210
        ConvertToDataFormat : function( rootNode, excludeRoot, ignoreIfEmptyParagraph, format )
 
211
        {
 
212
                // rootNode is <body>.
 
213
 
 
214
                // Normalize the document for text node processing (except IE - #1586).
 
215
                if ( !FCKBrowserInfo.IsIE )
 
216
                        rootNode.normalize() ;
 
217
 
 
218
                var stringBuilder = new Array() ;
 
219
                this._AppendNode( rootNode, stringBuilder, '' ) ;
 
220
                return stringBuilder.join( '' ).RTrim().replace(/^\n*/, "") ;
 
221
        },
 
222
 
 
223
        /*
 
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.
 
227
         */
 
228
        FixHtml : function( html )
 
229
        {
 
230
                return html ;
 
231
        },
 
232
 
 
233
        // Collection of element definitions:
 
234
        //              0 : Prefix
 
235
        //              1 : Suffix
 
236
        //              2 : Ignore children
 
237
        _BasicElements : {
 
238
                body    : [ ],
 
239
                b               : [ "'''", "'''" ],
 
240
                strong  : [ "'''", "'''" ],
 
241
                i               : [ "''", "''" ],
 
242
                em              : [ "''", "''" ],
 
243
                p               : [ '\n', '\n' ],
 
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 ]
 
252
        } ,
 
253
 
 
254
        // This function is based on FCKXHtml._AppendNode.
 
255
        _AppendNode : function( htmlNode, stringBuilder, prefix )
 
256
        {
 
257
                if ( !htmlNode )
 
258
                        return ;
 
259
 
 
260
                switch ( htmlNode.nodeType )
 
261
                {
 
262
                        // Element Node.
 
263
                        case 1 :
 
264
 
 
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 ) ;
 
269
 
 
270
                                // Mozilla insert custom nodes in the DOM.
 
271
                                if ( FCKBrowserInfo.IsGecko && htmlNode.hasAttribute('_moz_editor_bogus_node') )
 
272
                                        return ;
 
273
 
 
274
                                // This is for elements that are instrumental to FCKeditor and
 
275
                                // must be removed from the final HTML.
 
276
                                if ( htmlNode.getAttribute('_fcktemp') )
 
277
                                        return ;
 
278
 
 
279
                                // Get the element name.
 
280
                                var sNodeName = htmlNode.tagName.toLowerCase()  ;
 
281
 
 
282
                                if ( FCKBrowserInfo.IsIE )
 
283
                                {
 
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 ;
 
287
                                }
 
288
                                else
 
289
                                {
 
290
                                        if ( sNodeName.StartsWith( 'fck:' ) )
 
291
                                                sNodeName = sNodeName.Remove( 0,4 ) ;
 
292
                                }
 
293
 
 
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 ) )
 
298
                                        return ;
 
299
 
 
300
                                if ( sNodeName == 'br' && ( this._inPre || this._inLSpace ) )
 
301
                                {
 
302
                                        stringBuilder.push( "\n" ) ;
 
303
                                        if ( this._inLSpace )
 
304
                                                stringBuilder.push( " " ) ;
 
305
                                        return ;
 
306
                                }
 
307
 
 
308
                                // Remove the <br> if it is a bogus node.
 
309
                                if ( sNodeName == 'br' && htmlNode.getAttribute( 'type', 2 ) == '_moz' )
 
310
                                        return ;
 
311
 
 
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 )
 
315
                                        return ;
 
316
 
 
317
                                var basicElement = this._BasicElements[ sNodeName ] ;
 
318
                                if ( basicElement )
 
319
                                {
 
320
                                        var basic0 = basicElement[0];
 
321
                                        var basic1 = basicElement[1];
 
322
 
 
323
                                        if ( ( basicElement[0] == "''" || basicElement[0] == "'''" ) && stringBuilder.length > 2 )
 
324
                                        {
 
325
                                                var pr1 = stringBuilder[stringBuilder.length-1];
 
326
                                                var pr2 = stringBuilder[stringBuilder.length-2];
 
327
 
 
328
                                                if ( pr1 + pr2 == "'''''") {
 
329
                                                        if ( basicElement[0] == "''")
 
330
                                                        {
 
331
                                                                basic0 = '<i>';
 
332
                                                                basic1 = '</i>';
 
333
                                                        }
 
334
                                                        if ( basicElement[0] == "'''")
 
335
                                                        {
 
336
                                                                basic0 = '<b>';
 
337
                                                                basic1 = '</b>';
 
338
                                                        }
 
339
                                                }
 
340
                                        }
 
341
 
 
342
                                        if ( basic0 )
 
343
                                                stringBuilder.push( basic0 ) ;
 
344
 
 
345
                                        var len = stringBuilder.length ;
 
346
 
 
347
                                        if ( !basicElement[2] )
 
348
                                        {
 
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) == "'")
 
353
                                                {
 
354
                                                        stringBuilder.pop();
 
355
                                                        stringBuilder.pop();
 
356
                                                        return;
 
357
                                                }
 
358
                                        }
 
359
 
 
360
                                        if ( basic1 )
 
361
                                                stringBuilder.push( basic1 ) ;
 
362
                                }
 
363
                                else
 
364
                                {
 
365
                                        switch ( sNodeName )
 
366
                                        {
 
367
                                                case 'ol' :
 
368
                                                case 'ul' :
 
369
                                                        var isFirstLevel = !htmlNode.parentNode.nodeName.IEquals( 'ul', 'ol', 'li', 'dl', 'dt', 'dd' ) ;
 
370
 
 
371
                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
 
372
 
 
373
                                                        if ( isFirstLevel && stringBuilder[ stringBuilder.length - 1 ] != "\n" ) {
 
374
                                                                stringBuilder.push( '\n' ) ;
 
375
                                                        }
 
376
 
 
377
                                                        break ;
 
378
 
 
379
                                                case 'li' :
 
380
 
 
381
                                                        if( stringBuilder.length > 1)
 
382
                                                        {
 
383
                                                                var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ;
 
384
                                                                if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*")
 
385
                                                                        stringBuilder.push( '\n' + prefix ) ;
 
386
                                                        }
 
387
 
 
388
                                                        var parent = htmlNode.parentNode ;
 
389
                                                        var listType = "#" ;
 
390
 
 
391
                                                        while ( parent )
 
392
                                                        {
 
393
                                                                if ( parent.nodeName.toLowerCase() == 'ul' )
 
394
                                                                {
 
395
                                                                        listType = "*" ;
 
396
                                                                        break ;
 
397
                                                                }
 
398
                                                                else if ( parent.nodeName.toLowerCase() == 'ol' )
 
399
                                                                {
 
400
                                                                        listType = "#" ;
 
401
                                                                        break ;
 
402
                                                                }
 
403
                                                                else if ( parent.nodeName.toLowerCase() != 'li' )
 
404
                                                                        break ;
 
405
 
 
406
                                                                parent = parent.parentNode ;
 
407
                                                        }
 
408
 
 
409
                                                        stringBuilder.push( listType ) ;
 
410
                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix + listType ) ;
 
411
 
 
412
                                                        break ;
 
413
 
 
414
                                                case 'a' :
 
415
 
 
416
                                                        var pipeline = true;
 
417
                                                        // Get the actual Link href.
 
418
                                                        var href = htmlNode.getAttribute( '_fcksavedurl' ) ;
 
419
                                                        var hrefType            = htmlNode.getAttribute( '_fck_mw_type' ) || '' ;
 
420
 
 
421
                                                        if ( href == null )
 
422
                                                                href = htmlNode.getAttribute( 'href' , 2 ) || '' ;
 
423
 
 
424
                                                        var isWikiUrl = true ;
 
425
 
 
426
                                                        if ( hrefType == "media" )
 
427
                                                                stringBuilder.push( '[[Media:' ) ;
 
428
                                                        else if ( htmlNode.className == "extiw" )
 
429
                                                        {
 
430
                                                                stringBuilder.push( '[[' ) ;
 
431
                                                                var isWikiUrl = true;
 
432
                                                        }
 
433
                                                        else
 
434
                                                        {
 
435
                                                                var isWikiUrl = !( href.StartsWith( 'mailto:' ) || /^\w+:\/\//.test( href ) ) ;
 
436
                                                                stringBuilder.push( isWikiUrl ? '[[' : '[' ) ;
 
437
                                                        }
 
438
                                                        //#2223
 
439
                                                        if (htmlNode.getAttribute( '_fcknotitle' ) && htmlNode.getAttribute( '_fcknotitle' ) == "true")
 
440
                                                        {
 
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( /&amp;/, "&" ) ;
 
448
                                                                if ( testInner == testHref )
 
449
                                                                        pipeline = false ;
 
450
                                                        }
 
451
                                                        if (href.toLowerCase().StartsWith( 'rtecolon' ))                //change 'rtecolon=' => ':' in links
 
452
                                                        {
 
453
                                                                stringBuilder.push(':');
 
454
                                                                href = href.substring(8);
 
455
                                                        }
 
456
                                                        stringBuilder.push( href ) ;
 
457
                                                        if ( pipeline && htmlNode.innerHTML != '[n]' && (!isWikiUrl || href != htmlNode.innerHTML || !href.toLowerCase().StartsWith("category:")))
 
458
                                                        {
 
459
                                                                stringBuilder.push( isWikiUrl? '|' : ' ' ) ;
 
460
                                                                this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
 
461
                                                        }
 
462
                                                        stringBuilder.push( isWikiUrl ? ']]' : ']' ) ;
 
463
 
 
464
                                                        break ;
 
465
 
 
466
                                                case 'dl' :
 
467
 
 
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') ;
 
472
 
 
473
                                                        break ;
 
474
 
 
475
                                                case 'dt' :
 
476
 
 
477
                                                        if( stringBuilder.length > 1)
 
478
                                                        {
 
479
                                                                var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ;
 
480
                                                                if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*" )
 
481
                                                                        stringBuilder.push( '\n' + prefix ) ;
 
482
                                                        }
 
483
                                                        stringBuilder.push( ';' ) ;
 
484
                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix + ";") ;
 
485
 
 
486
                                                        break ;
 
487
 
 
488
                                                case 'dd' :
 
489
 
 
490
                                                        if( stringBuilder.length > 1)
 
491
                                                        {
 
492
                                                                var sLastStr = stringBuilder[ stringBuilder.length - 1 ] ;
 
493
                                                                if ( sLastStr != ";" && sLastStr != ":" && sLastStr != "#" && sLastStr != "*" )
 
494
                                                                        stringBuilder.push( '\n' + prefix ) ;
 
495
                                                        }
 
496
                                                        stringBuilder.push( ':' ) ;
 
497
                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix + ":" ) ;
 
498
 
 
499
                                                        break ;
 
500
 
 
501
                                                case 'table' :
 
502
 
 
503
                                                        var attribs = this._GetAttributesStr( htmlNode ) ;
 
504
 
 
505
                                                        stringBuilder.push( '\n{|' ) ;
 
506
                                                        if ( attribs.length > 0 )
 
507
                                                                stringBuilder.push( attribs ) ;
 
508
                                                        stringBuilder.push( '\n' ) ;
 
509
 
 
510
                                                        if ( htmlNode.caption && htmlNode.caption.innerHTML.length > 0 )
 
511
                                                        {
 
512
                                                                stringBuilder.push( '|+ ' ) ;
 
513
                                                                this._AppendChildNodes( htmlNode.caption, stringBuilder, prefix ) ;
 
514
                                                                stringBuilder.push( '\n' ) ;
 
515
                                                        }
 
516
 
 
517
                                                        for ( var r = 0 ; r < htmlNode.rows.length ; r++ )
 
518
                                                        {
 
519
                                                                attribs = this._GetAttributesStr( htmlNode.rows[r] ) ;
 
520
 
 
521
                                                                stringBuilder.push( '|-' ) ;
 
522
                                                                if ( attribs.length > 0 )
 
523
                                                                        stringBuilder.push( attribs ) ;
 
524
                                                                stringBuilder.push( '\n' ) ;
 
525
 
 
526
                                                                for ( var c = 0 ; c < htmlNode.rows[r].cells.length ; c++ )
 
527
                                                                {
 
528
                                                                        attribs = this._GetAttributesStr( htmlNode.rows[r].cells[c] ) ;
 
529
 
 
530
                                                                        if ( htmlNode.rows[r].cells[c].tagName.toLowerCase() == "th" )
 
531
                                                                                stringBuilder.push( '!' ) ;
 
532
                                                                        else
 
533
                                                                                stringBuilder.push( '|' ) ;
 
534
 
 
535
                                                                        if ( attribs.length > 0 )
 
536
                                                                                stringBuilder.push( attribs + ' |' ) ;
 
537
 
 
538
                                                                        stringBuilder.push( ' ' ) ;
 
539
 
 
540
                                                                        this._IsInsideCell = true ;
 
541
                                                                        this._AppendChildNodes( htmlNode.rows[r].cells[c], stringBuilder, prefix ) ;
 
542
                                                                        this._IsInsideCell = false ;
 
543
 
 
544
                                                                        stringBuilder.push( '\n' ) ;
 
545
                                                                }
 
546
                                                        }
 
547
 
 
548
                                                        stringBuilder.push( '|}\n' ) ;
 
549
 
 
550
                                                        break ;
 
551
 
 
552
                                                case 'img' :
 
553
 
 
554
                                                        var formula = htmlNode.getAttribute( '_fck_mw_math' ) ;
 
555
 
 
556
                                                        if ( formula && formula.length > 0 )
 
557
                                                        {
 
558
                                                                stringBuilder.push( '<math>' ) ;
 
559
                                                                stringBuilder.push( formula ) ;
 
560
                                                                stringBuilder.push( '</math>' ) ;
 
561
                                                                return ;
 
562
                                                        }
 
563
 
 
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' ) || '' ) + '' ;
 
574
 
 
575
                                                        stringBuilder.push( '[[Image:' ) ;
 
576
                                                        stringBuilder.push( imgName ) ;
 
577
 
 
578
                                                        if ( imgStyleWidth.length > 0 )
 
579
                                                                imgWidth = imgStyleWidth ;
 
580
                                                        else if ( imgWidth.length > 0 && imgRealWidth.length > 0 )
 
581
                                                                imgWidth = imgRealWidth ;
 
582
 
 
583
                                                        if ( imgStyleHeight.length > 0 )
 
584
                                                                imgHeight = imgStyleHeight ;
 
585
                                                        else if ( imgHeight.length > 0 && imgRealHeight.length > 0 )
 
586
                                                                imgHeight = imgRealHeight ;
 
587
 
 
588
                                                        if ( imgType.length > 0 )
 
589
                                                                stringBuilder.push( '|' + imgType ) ;
 
590
 
 
591
                                                        if ( imgLocation.length > 0 )
 
592
                                                                stringBuilder.push( '|' + imgLocation ) ;
 
593
 
 
594
                                                        if ( imgWidth.length > 0 )
 
595
                                                        {
 
596
                                                                stringBuilder.push( '|' + imgWidth ) ;
 
597
 
 
598
                                                                if ( imgHeight.length > 0 )
 
599
                                                                        stringBuilder.push( 'x' + imgHeight ) ;
 
600
 
 
601
                                                                stringBuilder.push( 'px' ) ;
 
602
                                                        }
 
603
 
 
604
                                                        if ( imgCaption.length > 0 )
 
605
                                                                stringBuilder.push( '|' + imgCaption ) ;
 
606
 
 
607
                                                        stringBuilder.push( ']]' ) ;
 
608
 
 
609
                                                        break ;
 
610
 
 
611
                                                case 'span' :
 
612
                                                        switch ( htmlNode.className )
 
613
                                                        {
 
614
                                                                case 'fck_mw_source' :
 
615
                                                                        var refLang = htmlNode.getAttribute( 'lang' ) ;
 
616
 
 
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>' ) ;
 
622
                                                                        return ;
 
623
 
 
624
                                                                case 'fck_mw_ref' :
 
625
                                                                        var refName = htmlNode.getAttribute( 'name' ) ;
 
626
 
 
627
                                                                        stringBuilder.push( '<ref' ) ;
 
628
 
 
629
                                                                        if ( refName && refName.length > 0 )
 
630
                                                                                stringBuilder.push( ' name="' + refName + '"' ) ;
 
631
 
 
632
                                                                        if ( htmlNode.innerHTML.length == 0 )
 
633
                                                                                stringBuilder.push( ' />' ) ;
 
634
                                                                        else
 
635
                                                                        {
 
636
                                                                                stringBuilder.push( '>' ) ;
 
637
                                                                                stringBuilder.push( htmlNode.innerHTML ) ;
 
638
                                                                                stringBuilder.push( '</ref>' ) ;
 
639
                                                                        }
 
640
                                                                        return ;
 
641
 
 
642
                                                                case 'fck_mw_references' :
 
643
                                                                        stringBuilder.push( '<references />' ) ;
 
644
                                                                        return ;
 
645
 
 
646
                                                                case 'fck_mw_signature' :
 
647
                                                                        stringBuilder.push( FCKConfig.WikiSignature ) ;
 
648
                                                                        return ;
 
649
 
 
650
                                                                case 'fck_mw_template' :
 
651
                                                                        stringBuilder.push( FCKTools.HTMLDecode(htmlNode.innerHTML).replace(/fckLR/g,'\r\n') ) ;
 
652
                                                                        return ;
 
653
 
 
654
                                                                case 'fck_mw_magic' :
 
655
                                                                        stringBuilder.push( htmlNode.innerHTML ) ;
 
656
                                                                        return ;
 
657
 
 
658
                                                                case 'fck_mw_nowiki' :
 
659
                                                                        sNodeName = 'nowiki' ;
 
660
                                                                        break ;
 
661
 
 
662
                                                                case 'fck_mw_html' :
 
663
                                                                        sNodeName = 'html' ;
 
664
                                                                        break ;
 
665
 
 
666
                                                                case 'fck_mw_includeonly' :
 
667
                                                                        sNodeName = 'includeonly' ;
 
668
                                                                        break ;
 
669
 
 
670
                                                                case 'fck_mw_noinclude' :
 
671
                                                                        sNodeName = 'noinclude' ;
 
672
                                                                        break ;
 
673
 
 
674
                                                                case 'fck_mw_gallery' :
 
675
                                                                        sNodeName = 'gallery' ;
 
676
                                                                        break ;
 
677
 
 
678
                                                                case 'fck_mw_onlyinclude' :
 
679
                                                                        sNodeName = 'onlyinclude' ;
 
680
 
 
681
                                                                        break ;
 
682
                                                        }
 
683
 
 
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' ) ;
 
687
 
 
688
                                                case 'pre' :
 
689
                                                        var attribs = this._GetAttributesStr( htmlNode ) ;
 
690
 
 
691
                                                        if ( htmlNode.className == "_fck_mw_lspace")
 
692
                                                        {
 
693
                                                                stringBuilder.push( "\n " ) ;
 
694
                                                                this._inLSpace = true ;
 
695
                                                                this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
 
696
                                                                this._inLSpace = false ;
 
697
                                                                var len = stringBuilder.length ;
 
698
                                                                if ( len>1 ) {
 
699
                                                                        var tail = stringBuilder[len-2] + stringBuilder[len-1];
 
700
                                                                        if ( len>2 ) {
 
701
                                                                                tail = stringBuilder[len-3] + tail ;
 
702
                                                                        }
 
703
                                                                        if (tail.EndsWith("\n ")) {
 
704
                                                                                stringBuilder[len-1] = stringBuilder[len-1].replace(/ $/, "");
 
705
                                                                        }
 
706
                                                                        else if ( !tail.EndsWith("\n") ) {
 
707
                                                                                stringBuilder.push( "\n" ) ;
 
708
                                                                        }
 
709
                                                                }
 
710
                                                        }
 
711
                                                        else
 
712
                                                        {
 
713
                                                                stringBuilder.push( '<' ) ;
 
714
                                                                stringBuilder.push( sNodeName ) ;
 
715
 
 
716
                                                                if ( attribs.length > 0 )
 
717
                                                                        stringBuilder.push( attribs ) ;
 
718
                                                                if(htmlNode.innerHTML == "")
 
719
                                                                        stringBuilder.push( ' />' ) ;
 
720
                                                                else
 
721
                                                                {
 
722
                                                                        stringBuilder.push( '>' ) ;
 
723
                                                                        this._inPre = true ;
 
724
                                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
 
725
                                                                        this._inPre = false ;
 
726
 
 
727
                                                                        stringBuilder.push( '<\/' ) ;
 
728
                                                                        stringBuilder.push( sNodeName ) ;
 
729
                                                                        stringBuilder.push( '>' ) ;
 
730
                                                                }
 
731
                                                        }
 
732
 
 
733
                                                        break ;
 
734
                                                default :
 
735
                                                        var attribs = this._GetAttributesStr( htmlNode ) ;
 
736
 
 
737
                                                        stringBuilder.push( '<' ) ;
 
738
                                                        stringBuilder.push( sNodeName ) ;
 
739
 
 
740
                                                        if ( attribs.length > 0 )
 
741
                                                                stringBuilder.push( attribs ) ;
 
742
 
 
743
                                                        stringBuilder.push( '>' ) ;
 
744
                                                        this._AppendChildNodes( htmlNode, stringBuilder, prefix ) ;
 
745
                                                        stringBuilder.push( '<\/' ) ;
 
746
                                                        stringBuilder.push( sNodeName ) ;
 
747
                                                        stringBuilder.push( '>' ) ;
 
748
                                                        break ;
 
749
                                        }
 
750
                                }
 
751
 
 
752
                                htmlNode._fckxhtmljob = FCKXHtml.CurrentJobNum ;
 
753
                                return ;
 
754
 
 
755
                        // Text Node.
 
756
                        case 3 :
 
757
 
 
758
                                var parentIsSpecialTag = htmlNode.parentNode.getAttribute( '_fck_mw_customtag' ) ;
 
759
                                var textValue = htmlNode.nodeValue;
 
760
                                if ( !parentIsSpecialTag )
 
761
                                {
 
762
                                        if ( FCKBrowserInfo.IsIE && this._inLSpace ) {
 
763
                                                textValue = textValue.replace( /\r/g, "\r " ) ;
 
764
                                                if (textValue.EndsWith( "\r " )) {
 
765
                                                        textValue = textValue.replace( /\r $/, "\r" );
 
766
                                                }
 
767
                                        }
 
768
                                        if ( !FCKBrowserInfo.IsIE && this._inLSpace ) {
 
769
                                                textValue = textValue.replace( /\n(?! )/g, "\n " ) ;
 
770
                                        }
 
771
 
 
772
                                        if (!this._inLSpace && !this._inPre) {
 
773
                                                textValue = textValue.replace( /[\n\t]/g, ' ' ) ;
 
774
                                        }
 
775
 
 
776
                                        textValue = FCKTools.HTMLEncode( textValue ) ;
 
777
                                        textValue = textValue.replace( /\u00A0/g, '&nbsp;' ) ;
 
778
 
 
779
                                        if ( ( !htmlNode.previousSibling ||
 
780
                                        ( stringBuilder.length > 0 && stringBuilder[ stringBuilder.length - 1 ].EndsWith( '\n' ) ) ) && !this._inLSpace && !this._inPre )
 
781
                                        {
 
782
                                                textValue = textValue.LTrim() ;
 
783
                                        }
 
784
 
 
785
                                        if ( !htmlNode.nextSibling && !this._inLSpace && !this._inPre && (!htmlNode.parentNode || !htmlNode.parentNode.nextSibling))
 
786
                                                textValue = textValue.RTrim() ;
 
787
 
 
788
                                        if (!this._inLSpace && !this._inPre)
 
789
                                                textValue = textValue.replace( / {2,}/g, ' ' ) ;
 
790
 
 
791
                                        if ( this._inLSpace && textValue.length == 1 && textValue.charCodeAt(0) == 13 )
 
792
                                                textValue = textValue + " " ;
 
793
 
 
794
                                        if ( !this._inLSpace && !this._inPre && textValue == " " ) {
 
795
                                                var len = stringBuilder.length;
 
796
                                                if (len > 1) {
 
797
                                                        var tail = stringBuilder[len-2] + stringBuilder[len-1];
 
798
                                                        if ( tail.toString().EndsWith( "\n" ) )
 
799
                                                                textValue = "";
 
800
                                                }
 
801
                                        }
 
802
 
 
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-->" ) ) ;
 
807
                                                }
 
808
                                                textValue = textValue.replace( /\|/g, '&#124;' ) ;
 
809
                                                textValue = textValue.replace( /<!--LINK_PIPE-->/g, '|' ) ;
 
810
                                        }
 
811
                                }
 
812
                                else
 
813
                                {
 
814
                                        textValue = FCKTools.HTMLDecode(textValue).replace(/fckLR/g,'\r\n');
 
815
                                }
 
816
 
 
817
                                stringBuilder.push( textValue ) ;
 
818
                                return ;
 
819
 
 
820
                        // Comment
 
821
                        case 8 :
 
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 )
 
825
                                        return ;
 
826
 
 
827
                                stringBuilder.push( "<!--"  ) ;
 
828
 
 
829
                                try     { stringBuilder.push( htmlNode.nodeValue ) ; }
 
830
                                catch (e) { /* Do nothing... probably this is a wrong format comment. */ }
 
831
 
 
832
                                stringBuilder.push( "-->" ) ;
 
833
                                return ;
 
834
                }
 
835
        },
 
836
 
 
837
        _AppendChildNodes : function( htmlNode, stringBuilder, listPrefix )
 
838
        {
 
839
                var child = htmlNode.firstChild ;
 
840
 
 
841
                while ( child )
 
842
                {
 
843
                        this._AppendNode( child, stringBuilder, listPrefix ) ;
 
844
                        child = child.nextSibling ;
 
845
                }
 
846
        },
 
847
 
 
848
        _GetAttributesStr : function( htmlNode )
 
849
        {
 
850
                var attStr = '' ;
 
851
                var aAttributes = htmlNode.attributes ;
 
852
 
 
853
                for ( var n = 0 ; n < aAttributes.length ; n++ )
 
854
                {
 
855
                        var oAttribute = aAttributes[n] ;
 
856
 
 
857
                        if ( oAttribute.specified )
 
858
                        {
 
859
                                var sAttName = oAttribute.nodeName.toLowerCase() ;
 
860
                                var sAttValue ;
 
861
 
 
862
                                // Ignore any attribute starting with "_fck".
 
863
                                if ( sAttName.StartsWith( '_fck' ) )
 
864
                                        continue ;
 
865
                                // There is a bug in Mozilla that returns '_moz_xxx' attributes as specified.
 
866
                                else if ( sAttName.indexOf( '_moz' ) == 0 )
 
867
                                        continue ;
 
868
                                // For "class", nodeValue must be used.
 
869
                                else if ( sAttName == 'class' )
 
870
                                {
 
871
                                        // Get the class, removing any fckXXX we can have there.
 
872
                                        sAttValue = oAttribute.nodeValue.replace( /(^|\s*)fck\S+/, '' ).Trim() ;
 
873
 
 
874
                                        if ( sAttValue.length == 0 )
 
875
                                                continue ;
 
876
                                }
 
877
                                else if ( sAttName == 'style' && FCKBrowserInfo.IsIE ) {
 
878
                                        sAttValue = htmlNode.style.cssText.toLowerCase() ;
 
879
                                }
 
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 ;
 
883
                                else
 
884
                                        sAttValue = htmlNode.getAttribute( sAttName, 2 ) ;      // We must use getAttribute to get it exactly as it is defined.
 
885
 
 
886
                                // leave templates
 
887
                                if ( sAttName.StartsWith( '{{' ) && sAttName.EndsWith( '}}' ) ) {
 
888
                                        attStr += ' ' + sAttName ;
 
889
                                }
 
890
                                else {
 
891
                                        attStr += ' ' + sAttName + '="' + String(sAttValue).replace( '"', '&quot;' ) + '"' ;
 
892
                                }
 
893
                        }
 
894
                }
 
895
                return attStr ;
 
896
        }
 
897
} ;
 
898
 
 
899
// Here we change the SwitchEditMode function to make the Ajax call when
 
900
// switching from Wikitext.
 
901
(function()
 
902
{
 
903
        if (window.parent.showFCKEditor & (2|4))                                //if popup or toggle link
 
904
        {
 
905
                var original_ULF = FCK.UpdateLinkedField ;
 
906
                FCK.UpdateLinkedField = function(){
 
907
                        if (window.parent.showFCKEditor & 1)                    //only if editor is up-to-date
 
908
                        {
 
909
                                original_ULF.apply();
 
910
                        }
 
911
                }
 
912
        }
 
913
        var original = FCK.SwitchEditMode ;
 
914
        window.parent.oFCKeditor.ready = true;
 
915
        FCK.SwitchEditMode = function()
 
916
        {
 
917
                var args = arguments ;
 
918
                window.parent.oFCKeditor.ready = false;
 
919
                var loadHTMLFromAjax = function( result )
 
920
                {
 
921
                        FCK.EditingArea.Textarea.value = result.responseText ;
 
922
                        original.apply( FCK, args ) ;
 
923
                        window.parent.oFCKeditor.ready = true;
 
924
                }
 
925
                var edittools_markup = parent.document.getElementById ('editpage-specialchars') ;
 
926
 
 
927
                if ( FCK.EditMode == FCK_EDITMODE_SOURCE )
 
928
                {
 
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 = '&nbsp;'+ (FCKLang.wikiLoadingWikitext || 'Loading Wikitext. Please wait...' )+'&nbsp;';
 
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' ;
 
940
                        }
 
941
 
 
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 ) ;
 
945
                        }
 
946
                        else{
 
947
                                window.parent.FCK_sajax( 'wfSajaxWikiToHTML', [FCK.EditingArea.Textarea.value], loadHTMLFromAjax ) ;
 
948
                        }
 
949
                }
 
950
                else {
 
951
                        original.apply( FCK, args ) ;
 
952
                        if (edittools_markup) {
 
953
                                edittools_markup.style.display = '' ;
 
954
                        }
 
955
                        window.parent.oFCKeditor.ready = true;
 
956
                }
 
957
        }
 
958
})() ;
 
959
 
 
960
// MediaWiki document processor.
 
961
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
 
962
{
 
963
        // #1011: change signatures to SPAN elements
 
964
        var aTextNodes = document.getElementsByTagName( '*' ) ;
 
965
        var i = 0 ;
 
966
        var signatureRegExp = new RegExp( FCKConfig.WikiSignature.replace( /([*:.*?();|$])/g, "\\$1" ), "i" );
 
967
        while (element = aTextNodes[i++])
 
968
        {
 
969
                var nodes = element.childNodes ;
 
970
                var j = 0 ;
 
971
                while ( node = nodes[j++] )
 
972
                {
 
973
                        if ( node.nodeType == 3 )
 
974
                        {//textNode
 
975
                                var index = 0 ;
 
976
 
 
977
                                while ( aSignatures = node.nodeValue.match( signatureRegExp ) )
 
978
                                {
 
979
                                        index = node.nodeValue.indexOf( aSignatures[0] ) ;
 
980
                                        if ( index != -1 )
 
981
                                        {
 
982
                                                var e = FCK.EditorDocument.createElement( 'span' ) ;
 
983
                                                e.className = "fck_mw_signature";
 
984
                                                var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__MWSignature', e ) ;
 
985
 
 
986
                                                var substr1 = FCK.EditorDocument.createTextNode( node.nodeValue.substring(0, index) ) ;
 
987
                                                var substr2 = FCK.EditorDocument.createTextNode( node.nodeValue.substring(index + aSignatures[0].length) ) ;
 
988
 
 
989
                                                node.parentNode.insertBefore( substr1, node ) ;
 
990
                                                node.parentNode.insertBefore( oFakeImage, node ) ;
 
991
                                                node.parentNode.insertBefore( substr2, node ) ;
 
992
 
 
993
                                                node.parentNode.removeChild( node ) ;
 
994
                                                if ( node )
 
995
                                                        node.nodeValue = '' ;
 
996
                                        }
 
997
                                }
 
998
                        }
 
999
                }
 
1000
        }
 
1001
 
 
1002
        // Templates and magic words.
 
1003
        var aSpans = document.getElementsByTagName( 'SPAN' ) ;
 
1004
 
 
1005
        var eSpan ;
 
1006
        var i = aSpans.length - 1 ;
 
1007
        while ( i >= 0 && ( eSpan = aSpans[i--] ) )
 
1008
        {
 
1009
                var className = null ;
 
1010
                switch ( eSpan.className )
 
1011
                {
 
1012
                        case 'fck_mw_source' :
 
1013
                                className = 'FCK__MWSource' ;
 
1014
                        case 'fck_mw_ref' :
 
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' ;
 
1050
 
 
1051
                                var oImg = FCKDocumentProcessor_CreateFakeImage( className, eSpan.cloneNode(true) ) ;
 
1052
                                oImg.setAttribute( '_' + eSpan.className, 'true', 0 ) ;
 
1053
 
 
1054
                                eSpan.parentNode.insertBefore( oImg, eSpan ) ;
 
1055
                                eSpan.parentNode.removeChild( eSpan ) ;
 
1056
                        break ;
 
1057
                }
 
1058
        }
 
1059
 
 
1060
        // Math tags without Tex.
 
1061
        var aImgs = document.getElementsByTagName( 'IMG' ) ;
 
1062
        var eImg ;
 
1063
        i = aImgs.length - 1 ;
 
1064
        while ( i >= 0 && ( eImg = aImgs[i--] ) )
 
1065
        {
 
1066
                var className = null ;
 
1067
                switch ( eImg.className )
 
1068
                {
 
1069
                        case 'FCK__MWMath' :
 
1070
                                eImg.src = FCKConfig.PluginsPath + 'mediawiki/images/icon_math.gif' ;
 
1071
                        break ;
 
1072
                }
 
1073
        }
 
1074
 
 
1075
        // InterWiki / InterLanguage links
 
1076
        var aHrefs = document.getElementsByTagName( 'A' ) ;
 
1077
        var a ;
 
1078
        var i = aHrefs.length - 1 ;
 
1079
        while ( i >= 0 && ( a = aHrefs[i--] ) )
 
1080
        {
 
1081
                if (a.className == 'extiw')
 
1082
                {
 
1083
                         a.href = a.title ;
 
1084
                         a.setAttribute( '_fcksavedurl', a.href ) ;
 
1085
                }
 
1086
                else
 
1087
                {
 
1088
                        if (a.href.toLowerCase().StartsWith( 'rtecolon' ))
 
1089
                        {
 
1090
                                a.href = ":" + a.href.substring(8);
 
1091
                                if (a.innerHTML.toLowerCase().StartsWith( 'rtecolon' ))
 
1092
                                {
 
1093
                                        a.innerHTML = a.innerHTML.substring(8);
 
1094
                                }
 
1095
                        }
 
1096
                }
 
1097
        }
 
1098
}
 
1099
 
 
1100
// Context menu for templates.
 
1101
FCK.ContextMenu.RegisterListener({
 
1102
        AddItems : function( contextMenu, tag, tagName )
 
1103
        {
 
1104
                if ( tagName == 'IMG' )
 
1105
                {
 
1106
                        if ( tag.getAttribute( '_fck_mw_template' ) )
 
1107
                        {
 
1108
                                contextMenu.AddSeparator() ;
 
1109
                                contextMenu.AddItem( 'MW_Template', FCKLang.wikiMnuTemplate || 'Template Properties' ) ;
 
1110
                        }
 
1111
                        if ( tag.getAttribute( '_fck_mw_magic' ) )
 
1112
                        {
 
1113
                                contextMenu.AddSeparator() ;
 
1114
                                contextMenu.AddItem( 'MW_MagicWord', FCKLang.wikiMnuMagicWord || 'Modify Magic Word' ) ;
 
1115
                        }
 
1116
                        if ( tag.getAttribute( '_fck_mw_ref' ) )
 
1117
                        {
 
1118
                                contextMenu.AddSeparator() ;
 
1119
                                contextMenu.AddItem( 'MW_Ref', FCKLang.wikiMnuReference || 'Reference Properties' ) ;
 
1120
                        }
 
1121
                        if ( tag.getAttribute( '_fck_mw_html' ) )
 
1122
                        {
 
1123
                                contextMenu.AddSeparator() ;
 
1124
                                contextMenu.AddItem( 'MW_Special', 'Edit HTML code' ) ;
 
1125
                        }
 
1126
                        if ( tag.getAttribute( '_fck_mw_source' ) )
 
1127
                        {
 
1128
                                contextMenu.AddSeparator() ;
 
1129
                                contextMenu.AddItem( 'MW_Source', FCKLang.wikiMnuSourceCode || 'Source Code Properties' ) ;
 
1130
                        }
 
1131
                        if ( tag.getAttribute( '_fck_mw_math' ) )
 
1132
                        {
 
1133
                                contextMenu.AddSeparator() ;
 
1134
                                contextMenu.AddItem( 'MW_Math', FCKLang.wikiMnuFormula || 'Edit Formula' ) ;
 
1135
                        }
 
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
 
1137
                        {
 
1138
                                contextMenu.AddSeparator() ;
 
1139
                                contextMenu.AddItem( 'MW_Special', FCKLang.wikiMnuSpecial || 'Special Tag Properties' ) ;
 
1140
                        }
 
1141
                }
 
1142
        }
 
1143
}) ;