Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -149,7 +149,9 @@ |
150 | 150 | 'mwe-upwiz-license-gfdl' => 'GNU Free Documentation License', |
151 | 151 | /* this is just for testing, we are not going to privilege the US and A */ |
152 | 152 | 'mwe-upwiz-license-pd-us' => 'Public Domain (US)', |
153 | | - 'mwe-upwiz-categories' => 'Categories' |
| 153 | + 'mwe-upwiz-categories' => 'Categories', |
| 154 | + 'mwe-upwiz-categories-add' => 'Add', |
| 155 | + 'mwe-upwiz-category-remove' => 'Remove this category' |
154 | 156 | ); |
155 | 157 | |
156 | 158 | /** Message documentation (Message documentation) |
Index: trunk/extensions/UploadWizard/SpecialUploadWizard.php |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | public function addJS() { |
96 | 96 | global $wgUser, $wgOut; |
97 | 97 | global $wgUseAjax, $wgAjaxLicensePreview, $wgEnableAPI; |
98 | | - global $wgEnableFirefogg, $wgFileExtensions, $wgCanonicalNamespaceNames; |
| 98 | + global $wgEnableFirefogg, $wgFileExtensions |
99 | 99 | |
100 | 100 | $wgOut->addScript( Skin::makeVariablesScript( array( |
101 | 101 | // uncertain if this is relevant. Can we do license preview with API? |
— | — | @@ -108,9 +108,6 @@ |
109 | 109 | // our edit token |
110 | 110 | 'wgEditToken' => $wgUser->editToken(), |
111 | 111 | |
112 | | - // URL prefixes in this MediaWiki, e.g. images under Image: |
113 | | - 'wgCanonicalNamespaceNames' => $wgCanonicalNamespaceNames |
114 | | - |
115 | 112 | // 'wgFilenamePrefixBlacklist' => UploadBase::getFilenamePrefixBlacklist(); |
116 | 113 | |
117 | 114 | |
Index: trunk/extensions/UploadWizard/js/jquery/plugins/jquery.mwCoolCats.js |
— | — | @@ -14,115 +14,117 @@ |
15 | 15 | })(); |
16 | 16 | (function($){ |
17 | 17 | $.fn.mwCoolCats = function(options) { |
18 | | - var defaults = { |
19 | | - showform: false, |
20 | | - formlabel: 'Add cat(s):', |
21 | | - buttontext: 'Add', |
22 | | - listlabel: 'Cats:', |
23 | | - deletetext: 'x', |
24 | | - delimitter: ',', |
25 | | - linkformat: '', |
26 | | - //submitstyle: 'string', |
27 | | - /* Events and Callbacks */ |
28 | | - addcat: function(e){ }, |
29 | | - removecat: function(e){ } |
30 | | - }; |
31 | | - var catList = Array(); |
32 | | - var self; |
33 | | - var orig; |
34 | | - var origname; |
| 18 | + var defaults = { |
| 19 | + buttontext: 'Add' |
| 20 | + }; |
35 | 21 | var settings = $.extend( {}, defaults, options); |
36 | | - return this.each( function() { |
37 | | - orig = $(this); |
38 | | - $(this).wrap('<div class="cat-widget"></div>'); |
39 | | - $(this).parent() |
40 | | - .append( $j( '<button type="button">'+settings.buttontext+'</button>' ) |
41 | | - .click( function(e) { |
42 | | - e.stopPropagation(); |
43 | | - e.preventDefault(); |
44 | | - _processInput(); |
45 | | - return false; |
46 | | - }) ); |
47 | | - $(this).parent().append('<ul class="cat-list pkg"></ul>'); |
48 | | - $(this).parent().append( $(this).clone().attr('type','hidden').removeAttr('class').val('') ); |
| 22 | + var $container; |
| 23 | + return this.each( function() { |
| 24 | + var _this = $j( this ); |
49 | 25 | |
| 26 | + _this.suggestions( { |
| 27 | + 'fetch': _fetchSuggestions, |
| 28 | + 'cancel': function() { |
| 29 | + var req = $j( this ).data( 'request' ); |
| 30 | + if ( req.abort ) { |
| 31 | + req.abort(); |
| 32 | + } |
| 33 | + } |
| 34 | + } ); |
| 35 | + _this.suggestions(); |
| 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>'); |
| 47 | + |
50 | 48 | //XXX ensure this isn't blocking other stuff needed. |
51 | | - $(this).parents('form').submit( function() { |
| 49 | + _this.parents('form').submit( function() { |
52 | 50 | _processInput(); |
53 | 51 | }); |
54 | | - $(this).parents('form').keydown( function(e) { |
| 52 | + |
| 53 | + _this.keyup(function(e) { |
55 | 54 | if(e.keyCode == 13) { |
56 | | - e.preventDefault(); |
57 | | - return false; |
58 | | - } |
59 | | - }); |
60 | | - |
61 | | - origname = $(this).attr('name'); |
62 | | - $(this).removeAttr('name'); |
63 | | - $(this).keyup(function(e) { |
64 | | - if(e.keyCode == 13) { |
65 | 55 | e.stopPropagation(); |
66 | 56 | e.preventDefault(); |
67 | 57 | _processInput(); |
68 | 58 | } |
69 | 59 | }); |
70 | | - obj = $(this).parent(); // set to the cat-widget class we just wrapped |
71 | | - self = obj; |
| 60 | + |
| 61 | + var categoryNamespace = mw.getConfig( 'categoryNamespace' ); |
| 62 | + this.getWikiText = function() { |
| 63 | + return _getCats().map( function() { return '[[' + categoryNamespace + ':' + this + ']]'; } ) |
| 64 | + .toArray() |
| 65 | + .join( "\n" ); |
| 66 | + }; |
| 67 | + |
72 | 68 | _processInput(); |
73 | | - }); |
74 | | - function _split( str ) { |
75 | | - var delim = RegExp.escape(settings.delimitter); |
76 | | - var delim_scan = new RegExp('^((([\'"])(.*?)\\3|.*?)(' + delim + '\\s*|$))', ''); |
77 | | - str = str.replace(/(^\s+|\s+$)/g, ''); |
78 | | - var cats = []; |
79 | | - while (str.length && str.match(delim_scan)) { |
80 | | - str = str.substr(RegExp.$1.length); |
81 | | - orig.val(str); |
82 | | - var cat = RegExp.$4 ? RegExp.$4 : RegExp.$2; |
83 | | - cat = cat.replace(/(^\s+|\s+$)/g, ''); |
84 | | - cat = cat.replace(/\s+/g, ' '); |
85 | | - if (cat != '') cats.push(cat); |
86 | | - } |
87 | | - return cats; |
88 | | - }; |
| 69 | + }); |
| 70 | + |
89 | 71 | function _processInput() { |
90 | | - var newcats = _split( self.find('input').val() ); |
91 | | - for(i = 0; i < newcats.length; i++) { |
92 | | - _insertCat( newcats[i] ); |
93 | | - }; |
94 | | - self.find('ul li a.delete').click( function() { |
95 | | - var cat = $(this).parent().find('a.cat').html(); |
96 | | - $(this).parent().remove(); |
97 | | - _removeCat( cat ); |
98 | | - }); |
99 | | - }; |
100 | | - function _removeCat( cat ) { |
101 | | - var str = ''; |
102 | | - for (var i=0;i < catList.length;i++) { |
103 | | - if (catList[i] == cat) { |
104 | | - catList.splice(i,1); |
105 | | - i--; |
106 | | - } else { |
107 | | - if (str != '') { str = str + settings.delimitter; } |
108 | | - str = str + catList[i]; |
109 | | - } |
110 | | - } |
111 | | - self.find('input[name='+origname+']').val( str ); |
| 72 | + var $input = $container.find('input'); |
| 73 | + _insertCat( $input.val().trim() ); |
| 74 | + $input.val(""); |
| 75 | + } |
112 | 76 | |
113 | | - }; |
114 | 77 | function _insertCat( cat ) { |
115 | | - if ( _containsCat( cat ) ) { return; } |
116 | | - var cat_esc = escape(cat).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/ /g,'+'); |
117 | | - self.find('ul').append('<li class="cat"><a class="cat" href="'+settings.linkformat + cat_esc+'">'+cat+'</a> <a href="javascript:void(0)" class="delete">'+settings.deletetext+'</a></li>'); |
118 | | - catList.push(cat); |
119 | | - var v = self.find('input[name='+origname+']').val(); |
120 | | - if (v != '') { v = v + settings.delimitter; } |
121 | | - self.find('input[name='+origname+']').val( v + cat ); |
122 | | - }; |
| 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 | + } |
| 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 | + } |
| 92 | + |
| 93 | + function _getCats() { |
| 94 | + return $container.find('ul li a.cat').map( function() { return this.text; } ); |
| 95 | + } |
| 96 | + |
123 | 97 | function _containsCat( cat ) { |
124 | | - for (var i = 0; i < catList.length; i++) { |
125 | | - if (cat == catList[i]) { return 1; } |
126 | | - } |
127 | | - return 0; |
128 | | - }; |
| 98 | + return _getCats().filter( function() { return this == cat; } ).length !== 0; |
| 99 | + } |
| 100 | + |
| 101 | + function _fetchSuggestions( query ) { |
| 102 | + var _this = this; |
| 103 | + var request = $j.ajax( { |
| 104 | + url: wgScriptPath + '/api.php', |
| 105 | + data: { |
| 106 | + 'action': 'query', |
| 107 | + 'list': 'allpages', |
| 108 | + 'apnamespace': wgNamespaceIds['category'], |
| 109 | + 'apprefix': $j( this ).val(), |
| 110 | + 'format': 'json' |
| 111 | + }, |
| 112 | + dataType: 'json', |
| 113 | + success: function( data ) { |
| 114 | + // Process data.query.allpages into an array of titles |
| 115 | + var pages = data.query.allpages; |
| 116 | + var titleArr = []; |
| 117 | + |
| 118 | + $j.each( pages, function( i, page ) { |
| 119 | + var title = page.title.split( ':', 2 )[1]; |
| 120 | + titleArr.push( title ); |
| 121 | + } ); |
| 122 | + |
| 123 | + $j( _this ).suggestions( 'suggestions', titleArr ); |
| 124 | + } |
| 125 | + } ); |
| 126 | + |
| 127 | + $j( _this ).data( 'request', request ); |
| 128 | + } |
| 129 | + |
| 130 | + |
129 | 131 | }})(jQuery); |
Index: trunk/extensions/UploadWizard/js/mw.UploadWizard.js |
— | — | @@ -494,7 +494,7 @@ |
495 | 495 | var _this = this; |
496 | 496 | |
497 | 497 | _this.filename = result.upload.filename; |
498 | | - _this.title = mw.getConfig( 'fileNamespace' ) + ':' + _this.filename; |
| 498 | + _this.title = wgFormattedNamespaces[wgNamespaceIds['file']] + ':' + _this.filename; |
499 | 499 | |
500 | 500 | _this.extractImageInfo( result.upload.imageinfo ); |
501 | 501 | |
— | — | @@ -1239,11 +1239,11 @@ |
1240 | 1240 | showAnim: 'slideDown', |
1241 | 1241 | altField: '#' + dateInputId, |
1242 | 1242 | altFormat: 'yy-mm-dd' } ) |
1243 | | - .click( function() { $j( this ).datepicker( 'show' ) } ) |
| 1243 | + .click( function() { $j( this ).datepicker( 'show' ); } ) |
1244 | 1244 | .readonly(); |
1245 | 1245 | |
1246 | 1246 | _this.$form.find( '.mwe-date' ) |
1247 | | - .bind( 'change', function() { $j( this ).valid() } ) |
| 1247 | + .bind( 'change', function() { $j( this ).valid(); } ) |
1248 | 1248 | .hide(); |
1249 | 1249 | |
1250 | 1250 | /* if the date is not valid, we need to pop open the "more options". How? |
— | — | @@ -1254,8 +1254,10 @@ |
1255 | 1255 | _this.addDescription( true, mw.getConfig('userLanguage') ); |
1256 | 1256 | $j( containerDiv ).append( _this.div ); |
1257 | 1257 | |
1258 | | - // make this a cool category picker |
1259 | | - $categoriesDiv.find( '.mwe-upwiz-details-input' ).find( 'input' ).mwCoolCats(); |
| 1258 | + // make this a category picker |
| 1259 | + $categoriesDiv.find( '.mwe-upwiz-details-input' ) |
| 1260 | + .find( 'input' ) |
| 1261 | + .mwCoolCats( { buttontext: gM( 'mwe-upwiz-categories-add' ) } ); |
1260 | 1262 | |
1261 | 1263 | }; |
1262 | 1264 | |
— | — | @@ -1312,7 +1314,8 @@ |
1313 | 1315 | */ |
1314 | 1316 | setFilenameFromTitle: function() { |
1315 | 1317 | var _this = this; |
1316 | | - _this.filename = mw.getConfig( 'fileNamespace' ) + ':' + _this.getFilenameFromTitle(); |
| 1318 | + |
| 1319 | + _this.filename = wgFormattedNamespaces[wgNamespaceIds['file']] + ':' + _this.getFilenameFromTitle(); |
1317 | 1320 | $j( '#mwe-upwiz-details-filename' ).text( _this.filename ); |
1318 | 1321 | |
1319 | 1322 | }, |
— | — | @@ -2901,7 +2904,7 @@ |
2902 | 2905 | var formValid = _this.$form.valid(); |
2903 | 2906 | var licenseInputValid = _this.licenseInput.valid(); |
2904 | 2907 | return formValid && licenseInputValid; |
2905 | | - }, |
| 2908 | + } |
2906 | 2909 | } ); |
2907 | 2910 | }; |
2908 | 2911 | |
— | — | @@ -3159,7 +3162,7 @@ |
3160 | 3163 | title = title.substr( 0, title.length - extension.length - 1 ); |
3161 | 3164 | } |
3162 | 3165 | // usually File: |
3163 | | - var namespace = mw.getConfig( 'fileNamespace' ); |
| 3166 | + var namespace = wgFormattedNamespaces[wgNamespaceIds['file']]; |
3164 | 3167 | if ( title.indexOf( namespace + ':' ) === 0 ) { |
3165 | 3168 | title = title.substr( namespace.length + 1 ); |
3166 | 3169 | } |
Index: trunk/extensions/UploadWizard/UploadWizardPage.js |
— | — | @@ -17,10 +17,6 @@ |
18 | 18 | var discussLink = discussListItem.getElementsByTagName( 'a' )[0]; |
19 | 19 | discussLink.setAttribute( 'target', 'usability_discussion' ); |
20 | 20 | |
21 | | - // The namespace for media files. We use this to look up what the URL prefix is on this MediaWiki, usually |
22 | | - // 'Image:' or something like that. Defined in defines.php |
23 | | - var NS_FILE = 6; |
24 | | - |
25 | 21 | mw.load( 'UploadWizard.UploadWizard', function () { |
26 | 22 | mw.setConfig( 'debug', true ); |
27 | 23 | |
— | — | @@ -68,10 +64,6 @@ |
69 | 65 | { template: 'GFDL', messageKey: 'mwe-upwiz-license-gfdl', 'default': false } |
70 | 66 | ], |
71 | 67 | |
72 | | - // usually, but not always, File: |
73 | | - fileNamespace: wgCanonicalNamespaceNames[NS_FILE], |
74 | | - |
75 | | - |
76 | 68 | // XXX this is horribly confusing -- some file restrictions are client side, others are server side |
77 | 69 | // the filename prefix blacklist is at least server side -- all this should be replaced with PHP regex config |
78 | 70 | // or actually, in an ideal world, we'd have some way to reliably detect gibberish, rather than trying to |