Partial implementation of $wgCapitalLinks differences between local wiki and file...
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 3 Jun 2007 10:44:27 +0000 (10:44 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 3 Jun 2007 10:44:27 +0000 (10:44 +0000)
includes/DefaultSettings.php
includes/Title.php
includes/filerepo/FSRepo.php
includes/filerepo/File.php
includes/filerepo/UnregisteredLocalFile.php

index e29e53f..79cfd63 100644 (file)
@@ -203,6 +203,10 @@ $wgFileStore['deleted']['hash'] = 3;         // 3-level subdirectory split
  *    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.
  *
  * These settings describe a foreign MediaWiki installation. They are optional, and will be ignored
  * for local repositories:
index 4a5f35b..8a21ab3 100644 (file)
@@ -47,6 +47,7 @@ class Title {
        var $mTextform;                 # Text form (spaces not underscores) of the main part
        var $mUrlform;                  # URL-encoded form of the main part
        var $mDbkeyform;                # Main part with underscores
+       var $mUserCaseDBKey;        # DB key with the initial letter in the case specified by the user
        var $mNamespace;                # Namespace index, i.e. one of the NS_xxxx constants
        var $mInterwiki;                # Interwiki prefix (or null string)
        var $mFragment;                 # Title fragment (i.e. the bit after the #)
@@ -555,6 +556,12 @@ class Title {
                }
                return $wgContLang->getNsText( $this->mNamespace );
        }
+       /**
+        * Get the DB key with the initial letter case as specified by the user
+        */
+       function getUserCaseDBKey() {
+               return $this->mUserCaseDBKey;
+       }
        /**
         * Get the namespace text of the subject (rather than talk) page
         * @return string
@@ -1749,6 +1756,7 @@ class Title {
                 * Don't force it for interwikis, since the other
                 * site might be case-sensitive.
                 */
+               $this->mUserCaseDBKey = $dbkey;
                if( $wgCapitalLinks && $this->mInterwiki == '') {
                        $dbkey = $wgContLang->ucfirst( $dbkey );
                }
index af5aa63..2c14e1b 100644 (file)
@@ -11,7 +11,7 @@ class FSRepo {
        const DELETE_SOURCE = 1;
 
        var $directory, $url, $hashLevels, $thumbScriptUrl, $transformVia404;
-       var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription;
+       var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription, $initialCapital;
        var $fileFactory = array( 'UnregisteredLocalFile', 'newFromTitle' );
        var $oldFileFactory = false;
 
@@ -24,8 +24,9 @@ class FSRepo {
                $this->transformVia404 = !empty( $info['transformVia404'] );
 
                // Optional settings
+               $this->initialCapital = true; // by default
                foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', 
-                       'thumbScriptUrl' ) as $var ) 
+                       'thumbScriptUrl', 'initialCapital' ) as $var ) 
                {
                        if ( isset( $info[$var] ) ) {
                                $this->$var = $info[$var];
@@ -298,7 +299,7 @@ class FSRepo {
        
        /**
         * Get a relative path including trailing slash, e.g. f/fa/
-        * If the repo is not hashed, returns an empty string
+        * If the repo is not hashed, returns a slash
         */
        function getHashPath( $name ) {
                if ( $this->isHashed() ) {
@@ -309,7 +310,7 @@ class FSRepo {
                        }
                        return $path;
                } else {
-                       return '';
+                       return '/';
                }
        }
 
@@ -407,6 +408,23 @@ class FSRepo {
        function enumFiles( $callback ) {
                $this->enumFilesInFS( $callback );
        }
+
+       /**
+        * Get the name of an image from its title object
+        */
+       function getNameFromTitle( $title ) {
+               global $wgCapitalLinks;
+               if ( $this->initialCapital != $wgCapitalLinks ) {
+                       global $wgContLang;
+                       $name = $title->getUserCaseDBKey();
+                       if ( $this->initialCapital ) {
+                               $name = $wgContLang->ucfirst( $name );
+                       }
+               } else {
+                       $name = $title->getDBkey();
+               }
+               return $name;
+       }
 }
 
 ?>
index 84de8e9..35eeac9 100644 (file)
@@ -119,7 +119,7 @@ class File {
         */
        function getName() {
                if ( !isset( $this->name ) ) {
-                       $this->name = $this->title->getDBkey();
+                       $this->name = $this->repo->getNameFromTitle( $this->title );
                }
                return $this->name; 
        }
index 15dcf00..72fdc80 100644 (file)
@@ -27,7 +27,7 @@ class UnregisteredLocalFile extends File {
                }
                if ( $title ) {
                        $this->title = $title;
-                       $this->name = $title->getDBkey();
+                       $this->name = $repo->getNameFromTitle( $title );
                } else {
                        $this->name = basename( $path );
                        $this->title = Title::makeTitleSafe( NS_IMAGE, $this->name );