Merge "Add option to chose what language to fetch file description in."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 25 Sep 2013 15:51:13 +0000 (15:51 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 25 Sep 2013 15:51:13 +0000 (15:51 +0000)
1  2 
includes/filerepo/file/File.php
includes/filerepo/file/LocalFile.php

@@@ -842,9 -842,8 +842,9 @@@ abstract class File 
        protected function transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ) {
                global $wgIgnoreImageErrors;
  
 -              if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
 -                      return $this->getHandler()->getTransform( $this, $thumbPath, $thumbUrl, $params );
 +              $handler = $this->getHandler();
 +              if ( $handler && $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
 +                      return $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
                } else {
                        return new MediaTransformError( 'thumbnail_error',
                                $params['width'], 0, wfMessage( 'thumbnail-dest-create' )->text() );
        /**
         * Get a MediaHandler instance for this file
         *
 -       * @return MediaHandler
 +       * @return MediaHandler|boolean Registered MediaHandler for file's mime type or false if none found
         */
        function getHandler() {
                if ( !isset( $this->handler ) ) {
        /**
         * Get the HTML text of the description page, if available
         *
+        * @param $lang Language Optional language to fetch description in
         * @return string
         */
-       function getDescriptionText() {
+       function getDescriptionText( $lang = false ) {
                global $wgMemc, $wgLang;
                if ( !$this->repo || !$this->repo->fetchDescription ) {
                        return false;
                }
-               $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgLang->getCode() );
+               if ( !$lang ) {
+                       $lang = $wgLang;
+               }
+               $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
                if ( $renderUrl ) {
                        if ( $this->repo->descriptionCacheExpiry > 0 ) {
                                wfDebug( "Attempting to get the description from cache..." );
-                               $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(),
+                               $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $lang->getCode(),
                                                                        $this->getName() );
                                $obj = $wgMemc->get( $key );
                                if ( $obj ) {
@@@ -610,11 -610,7 +610,11 @@@ class LocalFile extends File 
                $this->load();
  
                if ( $this->isMultipage() ) {
 -                      $dim = $this->getHandler()->getPageDimensions( $this, $page );
 +                      $handler = $this->getHandler();
 +                      if ( !$handler ) {
 +                              return 0;
 +                      }
 +                      $dim = $handler->getPageDimensions( $this, $page );
                        if ( $dim ) {
                                return $dim['width'];
                        } else {
                $this->load();
  
                if ( $this->isMultipage() ) {
 -                      $dim = $this->getHandler()->getPageDimensions( $this, $page );
 +                      $handler = $this->getHandler();
 +                      if ( !$handler ) {
 +                              return 0;
 +                      }
 +                      $dim = $handler->getPageDimensions( $this, $page );
                        if ( $dim ) {
                                return $dim['height'];
                        } else {
         * Get the HTML text of the description page
         * This is not used by ImagePage for local files, since (among other things)
         * it skips the parser cache.
+        *
+        * @param $lang Language What language to get description in (Optional)
         * @return bool|mixed
         */
-       function getDescriptionText() {
+       function getDescriptionText( $lang = null ) {
                $revision = Revision::newFromTitle( $this->title, false, Revision::READ_NORMAL );
                if ( !$revision ) {
                        return false;
                if ( !$content ) {
                        return false;
                }
-               $pout = $content->getParserOutput( $this->title, null, new ParserOptions() );
+               $pout = $content->getParserOutput( $this->title, null, new ParserOptions( null, $lang ) );
                return $pout->getText();
        }