From 61ce97e8c1752b5315467e74e6098ecff01d5b79 Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Tue, 27 Mar 2012 16:49:19 +0000 Subject: [PATCH] minimize use of textual page content, clean up hooks for custom page rendering --- includes/Article.php | 13 ++++++++----- includes/diff/DifferenceEngine.php | 21 +++++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index fd575aa05a..249d48f3a0 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -324,7 +324,7 @@ class Article extends Page { $content = $this->fetchContentObject(); - $this->mContent = ContentHandler::getContentText( $content ); + $this->mContent = ContentHandler::getContentText( $content ); #FIXME: get rid of mContent everywhere! wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ); #BC cruft! wfProfileOut( __METHOD__ ); @@ -609,7 +609,10 @@ class Article extends Page { wfDebug( __METHOD__ . ": showing CSS/JS source\n" ); $this->showCssOrJsPage(); $outputDone = true; - } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) { + } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) { #FIXME: document new hook! + # Allow extensions do their own custom view for certain pages + $outputDone = true; + } elseif( Hooks::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated! #FIXME: deprecate hook! # Allow extensions do their own custom view for certain pages $outputDone = true; } else { @@ -745,17 +748,17 @@ class Article extends Page { * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these * page views. */ - protected function showCssOrJsPage() { #FIXME: move this to ContentHandler! + protected function showCssOrJsPage() { global $wgOut; $dir = $this->getContext()->getLanguage()->getDir(); $lang = $this->getContext()->getLanguage()->getCode(); $wgOut->wrapWikiMsg( "
\n$1\n
", - 'clearyourcache' ); #FIXME: do this in handler + 'clearyourcache' ); // Give hooks a chance to customise the output - if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) { + if ( !Hooks::isRegistered('ShowRawCssJs') || wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated #FIXME: hook is deprecated $po = $this->mContentObject->getParserOutput(); $wgOut->addHTML( $po->getText() ); } diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 6e1b1f1399..2fb203ef3d 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -486,20 +486,21 @@ class DifferenceEngine extends ContextSource { $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() ); $out->setArticleFlag( true ); - if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) { #FIXME: don't do this, use the content handler instead!! + if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) { #NOTE: only needed for B/C: custom rendering of JS/CSS via hook // Stolen from Article::view --AG 2007-10-11 // Give hooks a chance to customise the output // @TODO: standardize this crap into one function - if ( wfRunHooks( 'ShowRawCssJs', array( $this->mNewtext, $this->mNewPage, $out ) ) ) { #FIXME: what to do with this hook?? - // Wrap the whole lot in a
 and don't parse
-					$m = array();
-					preg_match( '!\.(css|js)$!u', $this->mNewPage->getText(), $m );
-					$out->addHTML( "
\n" );
-					$out->addHTML( htmlspecialchars( $this->mNewtext ) );
-					$out->addHTML( "\n
\n" ); + if ( !Hook::isRegistered( 'ShowRawCssJs' ) + || wfRunHooks( 'ShowRawCssJs', array( ContentHandler::getContentText( $this->mNewContent ), $this->mNewPage, $out ) ) ) { #NOTE: deperecated hook, B/C only + // use the content object's own rendering + $po = $this->mContentObject->getParserOutput(); + $out->addHTML( $po->getText() ); } - } elseif ( !wfRunHooks( 'ArticleViewCustom', array( $this->mNewtext, $this->mNewPage, $out ) ) ) { #FIXME: what do we pass here - // Handled by extension + } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) { + // Handled by extension + } elseif( Hooks::isRegistered( 'ArticleViewCustom' ) + && !wfRunHooks( 'ArticleViewCustom', array( ContentHandler::getContentText( $this->mNewContent ), $this->mNewPage, $out ) ) ) { #NOTE: deperecated hook, B/C only + // Handled by extension } else { // Normal page if ( $this->getTitle()->equals( $this->mNewPage ) ) { -- 2.20.1