r105647 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105646‎ | r105647 | r105648 >
Date:04:49, 9 December 2011
Author:neilk
Status:ok
Tags:
Comment:
switch UploadWizard to use core libraries for api, title, feedback
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardUpload.js (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mw.Title.spec.js (deleted) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html
@@ -14,9 +14,9 @@
1515 <script type="text/javascript" src="../../../../resources/mediawiki.language/mediawiki.language.js"></script>
1616 <script type="text/javascript" src="../../../../resources/mediawiki/mediawiki.Uri.js"></script>
1717 <script type="text/javascript" src="../../resources/mediawiki.language.parser.js"></script>
18 - <script type="text/javascript" src="../../resources/mw.Api.js"></script>
19 - <script type="text/javascript" src="../../resources/mw.Api.edit.js"></script>
20 - <script type="text/javascript" src="../../resources/mw.Title.js"></script>
 18+ <script type="text/javascript" src="../../../../resources/mediawiki/mediawiki.api.js"></script>
 19+ <script type="text/javascript" src="../../../../resources/mediawiki/mediawiki.api.edit.js"></script>
 20+ <script type="text/javascript" src="../../../../resources/mediawiki/mediawiki.Title.js"></script>
2121 <script type="text/javascript" src="../../resources/mw.units.js"></script>
2222 <script type="text/javascript" src="../../resources/jquery/jquery.pubsub.js"></script>
2323
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mw.Title.spec.js
@@ -1,112 +0,0 @@
2 -( function( mw ) {
3 - describe( "mw.Title", function() {
4 -
5 - // these are typically initialized as globals...
6 - wgFormattedNamespaces = {
7 - "-2":"Media",
8 - "-1":"Special",
9 - "0":"",
10 - "1":"Talk",
11 - "2":"User",
12 - "3":"User talk",
13 - "4":"CommonsDev",
14 - "5":"CommonsDev talk",
15 - "6":"File",
16 - "7":"File talk",
17 - "8":"MediaWiki",
18 - "9":"MediaWiki talk",
19 - "10":"Template",
20 - "11":"Template talk",
21 - "12":"Help",
22 - "13":"Help talk",
23 - "14":"Category",
24 - "15":"Category talk",
25 - /* testing custom / localized */
26 - "99":"Penguins"
27 - };
28 - wgNamespaceIds = {
29 - "media":-2,
30 - "special":-1,
31 - "":0,
32 - "talk":1,
33 - "user":2,
34 - "user_talk":3,
35 - "commonsdev":4,
36 - "commonsdev_talk":5,
37 - "file":6,
38 - "file_talk":7,
39 - "mediawiki":8,
40 - "mediawiki_talk":9,
41 - "template":10,
42 - "template_talk":11,
43 - "help":12,
44 - "help_talk":13,
45 - "category":14,
46 - "category_talk":15,
47 - "image":6,
48 - "image_talk":7,
49 - /* testing custom / localized */
50 - "antarctic_waterfowl":99
51 - };
52 -
53 -
54 - describe( "basic" , function() {
55 -
56 - it( "should initialize from filename", function() {
57 - var title = new mw.Title( "File:foo_bar.JPG" );
58 - expect( title.getMain() ).toEqual( 'Foo_bar.jpg' );
59 - expect( title.getMainText() ).toEqual( 'Foo bar.jpg' );
60 - expect( title.getNameText() ).toEqual( 'Foo bar' );
61 - expect( title.toString() ).toEqual( "File:Foo_bar.jpg" );
62 - } );
63 -
64 - it( "should translate back and forth between human-readable and not", function() {
65 - var title = new mw.Title( "File:foo_bar.JPG" );
66 - title.setName( "quux pif" );
67 - expect( title.getMain() ).toEqual( "Quux_pif.jpg" );
68 - expect( title.getMainText() ).toEqual( "Quux pif.jpg" );
69 - expect( title.getNameText() ).toEqual( "Quux pif" );
70 - expect( title.toString() ).toEqual( "File:Quux_pif.jpg" );
71 - title.setName( "glarg_foo_glang" );
72 - expect( title.toString() ).toEqual( "File:Glarg_foo_glang.jpg" );
73 - expect( title.getMainText() ).toEqual( "Glarg foo glang.jpg" );
74 - } );
75 -
76 - it( "should allow initialization from filename + namespace", function() {
77 - var title = new mw.Title( "catalonian_penguins.PNG" );
78 - title.setNamespace( 'file' );
79 - expect( title.toString() ).toEqual( "File:Catalonian_penguins.png" );
80 - } );
81 -
82 - it( "should allow initialization using mediawiki global namespaces", function() {
83 - var title = new mw.Title( "something.PDF" );
84 - title.setNamespace( 'file' );
85 - expect( title.toString() ).toEqual( "File:Something.pdf" );
86 -
87 - title = new mw.Title( "NeilK" );
88 - title.setNamespace( 'user_talk' );
89 - expect( title.toString() ).toEqual( "User_talk:NeilK" );
90 - expect( title.toText() ).toEqual( "User talk:NeilK" );
91 -
92 - title = new mw.Title( "Frobisher" );
93 - title.setNamespaceById( 99 );
94 - expect( title.toString() ).toEqual( "Penguins:Frobisher" );
95 -
96 - title = new mw.Title( "flightless_yet_cute.jpg" );
97 - title.setNamespace( "antarctic_waterfowl" );
98 - expect( title.toString() ).toEqual( "Penguins:Flightless_yet_cute.jpg" );
99 -
100 - title = new mw.Title( "flightless_yet_cute.jpg" );
101 - title.setPrefix( "Penguins" );
102 - expect( title.toString() ).toEqual( "Penguins:Flightless_yet_cute.jpg" );
103 -
104 - title = new mw.Title( "flightless_yet_cute.jpg" );
105 - expect( function() {
106 - title.setPrefix( "Entirely Unknown" );
107 - } ).toThrow( "unrecognized namespace prefix" );
108 - } );
109 -
110 - } );
111 -
112 - } );
113 -} )( mediaWiki );
Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -28,9 +28,15 @@
2929 'mediawiki.util',
3030 'mediawiki.libs.jpegmeta',
3131 'ext.uploadwizard.mediawiki.language.parser',
 32+ 'mediawiki.api',
 33+ 'mediawiki.api.edit',
 34+ 'mediawiki.api.category',
 35+ 'mediawiki.api.parse',
 36+ 'mediawiki.api.titleblacklist',
 37+ 'mediawiki.Title',
 38+ 'mediawiki.feedback'
3239 ),
3340 'scripts' => array(
34 -
3541 // jquery interface helpers
3642 'resources/jquery/jquery.tipsy.js',
3743 'resources/jquery/jquery.morphCrossfade.js',
@@ -48,13 +54,6 @@
4955 'resources/mw.canvas.js',
5056 'resources/mw.Log.js',
5157 'resources/mw.UtilitiesTime.js',
52 - 'resources/mw.Api.js',
53 - 'resources/mw.Api.edit.js',
54 - 'resources/mw.Api.category.js',
55 - 'resources/mw.Api.parse.js',
56 - 'resources/mw.Api.titleblacklist.js',
57 - 'resources/mw.Title.js',
58 - 'resources/mw.Feedback.js',
5958 'resources/mw.ErrorDialog.js',
6059 'resources/mw.ConfirmCloseWindow.js',
6160
Index: trunk/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js
@@ -12,6 +12,8 @@
1313 */
1414 ( function ( $j ) { $j.fn.mwCoolCats = function( options ) {
1515
 16+ var catNsId = mw.config.get( 'wgNamespaceIds' ).category;
 17+
1618 /**
1719 * Get content from our text field, and attempt to insert it as a category.
1820 * May require confirmation from user if they appear to be adding a new category.
@@ -23,7 +25,7 @@
2426 return;
2527 }
2628
27 - var title = new mw.Title( text, 'category' );
 29+ var title = new mw.Title( text, catNsId );
2830
2931 var insertIt = function() {
3032 _insertCat( title );
@@ -228,8 +230,8 @@
229231 };
230232
231233 // initialize with some categories, if so configured
232 - $j.each( settings.cats, function( i, cat ) { _insertCat( new mw.Title( cat, 'category' ) ); } );
233 - $j.each( settings.hiddenCats, function( i, cat ) { _insertCat( new mw.Title( cat, 'category' ), true ); } );
 234+ $j.each( settings.cats, function( i, cat ) { _insertCat( new mw.Title( cat, catNsId ) ); } );
 235+ $j.each( settings.hiddenCats, function( i, cat ) { _insertCat( new mw.Title( cat, catNsId ), true ); } );
234236
235237 _processInput();
236238 } );
Index: trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js
@@ -17,13 +17,14 @@
1818 var _this = this;
1919 this.upload = upload;
2020 this.api = upload.api;
 21+ var fileNsId = mw.config.get( 'wgNamespaceIds' ).file;
2122 // pass file to Firefogg after selection
2223 this.upload.ui.$fileInputCtrl.bind('change', function(event) {
2324 if(_this.upload.ui.$fileInputCtrl[0].files.length) {
2425 _this.getFogg().setInput(_this.upload.ui.$fileInputCtrl[0].files[0]);
2526 //This is required to get the right requestedTitle in UploadWizardUpload
2627 var title = _this.getTransport().getFileName().replace( /:/g, '_' );
27 - _this.upload.title = new mw.Title( title , 'file' );
 28+ _this.upload.title = new mw.Title( title, fileNsId );
2829 }
2930 });
3031 // update the "valid" extension to include firefogg transcode extensions:
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js
@@ -14,8 +14,11 @@
1515 * @param {mw.Api} api object; useful for previews
1616 */
1717
18 -( function( $j, undefined ) {
 18+( function( mw, $j, undefined ) {
1919
 20+var catNsId = mw.config.get( 'wgNamespaceIds' ).category,
 21+ templateNsId = mw.config.get( 'wgNamespaceIds' ).template;
 22+
2023 mw.UploadWizardLicenseInput = function( selector, values, config, count, api ) {
2124 var _this = this;
2225 _this.count = count;
@@ -542,11 +545,11 @@
543546 // this proceeds synchronously, so we pick up in the next line
544547 _this.api.getCategories( title, ok, err, false );
545548 }
546 -
547 - var licenseCategory = new mw.Title( mw.UploadWizard.config.licenseCategory, 'category' );
548549
 550+ var licenseCategory = new mw.Title( mw.UploadWizard.config.licenseCategory, catNsId );
 551+
549552 $.each( templates, function( i, t ) {
550 - var title = new mw.Title( t, 'template' );
 553+ var title = new mw.Title( t, templateNsId );
551554 recurseCategories( licenseCategory, title, 5 );
552555 if ( found ) {
553556 return false;
@@ -583,4 +586,4 @@
584587
585588 };
586589
587 -} )( jQuery );
 590+} )( window.mediaWiki, jQuery );
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardUpload.js
@@ -7,6 +7,8 @@
88 */
99 ( function( $j, undefined ) {
1010
 11+var fileNsId = mw.config.get( 'wgNamespaceIds' ).file;
 12+
1113 /**
1214 * Constructor for objects representing uploads. The workhorse of this entire extension.
1315 *
@@ -155,7 +157,7 @@
156158 var existsFileName = result.upload.warnings.exists;
157159 try {
158160 code = 'exists';
159 - info = new mw.Title( existsFileName, 'file' ).getUrl();
 161+ info = new mw.Title( existsFileName, fileNsId ).getUrl();
160162 } catch ( e ) {
161163 code = 'unknown';
162164 info = 'Warned about existing filename, but filename is unparseable: "' + existsFileName + "'";
@@ -226,7 +228,7 @@
227229 $j.each( duplicates, function( i, filename ) {
228230 var $a = $j( '<a/>' ).append( filename );
229231 try {
230 - var href = new mw.Title( filename, 'file' ).getUrl();
 232+ var href = new mw.Title( filename, fileNsId ).getUrl();
231233 $a.attr( { 'href': href, 'target': '_blank' } );
232234 } catch ( e ) {
233235 $a.click( function() { alert('could not parse filename=' + filename ); } );
@@ -309,7 +311,7 @@
310312 }
311313
312314 try {
313 - this.title = new mw.Title( basename.replace( /:/g, '_' ), 'file' );
 315+ this.title = new mw.Title( basename.replace( /:/g, '_' ), fileNsId );
314316 } catch ( e ) {
315317 fileNameErr( 'unparseable' );
316318 }
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
@@ -13,6 +13,8 @@
1414 */
1515 ( function( mw, $j, undefined ) {
1616
 17+var fileNsId = mw.config.get( 'wgNamespaceIds' ).file;
 18+
1719 mw.UploadWizardDetails = function( upload, api, containerDiv ) {
1820
1921 var _this = this;
@@ -469,8 +471,8 @@
470472 var titleString;
471473 var errHtml;
472474
473 - try {
474 - titleString = new mw.Title( result.title ).setNamespace( 'file' ).toString();
 475+ try {
 476+ titleString = new mw.Title( result.title, fileNsId ).toString();
475477 } catch ( e ) {
476478 // unparseable result from unique test?
477479 titleString = '[unparseable name]';
@@ -1005,9 +1007,11 @@
10061008 * @return {String} cleaned title with prefix and extension, stringified.
10071009 */
10081010 setCleanTitle: function( s ) {
 1011+ var ext = this.upload.title.getExtension();
10091012 var re = new RegExp( '\\.' + this.upload.title.getExtension() + '$', 'i' );
10101013 var cleaned = $j.trim( s.replace( re, '' ) );
1011 - return this.upload.title.setNameText( cleaned ).toString();
 1014+ this.upload.title = new mw.Title( cleaned + '.' + ext, fileNsId );
 1015+ return this.upload.title;
10121016 }
10131017
10141018 };

Status & tagging log