* Added scriptExtension setting to $wgForeignFileRepos
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 2 Jul 2010 18:37:06 +0000 (18:37 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 2 Jul 2010 18:37:06 +0000 (18:37 +0000)
* 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
includes/DefaultSettings.php
includes/filerepo/FileRepo.php
includes/filerepo/ForeignAPIFile.php
includes/filerepo/ForeignAPIRepo.php

index 9c987ce..70ca062 100644 (file)
@@ -98,6 +98,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Stop emitting named entities, so we can use <!DOCTYPE html> 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
index a506f8b..3b5cff2 100644 (file)
@@ -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
index c97423c..e5ea48d 100644 (file)
@@ -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 ) {
index 9987537..c00fcd8 100644 (file)
@@ -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() {
index 00020ff..2c74ac2 100644 (file)
@@ -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'] ) ) {