~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/dialogs/category.html

  • 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
2
<!--
 
3
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 
4
 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
 
5
 *
 
6
 * == BEGIN LICENSE ==
 
7
 *
 
8
 * Licensed under the terms of any of the following licenses at your
 
9
 * choice:
 
10
 *
 
11
 *  - GNU General Public License Version 2 or later (the "GPL")
 
12
 *    http://www.gnu.org/licenses/gpl.html
 
13
 *
 
14
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 
15
 *    http://www.gnu.org/licenses/lgpl.html
 
16
 *
 
17
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 
18
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 
19
 *
 
20
 * == END LICENSE ==
 
21
 *
 
22
 * Category dialog window.
 
23
-->
 
24
<html>
 
25
<head>
 
26
<title>Categories</title>
 
27
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
28
<meta name="robots" content="noindex, nofollow" />
 
29
<script type="text/javascript">
 
30
var oEditor = window.parent.InnerDialogLoaded();
 
31
var FCK = oEditor.FCK;
 
32
var FCKLang = oEditor.FCKLang;
 
33
var FCKConfig = oEditor.FCKConfig;
 
34
var FCKRegexLib = oEditor.FCKRegexLib;
 
35
var FCKTools = oEditor.FCKTools;
 
36
var FCKBrowserInfo = oEditor.FCKBrowserInfo;
 
37
var EditorDocument = oEditor.FCK.EditorDocument;
 
38
 
 
39
document.write( '<script src="' + FCKConfig.BasePath + 'dialog/common/fck_dialog_common.js" type="text/javascript"><\/script>' );
 
40
 
 
41
window.onload = function()
 
42
{
 
43
        // Translate the dialog box texts.
 
44
        oEditor.FCKLanguageManager.TranslatePage( document );
 
45
 
 
46
        // Load the selected link information (if any).
 
47
        InitSelected();
 
48
        SetSearchMessage( FCKLang.wikiLoadingCategories || 'loading categories...' );
 
49
        oEditor.window.parent.sajax_request_type = 'GET';
 
50
        oEditor.window.parent.sajax_do_call( 'wfSajaxSearchCategoryFCKeditor', [], InitCategoryTree );
 
51
 
 
52
        // Activate the "OK" button.
 
53
        window.parent.SetOkButton( true );
 
54
        window.parent.SetAutoSize( true );
 
55
};
 
56
 
 
57
var selectedCats;
 
58
 
 
59
function InitSelected()
 
60
{
 
61
        selectedCats = new Array();
 
62
        var node = EditorDocument;
 
63
        while ( node )
 
64
        {
 
65
                if ( node.nodeType == 1 && node.tagName.toLowerCase() == 'a' )
 
66
                {
 
67
                        // Get the actual Link href.
 
68
                        var sHRef = node.getAttribute( '_fcksavedurl' );
 
69
                        if ( sHRef == null )
 
70
                                sHRef = node.getAttribute( 'href', 2 ) || '';
 
71
                        if ( sHRef.StartsWith( 'Category:' ) )
 
72
                        {
 
73
                                var select = GetE( 'xCategories' );
 
74
                                var cat = sHRef.slice( 9 );
 
75
                                SelectCategory( cat, -1 );
 
76
                        }
 
77
                }
 
78
                node = FCKTools.GetNextNode( node, EditorDocument );
 
79
        }
 
80
}
 
81
 
 
82
function SelectCategory( cat, catTreeRow )
 
83
{
 
84
        var select, row = parseInt( catTreeRow );
 
85
        if ( row >= 0 )
 
86
        {
 
87
                select = GetE( 'xWikiResults' );
 
88
                cat = select.options[ row ].text;
 
89
                var lvl = 0;
 
90
                while ( cat.charAt( lvl ) == placeholder )
 
91
                        lvl++;
 
92
                cat = cat.slice( lvl );
 
93
                if ( cat.charAt( 0 ) == '[' && cat.charAt( cat.length - 1 ) == ']' )
 
94
                        cat = cat.substring( 1, cat.length - 1 );
 
95
        }
 
96
 
 
97
        if ( selectedCats[ cat ] )
 
98
                delete selectedCats[ cat ];
 
99
        else
 
100
                selectedCats[ cat ] = cat;
 
101
 
 
102
        select = GetE( 'xCategories' );
 
103
 
 
104
        while ( select.options.length > 0 )
 
105
                select.remove( 0 );
 
106
 
 
107
        for ( cat in selectedCats )
 
108
                FCKTools.AddSelectOption( select, cat, cat );
 
109
}
 
110
 
 
111
var catTree;
 
112
 
 
113
function InitCategoryTree( result )
 
114
{
 
115
        SetSearchMessage( FCKLang.wikiLnkStartTyping || 'start typing in the above field' );
 
116
 
 
117
        catTree = new Object();
 
118
        var levelsHead = new Array( 'root' );
 
119
        var levelsBody = new Array( '' );
 
120
 
 
121
        var results = result.responseText.Trim().split( '\n' );
 
122
        var previousLvl = -1;
 
123
        for ( var i = 0 ; i < results.length ; i++ )
 
124
        {
 
125
                var lvl = 0;
 
126
                while ( results[ i ].charAt( lvl ) == ' ' )
 
127
                        lvl++;
 
128
                var t = results[ i ].slice( lvl );
 
129
                for ( var j = previousLvl ; j > lvl - 1 ; j-- )
 
130
                {
 
131
 
 
132
                        if ( levelsBody[ j + 1 ] != '' )
 
133
                                catTree[ levelsHead[ j + 1 ] ] = levelsBody[ j + 1 ];
 
134
                        delete levelsHead[ j + 1 ];
 
135
                        delete levelsBody[ j + 1 ];
 
136
                }
 
137
                if ( lvl > previousLvl )
 
138
                        levelsBody[ lvl ] = t;
 
139
                else
 
140
                        levelsBody[ lvl ] = levelsBody[ lvl ] + ' ' + t;
 
141
                levelsHead[ lvl + 1 ] = t;
 
142
                levelsBody[ lvl + 1 ] = '';
 
143
                previousLvl = lvl;
 
144
        }
 
145
        for ( var j = previousLvl ; j >= -1 ; j-- )
 
146
        {
 
147
                if ( levelsBody[ j + 1 ] != '' )
 
148
                        catTree[ levelsHead[ j + 1 ] ] = levelsBody[ j + 1 ];
 
149
                delete levelsHead[ j + 1 ];
 
150
                delete levelsBody[ j + 1 ];
 
151
        }
 
152
 
 
153
        ShowCategoriesSubTree( -1 );
 
154
}
 
155
 
 
156
var placeholder = '.';
 
157
 
 
158
//draw category subtree
 
159
function ShowCategoriesSubTree( rowInTree )
 
160
{
 
161
        var row = parseInt( rowInTree );
 
162
        var select = GetE( 'xWikiResults' );
 
163
        var root = 'root';
 
164
        var lvl = -1;
 
165
        var prefix = '';
 
166
        if ( row >= 0 )
 
167
        {
 
168
                root = select.options[ row ].text;
 
169
                lvl = 0;
 
170
                while ( root.charAt( lvl ) == placeholder )
 
171
                        lvl++;
 
172
                root = root.slice( lvl );
 
173
                if ( root.charAt( 0 ) == '[' && root.charAt( root.length - 1 ) == ']' )
 
174
                        root = root.substring( 1, root.length - 1 );
 
175
                prefix = new Array( lvl + 1 + 3 ).join( placeholder );
 
176
        }
 
177
        if ( !catTree[ root ] )
 
178
                return;
 
179
 
 
180
        var itCount = select.options.length;
 
181
        var itSkip = row + 1;
 
182
        var opts = new Array();
 
183
        for ( var i = row + 1 ; i < itCount ; i++ )
 
184
        {
 
185
                var t = select.options[ i ].text;
 
186
                var sublvl = 0;
 
187
                while ( t.charAt( sublvl ) == placeholder )
 
188
                        sublvl++;
 
189
                if ( sublvl > lvl )
 
190
                        itSkip = i + 1;
 
191
                else
 
192
                        break;
 
193
        }
 
194
        for ( var i = itCount - 1 ; i > row ; i-- )
 
195
        {
 
196
                var t = select.options[ i ].text;
 
197
                if ( i >= itSkip )
 
198
                        opts.push( t );
 
199
                select.remove( i );
 
200
        }
 
201
        if ( itSkip == row + 1 )
 
202
        {
 
203
                var cats = catTree[ root ].split( ' ' );
 
204
 
 
205
                for ( var k in cats )
 
206
                {
 
207
                        var p = cats[ k ];
 
208
                        if ( catTree[ cats[ k ] ] )
 
209
                                p = '[' + p + ']';
 
210
                        var e = FCKTools.AddSelectOption( select, prefix + p, ++row );
 
211
                        if ( catTree[ cats[ k ] ] )
 
212
                                e.style.color = '#00f';
 
213
 
 
214
                }
 
215
        }
 
216
        for ( var i = opts.length - 1 ; i >= 0 ; i-- )
 
217
        {
 
218
                var e = FCKTools.AddSelectOption( select, opts[ i ], ++row );
 
219
                if ( opts[ i ].indexOf( '[' ) >= 0 )
 
220
                        e.style.color = '#00f';
 
221
        }
 
222
 
 
223
}
 
