Index: trunk/extensions/UploadWizard/UploadWizard.config.php |
— | — | @@ -24,6 +24,10 @@ |
25 | 25 | // Categories to list by default in the list of cats to add. |
26 | 26 | 'defaultCategories' => array(), |
27 | 27 | |
| 28 | + // If the user didn't add categories, or removed the default categories, add this wikitext. |
| 29 | + // Use this to indicate that some human should categorize this file. Does not consider autoCategories, which are hidden. |
| 30 | + 'missingCategoriesWikiText' => '', |
| 31 | + |
28 | 32 | // WikiText to automatically (and silently) add to all uploaded images. |
29 | 33 | 'autoWikiText' => '', |
30 | 34 | |
Index: trunk/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js |
— | — | @@ -2,6 +2,13 @@ |
3 | 3 | * Simple predictive typing category adder for Mediawiki. |
4 | 4 | * Relies on mw.Title, mw.api.category, $.fn.removeCtrl |
5 | 5 | * Add to the page and then use getWikiText() to get wiki text representing the categories. |
| 6 | + * |
| 7 | + * N.B. Relies on the DOM to store the widget state. |
| 8 | + * On user action, list items are created, which have Titles as data properties. |
| 9 | + * To get the wikiText, we just select the list items again, get the Titles, convert to text, and return that. |
| 10 | + * This gets a bit complex as there is a hack for hidden categories too, and then another hack for default text |
| 11 | + * when the user hasn't entered any categories (not counting hidden categories!). |
| 12 | + * This should probably not be going through the DOM, could be more MVC. |
6 | 13 | */ |
7 | 14 | ( function ( $j ) { $j.fn.mwCoolCats = function( options ) { |
8 | 15 | |
— | — | @@ -77,9 +84,11 @@ |
78 | 85 | var $li = $j( '<li/>' ).addClass( 'cat' ); |
79 | 86 | var $anchor = $j( '<a/>' ).addClass( 'cat' ).append( title.getMainText() ); |
80 | 87 | $li.append( $anchor ); |
81 | | - $li.data( 'title', title ); |
| 88 | + $li.data( 'title', title ); |
82 | 89 | if ( isHidden ) { |
83 | | - $li.hide(); |
| 90 | + $li.hide().addClass( 'hidden' ); |
| 91 | + // extra 'hidden' class is necessary to distinguish deliberately hidden categories from those |
| 92 | + // which are hidden because the whole widget is closed |
84 | 93 | } else { |
85 | 94 | $anchor.attr( { target: "_blank", href: title.getUrl() } ); |
86 | 95 | $li.append( $j.fn.removeCtrl( null, 'mwe-upwiz-category-remove', function() { $li.remove(); } ) ); |
— | — | @@ -88,11 +97,17 @@ |
89 | 98 | } |
90 | 99 | |
91 | 100 | /** |
92 | | - * Get all the HTML elements representing categories on the page |
| 101 | + * Get all the categories on the page as mw.Titles, optionally filtered |
| 102 | + * @param selector {String} optional extra filter |
93 | 103 | * @return {Array of mw.Title} |
94 | 104 | */ |
95 | | - function _getCats() { |
96 | | - return $container.find('ul li.cat').map( function() { return $j( this ).data( 'title' ); } ); |
| 105 | + function _getCats( selector ) { |
| 106 | + if ( typeof selector === 'undefined' ) { |
| 107 | + selector = '*'; // fetch _ALL_ the categories! |
| 108 | + } |
| 109 | + return $container.find( 'ul li.cat' ) |
| 110 | + .filter( selector ) |
| 111 | + .map( function() { return $j( this ).data( 'title' ); } ); |
97 | 112 | } |
98 | 113 | |
99 | 114 | /** |
— | — | @@ -136,6 +151,7 @@ |
137 | 152 | var defaults = { |
138 | 153 | buttontext: 'Add', |
139 | 154 | hiddenCats: [], |
| 155 | + missingCatsWikiText: null, |
140 | 156 | cats: [] |
141 | 157 | }; |
142 | 158 | |
— | — | @@ -196,13 +212,15 @@ |
197 | 213 | }); |
198 | 214 | |
199 | 215 | this.getWikiText = function() { |
200 | | - var wikiText = '{{subst:unc}}'; |
201 | | - var $cats = _getCats(); |
202 | | - if ( $cats.length ) { |
203 | | - wikiText = $cats.map( function() { return '[[' + this.toString() + ']]'; } ) |
204 | | - .toArray() |
205 | | - .join( "\n" ); |
| 216 | + var wikiText = _getCats().map( function() { return '[[' + this.toString() + ']]'; } ) |
| 217 | + .toArray() |
| 218 | + .join( "\n" ); |
| 219 | + |
| 220 | + // if so configured, and there are no user-visible categories, add warning |
| 221 | + if ( settings.missingCatsWikiText !== null && ! ( _getCats( ':not(.hidden)' ).length ) ) { |
| 222 | + wikiText += '\n\n' + settings.missingCatsWikiText; |
206 | 223 | } |
| 224 | + |
207 | 225 | return wikiText; |
208 | 226 | }; |
209 | 227 | |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js |
— | — | @@ -291,14 +291,21 @@ |
292 | 292 | if ( mw.isDefined( mw.UploadWizard.config.autoCategory ) && mw.UploadWizard.config.autoCategory !== '' ) { |
293 | 293 | hiddenCats.push( mw.UploadWizard.config.autoCategory ); |
294 | 294 | } |
| 295 | + |
| 296 | + var missingCatsWikiText = null; |
| 297 | + if ( typeof mw.UploadWizard.config.missingCategoriesWikiText !== 'undefined' |
| 298 | + && mw.UploadWizard.config.missingCategoriesWikiText !== '' ) { |
| 299 | + missingCatsWikiText = mw.UploadWizard.config.missingCategoriesWikiText; |
| 300 | + } |
295 | 301 | |
296 | 302 | $categoriesDiv.find( '.mwe-upwiz-details-input' ) |
297 | 303 | .find( 'input' ) |
298 | 304 | .mwCoolCats( { |
299 | 305 | api: _this.upload.api, |
300 | 306 | hiddenCats: hiddenCats, |
301 | | - buttontext: gM( 'mwe-upwiz-categories-add' ) , |
302 | | - cats: mw.isDefined( mw.UploadWizard.config.defaultCategories ) ? mw.UploadWizard.config.defaultCategories : [] |
| 307 | + buttontext: gM( 'mwe-upwiz-categories-add' ), |
| 308 | + cats: mw.isDefined( mw.UploadWizard.config.defaultCategories ) ? mw.UploadWizard.config.defaultCategories : [], |
| 309 | + missingCatsWikiText: missingCatsWikiText |
303 | 310 | } ); |
304 | 311 | |
305 | 312 | }; |