* File redirects are slow: 2 queries per image per repository on parse. We previously...
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 6 Apr 2008 10:18:47 +0000 (10:18 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 6 Apr 2008 10:18:47 +0000 (10:18 +0000)
* 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
includes/filerepo/FileRepo.php
includes/filerepo/LocalRepo.php

index 563ece8..06bb151 100644 (file)
@@ -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
index dc0d0a8..a5ef5e5 100644 (file)
@@ -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 ) {
index 6001d93..b2ef327 100644 (file)
@@ -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() );
                }