r68897 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68896‎ | r68897 | r68898 >
Date:18:37, 2 July 2010
Author:btongminh
Status:ok
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/ForeignAPIFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/ForeignAPIRepo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -12,7 +12,8 @@
1313 const OVERWRITE_SAME = 4;
1414
1515 var $thumbScriptUrl, $transformVia404;
16 - var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription, $initialCapital;
 16+ var $descBaseUrl, $scriptDirUrl, $scriptExtension, $articleUrl;
 17+ var $fetchDescription, $initialCapital;
1718 var $pathDisclosureProtection = 'paranoid';
1819 var $descriptionCacheExpiry, $hashLevels, $url, $thumbUrl;
1920
@@ -31,7 +32,8 @@
3233 $this->initialCapital = MWNamespace::isCapitalized( NS_FILE );
3334 foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
3435 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection',
35 - 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl' ) as $var )
 36+ 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl', 'scriptExtension' )
 37+ as $var )
3638 {
3739 if ( isset( $info[$var] ) ) {
3840 $this->$var = $info[$var];
@@ -296,6 +298,18 @@
297299 function getName() {
298300 return $this->name;
299301 }
 302+
 303+ /**
 304+ * Make an url to this repo
 305+ *
 306+ * @param $query mixed Query string to append
 307+ * @param $entry string Entry point; defaults to index
 308+ * @return string
 309+ */
 310+ function makeUrl( $query = '', $entry = 'index' ) {
 311+ $ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php';
 312+ return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}?", $query );
 313+ }
300314
301315 /**
302316 * Get the URL of an image description page. May return false if it is
@@ -326,8 +340,7 @@
327341 # We use "Image:" as the canonical namespace for
328342 # compatibility across all MediaWiki versions,
329343 # and just sort of hope index.php is right. ;)
330 - return $this->scriptDirUrl .
331 - "/index.php?title=Image:$encName";
 344+ return $this->makeUrl( "title=Image:$encName" );
332345 }
333346 return false;
334347 }
@@ -346,9 +359,10 @@
347360 $query .= '&uselang=' . $lang;
348361 }
349362 if ( isset( $this->scriptDirUrl ) ) {
350 - return $this->scriptDirUrl . '/index.php?title=' .
 363+ return $this->makeUrl(
 364+ 'title=' .
351365 wfUrlencode( 'Image:' . $name ) .
352 - "&$query";
 366+ "&$query" );
353367 } else {
354368 $descUrl = $this->getDescriptionUrl( $name );
355369 if ( $descUrl ) {
Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php
@@ -25,7 +25,10 @@
2626
2727 function __construct( $info ) {
2828 parent::__construct( $info );
29 - $this->mApiBase = $info['apibase']; // http://commons.wikimedia.org/w/api.php
 29+
 30+ // http://commons.wikimedia.org/w/api.php
 31+ $this->mApiBase = isset( $info['apibase'] ) ? $info['apibase'] : null;
 32+
3033 if( isset( $info['apiThumbCacheExpiry'] ) ) {
3134 $this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry'];
3235 }
@@ -106,14 +109,17 @@
107110 function fetchImageQuery( $query ) {
108111 global $wgMemc;
109112
110 - $url = $this->mApiBase .
111 - '?' .
112 - wfArrayToCgi(
113 - array_merge( $query,
114 - array(
115 - 'format' => 'json',
116 - 'action' => 'query',
117 - 'redirects' => 'true' ) ) );
 113+ $query = array_merge( $query,
 114+ array(
 115+ 'format' => 'json',
 116+ 'action' => 'query',
 117+ 'redirects' => 'true'
 118+ ) );
 119+ if ( $this->mApiBase ) {
 120+ $url = wfAppendQuery( $this->mApiBase, $query );
 121+ } else {
 122+ $url = $this->makeUrl( $query, 'api' );
 123+ }
118124
119125 if( !isset( $this->mQueryCache[$url] ) ) {
120126 $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) );
@@ -149,7 +155,7 @@
150156 function findBySha1( $hash ) {
151157 $results = $this->fetchImageQuery( array(
152158 'aisha1base36' => $hash,
153 - 'aiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime',
 159+ 'aiprop' => ForeignAPIFile::getProps(),
154160 'list' => 'allimages', ) );
155161 $ret = array();
156162 if ( isset( $results['query']['allimages'] ) ) {
Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php
@@ -19,7 +19,7 @@
2020 static function newFromTitle( $title, $repo ) {
2121 $data = $repo->fetchImageQuery( array(
2222 'titles' => 'File:' . $title->getText(),
23 - 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime',
 23+ 'iiprop' => self::getProps(),
2424 'prop' => 'imageinfo' ) );
2525
2626 $info = $repo->getImageInfo( $data );
@@ -38,6 +38,13 @@
3939 }
4040 }
4141
 42+ /**
 43+ * Get the property string for iiprop and aiprop
 44+ */
 45+ static function getProps() {
 46+ return 'timestamp|user|comment|url|size|sha1|metadata|mime';
 47+ }
 48+
4249 // Dummy functions...
4350 public function exists() {
4451 return $this->mExists;
@@ -87,27 +94,33 @@
8895 }
8996
9097 public function getSize() {
91 - return intval( @$this->mInfo['size'] );
 98+ return isset( $this->mInfo['size'] ) ? intval( $this->mInfo['size'] ) : null;
9299 }
93100
94101 public function getUrl() {
95 - return strval( @$this->mInfo['url'] );
 102+ return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null;
96103 }
97104
98105 public function getUser( $method='text' ) {
99 - return strval( @$this->mInfo['user'] );
 106+ return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null;
100107 }
101108
102109 public function getDescription() {
103 - return strval( @$this->mInfo['comment'] );
 110+ return isset( $this->mInfo['comment'] ) ? strval( $this->mInfo['comment'] ) : null;
104111 }
105112
106113 function getSha1() {
107 - return wfBaseConvert( strval( @$this->mInfo['sha1'] ), 16, 36, 31 );
 114+ return isset( $this->mInfo['sha1'] ) ?
 115+ wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 ) :
 116+ null;
108117 }
109118
110119 function getTimestamp() {
111 - return wfTimestamp( TS_MW, strval( @$this->mInfo['timestamp'] ) );
 120+ return wfTimestamp( TS_MW,
 121+ isset( $this->mInfo['timestamp'] ) ?
 122+ strval( $this->mInfo['timestamp'] ) :
 123+ null
 124+ );
112125 }
113126
114127 function getMimeType() {
Index: trunk/phase3/includes/DefaultSettings.php
@@ -344,7 +344,9 @@
345345 * for local repositories:
346346 * - descBaseUrl URL of image description pages, e.g. http://en.wikipedia.org/wiki/Image:
347347 * - scriptDirUrl URL of the MediaWiki installation, equivalent to $wgScriptPath, e.g.
348 - * http://en.wikipedia.org/w
 348+ * http://en.wikipedia.org/w
 349+ * - scriptExtension Script extension of the MediaWiki installation, equivalent to
 350+ * $wgScriptExtension, e.g. .php5 defaults to .php
349351 *
350352 * - articleUrl Equivalent to $wgArticlePath, e.g. http://en.wikipedia.org/wiki/$1
351353 * - fetchDescription Fetch the text of the remote file description page. Equivalent to
Index: trunk/phase3/RELEASE-NOTES
@@ -98,6 +98,8 @@
9999 * Stop emitting named entities, so we can use <!DOCTYPE html> while still being
100100 well-formed XML
101101 * texvc now supports \bcancel and \xcancel in addition to \cancel and \cancelto
 102+* Added scriptExtension setting to $wgForeignFileRepos
 103+* ForeignApiRepo uses scriptDirUrl if apiBase not set
102104
103105 === Bug fixes in 1.17 ===
104106 * (bug 17560) Half-broken deletion moved image files to deletion archive

Follow-up revisions

RevisionCommit summaryAuthorDate
r70642Fix for r68897: correct use of wfAppendQuery()ialex19:10, 7 August 2010

Status & tagging log