224
 
 
225
//draw filtered
 
226
function ShowFilteredCategories( filter )
 
227
{
 
228
        var select = GetE( 'xWikiResults' );
 
229
        while ( select.options.length > 0 )
 
230
                select.remove( 0 );
 
231
        var found = new Object();
 
232
        if ( filter.length == 0 )
 
233
        {
 
234
                ShowCategoriesSubTree( -1 );
 
235
                return;
 
236
        }
 
237
        filter = filter.toLowerCase();
 
238
        var row = -1;
 
239
        for ( var folder in catTree )
 
240
        {
 
241
                var cats = catTree[ folder ].split( ' ' );
 
242
                for ( var k in cats )
 
243
                {
 
244
                        var p = cats[ k ].toLowerCase();
 
245
                        if ( p.indexOf( filter ) >= 0 )
 
246
                        {
 
247
                                if ( found[ cats[ k ] ] )
 
248
                                        ;
 
249
                                else
 
250
                                {
 
251
                                        found[ cats[ k ] ] = cats[ k ];
 
252
                                        FCKTools.AddSelectOption( select, cats[ k ], ++row );
 
253
                                }
 
254
                        }
 
255
                }
 
256
        }
 
257
}
 
258
 
 
259
function AddNew()
 
260
{
 
261
        var select = GetE( 'txtUrl' );
 
262
        if ( select.value.Trim() )
 
263
                SelectCategory( select.value, -1 );
 
264
        select.value = '';
 
265
}
 
266
 
 
267
//#### The OK button was hit.
 
268
function Ok()
 
269
{
 
270
        var nodes = new Array();
 
271
        var node = EditorDocument;
 
272
        var nodeNext;
 
273
        var s = '';
 
274
        var i = 0;
 
275
        while ( node )
 
276
        {
 
277
                nodeNext = FCKTools.GetNextNode( node, EditorDocument );
 
278
                if ( node.nodeType == 1 && node.tagName.toLowerCase() == 'a' )
 
279
                {
 
280
                        // Get the actual Link href.
 
281
                        var sHRef = node.getAttribute( '_fcksavedurl' );
 
282
                        if ( sHRef == null )
 
283
                                sHRef = node.getAttribute( 'href', 2 ) || '';
 
284
                        if ( sHRef.StartsWith( 'Category:' ) )
 
285
                                nodes[ i++ ] = node;
 
286
                }
 
287
                node = nodeNext;
 
288
        }
 
289
        for ( var i = 0 ; i < nodes.length ; i++ )
 
290
                nodes[ i ].parentNode.removeChild( nodes[ i ] );
 
291
 
 
292
        for ( var cat in selectedCats )
 
293
                AddCategoryLink( cat );
 
294
 
 
295
        CleanUpCategoryLinks();
 
296
 
 
297
        return true;
 
298
}
 
299
 
 
300
function CleanUpCategoryLinks()
 
