http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84659
Revision: 84659
Author: aaron
Date: 2011-03-24 01:44:48 +0000 (Thu, 24 Mar 2011)
Log Message:
-----------
* Replaced crufty BeforeParserMakeImageLinkObj/BeforeGalleryFindFile hooks with
BeforeParserFetchFileAndTile hook
* Updated the only calling extension (these was basically single-purpose hooks)
Modified Paths:
--------------
trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
trunk/extensions/FlaggedRevs/FlaggedRevs.php
trunk/phase3/docs/hooks.txt
trunk/phase3/includes/ImageGallery.php
trunk/phase3/includes/parser/Parser.php
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php 2011-03-24 01:25:08 UTC
(rev 84658)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php 2011-03-24 01:44:48 UTC
(rev 84659)
@@ -329,12 +329,9 @@
}
/**
- * (a) Select the desired images based on the selected stable version
time/SHA-1
- * (b) Set specified versions in mImageTimeKeys
+ * Select the desired images based on the selected stable version
time/SHA-1
*/
- public static function parserFetchStableFile(
- $parser, Title $nt, &$skip, &$time, &$query, &$sha1
- ) {
+ public static function parserFetchStableFile( $parser, Title $nt,
&$time, &$sha1, &$query ) {
if ( !( $parser instanceof Parser ) ) {
return true; // nothing to do
}
@@ -359,31 +356,8 @@
}
/**
- * (a) Select the desired images based on the selected stable version
time/SHA-1
- * (b) Set specified versions in mImageTimeKeys
+ * Select the desired images based on the selected stable version
time/SHA-1
*/
- public static function galleryFetchStableFile( $ig, Title $nt, &$time,
&$query, &$sha1 ) {
- $parser =& $ig->mParser; // convenience
- if ( !( $parser instanceof Parser ) || $nt->getNamespace() !=
NS_FILE ) {
- return true; // nothing to do
- }
- if (
!FRInclusionManager::singleton()->parserOutputIsStabilized() ) {
- return true; // trigger for stable version parsing only
- }
- # Get version, update mImageTimeKeys...
- list( $time, $sha1 ) = self::parserFindStableFile( $parser, $nt
);
- # Stabilize the file link
- if ( $time ) {
- if ( $query != '' ) $query .= '&';
- $query = "filetimestamp=" . urlencode( wfTimestamp(
TS_MW, $time ) );
- }
- return true;
- }
-
- /**
- * (a) Select the desired images based on the selected stable version
time/SHA-1
- * (b) Set specified versions in mImageTimeKeys
- */
protected static function parserFindStableFile( Parser $parser, Title
$title ) {
$time = false; // current version
$sha1 = false; // corresponds to $time
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.php 2011-03-24 01:25:08 UTC
(rev 84658)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.php 2011-03-24 01:44:48 UTC
(rev 84659)
@@ -436,8 +436,7 @@
# Parser hooks, selects the desired images/templates
$wgHooks['ParserClearState'][] = 'FlaggedRevsHooks::parserAddFields';
$wgHooks['BeforeParserFetchTemplateAndtitle'][] =
'FlaggedRevsHooks::parserFetchStableTemplate';
-$wgHooks['BeforeParserMakeImageLinkObj'][] =
'FlaggedRevsHooks::parserFetchStableFile';
-$wgHooks['BeforeGalleryFindFile'][] =
'FlaggedRevsHooks::galleryFetchStableFile';
+$wgHooks['BeforeParserFetchFileAndTitle'][] =
'FlaggedRevsHooks::parserFetchStableFile';
# ########
# ######## DB write operations #########
Modified: trunk/phase3/docs/hooks.txt
===================================================================
--- trunk/phase3/docs/hooks.txt 2011-03-24 01:25:08 UTC (rev 84658)
+++ trunk/phase3/docs/hooks.txt 2011-03-24 01:44:48 UTC (rev 84659)
@@ -550,13 +550,6 @@
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 @@
&$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
Modified: trunk/phase3/includes/ImageGallery.php
===================================================================
--- trunk/phase3/includes/ImageGallery.php 2011-03-24 01:25:08 UTC (rev
84658)
+++ trunk/phase3/includes/ImageGallery.php 2011-03-24 01:44:48 UTC (rev
84659)
@@ -239,9 +239,8 @@
}
$attribs = Sanitizer::mergeAttributes(
- array(
- 'class' => 'gallery'),
- $this->mAttribs );
+ array( 'class' => 'gallery' ), $this->mAttribs );
+
$s = Xml::openElement( 'ul', $attribs );
if ( $this->mCaption ) {
$s .= "\n\t<li
class='gallerycaption'>{$this->mCaption}</li>";
@@ -253,24 +252,18 @@
$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;
Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php 2011-03-24 01:25:08 UTC (rev
84658)
+++ trunk/phase3/includes/parser/Parser.php 2011-03-24 01:44:48 UTC (rev
84659)
@@ -1909,19 +1909,14 @@
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 @@
$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;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs