http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95677

Revision: 95677
Author:   neilk
Date:     2011-08-29 16:28:15 +0000 (Mon, 29 Aug 2011)
Log Message:
-----------
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
    
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js
    
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/mw.UploadWizardDetails.js

Modified: branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizard.config.php
===================================================================
--- branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizard.config.php       
2011-08-29 16:20:14 UTC (rev 95676)
+++ branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizard.config.php       
2011-08-29 16:28:15 UTC (rev 95677)
@@ -24,6 +24,10 @@
        // Categories to list by default in the list of cats to add.
        'defaultCategories' => array(),
 
+       // If the user didn't add categories, or removed the default 
categories, add this wikitext.
+       // Use this to indicate that some human should categorize this file. 
Does not consider autoCategories, which are hidden.
+       'missingCategoriesWikiText' => '',      
+
        // WikiText to automatically (and silently) add to all uploaded images.
        'autoWikiText' => '',
 

Modified: 
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js
===================================================================
--- 
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js
 2011-08-29 16:20:14 UTC (rev 95676)
+++ 
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js
 2011-08-29 16:28:15 UTC (rev 95677)
@@ -2,6 +2,13 @@
  * Simple predictive typing category adder for Mediawiki.
  * Relies on mw.Title, mw.api.category, $.fn.removeCtrl
  * Add to the page and then use getWikiText() to get wiki text representing 
the categories.
+ *
+ * N.B. Relies on the DOM to store the widget state.
+ * On user action, list items are created, which have Titles as data 
properties.
+ * To get the wikiText, we just select the list items again, get the Titles, 
convert to text, and return that.
+ * This gets a bit complex as there is a hack for hidden categories too, and 
then another hack for default text
+ * when the user hasn't entered any categories (not counting hidden 
categories!). 
+ * This should probably not be going through the DOM, could be more MVC.
  */
 ( function ( $j ) { $j.fn.mwCoolCats = function( options ) {
 
@@ -70,9 +77,11 @@
                var $li = $j( '<li/>' ).addClass( 'cat' );
                var $anchor = $j( '<a/>' ).addClass( 'cat' ).append( 
title.getMainText() );
                $li.append( $anchor );
-               $li.data( 'title', title );             
+               $li.data( 'title', title );
                if ( isHidden ) {
-                       $li.hide();
+                       $li.hide().addClass( 'hidden' );
+                       // extra 'hidden' class is necessary to distinguish 
deliberately hidden categories from those 
+                       // which are hidden because the whole widget is closed
                } else {
                        $anchor.attr( { target: "_blank", href: title.getUrl() 
} );
                        $li.append( $j.fn.removeCtrl( null, 
'mwe-upwiz-category-remove', function() { $li.remove(); } ) );
@@ -81,11 +90,17 @@
        }
 
        /**
-        * Get all the HTML elements representing categories on the page
+        * Get all the categories on the page as mw.Titles, optionally filtered
+        * @param selector {String} optional extra filter
         * @return {Array of mw.Title}
         */
-       function _getCats() {
-               return $container.find('ul li.cat').map( function() { return 
$j( this ).data( 'title' ); } );
+       function _getCats( selector ) {
+               if ( typeof selector === 'undefined' ) {
+                       selector = '*'; // fetch _ALL_ the categories!
+               }
+               return $container.find( 'ul li.cat' )
+                               .filter( selector )
+                               .map( function() { return $j( this ).data( 
'title' ); } );
        }
 
        /**
@@ -129,6 +144,7 @@
        var defaults = {
                buttontext: 'Add',
                hiddenCats: [],
+               missingCatsWikiText: null,
                cats: []
        };
 
@@ -189,13 +205,15 @@
                });
 
                this.getWikiText = function() {
-                       var wikiText = '{{subst:unc}}';
-                       var $cats = _getCats();
-                       if ( $cats.length ) {
-                               wikiText = $cats.map( function() { return '[[' 
+ this.toString() + ']]'; } )
-                                               .toArray()
-                                               .join( "\n" );
+                       var wikiText = _getCats().map( function() { return '[[' 
+ this.toString() + ']]'; } )
+                                                       .toArray()
+                                                       .join( "\n" );
+
+                       // if so configured, and there are no user-visible 
categories, add warning
+                       if ( settings.missingCatsWikiText !== null && ! ( 
_getCats( ':not(.hidden)' ).length ) ) {
+                               wikiText += '\n\n' + 
settings.missingCatsWikiText;
                        }
+
                        return wikiText;
                };
 

Modified: 
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
===================================================================
--- 
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
   2011-08-29 16:20:14 UTC (rev 95676)
+++ 
branches/wmf/1.17wmf1/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
   2011-08-29 16:28:15 UTC (rev 95677)
@@ -291,14 +291,21 @@
        if ( mw.isDefined( mw.UploadWizard.config.autoCategory ) && 
mw.UploadWizard.config.autoCategory !== '' ) {
                hiddenCats.push( mw.UploadWizard.config.autoCategory );
        }
+
+       var missingCatsWikiText = null;
+       if ( typeof mw.UploadWizard.config.missingCategoriesWikiText !== 
'undefined' 
+                       && mw.UploadWizard.config.missingCategoriesWikiText !== 
'' ) {
+               missingCatsWikiText = 
mw.UploadWizard.config.missingCategoriesWikiText;
+       }
        
        $categoriesDiv.find( '.mwe-upwiz-details-input' )
                        .find( 'input' )
                        .mwCoolCats( { 
                                api: _this.upload.api,
                                hiddenCats: hiddenCats,
-                               buttontext: gM( 'mwe-upwiz-categories-add' )  ,
-                               cats: mw.isDefined( 
mw.UploadWizard.config.defaultCategories ) ? 
mw.UploadWizard.config.defaultCategories : []
+                               buttontext: gM( 'mwe-upwiz-categories-add' ),
+                               cats: mw.isDefined( 
mw.UploadWizard.config.defaultCategories ) ? 
mw.UploadWizard.config.defaultCategories : [],
+                               missingCatsWikiText: missingCatsWikiText
                        } );
 
 };


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to