r69302 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69301‎ | r69302 | r69303 >
Date:01:13, 13 July 2010
Author:neilk
Status:deferred
Tags:
Comment:
crude but effective category adding
Modified paths:
  • /trunk/extensions/UploadWizard/js/jquery/plugins/jquery.mwCoolCats.js (modified) (history)
  • /trunk/extensions/UploadWizard/js/mw.UploadWizard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/js/jquery/plugins/jquery.mwCoolCats.js
@@ -1,26 +1,18 @@
2 -RegExp.escape = (function() {
3 - var specials = [
4 - '/', '.', '*', '+', '?', '|',
5 - '(', ')', '[', ']', '{', '}', '\\'
6 - ];
 2+( function ( $j ) { $j.fn.mwCoolCats = function( options ) {
73
8 - sRE = new RegExp(
9 - '(\\' + specials.join('|\\') + ')', 'g'
10 - );
11 -
12 - return function(text) {
13 - return text.replace(sRE, '\\$1');
14 - }
15 -})();
16 -(function($){
17 - $.fn.mwCoolCats = function(options) {
184 var defaults = {
195 buttontext: 'Add'
206 };
21 - var settings = $.extend( {}, defaults, options);
 7+
 8+ var settings = $j.extend( {}, defaults, options);
 9+
 10+ // usually Category:Foo
 11+ var categoryNamespace = wgFormattedNamespaces[wgNamespaceIds['category']];
 12+
2213 var $container;
2314 return this.each( function() {
2415 var _this = $j( this );
 16+ _this.addClass( 'categoryInput' );
2517
2618 _this.suggestions( {
2719 'fetch': _fetchSuggestions,
@@ -57,7 +49,6 @@
5850 }
5951 });
6052
61 - var categoryNamespace = mw.getConfig( 'categoryNamespace' );
6253 this.getWikiText = function() {
6354 return _getCats().map( function() { return '[[' + categoryNamespace + ':' + this + ']]'; } )
6455 .toArray()
@@ -86,9 +77,9 @@
8778
8879 function _catLink( cat ) {
8980 var catLink =
90 - encodeURIComponent( wgFormattedNamespaces[wgNamespaceIds['category']] )
 81+ encodeURIComponent( categoryNamespace )
9182 + ':'
92 - + encodeURIComponent( mw.ucfirst( $j.trim( cat ).replace(/ /g, '_' ) ) );
 83+ + encodeURIComponent( mw.ucfirst( cat.replace(/ /g, '_' ) ) );
9384
9485 // wgServer typically like 'http://commons.prototype.wikimedia.org'
9586 // wgArticlePath typically like '/wiki/$1'
@@ -100,7 +91,7 @@
10192 }
10293
10394 function _getCats() {
104 - return $container.find('ul li a.cat').map( function() { return this.text; } );
 95+ return $container.find('ul li a.cat').map( function() { return $j.trim( this.text ); } );
10596 }
10697
10798 function _containsCat( cat ) {
@@ -136,5 +127,4 @@
137128 $j( _this ).data( 'request', request );
138129 }
139130
140 -
141 - }})(jQuery);
 131+}})(jQuery);
Index: trunk/extensions/UploadWizard/js/mw.UploadWizard.js
@@ -1284,7 +1284,9 @@
12851285 // all other fields validated with validator js
12861286 var formValid = _this.$form.valid();
12871287 return titleInputValid && formValid;
1288 -
 1288+
 1289+ // categories are assumed valid
 1290+
12891291 // the license, if any
12901292
12911293 // pop open the 'more-options' if the date is bad
@@ -1720,14 +1722,12 @@
17211723 getWikiText: function() {
17221724 var _this = this;
17231725
1724 - // XXX validate!
 1726+ // if invalid, should produce side effects in the form
 1727+ // instructing user to fix.
17251728 if ( ! _this.valid() ) {
1726 - alert( "THIS DEED IS NOT READY" );
17271729 return null;
17281730 }
17291731
1730 -
1731 -
17321732 wikiText = '';
17331733
17341734
@@ -1773,19 +1773,21 @@
17741774
17751775 wikiText += '{{Information\n' + info + '}}\n';
17761776
1777 -
1778 - wikiText += "=={{int:license-header}}==\n";
1779 -
1780 - wikiText += deed.getLicenseWikiText();
 1777+ // add a location template if possible
17811778
1782 - // add a location template
1783 -
17841779 // add an "anything else" template if needed
17851780 var otherInfoWikiText = $j( _this.otherInformationInput ).val().trim();
17861781 if ( ! mw.isEmpty( otherInfoWikiText ) ) {
17871782 wikiText += "=={{int:otherinfo}}==\n";
17881783 wikiText += otherInfoWikiText;
17891784 }
 1785+
 1786+ wikiText += "=={{int:license-header}}==\n";
 1787+
 1788+ // in the other implementations, category text follows immediately after license text. This helps
 1789+ // group categories together, maybe?
 1790+ wikiText += deed.getLicenseWikiText() + _this.div.find( '.categoryInput' ).get(0).getWikiText();
 1791+
17901792
17911793 return wikiText;
17921794 },

Status & tagging log