From 467f4affd1fb541c11d582c274fc20d6df47479a Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 13 Jun 2014 16:08:52 -0700 Subject: [PATCH] New hook, AfterParserFetchFileAndTitle It is needed for PageImages to collect information about galleries, improving results for Commons mainspace. Bug: 66510 Change-Id: I3136d648ef2c1841767db0ab33855cd168e3de3e --- docs/hooks.txt | 7 +++++++ includes/gallery/ImageGalleryBase.php | 8 ++++++++ includes/parser/Parser.php | 1 + 3 files changed, 16 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index 1673f06543..b1ef47ca0d 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -326,6 +326,13 @@ $revCount: Number of revisions in the XML file $sRevCount: Number of successfully imported revisions $pageInfo: associative array of page information +'AfterParserFetchFileAndTitle': After an image gallery is formed by Parser, +just before adding its HTML to parser output. +$parser: Parser object that called the hook +$ig: Gallery, an object of one of the gallery classes (inheriting from +ImageGalleryBase) +$html: HTML generated by the gallery + 'AjaxAddScript': Called in output page just before the initialisation of the javascript ajax engine. The hook is only called when ajax is enabled ( $wgUseAjax = true; ). diff --git a/includes/gallery/ImageGalleryBase.php b/includes/gallery/ImageGalleryBase.php index 8d2b94964c..837a73173e 100644 --- a/includes/gallery/ImageGalleryBase.php +++ b/includes/gallery/ImageGalleryBase.php @@ -258,6 +258,14 @@ abstract class ImageGalleryBase extends ContextSource { array_unshift( $this->mImages, array( &$title, $html, $alt, $link, $handlerOpts ) ); } + /** + * Returns the list of images this gallery contains + * @return array + */ + public function getImages() { + return $this->mImages; + } + /** * isEmpty() returns true if the gallery contains no images * @return bool diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index eb7bd1b0c8..89ed60d234 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -5369,6 +5369,7 @@ class Parser { $ig->add( $title, $label, $alt, $link, $handlerOptions ); } $html = $ig->toHTML(); + wfRunHooks( 'AfterParserFetchFileAndTitle', array( $this, $ig, &$html ) ); wfProfileOut( __METHOD__ ); return $html; } -- 2.20.1