r114529 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114528‎ | r114529 | r114530 >
Date:16:49, 27 March 2012
Author:daniel
Status:deferred
Tags:
Comment:
minimize use of textual page content, clean up hooks for custom page rendering
Modified paths:
  • /branches/Wikidata/phase3/includes/Article.php (modified) (history)
  • /branches/Wikidata/phase3/includes/diff/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: branches/Wikidata/phase3/includes/diff/DifferenceEngine.php
@@ -486,20 +486,21 @@
487487 $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
488488 $out->setArticleFlag( true );
489489
490 - if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) { #FIXME: don't do this, use the content handler instead!!
 490+ if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) { #NOTE: only needed for B/C: custom rendering of JS/CSS via hook
491491 // Stolen from Article::view --AG 2007-10-11
492492 // Give hooks a chance to customise the output
493493 // @TODO: standardize this crap into one function
494 - if ( wfRunHooks( 'ShowRawCssJs', array( $this->mNewtext, $this->mNewPage, $out ) ) ) { #FIXME: what to do with this hook??
495 - // Wrap the whole lot in a <pre> and don't parse
496 - $m = array();
497 - preg_match( '!\.(css|js)$!u', $this->mNewPage->getText(), $m );
498 - $out->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
499 - $out->addHTML( htmlspecialchars( $this->mNewtext ) );
500 - $out->addHTML( "\n</pre>\n" );
 494+ if ( !Hook::isRegistered( 'ShowRawCssJs' )
 495+ || wfRunHooks( 'ShowRawCssJs', array( ContentHandler::getContentText( $this->mNewContent ), $this->mNewPage, $out ) ) ) { #NOTE: deperecated hook, B/C only
 496+ // use the content object's own rendering
 497+ $po = $this->mContentObject->getParserOutput();
 498+ $out->addHTML( $po->getText() );
501499 }
502 - } elseif ( !wfRunHooks( 'ArticleViewCustom', array( $this->mNewtext, $this->mNewPage, $out ) ) ) { #FIXME: what do we pass here
503 - // Handled by extension
 500+ } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
 501+ // Handled by extension
 502+ } elseif( Hooks::isRegistered( 'ArticleViewCustom' )
 503+ && !wfRunHooks( 'ArticleViewCustom', array( ContentHandler::getContentText( $this->mNewContent ), $this->mNewPage, $out ) ) ) { #NOTE: deperecated hook, B/C only
 504+ // Handled by extension
504505 } else {
505506 // Normal page
506507 if ( $this->getTitle()->equals( $this->mNewPage ) ) {
Index: branches/Wikidata/phase3/includes/Article.php
@@ -324,7 +324,7 @@
325325
326326 $content = $this->fetchContentObject();
327327
328 - $this->mContent = ContentHandler::getContentText( $content );
 328+ $this->mContent = ContentHandler::getContentText( $content ); #FIXME: get rid of mContent everywhere!
329329 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ); #BC cruft!
330330
331331 wfProfileOut( __METHOD__ );
@@ -609,7 +609,10 @@
610610 wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
611611 $this->showCssOrJsPage();
612612 $outputDone = true;
613 - } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
 613+ } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) { #FIXME: document new hook!
 614+ # Allow extensions do their own custom view for certain pages
 615+ $outputDone = true;
 616+ } elseif( Hooks::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated! #FIXME: deprecate hook!
614617 # Allow extensions do their own custom view for certain pages
615618 $outputDone = true;
616619 } else {
@@ -745,17 +748,17 @@
746749 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
747750 * page views.
748751 */
749 - protected function showCssOrJsPage() { #FIXME: move this to ContentHandler!
 752+ protected function showCssOrJsPage() {
750753 global $wgOut;
751754
752755 $dir = $this->getContext()->getLanguage()->getDir();
753756 $lang = $this->getContext()->getLanguage()->getCode();
754757
755758 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
756 - 'clearyourcache' ); #FIXME: do this in handler
 759+ 'clearyourcache' );
757760
758761 // Give hooks a chance to customise the output
759 - if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
 762+ if ( !Hooks::isRegistered('ShowRawCssJs') || wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated #FIXME: hook is deprecated
760763 $po = $this->mContentObject->getParserOutput();
761764 $wgOut->addHTML( $po->getText() );
762765 }

Status & tagging log