r93068 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93067‎ | r93068 | r93069 >
Date:17:12, 25 July 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
make mw.Title.js understand standard MW namespaces, even if translated
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.Title.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.Title.js
@@ -26,9 +26,9 @@
2727 *
2828 * n.b. this class does not handle URI-escaping
2929 *
30 - * n.b. this class relies on the existence of two globals:
 30+ * n.b. this class relies on the existence of the globals:
3131 * wgFormattedNamespaces - array of id numbers (as strings) to localized namespace names
32 - * wgNamespaceIds - abstract namespace names to integer ids
 32+ * wgArticlePath
3333 */
3434
3535 /**
@@ -68,7 +68,7 @@
6969 }
7070
7171 function text( s ) {
72 - if ( s != null ) {
 72+ if ( typeof s === 'string' ) {
7373 return s.replace( /_/g, ' ' );
7474 } else {
7575 return '';
@@ -153,10 +153,10 @@
154154 * @return {mw.Title} this
155155 */
156156 this.setNamespace = function( s ) {
157 - if ( !mw.isDefined( wgNamespaceIds[ s ] ) ) {
 157+ if ( !mw.isDefined( mw.Title.ns[s] ) ) {
158158 throw new Error( 'unrecognized namespace: ' + s );
159159 }
160 - return this.setNamespaceById( wgNamespaceIds[ s ] );
 160+ return this.setNamespaceById( mw.Title.ns[s] );
161161 };
162162
163163 /**
@@ -225,5 +225,25 @@
226226 }
227227
228228 };
 229+
 230+ // This is similar to the NS_* constants in MediaWiki.
 231+ mw.Title.ns = {
 232+ 'main': 0,
 233+ 'talk': 1,
 234+ 'user': 2,
 235+ 'user_talk': 3,
 236+ 'project': 4,
 237+ 'project_talk': 5,
 238+ 'file': 6,
 239+ 'file_talk': 7,
 240+ 'mediawiki': 8,
 241+ 'mediawiki_talk': 9,
 242+ 'template': 10,
 243+ 'template_talk': 11,
 244+ 'help': 12,
 245+ 'help_talk': 13,
 246+ 'category': 14,
 247+ 'category_talk': 15
 248+ };
229249 } )( jQuery, mediaWiki );
230250

Comments

#Comment by NeilK (talk | contribs)   14:57, 22 August 2011

This is now redundant, given Krinkle's changes to the main mw.Title.js -- we now get similar data from a global. but I haven't switched UploadWizard over to use that yet nor tested it.

Status & tagging log