- $text = $pair[1];
-
- # Give extensions a chance to select the file revision for us
- $time = false;
- wfRunHooks( 'BeforeGalleryFindFile', array( &$this, &$nt, &$time ) );
-
- $img = wfFindFile( $nt, $time );
+ $text = $pair[1]; # "text" means "caption" here
+ $alt = $pair[2];
+
+ $descQuery = false;
+ if ( $nt->getNamespace() == NS_FILE ) {
+ # Get the file...
+ if ( $this->mParser instanceof Parser ) {
+ # Give extensions a chance to select the file revision for us
+ $time = $sha1 = false;
+ wfRunHooks( 'BeforeParserFetchFileAndTitle',
+ array( $this->mParser, $nt, &$time, &$sha1, &$descQuery ) );
+ # Fetch and register the file (file title may be different via hooks)
+ list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $time, $sha1 );
+ } else {
+ $img = wfFindFile( $nt );
+ }
+ } else {
+ $img = false;
+ }