Index: trunk/extensions/UploadWizard/js/jquery/plugins/jquery.mwCoolCats.js |
— | — | @@ -1,101 +1,111 @@ |
2 | 2 | RegExp.escape = (function() { |
3 | 3 | var specials = [ |
4 | | - '/', '.', '*', '+', '?', '|', |
5 | | - '(', ')', '[', ']', '{', '}', '\\' |
| 4 | + '/', '.', '*', '+', '?', '|', |
| 5 | + '(', ')', '[', ']', '{', '}', '\\' |
6 | 6 | ]; |
7 | 7 | |
8 | 8 | sRE = new RegExp( |
9 | | - '(\\' + specials.join('|\\') + ')', 'g' |
| 9 | + '(\\' + specials.join('|\\') + ')', 'g' |
10 | 10 | ); |
11 | 11 | |
12 | 12 | return function(text) { |
13 | | - return text.replace(sRE, '\\$1'); |
| 13 | + return text.replace(sRE, '\\$1'); |
14 | 14 | } |
15 | 15 | })(); |
16 | 16 | (function($){ |
17 | | - $.fn.mwCoolCats = function(options) { |
| 17 | + $.fn.mwCoolCats = function(options) { |
18 | 18 | var defaults = { |
19 | | - buttontext: 'Add' |
| 19 | + buttontext: 'Add' |
20 | 20 | }; |
21 | | - var settings = $.extend( {}, defaults, options); |
| 21 | + var settings = $.extend( {}, defaults, options); |
22 | 22 | var $container; |
23 | 23 | return this.each( function() { |
24 | | - var _this = $j( this ); |
| 24 | + var _this = $j( this ); |
25 | 25 | |
26 | | - _this.suggestions( { |
| 26 | + _this.suggestions( { |
27 | 27 | 'fetch': _fetchSuggestions, |
28 | 28 | 'cancel': function() { |
29 | 29 | var req = $j( this ).data( 'request' ); |
30 | 30 | if ( req.abort ) { |
31 | 31 | req.abort(); |
32 | | - } |
| 32 | + } |
33 | 33 | } |
34 | 34 | } ); |
35 | | - _this.suggestions(); |
| 35 | + _this.suggestions(); |
36 | 36 | |
37 | | - _this.wrap('<div class="cat-widget"></div>'); |
38 | | - $container = _this.parent(); // set to the cat-widget class we just wrapped |
39 | | - $container.append( $j( '<button type="button">'+settings.buttontext+'</button>' ) |
40 | | - .click( function(e) { |
41 | | - e.stopPropagation(); |
42 | | - e.preventDefault(); |
43 | | - _processInput(); |
44 | | - return false; |
45 | | - }) ); |
46 | | - $container.prepend('<ul class="cat-list pkg"></ul>'); |
| 37 | + _this.wrap('<div class="cat-widget"></div>'); |
| 38 | + $container = _this.parent(); // set to the cat-widget class we just wrapped |
| 39 | + $container.append( $j( '<button type="button">'+settings.buttontext+'</button>' ) |
| 40 | + .click( function(e) { |
| 41 | + e.stopPropagation(); |
| 42 | + e.preventDefault(); |
| 43 | + _processInput(); |
| 44 | + return false; |
| 45 | + }) ); |
| 46 | + $container.prepend('<ul class="cat-list pkg"></ul>'); |
47 | 47 | |
48 | | - //XXX ensure this isn't blocking other stuff needed. |
49 | | - _this.parents('form').submit( function() { |
50 | | - _processInput(); |
51 | | - }); |
52 | | - |
53 | | - _this.keyup(function(e) { |
54 | | - if(e.keyCode == 13) { |
55 | | - e.stopPropagation(); |
56 | | - e.preventDefault(); |
57 | | - _processInput(); |
58 | | - } |
59 | | - }); |
| 48 | + //XXX ensure this isn't blocking other stuff needed. |
| 49 | + _this.parents('form').submit( function() { |
| 50 | + _processInput(); |
| 51 | + }); |
| 52 | + |
| 53 | + _this.keyup(function(e) { |
| 54 | + if(e.keyCode == 13) { |
| 55 | + e.stopPropagation(); |
| 56 | + e.preventDefault(); |
| 57 | + _processInput(); |
| 58 | + } |
| 59 | + }); |
60 | 60 | |
61 | | - var categoryNamespace = mw.getConfig( 'categoryNamespace' ); |
62 | | - this.getWikiText = function() { |
63 | | - return _getCats().map( function() { return '[[' + categoryNamespace + ':' + this + ']]'; } ) |
| 61 | + var categoryNamespace = mw.getConfig( 'categoryNamespace' ); |
| 62 | + this.getWikiText = function() { |
| 63 | + return _getCats().map( function() { return '[[' + categoryNamespace + ':' + this + ']]'; } ) |
64 | 64 | .toArray() |
65 | 65 | .join( "\n" ); |
66 | | - }; |
| 66 | + }; |
67 | 67 | |
68 | | - _processInput(); |
| 68 | + _processInput(); |
69 | 69 | }); |
70 | 70 | |
71 | | - function _processInput() { |
72 | | - var $input = $container.find('input'); |
73 | | - _insertCat( $input.val().trim() ); |
74 | | - $input.val(""); |
75 | | - } |
| 71 | + function _processInput() { |
| 72 | + var $input = $container.find( 'input' ); |
| 73 | + _insertCat( $input.val().trim() ); |
| 74 | + $input.val(""); |
| 75 | + } |
76 | 76 | |
77 | | - function _insertCat( cat ) { |
78 | | - if ( mw.isEmpty( cat ) || _containsCat( cat ) ) { |
79 | | - return; |
80 | | - } |
81 | | - var href = _catLink( cat ); |
82 | | - var $li = $j( '<li class="cat"></li>' ); |
83 | | - $container.find('ul').append( $li ); |
84 | | - $li.append( '<a class="cat" href="'+href+'">'+cat+'</a>' ); |
85 | | - $li.append( $j.fn.removeCtrl( 'mwe-upwiz-category-remove', function() { $li.remove(); } ) ); |
86 | | - } |
| 77 | + function _insertCat( cat ) { |
| 78 | + if ( mw.isEmpty( cat ) || _containsCat( cat ) ) { |
| 79 | + return; |
| 80 | + } |
| 81 | + var href = _catLink( cat ); |
| 82 | + var $li = $j( '<li class="cat"></li>' ); |
| 83 | + $container.find( 'ul' ).append( $li ); |
| 84 | + $li.append( '<a class="cat" target="_new" href="' + href + '">' + cat +' </a>' ); |
| 85 | + $li.append( $j.fn.removeCtrl( 'mwe-upwiz-category-remove', function() { $li.remove(); } ) ); |
| 86 | + } |
87 | 87 | |
88 | | - function _catLink( cat ) { |
89 | | - return "XXX FIX LATER"; // XXX dummy |
90 | | - // var cat_esc = escape(cat).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/ /g,'+'); |
91 | | - } |
| 88 | + function _catLink( cat ) { |
| 89 | + var catLink = |
| 90 | + encodeURIComponent( wgFormattedNamespaces[wgNamespaceIds['category']] ) |
| 91 | + + ':' |
| 92 | + + encodeURIComponent( mw.ucfirst( $j.trim( cat ).replace(/ /g, '_' ) ) ); |
92 | 93 | |
| 94 | + // wgServer typically like 'http://commons.prototype.wikimedia.org' |
| 95 | + // wgArticlePath typically like '/wiki/$1' |
| 96 | + if ( ! ( mw.isEmpty( wgServer ) && mw.isEmpty( wgArticlePath ) ) ) { |
| 97 | + catLink = wgServer + wgArticlePath.replace( /\$1/, catLink ); |
| 98 | + } |
| 99 | + |
| 100 | + return catLink; |
| 101 | + } |
| 102 | + |
93 | 103 | function _getCats() { |
94 | 104 | return $container.find('ul li a.cat').map( function() { return this.text; } ); |
95 | 105 | } |
96 | 106 | |
97 | | - function _containsCat( cat ) { |
98 | | - return _getCats().filter( function() { return this == cat; } ).length !== 0; |
99 | | - } |
| 107 | + function _containsCat( cat ) { |
| 108 | + return _getCats().filter( function() { return this == cat; } ).length !== 0; |
| 109 | + } |
100 | 110 | |
101 | 111 | function _fetchSuggestions( query ) { |
102 | 112 | var _this = this; |
— | — | @@ -127,4 +137,4 @@ |
128 | 138 | } |
129 | 139 | |
130 | 140 | |
131 | | - }})(jQuery); |
| 141 | + }})(jQuery); |
Index: trunk/extensions/UploadWizard/js/mw.UploadWizard.js |
— | — | @@ -3143,7 +3143,7 @@ |
3144 | 3144 | /** |
3145 | 3145 | * Capitalise first letter and replace underscores by spaces |
3146 | 3146 | * @param title typical title as would appear on MediaWiki |
3147 | | - * @return plausible local filename, with spaces changed to underscores. |
| 3147 | + * @return plausible local filename |
3148 | 3148 | */ |
3149 | 3149 | titleToPath: function ( title ) { |
3150 | 3150 | return mw.ucfirst( $j.trim( title ).replace(/_/g, ' ' ) ); |