301
{
 
302
        var node = EditorDocument;
 
303
        var nodes = [];
 
304
        while ( node )
 
305
        {
 
306
                if ( node.nodeType == 1 && node.tagName.toLowerCase() == 'a' )
 
307
                {
 
308
                        // Get the actual Link href.
 
309
                        var sHRef = node.getAttribute( '_fcksavedurl' );
 
310
                        if ( sHRef == null )
 
311
                                sHRef = node.getAttribute( 'href', 2 ) || '';
 
312
                        if ( sHRef.StartsWith( 'Category:' ) )
 
313
                                nodes.push(node);
 
314
                }
 
315
                node = FCKTools.GetNextNode( node, EditorDocument );
 
316
        }
 
317
 
 
318
        for ( var i = 0; i < nodes.length ; i++ )
 
319
                EditorDocument.body.appendChild( nodes[i] );
 
320
}
 
321
 
 
322
function AddCategoryLink( cat )
 
323
{
 
324
        var sUri = 'Category:' + cat;
 
325
        var sInnerHtml;
 
326
 
 
327
        // If no link is selected, create a new one (it may result in more than one link creation - #220).
 
328
        var aLinks = oEditor.FCK.CreateLink( sUri );
 
329
 
 
330
        // If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26)
 
331
        var aHasSelection = (aLinks.length > 0);
 
332
        if ( !aHasSelection )
 
333
        {
 
334
                sInnerHtml = sUri;
 
335
 
 
336
                var oLinkPathRegEx = new RegExp( "//?([^?\"']+)([?].*)?$" );
 
337
                var asLinkPath = oLinkPathRegEx.exec( sUri );
 
338
                if ( asLinkPath != null )
 
339
                        sInnerHtml = asLinkPath[ 1 ]; // use matched path
 
340
 
 
341
                // Create a new (empty) anchor.
 
342
                aLinks = [ oEditor.FCK.InsertElement( 'a' ) ];
 
343
        }
 
344
 
 
345
        oEditor.FCKUndo.SaveUndoStep();
 
346
 
 
347
        for ( var i = 0 ; i < aLinks.length ; i++ )
 
348
        {
 
349
                oLink = aLinks[ i ];
 
350
 
 
351
                if ( aHasSelection )
 
352
                        sInnerHtml = oLink.innerHTML; // Save the innerHTML (IE changes it if it is like an URL).
 
353
 
 
354
                oLink.href = sUri;
 
355
                SetAttribute( oLink, '_fcksavedurl', sUri );
 
356
 
 
357
                oLink.innerHTML = sInnerHtml; // Set (or restore) the innerHTML
 
358
        }
 
359
 
 
360
        return true;
 
361
}
 
362
 
 
363
//#### Called while the user types the URL.
 
364
function OnUrlChange()
 
365
{
 
366
        var link = GetE( 'txtUrl' ).value.Trim();
 
367
        ShowFilteredCategories( link );
 
368
        return;
 
369
}
 
370
 
 
371
function SetSearchMessage( message )
 
372
{
 
373
        GetE( 'xWikiSearchStatus' ).innerHTML = message;
 
374
}
 
375
</script>
 
376
</head>
 
377
<body scroll="no" style="overflow: hidden">
 
378
<div id="divInfo">
 
379
<div id="divLinkTypeUrl"><span fcklang="wikiSelectedCategories">Selected categories</span><br />
 
380
<select id="xCategories" size="10" style="width: 100%; height: 70px"
 
381
        ondblclick="SelectCategory( this.value,-1);">
 
382
</select><br />
 
383
<span fcklang="wikiSearchCategory">Search category</span><br />
 
384
<input id="txtUrl" style="width: 76%" type="text"
 
385
        onkeyup="OnUrlChange();" /> <input id="btnNew" style="width: 22%"
 
386
        type="button" onclick="AddNew();" value="Add new" fcklang="wikiAddNewCategory"/> <br />
 
387
<span fcklang="wikiCategoryTree">Category tree</span> (<span fcklang="wikiLnkStartTyping" id="xWikiSearchStatus">start typing in the
 
388
above field</span>)<br />
 
389
<select id="xWikiResults" size="10" style="width: 100%; height: 300px"
 
390
        onclick="ShowCategoriesSubTree( this.value );"
 
391
        ondblclick="SelectCategory('', this.value );">
 
392
</select></div>
 
393
</div>
 
394
</body>
 
395
</html>