r95677 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95676‎ | r95677 | r95678 >
Date:16:28, 29 August 2011
Author:neilk
Status:ok
Tags:
Comment:
MFT of r95551. when deploying to Commons, set $wgUploadWizardConfig["missingCategoriesWikiText"] = "{{subst:unc}}" in LocalSettings
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizard.config.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/UploadWizard/resources/mw.UploadWizardDetails.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/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: branches/wmf/1.17wmf1/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
@@ -70,9 +77,11 @@
7178 var $li = $j( '<li/>' ).addClass( 'cat' );
7279 var $anchor = $j( '<a/>' ).addClass( 'cat' ).append( title.getMainText() );
7380 $li.append( $anchor );
74 - $li.data( 'title', title );
 81+ $li.data( 'title', title );
7582 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
7786 } else {
7887 $anchor.attr( { target: "_blank", href: title.getUrl() } );
7988 $li.append( $j.fn.removeCtrl( null, 'mwe-upwiz-category-remove', function() { $li.remove(); } ) );
@@ -81,11 +90,17 @@
8291 }
8392
8493 /**
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
8696 * @return {Array of mw.Title}
8797 */
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' ); } );
90105 }
91106
92107 /**
@@ -129,6 +144,7 @@
130145 var defaults = {
131146 buttontext: 'Add',
132147 hiddenCats: [],
 148+ missingCatsWikiText: null,
133149 cats: []
134150 };
135151
@@ -189,13 +205,15 @@
190206 });
191207
192208 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;
199216 }
 217+
200218 return wikiText;
201219 };
202220
Index: branches/wmf/1.17wmf1/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 };

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95551properly configurable warning for missing categories -- when deploying to Com...neilk04:26, 26 August 2011

Status & tagging log