From b8aebef25bb161cc0746b9589b63cbf6b56601a2 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 6 Apr 2008 10:18:47 +0000 Subject: [PATCH] * File redirects are slow: 2 queries per image per repository on parse. We previously found one query per image on parse to be prohibitively slow, that's why we introduced the image cache. Thus, reintroduced $wgFileRedirects. * Fixed bug due to checkRedirect() not accepting a string title like findFile() * Use protected instead of private. Private should not be used ever. --- includes/DefaultSettings.php | 5 +++++ includes/filerepo/FileRepo.php | 11 +++++++++-- includes/filerepo/LocalRepo.php | 7 ++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 563ece8626..06bb151da0 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -461,6 +461,11 @@ $wgHashedSharedUploadDirectory = true; */ $wgRepositoryBaseUrl = "http://commons.wikimedia.org/wiki/Image:"; +/** + * File redirects + * If enabled, MediaWiki checks redirects in Image: namespace. + */ +$wgFileRedirects = false; # # Email settings diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index dc0d0a8040..a5ef5e5d25 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -46,7 +46,7 @@ abstract class FileRepo { /** * Create a new File object from the local repository * @param mixed $title Title object or string - * @param mixed $time Time at which the image is supposed to have existed. + * @param mixed $time Time at which the image was uploaded. * If this is specified, the returned object will be an * instance of the repository's old file class instead of * a current file. Repositories not supporting version @@ -72,12 +72,19 @@ abstract class FileRepo { /** * Find an instance of the named file created at the specified time - * Returns false if the file did not exist. Repositories not supporting + * Returns false if the file does not exist. Repositories not supporting * version control should return false if the time is specified. * + * @param mixed $title Title object or string * @param mixed $time 14-character timestamp, or false for the current version */ function findFile( $title, $time = false, $flags = 0 ) { + if ( !($title instanceof Title) ) { + $title = Title::makeTitleSafe( NS_IMAGE, $title ); + if ( !is_object( $title ) ) { + return false; + } + } # First try the current version of the file to see if it precedes the timestamp $img = $this->newFile( $title ); if ( !$img ) { diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 6001d936e2..b2ef327d7d 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -74,7 +74,7 @@ class LocalRepo extends FSRepo { * Function link Title::getArticleID(). * We can't say Title object, what database it should use, so we duplicate that function here. */ - private function getArticleID( $title ) { + protected function getArticleID( $title ) { if( !$title instanceof Title ) { return 0; } @@ -92,6 +92,11 @@ class LocalRepo extends FSRepo { } function checkRedirect( $title ) { + global $wgFileRedirects; + if( !$wgFileRedirects ) { + return false; + } + if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) { $title = Title::makeTitle( NS_IMAGE, $title->getText() ); } -- 2.20.1