Merge "Add method parameter type documentation"
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 39ef62c..627defd 100644 (file)
@@ -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 {
@@ -633,7 +637,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['height'];
                        } else {
@@ -780,10 +788,12 @@ class LocalFile extends File {
 
                $backend = $this->repo->getBackend();
                $files = array( $dir );
-               $iterator = $backend->getFileList( array( 'dir' => $dir ) );
-               foreach ( $iterator as $file ) {
-                       $files[] = $file;
-               }
+               try {
+                       $iterator = $backend->getFileList( array( 'dir' => $dir ) );
+                       foreach ( $iterator as $file ) {
+                               $files[] = $file;
+                       }
+               } catch ( FileBackendError $e ) {} // suppress (bug 54674)
 
                return $files;
        }
@@ -1664,9 +1674,11 @@ class LocalFile extends File {
         * 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;
@@ -1675,7 +1687,7 @@ class LocalFile extends File {
                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();
        }
 
@@ -1752,6 +1764,16 @@ class LocalFile extends File {
                                $this->lockedOwnTrx = true;
                        }
                        $this->locked++;
+                       // Bug 54736: use simple lock to handle when the file does not exist.
+                       // SELECT FOR UPDATE only locks records not the gaps where there are none.
+                       $cache = wfGetMainCache();
+                       $key = $this->getCacheKey();
+                       if ( !$cache->lock( $key, 60 ) ) {
+                               throw new MWException( "Could not acquire lock for '{$this->getName()}.'" );
+                       }
+                       $dbw->onTransactionIdle( function() use ( $cache, $key ) {
+                               $cache->unlock( $key ); // release on commit
+                       } );
                }
 
                return $dbw->selectField( 'image', '1',