From 40f131c6d4226dd57cff010b5c3c1795ad989848 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 3 Dec 2008 19:30:44 +0000 Subject: [PATCH] Foreign repos (API or DB) now fetch images and/or description pages if the repo wiki has a different canonical name for the File: namespace. Added 'fileNamespace' configuration item to $wgForeignFileRepos to override the local canonical name. --- RELEASE-NOTES | 4 ++++ includes/filerepo/FileRepo.php | 18 +++++++++++++----- includes/filerepo/ForeignAPIRepo.php | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3873c1e997..73b645e087 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 6208976c93..0cbc1f1efd 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -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; + } } diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index a6773e11ec..fead30c6cb 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -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' ) ); } -- 2.20.1