From 52ddf77a9c0dff3f306ae3b26bb3f0e4186044ad Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 3 Jun 2007 10:44:27 +0000 Subject: [PATCH] Partial implementation of $wgCapitalLinks differences between local wiki and file repository. Description pages don't work when $wgCapitalLinks=true and initialCapital=false, but it should work well enough in the converse situation. --- includes/DefaultSettings.php | 4 ++++ includes/Title.php | 8 +++++++ includes/filerepo/FSRepo.php | 26 +++++++++++++++++---- includes/filerepo/File.php | 2 +- includes/filerepo/UnregisteredLocalFile.php | 2 +- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e29e53ff51..79cfd630f1 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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: diff --git a/includes/Title.php b/includes/Title.php index 4a5f35b5bd..8a21ab3954 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ); } diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php index af5aa63558..2c14e1bc22 100644 --- a/includes/filerepo/FSRepo.php +++ b/includes/filerepo/FSRepo.php @@ -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; + } } ?> diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 84de8e9935..35eeac93fe 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -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; } diff --git a/includes/filerepo/UnregisteredLocalFile.php b/includes/filerepo/UnregisteredLocalFile.php index 15dcf00c95..72fdc80d29 100644 --- a/includes/filerepo/UnregisteredLocalFile.php +++ b/includes/filerepo/UnregisteredLocalFile.php @@ -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 ); -- 2.20.1