* FU r106752: unbreak urls to ForeignAPIRepo file thumbnails. FileRepo no longer...
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 21 Dec 2011 21:29:16 +0000 (21:29 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 21 Dec 2011 21:29:16 +0000 (21:29 +0000)
* Cleaned up and added some missing sanity checks for scriptDirUrl member in FileRepo. Made some related documentation tweaks.
* Removed pointless getRepo() call in File.

includes/filerepo/FileRepo.php
includes/filerepo/file/File.php

index 1bebf4a..6a48d88 100644 (file)
@@ -42,9 +42,6 @@ class FileRepo {
        function __construct( $info ) {
                // Required settings
                $this->name = $info['name'];
-               $this->url = isset( $info['url'] )
-                       ? $info['url']
-                       : false;  // a subclass will need to set the URL (e.g. ForeignAPIRepo)
                if ( $info['backend'] instanceof FileBackendBase ) {
                        $this->backend = $info['backend']; // useful for testing
                } else {
@@ -67,9 +64,14 @@ class FileRepo {
                $this->initialCapital = isset( $info['initialCapital'] )
                        ? $info['initialCapital']
                        : MWNamespace::isCapitalized( NS_FILE );
-               $this->thumbUrl = isset( $info['thumbUrl'] )
-                       ? $info['thumbUrl']
-                       : "{$this->url}/thumb";
+               $this->url = isset( $info['url'] )
+                       ? $info['url']
+                       : false; // a subclass may set the URL (e.g. ForeignAPIRepo)
+               if ( isset( $info['thumbUrl'] ) ) {
+                       $this->thumbUrl = $info['thumbUrl'];
+               } else {
+                       $this->thumbUrl = $this->url ? "{$this->url}/thumb" : false;
+               }
                $this->hashLevels = isset( $info['hashLevels'] )
                        ? $info['hashLevels']
                        : 2;
@@ -414,7 +416,7 @@ class FileRepo {
        /**
         * Get the public root URL of the repository
         *
-        * @return string
+        * @return string|false
         */
        public function getRootUrl() {
                return $this->url;
@@ -526,11 +528,14 @@ class FileRepo {
         *
         * @param $query mixed Query string to append
         * @param $entry string Entry point; defaults to index
-        * @return string
+        * @return string|false
         */
        public function makeUrl( $query = '', $entry = 'index' ) {
-               $ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php';
-               return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query );
+               if ( isset( $this->scriptDirUrl ) ) {
+                       $ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php';
+                       return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query );
+               }
+               return false;
        }
 
        /**
@@ -603,13 +608,14 @@ class FileRepo {
        /**
         * Get the URL of the stylesheet to apply to description pages
         *
-        * @return string
+        * @return string|false
         */
        public function getDescriptionStylesheetUrl() {
-               if ( $this->scriptDirUrl ) {
+               if ( isset( $this->scriptDirUrl ) ) {
                        return $this->makeUrl( 'title=MediaWiki:Filepage.css&' .
                                wfArrayToCGI( Skin::getDynamicStylesheetQuery() ) );
                }
+               return false;
        }
 
        /**
index 9fc552e..a241d6b 100644 (file)
@@ -1293,8 +1293,7 @@ abstract class File {
         * @return bool
         */
        function isLocal() {
-               $repo = $this->getRepo();
-               return $repo && $repo->isLocal();
+               return $this->repo && $this->repo->isLocal();
        }
 
        /**