(bug 13750) $wgCapitalLinks should be a per-namespace setting
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 9 Oct 2009 12:52:16 +0000 (12:52 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 9 Oct 2009 12:52:16 +0000 (12:52 +0000)
13 files changed:
RELEASE-NOTES
docs/export-0.4.xsd
includes/DefaultSettings.php
includes/Export.php
includes/Namespace.php
includes/Setup.php
includes/Title.php
includes/User.php
includes/api/ApiQuerySiteinfo.php
includes/filerepo/FileRepo.php
includes/specials/SpecialCategories.php
includes/specials/SpecialWithoutinterwiki.php
includes/upload/UploadBase.php

index d13dddf..5de904c 100644 (file)
@@ -89,6 +89,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   maintenance
 * New hook AbortNewAccountAuto, called before account creation from AuthPlugin-
   or ExtUser-driven requests.
+* $wgCapitalLinkOverrides added to configure per-namespace capitalization
 
 === New features in 1.16 ===
 
@@ -241,7 +242,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   called after a user's email has been successfully confirmed or invalidated.
 * (bug 19741) Moved the XCF files out of the main MediaWiki distribution, for 
   a smaller subversion checkout.
-
+* (bug 13750) First letter capitalization can now be a per-namespace setting
 
 === Bug fixes in 1.16 ===
 
index f40a3f2..3821b63 100644 (file)
@@ -10,8 +10,9 @@
        as a list of defined namespaces.
        
        Version 0.4 adds per-revision delete flags, log exports,
-       discussion threading data, and a per-page redirect flag.
+       discussion threading data, a per-page redirect flag, and
+       per-namespace capitalization.
+
        The canonical URL to the schema document is:
        http://www.mediawiki.org/xml/export-0.4.xsd
        
@@ -90,6 +91,7 @@
                <simpleContent>
                        <extension base="string">
                                <attribute name="key" type="integer" />
+                               <attribute name="case" type="mw:CaseType" />
                        </extension>
                </simpleContent>
        </complexType>
index b990d25..c135b37 100644 (file)
@@ -213,10 +213,10 @@ $wgImgAuthPublicTest = true; ///< defaults to true - if public read is turned on
  *    thumbScriptUrl    The URL for thumb.php (optional, not recommended)
  *    transformVia404   Whether to skip media file transformation on parse and rely on a 404
  *                      handler instead.
- *    initialCapital    Equivalent to $wgCapitalLinks, determines whether filenames implicitly
- *                      start with a capital letter. The current implementation may give incorrect
- *                      description page links when the local $wgCapitalLinks and initialCapital
- *                      are mismatched.
+ *    initialCapital    Equivalent to $wgCapitalLinks (or $wgCapitalLinkOverrides[NS_FILE], 
+ *                      determines whether filenames implicitly start with a capital letter. 
+ *                      The current implementation may give incorrect description page links 
+ *                      when the local $wgCapitalLinks and initialCapital are mismatched.
  *    pathDisclosureProtection
  *                      May be 'paranoid' to remove all parameters from error messages, 'none' to
  *                      leave the paths in unchanged, or 'simple' to replace paths with
@@ -2436,6 +2436,18 @@ $wgShowCreditsIfMax = true;
  */
 $wgCapitalLinks = true;
 
+/**
+ * @since 1.16 - This can now be set per-namespace. Some special namespaces (such
+ * as Special, see Namespace::$alwaysCapitalizedNamespaces for the full list) must be 
+ * true by default (and setting them has no effect), due to various things that 
+ * require them to be so. Also, since Talk namespaces need to directly mirror their 
+ * associated content namespaces, the values for those are ignored in favor of the 
+ * subject namespace's setting. Setting for NS_MEDIA is taken automatically from 
+ * NS_FILE.
+ * EX: $wgCapitalLinkOverrides[ NS_FILE ] = false;
+ */
+$wgCapitalLinkOverrides = array();
+
 /**
  * List of interwiki prefixes for wikis we'll accept as sources for
  * Special:Import (for sysops). Since complete page history can be imported,
@@ -3448,7 +3460,7 @@ $wgNamespaceRobotPolicies = array();
  *     'Main_Page' => 'noindex,follow',
  *     # "Project", not the actual project name!
  *     'Project:X' => 'index,follow',
- *     # Needs to be "Abc", not "abc" (unless $wgCapitalLinks is false)!
+ *     # Needs to be "Abc", not "abc" (unless $wgCapitalLinks is false for that namespace)!
  *     'abc' => 'noindex,nofollow'
  *   );
  */
index c33ff42..dd58d4b 100644 (file)
@@ -414,7 +414,11 @@ class XmlDumpWriter {
                global $wgContLang;
                $spaces = "<namespaces>\n";
                foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
-                       $spaces .= '      ' . Xml::element( 'namespace', array( 'key' => $ns ), $title ) . "\n";
+                       $spaces .= '      ' . 
+                               Xml::element( 'namespace', 
+                                       array(  'key' => $ns,
+                                                       'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
+                                       ), $title ) . "\n";
                }
                $spaces .= "    </namespaces>";
                return $spaces;
index 3d618e6..f9c2311 100644 (file)
@@ -45,6 +45,13 @@ if( is_array( $wgExtraNamespaces ) ) {
 
 class MWNamespace {
 
+       /**
+        * These namespaces should always be first-letter capitalized, now and 
+        * forevermore. Historically, they could've probably been lowercased too, 
+        * but some things are just too ingrained now. :)
+        */
+       private static $alwaysCapitalizedNamespaces = array( NS_SPECIAL, NS_MEDIAWIKI );
+
        /**
         * Can pages in the given namespace be moved?
         *
@@ -181,5 +188,30 @@ class MWNamespace {
                global $wgNamespacesWithSubpages;
                return !empty( $wgNamespacesWithSubpages[$index] );
        }
-
+       
+       /**
+        * Is the namespace first-letter capitalized?
+        * 
+        * @param $index int Index to check
+        * @return bool
+        */
+       public static function isCapitalized( $index ) {
+               global $wgCapitalLinks, $wgCapitalLinkOverrides;
+               // Turn NS_MEDIA into NS_FILE
+               $index = $index === NS_MEDIA ? NS_FILE : $index;
+               
+               // Make sure to get the subject of our namespace
+               $index = self::getSubject( $index );
+               
+               // Some namespaces are special and should always be upper case
+               if ( in_array( $index, self::$alwaysCapitalizedNamespaces ) ) {
+                       return true;
+               }
+               if ( isset( $wgCapitalLinkOverrides[ $index ] ) ) {
+                       // $wgCapitalLinkOverrides is explicitly set
+                       return $wgCapitalLinkOverrides[ $index ];
+               }
+               // Default to the global setting
+               return $wgCapitalLinks;
+       }
 }
index c736207..2f16ed4 100644 (file)
@@ -8,7 +8,6 @@
  * MEDIAWIKI is defined
  */
 if( !defined( 'MEDIAWIKI' ) ) {
-       echo "This file is part of MediaWiki, it is not a valid entry point.\n";
        exit( 1 );
 }
 
@@ -87,7 +86,6 @@ if ( !$wgLocalFileRepo ) {
                'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
                'thumbScriptUrl' => $wgThumbnailScriptPath,
                'transformVia404' => !$wgGenerateThumbnailOnParse,
-               'initialCapital' => $wgCapitalLinks,
                'deletedDir' => $wgFileStore['deleted']['directory'],
                'deletedHashLevels' => $wgFileStore['deleted']['hash']
        );
index dd6e389..134ad28 100644 (file)
@@ -2229,6 +2229,18 @@ class Title {
                
                return $rxTc;
        }
+       
+       /**
+        * Capitalize a text if it belongs to a namespace that capitalizes
+        */
+       public static function capitalize( $text, $ns = NS_MAIN ) {
+               global $wgContLang;
+               
+               if ( MWNamespace::isCapitalized( $ns ) )
+                       return $wgContLang->ucfirst( $text );
+               else
+                       return $text;
+       }
 
        /**
         * Secure and split - main initialisation function for this object
@@ -2241,7 +2253,7 @@ class Title {
         * @return \type{\bool} true on success
         */
        private function secureAndSplit() {
-               global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
+               global $wgContLang, $wgLocalInterwiki;
 
                # Initialisation
                $rxTc = self::getTitleInvalidRegex();
@@ -2403,8 +2415,8 @@ class Title {
                 * site might be case-sensitive.
                 */
                $this->mUserCaseDBKey = $dbkey;
-               if( $wgCapitalLinks && $this->mInterwiki == '') {
-                       $dbkey = $wgContLang->ucfirst( $dbkey );
+               if(  $this->mInterwiki == '') {
+                       $dbkey = self::capitalize( $dbkey, $this->mNamespace );
                }
 
                /**
index 7b9b5ae..a5a5423 100644 (file)
@@ -521,7 +521,7 @@ class User {
                || User::isIP( $name )
                || strpos( $name, '/' ) !== false
                || strlen( $name ) > $wgMaxNameChars
-               || $name != $wgContLang->ucfirst( $name ) ) {
+               || $name != Title::capitalize( $name, NS_USER ) ) {
                        wfDebugLog( 'username', __METHOD__ .
                                ": '$name' invalid due to empty, IP, slash, length, or lowercase" );
                        return false;
@@ -669,9 +669,8 @@ class User {
         *                - 'creatable'  Valid for batch processes, login and account creation
         */
        static function getCanonicalName( $name, $validate = 'valid' ) {
-               # Force usernames to capital
-               global $wgContLang;
-               $name = $wgContLang->ucfirst( $name );
+               # Maybe force usernames to capital
+               $name = Title::capitalize( $name, NS_USER );
 
                # Reject names containing '#'; these will be cleaned up
                # with title normalisation, but then it's too late to
index 8b84b70..8439e47 100644 (file)
@@ -164,7 +164,8 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                foreach( $wgContLang->getFormattedNamespaces() as $ns => $title )
                {
                        $data[$ns] = array(
-                               'id' => intval($ns)
+                               'id' => intval($ns),
+                               'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
                        );
                        ApiResult :: setContent( $data[$ns], $title );
                        $canonical = MWNamespace::getCanonicalName( $ns );
index 64a7bfd..24cdfa2 100644 (file)
@@ -28,7 +28,7 @@ abstract class FileRepo {
                $this->name = $info['name'];
 
                // Optional settings
-               $this->initialCapital = true; // by default
+               $this->initialCapital = MWNamespace::isCapitalized( NS_FILE );
                foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
                        'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', 
                        'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl' ) as $var )
@@ -256,7 +256,7 @@ abstract class FileRepo {
         */
        function getNameFromTitle( $title ) {
                global $wgCapitalLinks;
-               if ( $this->initialCapital != $wgCapitalLinks ) {
+               if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) {
                        global $wgContLang;
                        $name = $title->getUserCaseDBKey();
                        if ( $this->initialCapital ) {
index d2d03eb..a649eaf 100644 (file)
@@ -36,10 +36,7 @@ class CategoryPager extends AlphabeticPager {
                parent::__construct();
                $from = str_replace( ' ', '_', $from );
                if( $from !== '' ) {
-                       global $wgCapitalLinks, $wgContLang;
-                       if( $wgCapitalLinks ) {
-                               $from = $wgContLang->ucfirst( $from );
-                       }
+                       $from = Title::capitalize( $from, NS_CATEGORY );
                        $this->mOffset = $from;
                }
        }
index 2092e43..740b434 100644 (file)
@@ -75,13 +75,10 @@ class WithoutInterwikiPage extends PageQueryPage {
 }
 
 function wfSpecialWithoutinterwiki() {
-       global $wgRequest, $wgContLang, $wgCapitalLinks;
+       global $wgRequest, $wgContLang;
        list( $limit, $offset ) = wfCheckLimits();
-       if( $wgCapitalLinks ) {
-               $prefix = $wgContLang->ucfirst( $wgRequest->getVal( 'prefix' ) );
-       } else {
-               $prefix = $wgRequest->getVal( 'prefix' );
-       }
+       // Only searching the mainspace anyway
+       $prefix = Title::capitalize( $wgRequest->getVal( 'prefix' ), NS_MAIN );
        $wip = new WithoutInterwikiPage();
        $wip->setPrefix( $prefix );
        $wip->doQuery( $offset, $limit );
index 700338f..8d8de4e 100644 (file)
@@ -305,10 +305,7 @@ abstract class UploadBase {
                 * but ignore things like ucfirst() and spaces/underscore things
                 */
                $comparableName = str_replace( ' ', '_', $this->mDesiredDestName );
-               global $wgCapitalLinks, $wgContLang;
-               if ( $wgCapitalLinks ) {
-                       $comparableName = $wgContLang->ucfirst( $comparableName );
-               }
+               $comparableName = Title::capitalize( $comparableName, NS_FILE );
                if( $this->mDesiredDestName != $filename && $comparableName != $filename )
                        $warnings['badfilename'] = $filename;