* (bug 4104) 'OutputPageBeforeHTML' hook to postprocess article HTML on
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 13 Jan 2006 17:00:05 +0000 (17:00 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 13 Jan 2006 17:00:05 +0000 (17:00 +0000)
  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
docs/hooks.txt
includes/Article.php
includes/OutputPage.php

index fe6037e..f76979a 100644 (file)
@@ -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 ===
index ae05905..d05b064 100644 (file)
@@ -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.
index 9f1d3b8..6a1c0e3 100644 (file)
@@ -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 );
index 8a5a5db..f356e23 100644 (file)
@@ -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 );