From 03b9a2303d1605c174482f798f42220945d8a0a1 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 13 Jan 2006 17:00:05 +0000 Subject: [PATCH] * (bug 4104) 'OutputPageBeforeHTML' hook to postprocess article HTML on page view (comes after parser cache, if used). Patch by ThomasV. http://bugzilla.wikimedia.org/attachment.cgi?id=1290&action=view http://bugzilla.wikimedia.org/attachment.cgi?id=1296&action=view http://bugzilla.wikimedia.org/attachment.cgi?id=1297&action=view --- RELEASE-NOTES | 2 ++ docs/hooks.txt | 5 +++++ includes/Article.php | 3 ++- includes/OutputPage.php | 12 +++++++++--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fe6037e1a5..f76979ae9d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -477,6 +477,8 @@ fully support the editing toolbar, but was found to be too confusing. * (bug 1103) Fix up redirect handling for images, categories Redirects are now followed from the top-level, outside of the Article content loading and viewing, for clarity and consistency. +* (bug 4104) 'OutputPageBeforeHTML' hook to postprocess article HTML on + page view (comes after parser cache, if used). Patch by ThomasV. === Caveats === diff --git a/docs/hooks.txt b/docs/hooks.txt index ae05905981..d05b064f4e 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -344,6 +344,11 @@ $user: user (object) who marked the edit patrolled $wcOnlySysopsCanPatrol: config setting indicating whether the user must be a sysop to patrol the edit +'OutputPageBeforeHTML': a page has been processed by the parser and +the resulting HTML is about to be displayed. +$parserOutput: the parserOutput (object) that corresponds to the page +$text: the text that will be displayed, in HTML (string) + 'PageRenderingHash': alter the parser cache option hash key A parser extension which depends on user options should install this hook and append its values to the key. diff --git a/includes/Article.php b/includes/Article.php index 9f1d3b8fab..6a1c0e3132 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -877,7 +877,8 @@ class Article { if( !$this->isCurrent() ) { $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false ); } - $wgOut->addWikiText( $text ); + # Display content and don't save to parser cache + $wgOut->addPrimaryWikiText( $text, $this, false ); if( !$this->isCurrent() ) { $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 8a5a5db9b4..f356e233e4 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -309,12 +309,16 @@ class OutputPage { $parserOutput = $wgParser->parse( $text, $article->mTitle, $this->mParserOptions, true, true, $this->mRevisionId ); - if ( $article && $parserOutput->getCacheTime() != -1 ) { + if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) { $parserCache =& ParserCache::singleton(); $parserCache->save( $parserOutput, $article, $wgUser ); } - $this->addParserOutput( $parserOutput ); + $this->addParserOutputNoText( $parserOutput ); + $text = $parserOutput->getText(); + wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) ); + $parserOutput->setText( $text ); + $this->addHTML( $parserOutput->getText() ); } /** @@ -351,7 +355,9 @@ class OutputPage { $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->addCategoryLinks( $parserOutput->getCategories() ); $this->addKeywords( $parserOutput ); - $this->addHTML( $parserOutput->getText() ); + $text = $parserOutput->getText(); + wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) ); + $this->addHTML( $text ); $t = $parserOutput->getTitleText(); if( !empty( $t ) ) { $this->setPageTitle( $t ); -- 2.20.1