r95551 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95550‎ | r95551 | r95552 >
Date:04:26, 26 August 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
properly configurable warning for missing categories -- when deploying to Commons, set $wgUploadWizardConfig["missingCategoriesWikiText"] = "{{subst:unc}}" in LocalSettings
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.config.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/UploadWizard.config.php
@@ -24,6 +24,10 @@
2525 // Categories to list by default in the list of cats to add.
2626 'defaultCategories' => array(),
2727
 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+
2832 // WikiText to automatically (and silently) add to all uploaded images.
2933 'autoWikiText' => '',
3034
Index: trunk/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js
@@ -2,6 +2,13 @@
33 * Simple predictive typing category adder for Mediawiki.
44 * Relies on mw.Title, mw.api.category, $.fn.removeCtrl
55 * 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.
613 */
714 ( function ( $j ) { $j.fn.mwCoolCats = function( options ) {
815
@@ -77,9 +84,11 @@
7885 var $li = $j( '<li/>' ).addClass( 'cat' );
7986 var $anchor = $j( '<a/>' ).addClass( 'cat' ).append( title.getMainText() );
8087 $li.append( $anchor );
81 - $li.data( 'title', title );
 88+ $li.data( 'title', title );
8289 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
8493 } else {
8594 $anchor.attr( { target: "_blank", href: title.getUrl() } );
8695 $li.append( $j.fn.removeCtrl( null, 'mwe-upwiz-category-remove', function() { $li.remove(); } ) );
@@ -88,11 +97,17 @@
8998 }
9099
91100 /**
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
93103 * @return {Array of mw.Title}
94104 */
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' ); } );
97112 }
98113
99114 /**
@@ -136,6 +151,7 @@
137152 var defaults = {
138153 buttontext: 'Add',
139154 hiddenCats: [],
 155+ missingCatsWikiText: null,
140156 cats: []
141157 };
142158
@@ -196,13 +212,15 @@
197213 });
198214
199215 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;
206223 }
 224+
207225 return wikiText;
208226 };
209227
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
@@ -291,14 +291,21 @@
292292 if ( mw.isDefined( mw.UploadWizard.config.autoCategory ) && mw.UploadWizard.config.autoCategory !== '' ) {
293293 hiddenCats.push( mw.UploadWizard.config.autoCategory );
294294 }
 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+ }
295301
296302 $categoriesDiv.find( '.mwe-upwiz-details-input' )
297303 .find( 'input' )
298304 .mwCoolCats( {
299305 api: _this.upload.api,
300306 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
303310 } );
304311
305312 };

Follow-up revisions

RevisionCommit summaryAuthorDate
r95677MFT of r95551. when deploying to Commons, set $wgUploadWizardConfig["missingC...neilk16:28, 29 August 2011

Comments

#Comment by NeilK (talk | contribs)   04:42, 26 August 2011

added tags for Roan to review

next week (Aug 29 - Sep 4) I will be out & hopefully this can be deployed

despite being a simple change this should dramatically reduce workload of Commons admins when dealing w/UploadWizard

Status & tagging log