Foreign repos (API or DB) now fetch images and/or description pages if the repo wiki...
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 3 Dec 2008 19:30:44 +0000 (19:30 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 3 Dec 2008 19:30:44 +0000 (19:30 +0000)
RELEASE-NOTES
includes/filerepo/FileRepo.php
includes/filerepo/ForeignAPIRepo.php

index 3873c1e..73b645e 100644 (file)
@@ -388,6 +388,10 @@ The following extensions are migrated into MediaWiki 1.14:
 * (bug 16026) 'Revision-info' and 'revision-info-current' both accept wiki 
   markup now.
 * (bug 16529) Fix for search suggestions with some third-party JS libraries
+* Foreign repositories (API or DB) would fail to fetch images and/or description
+  pages if the repo wiki had a different canonical name for the File: namespace.
+  Added 'fileNamespace' configuration item to $wgForeignFileRepos to override
+  the local canonical name 'File' with another string.
 
 
 === API changes in 1.14 ===
index 6208976..0cbc1f1 100644 (file)
@@ -15,7 +15,7 @@ abstract class FileRepo {
        var $thumbScriptUrl, $transformVia404;
        var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription, $initialCapital;
        var $pathDisclosureProtection = 'paranoid';
-       var $descriptionCacheExpiry, $apiThumbCacheExpiry, $hashLevels;
+       var $descriptionCacheExpiry, $apiThumbCacheExpiry, $hashLevels, $fileNamespace;
 
        /**
         * Factory functions for creating new files
@@ -30,9 +30,10 @@ abstract class FileRepo {
 
                // Optional settings
                $this->initialCapital = true; // by default
+               $this->fileNamespace  = MWNamespace::getCanonicalName( NS_FILE ); // fallback to 'File'
                foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
                        'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', 
-                       'descriptionCacheExpiry', 'apiThumbCacheExpiry', 'hashLevels' ) as $var )
+                       'descriptionCacheExpiry', 'apiThumbCacheExpiry', 'hashLevels', 'fileNamespace' ) as $var )
                {
                        if ( isset( $info[$var] ) ) {
                                $this->$var = $info[$var];
@@ -262,10 +263,10 @@ abstract class FileRepo {
                if ( is_null( $this->descBaseUrl ) ) {
                        if ( !is_null( $this->articleUrl ) ) {
                                $this->descBaseUrl = str_replace( '$1',
-                                       wfUrlencode( MWNamespace::getCanonicalName( NS_FILE ) ) . ':', $this->articleUrl );
+                                       wfUrlencode( $this->getFileNamespace() ) . ':', $this->articleUrl );
                        } elseif ( !is_null( $this->scriptDirUrl ) ) {
                                $this->descBaseUrl = $this->scriptDirUrl . '/index.php?title=' .
-                                       wfUrlencode( MWNamespace::getCanonicalName( NS_FILE ) ) . ':';
+                                       wfUrlencode( $this->getFileNamespace() ) . ':';
                        } else {
                                $this->descBaseUrl = false;
                        }
@@ -300,7 +301,7 @@ abstract class FileRepo {
        function getDescriptionRenderUrl( $name ) {
                if ( isset( $this->scriptDirUrl ) ) {
                        return $this->scriptDirUrl . '/index.php?title=' .
-                               wfUrlencode( MWNamespace::getCanonicalName( NS_FILE ) . ':' . $name ) .
+                               wfUrlencode( $this->getFileNamespace() . ':' . $name ) .
                                '&action=render';
                } else {
                        $descBase = $this->getDescBaseUrl();
@@ -534,4 +535,11 @@ abstract class FileRepo {
        function findBySha1( $hash ) {
                return array();
        }
+       /**
+        * Returns the file namespace string
+        * @return strig
+        */
+       function getFileNamespace() {
+               return $this->fileNamespace;
+       }
 }
index a6773e1..fead30c 100644 (file)
@@ -94,7 +94,7 @@ class ForeignAPIRepo extends FileRepo {
        
        function getImageInfo( $title, $time = false ) {
                return $this->queryImage( array(
-                       'titles' => 'Image:' . $title->getText(),
+                       'titles' => $this->getFileNamespace() . ':' . $title->getText(),
                        'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime' ) );
        }