From 8f2c463b25faf162d51bc9d6f8edcd4865f4db0f Mon Sep 17 00:00:00 2001 From: Krinkle Date: Thu, 16 Jun 2011 21:16:50 +0000 Subject: [PATCH] Implement mw.Title in core * Based on UploadWizard/resources/mw.Title.js * Refactored to use local scope and prototypes instead of per-instance private scope (less references, faster instantiation) * Fix potential ReferenceError in the check for wgArticlePath (inline if statements will fail to evaluate for undeclared variables). Using mw.config instead * The following were not ported because they are or were already redundant and/or merged with another method: -- setNameText (redundant with the improved setName) -- setPrefix (redundant wit the improved setNamespace) * Ported all jasmine tests to QUnit. Left them exactly the same to make sure it's compatible with UploadWizard. Perhaps I'll expand or adjust the suite later to be less file-specific, but for now make sure it's compatible and the same. @todo FIXME * Removed assumption that every title has a namespace prefix in it by creating a separate RegExp when there is a namespace given ** Fixes strip-bug in cases where a namespace appears to be part of a title when the namespace is also given: "Project:User:Foobar" new mw.Title( 'User:Foobar', 4 ).toString() > 'Project:Foobar' ** Fixes a thrown exception in case a colon is part of the title (colons are valid in MediaWiki pagenames!) new mw.Title( 'Just some:Random page') > Error: mw.Title> Unrecognized canonical namespace: just_some * Added check for capitalLinks et (wasn't possible before due to bug X) ** Prevents breakages on wiktionary and other wikis with case sensitivity. --- .../resourceloader/ResourceLoaderStartUpModule.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 90963b1bfe..8ce592e01c 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -55,14 +55,21 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { ); $mainPage = Title::newMainPage(); - // Build wgNamespaceIds - // A complete key-value pair object mapping localized, canonical and aliases for namespaces - // to their numerical ids (case insensitive and with underscores) + /** + * Namespace related preparation + * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. + * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. + */ $namespaceIds = $wgContLang->getNamespaceIds(); + $caseSensitiveNamespaces = array(); foreach( MWNamespace::getCanonicalNamespaces() as $index => $name ) { $namespaceIds[$wgContLang->lc( $name )] = $index; + if ( !MWNamespace::isCapitalized( $index ) ) { + $caseSensitiveNamespaces[] = $index; + } } + $serverBits = wfParseUrl( $wgServer ); $protocol = $serverBits ? $serverBits['scheme'] : 'http'; @@ -106,6 +113,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgLegacyJavaScriptGlobals' => $wgLegacyJavaScriptGlobals, + 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, ); if ( $wgUseAjax && $wgEnableMWSuggest ) { $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate(); -- 2.20.1