From: Aaron Schulz Date: Thu, 24 Mar 2011 01:44:48 +0000 (+0000) Subject: * Replaced crufty BeforeParserMakeImageLinkObj/BeforeGalleryFindFile hooks with Befor... X-Git-Tag: 1.31.0-rc.0~31218 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=67955599f8f60401b4eb48aa858e682c3e20d12b;p=lhc%2Fweb%2Fwiklou.git * Replaced crufty BeforeParserMakeImageLinkObj/BeforeGalleryFindFile hooks with BeforeParserFetchFileAndTile hook * Updated the only calling extension (these was basically single-purpose hooks) --- diff --git a/docs/hooks.txt b/docs/hooks.txt index bed562e11c..9f96607a5a 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -550,13 +550,6 @@ $name: Image name being checked Change $bad and return false to override. If an image is "bad", it is not rendered inline in wiki pages or galleries in category pages. -'BeforeGalleryFindFile': before an image is fetched for a gallery -&$gallery,: the gallery object -&$nt: the image title -&$time: image timestamp (used to specify the file) -&$descQuery: query string to add to thumbnail URL -&$sha1: image base 36 sha1 (used to specify the file, $nt will be ignored if this is set) - 'BeforeInitialize': before anything is initialized in performRequestForTitle() &$title: Title being used for request &$article: The associated Article object @@ -569,20 +562,19 @@ $mediaWiki: Mediawiki object &$out: OutputPage object &$skin: Skin object +'BeforeParserFetchFileAndTitle': before an image is rendered by Parser +&$parser: Parser object +&$nt: the image title +&$time: the image timestamp (use '0' to force a broken thumbnail) +&$sha1: image base 36 sha1 (used to specify the file, $nt will be ignored if this is set) +&$descQuery: query string to add to thumbnail URL + 'BeforeParserFetchTemplateAndtitle': before a template is fetched by Parser &$parser: Parser object &$title: title of the template &$skip: skip this template and link it? &$id: the id of the revision being parsed -'BeforeParserMakeImageLinkObj': before an image is rendered by Parser -&$parser: Parser object -&$nt: the image title -&$skip: skip this image and link it? -&$time: the image timestamp -&$descQuery: query string to add to thumbnail URL -&$sha1: image base 36 sha1 (used to specify the file, $nt will be ignored if this is set) - 'BeforeParserrenderImageGallery': before an image gallery is rendered by Parser &$parser: Parser object &$ig: ImageGallery object diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index fc980af9cb..dba284e85e 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -239,9 +239,8 @@ class ImageGallery } $attribs = Sanitizer::mergeAttributes( - array( - 'class' => 'gallery'), - $this->mAttribs ); + array( 'class' => 'gallery' ), $this->mAttribs ); + $s = Xml::openElement( 'ul', $attribs ); if ( $this->mCaption ) { $s .= "\n\t
  • {$this->mCaption}
  • "; @@ -253,24 +252,18 @@ class ImageGallery $nt = $pair[0]; $text = $pair[1]; # "text" means "caption" here + $descQuery = false; if ( $nt->getNamespace() == NS_FILE ) { - # Give extensions a chance to select the file revision for us - $time = $sha1 = $descQuery = false; - wfRunHooks( 'BeforeGalleryFindFile', - array( &$this, &$nt, &$time, &$descQuery, &$sha1 ) ); # 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 { - if ( $time === '0' ) { - $img = false; // broken thumbnail forced by hook - } elseif ( $sha1 ) { // get by (sha1,timestamp) - $img = RepoGroup::singleton()->findFileFromKey( - $sha1, array( 'time' => $time ) ); - } else { // get by (name,timestamp) - $img = wfFindFile( $nt, array( 'time' => $time ) ); - } + $img = wfFindFile( $nt ); } } else { $img = false; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 6bbd95cb32..c8af287e92 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1909,19 +1909,14 @@ class Parser { if ( $ns == NS_MEDIA ) { wfProfileIn( __METHOD__."-media" ); # Give extensions a chance to select the file revision for us - $skip = $time = $sha1 = $descQuery = false; - wfRunHooks( 'BeforeParserMakeImageLinkObj', - array( &$this, &$nt, &$skip, &$time, &$descQuery, &$sha1 ) ); - if ( $skip ) { - $this->mOutput->addImage( $nt->getDBkey(), null, null ); // register - $link = $sk->link( $nt ); - } else { - # Fetch and register the file (file title may be different via hooks) - list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 ); - $link = $sk->makeMediaLinkFile( $nt, $file, $text ); - } + $time = $sha1 = $descQuery = false; + wfRunHooks( 'BeforeParserFetchFileAndTitle', + array( &$this, &$nt, &$time, &$sha1, &$descQuery ) ); + # Fetch and register the file (file title may be different via hooks) + list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 ); # Cloak with NOPARSE to avoid replacement in replaceExternalLinks - $s .= $prefix . $this->armorLinks( $link ) . $trail; + $s .= $prefix . $this->armorLinks( + $sk->makeMediaLinkFile( $nt, $file, $text ) ) . $trail; wfProfileOut( __METHOD__."-media" ); continue; } @@ -4702,15 +4697,12 @@ class Parser { $sk = $this->mOptions->getSkin( $this->mTitle ); # Give extensions a chance to select the file revision for us - $skip = $time = $sha1 = $descQuery = false; - wfRunHooks( 'BeforeParserMakeImageLinkObj', - array( &$this, &$title, &$skip, &$time, &$descQuery, &$sha1 ) ); - if ( $skip ) { - $this->mOutput->addImage( $title->getDBkey(), null, null ); // register - return $sk->link( $title ); - } + $time = $sha1 = $descQuery = false; + wfRunHooks( 'BeforeParserFetchFileAndTitle', + array( &$this, &$title, &$time, &$sha1, &$descQuery ) ); # Fetch and register the file (file title may be different via hooks) list( $file, $title ) = $this->fetchFileAndTitle( $title, $time, $sha1 ); + # Get parameter map $handler = $file ? $file->getHandler() : false;