Index: branches/wmf/1.17wmf1/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: branches/wmf/1.17wmf1/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 | |
— | — | @@ -70,9 +77,11 @@ |
71 | 78 | var $li = $j( '<li/>' ).addClass( 'cat' ); |
72 | 79 | var $anchor = $j( '<a/>' ).addClass( 'cat' ).append( title.getMainText() ); |
73 | 80 | $li.append( $anchor ); |
74 | | - $li.data( 'title', title ); |
| 81 | + $li.data( 'title', title ); |
75 | 82 | if ( isHidden ) { |
76 | | - $li.hide(); |
| 83 | + $li.hide().addClass( 'hidden' ); |
| 84 | + // extra 'hidden' class is necessary to distinguish deliberately hidden categories from those |
| 85 | + // which are hidden because the whole widget is closed |
77 | 86 | } else { |
78 | 87 | $anchor.attr( { target: "_blank", href: title.getUrl() } ); |
79 | 88 | $li.append( $j.fn.removeCtrl( null, 'mwe-upwiz-category-remove', function() { $li.remove(); } ) ); |
— | — | @@ -81,11 +90,17 @@ |
82 | 91 | } |
83 | 92 | |
84 | 93 | /** |
85 | | - * Get all the HTML elements representing categories on the page |
| 94 | + * Get all the categories on the page as mw.Titles, optionally filtered |
| 95 | + * @param selector {String} optional extra filter |
86 | 96 | * @return {Array of mw.Title} |
87 | 97 | */ |
88 | | - function _getCats() { |
89 | | - return $container.find('ul li.cat').map( function() { return $j( this ).data( 'title' ); } ); |
| 98 | + function _getCats( selector ) { |
| 99 | + if ( typeof selector === 'undefined' ) { |
| 100 | + selector = '*'; // fetch _ALL_ the categories! |
| 101 | + } |
| 102 | + return $container.find( 'ul li.cat' ) |
| 103 | + .filter( selector ) |
| 104 | + .map( function() { return $j( this ).data( 'title' ); } ); |
90 | 105 | } |
91 | 106 | |
92 | 107 | /** |
— | — | @@ -129,6 +144,7 @@ |
130 | 145 | var defaults = { |
131 | 146 | buttontext: 'Add', |
132 | 147 | hiddenCats: [], |
| 148 | + missingCatsWikiText: null, |
133 | 149 | cats: [] |
134 | 150 | }; |
135 | 151 | |
— | — | @@ -189,13 +205,15 @@ |
190 | 206 | }); |
191 | 207 | |
192 | 208 | this.getWikiText = function() { |
193 | | - var wikiText = '{{subst:unc}}'; |
194 | | - var $cats = _getCats(); |
195 | | - if ( $cats.length ) { |
196 | | - wikiText = $cats.map( function() { return '[[' + this.toString() + ']]'; } ) |
197 | | - .toArray() |
198 | | - .join( "\n" ); |
| 209 | + var wikiText = _getCats().map( function() { return '[[' + this.toString() + ']]'; } ) |
| 210 | + .toArray() |
| 211 | + .join( "\n" ); |
| 212 | + |
| 213 | + // if so configured, and there are no user-visible categories, add warning |
| 214 | + if ( settings.missingCatsWikiText !== null && ! ( _getCats( ':not(.hidden)' ).length ) ) { |
| 215 | + wikiText += '\n\n' + settings.missingCatsWikiText; |
199 | 216 | } |
| 217 | + |
200 | 218 | return wikiText; |
201 | 219 | }; |
202 | 220 | |
Index: branches/wmf/1.17wmf1/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 | }; |