Index: trunk/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -12,7 +12,8 @@ |
13 | 13 | const OVERWRITE_SAME = 4; |
14 | 14 | |
15 | 15 | var $thumbScriptUrl, $transformVia404; |
16 | | - var $descBaseUrl, $scriptDirUrl, $articleUrl, $fetchDescription, $initialCapital; |
| 16 | + var $descBaseUrl, $scriptDirUrl, $scriptExtension, $articleUrl; |
| 17 | + var $fetchDescription, $initialCapital; |
17 | 18 | var $pathDisclosureProtection = 'paranoid'; |
18 | 19 | var $descriptionCacheExpiry, $hashLevels, $url, $thumbUrl; |
19 | 20 | |
— | — | @@ -31,7 +32,8 @@ |
32 | 33 | $this->initialCapital = MWNamespace::isCapitalized( NS_FILE ); |
33 | 34 | foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', |
34 | 35 | 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection', |
35 | | - 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl' ) as $var ) |
| 36 | + 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl', 'scriptExtension' ) |
| 37 | + as $var ) |
36 | 38 | { |
37 | 39 | if ( isset( $info[$var] ) ) { |
38 | 40 | $this->$var = $info[$var]; |
— | — | @@ -296,6 +298,18 @@ |
297 | 299 | function getName() { |
298 | 300 | return $this->name; |
299 | 301 | } |
| 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 | + } |
300 | 314 | |
301 | 315 | /** |
302 | 316 | * Get the URL of an image description page. May return false if it is |
— | — | @@ -326,8 +340,7 @@ |
327 | 341 | # We use "Image:" as the canonical namespace for |
328 | 342 | # compatibility across all MediaWiki versions, |
329 | 343 | # 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" ); |
332 | 345 | } |
333 | 346 | return false; |
334 | 347 | } |
— | — | @@ -346,9 +359,10 @@ |
347 | 360 | $query .= '&uselang=' . $lang; |
348 | 361 | } |
349 | 362 | if ( isset( $this->scriptDirUrl ) ) { |
350 | | - return $this->scriptDirUrl . '/index.php?title=' . |
| 363 | + return $this->makeUrl( |
| 364 | + 'title=' . |
351 | 365 | wfUrlencode( 'Image:' . $name ) . |
352 | | - "&$query"; |
| 366 | + "&$query" ); |
353 | 367 | } else { |
354 | 368 | $descUrl = $this->getDescriptionUrl( $name ); |
355 | 369 | if ( $descUrl ) { |
Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php |
— | — | @@ -25,7 +25,10 @@ |
26 | 26 | |
27 | 27 | function __construct( $info ) { |
28 | 28 | 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 | + |
30 | 33 | if( isset( $info['apiThumbCacheExpiry'] ) ) { |
31 | 34 | $this->apiThumbCacheExpiry = $info['apiThumbCacheExpiry']; |
32 | 35 | } |
— | — | @@ -106,14 +109,17 @@ |
107 | 110 | function fetchImageQuery( $query ) { |
108 | 111 | global $wgMemc; |
109 | 112 | |
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 | + } |
118 | 124 | |
119 | 125 | if( !isset( $this->mQueryCache[$url] ) ) { |
120 | 126 | $key = $this->getLocalCacheKey( 'ForeignAPIRepo', 'Metadata', md5( $url ) ); |
— | — | @@ -149,7 +155,7 @@ |
150 | 156 | function findBySha1( $hash ) { |
151 | 157 | $results = $this->fetchImageQuery( array( |
152 | 158 | 'aisha1base36' => $hash, |
153 | | - 'aiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime', |
| 159 | + 'aiprop' => ForeignAPIFile::getProps(), |
154 | 160 | 'list' => 'allimages', ) ); |
155 | 161 | $ret = array(); |
156 | 162 | if ( isset( $results['query']['allimages'] ) ) { |
Index: trunk/phase3/includes/filerepo/ForeignAPIFile.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | static function newFromTitle( $title, $repo ) { |
21 | 21 | $data = $repo->fetchImageQuery( array( |
22 | 22 | 'titles' => 'File:' . $title->getText(), |
23 | | - 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime', |
| 23 | + 'iiprop' => self::getProps(), |
24 | 24 | 'prop' => 'imageinfo' ) ); |
25 | 25 | |
26 | 26 | $info = $repo->getImageInfo( $data ); |
— | — | @@ -38,6 +38,13 @@ |
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
| 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 | + |
42 | 49 | // Dummy functions... |
43 | 50 | public function exists() { |
44 | 51 | return $this->mExists; |
— | — | @@ -87,27 +94,33 @@ |
88 | 95 | } |
89 | 96 | |
90 | 97 | public function getSize() { |
91 | | - return intval( @$this->mInfo['size'] ); |
| 98 | + return isset( $this->mInfo['size'] ) ? intval( $this->mInfo['size'] ) : null; |
92 | 99 | } |
93 | 100 | |
94 | 101 | public function getUrl() { |
95 | | - return strval( @$this->mInfo['url'] ); |
| 102 | + return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null; |
96 | 103 | } |
97 | 104 | |
98 | 105 | public function getUser( $method='text' ) { |
99 | | - return strval( @$this->mInfo['user'] ); |
| 106 | + return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null; |
100 | 107 | } |
101 | 108 | |
102 | 109 | public function getDescription() { |
103 | | - return strval( @$this->mInfo['comment'] ); |
| 110 | + return isset( $this->mInfo['comment'] ) ? strval( $this->mInfo['comment'] ) : null; |
104 | 111 | } |
105 | 112 | |
106 | 113 | 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; |
108 | 117 | } |
109 | 118 | |
110 | 119 | 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 | + ); |
112 | 125 | } |
113 | 126 | |
114 | 127 | function getMimeType() { |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -344,7 +344,9 @@ |
345 | 345 | * for local repositories: |
346 | 346 | * - descBaseUrl URL of image description pages, e.g. http://en.wikipedia.org/wiki/Image: |
347 | 347 | * - 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 |
349 | 351 | * |
350 | 352 | * - articleUrl Equivalent to $wgArticlePath, e.g. http://en.wikipedia.org/wiki/$1 |
351 | 353 | * - fetchDescription Fetch the text of the remote file description page. Equivalent to |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -98,6 +98,8 @@ |
99 | 99 | * Stop emitting named entities, so we can use <!DOCTYPE html> while still being |
100 | 100 | well-formed XML |
101 | 101 | * 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 |
102 | 104 | |
103 | 105 | === Bug fixes in 1.17 === |
104 | 106 | * (bug 17560) Half-broken deletion moved image files to deletion archive |