From 649e2635259364d04328390274f6fbce30001bdd Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Fri, 2 Jul 2010 18:37:06 +0000 Subject: [PATCH] * Added scriptExtension setting to $wgForeignFileRepos * Added FileRepo::makeUrl() to remove code duplication * Made ForeignApiRepo use scriptDirUrl if apiBase not set * Factored out 'timestamp|user|comment|url|size|sha1|metadata|mime' to ForeignApiFile::getProps() * Killed some @ error suppression --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 4 +++- includes/filerepo/FileRepo.php | 26 ++++++++++++++++++++------ includes/filerepo/ForeignAPIFile.php | 27 ++++++++++++++++++++------- includes/filerepo/ForeignAPIRepo.php | 26 ++++++++++++++++---------- 5 files changed, 61 insertions(+), 24 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 9c987cecc4..70ca062076 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -98,6 +98,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Stop emitting named entities, so we can use while still being well-formed XML * texvc now supports \bcancel and \xcancel in addition to \cancel and \cancelto +* Added scriptExtension setting to $wgForeignFileRepos +* ForeignApiRepo uses scriptDirUrl if apiBase not set === Bug fixes in 1.17 === * (bug 17560) Half-broken deletion moved image files to deletion archive diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a506f8b662..3b5cff2be9 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -344,7 +344,9 @@ $wgImgAuthPublicTest = true; * for local repositories: * - descBaseUrl URL of image description pages, e.g. http://en.wikipedia.org/wiki/Image: * - scriptDirUrl URL of the MediaWiki installation, equivalent to $wgScriptPath, e.g. - * http://en.wikipedia.org/w + * http://en.wikipedia.org/w + * - scriptExtension Script extension of the MediaWiki installation, equivalent to + * $wgScriptExtension, e.g. .php5 defaults to .php * * - articleUrl Equivalent to $wgArticlePath, e.g. http://en.wikipedia.org/wiki/$1 * - fetchDescription Fetch the text of the remote file description page. Equivalent to diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index c97423c80b..e5ea48df55 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -12,7 +12,8 @@ abstract class FileRepo { const OVERWRITE_SAME = 4; var $thumbScriptUrl, $transformVia404; - var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription, $initialCapital; + var $descBaseUrl, $scriptDirUrl, $scriptExtension, $articleUrl; + var $fetchDescription, $initialCapital; var $pathDisclosureProtection = 'paranoid'; var $descriptionCacheExpiry, $hashLevels, $url, $thumbUrl; @@ -31,7 +32,8 @@ abstract class FileRepo { $this->initialCapital = MWNamespace::isCapitalized( NS_FILE ); foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', - 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl' ) as $var ) + 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl', 'scriptExtension' ) + as $var ) { if ( isset( $info[$var] ) ) { $this->$var = $info[$var]; @@ -296,6 +298,18 @@ abstract class FileRepo { function getName() { return $this->name; } + + /** + * Make an url to this repo + * + * @param $query mixed Query string to append + * @param $entry string Entry point; defaults to index + * @return string + */ + function makeUrl( $query = '', $entry = 'index' ) { + $ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php'; + return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}?", $query ); + } /** * Get the URL of an image description page. May return false if it is @@ -326,8 +340,7 @@ abstract class FileRepo { # We use "Image:" as the canonical namespace for # compatibility across all MediaWiki versions, # and just sort of hope index.php is right. ;) - return $this->scriptDirUrl . - "/index.php?title=Image:$encName"; + return $this->makeUrl( "title=Image:$encName" ); } return false; } @@ -346,9 +359,10 @@ abstract class FileRepo { $query .= '&uselang=' . $lang; } if ( isset( $this->scriptDirUrl ) ) { - return $this->scriptDirUrl . '/index.php?title=' . + return $this->makeUrl( + 'title=' . wfUrlencode( 'Image:' . $name ) . - "&$query"; + "&$query" ); } else { $descUrl = $this->getDescriptionUrl( $name ); if ( $descUrl ) { diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php index 9987537725..c00fcd8ee5 100644 --- a/includes/filerepo/ForeignAPIFile.php +++ b/includes/filerepo/ForeignAPIFile.php @@ -19,7 +19,7 @@ class ForeignAPIFile extends File { static function newFromTitle( $title, $repo ) { $data = $repo->fetchImageQuery( array( 'titles' => 'File:' . $title->getText(), - 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime', + 'iiprop' => self::getProps(), 'prop' => 'imageinfo' ) ); $info = $repo->getImageInfo( $data ); @@ -38,6 +38,13 @@ class ForeignAPIFile extends File { } } + /** + * Get the property string for iiprop and aiprop + */ + static function getProps() { + return 'timestamp|user|comment|url|size|sha1|metadata|mime'; + } + // Dummy functions... public function exists() { return $this->mExists; @@ -87,27 +94,33 @@ class ForeignAPIFile extends File { } public function getSize() { - return intval( @$this->mInfo['size'] ); + return isset( $this->mInfo['size'] ) ? intval( $this->mInfo['size'] ) : null; } public function getUrl() { - return strval( @$this->mInfo['url'] ); + return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null; } public function getUser( $method='text' ) { - return strval( @$this->mInfo['user'] ); + return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null; } public function getDescription() { - return strval( @$this->mInfo['comment'] ); + return isset( $this->mInfo['comment'] ) ? strval( $this->mInfo['comment'] ) : null; } function getSha1() { - return wfBaseConvert( strval( @$this->mInfo['sha1'] ), 16, 36, 31 ); + return isset( $this->mInfo['sha1'] ) ? + wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 ) : + null; } function getTimestamp() { - return wfTimestamp( TS_MW, strval( @$this->mInfo['timestamp'] ) ); + return wfTimestamp( TS_MW, + isset( $this->mInfo['timestamp'] ) ? + strval( $this->mInfo['timestamp'] ) : + null + ); } function getMimeType() { diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 00020ff03f..2c74ac2879 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -25,7 +25,10 @@ class ForeignAPIRepo extends FileRepo { function __construct( $info ) { parent::__construct( $info ); - $this->mApiBase = $info['apibase']; // http://commons.wikimedia.org/w/api.php + + // http://commons.wikimedia.org/w/api.php + $this->mApiBase = isset( $info['apibase'] ) ? $info['apibase'] : null; + if( isset( $info['apiThumbCacheExpiry'] ) ) { $this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry']; } @@ -106,14 +109,17 @@ class ForeignAPIRepo extends FileRepo { function fetchImageQuery( $query ) { global $wgMemc; - $url = $this->mApiBase . - '?' . - wfArrayToCgi( - array_merge( $query, - array( - 'format' => 'json', - 'action' => 'query', - 'redirects' => 'true' ) ) ); + $query = array_merge( $query, + array( + 'format' => 'json', + 'action' => 'query', + 'redirects' => 'true' + ) ); + if ( $this->mApiBase ) { + $url = wfAppendQuery( $this->mApiBase, $query ); + } else { + $url = $this->makeUrl( $query, 'api' ); + } if( !isset( $this->mQueryCache[$url] ) ) { $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) ); @@ -149,7 +155,7 @@ class ForeignAPIRepo extends FileRepo { function findBySha1( $hash ) { $results = $this->fetchImageQuery( array( 'aisha1base36' => $hash, - 'aiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime', + 'aiprop' => ForeignAPIFile::getProps(), 'list' => 'allimages', ) ); $ret = array(); if ( isset( $results['query']['allimages'] ) ) { -- 2.20.1