r102897 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102896‎ | r102897 | r102898 >
Date:14:22, 13 November 2011
Author:ialex
Status:ok
Tags:
Comment:
* No need to feed the oldid Article::fetchContent() and retrive it with Article::getRevIdFetched(), just pass it directly to Parser::parse() or use the latest revision when not passed
* Deferred creation of the Article object where it's more likely to be used
* Title also has an exists() method
Modified paths:
  • /trunk/extensions/Cite/SpecialCite_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Cite/SpecialCite_body.php
@@ -23,21 +23,15 @@
2424 $this->setHeaders();
2525 $this->outputHeader();
2626
27 - $page = isset( $par ) ? $par : $wgRequest->getText( 'page' );
28 - $id = $wgRequest->getInt( 'id' );
 27+ $page = $par !== null ? $par : $wgRequest->getText( 'page' );
 28+ $title = Title::newFromText( $page );
2929
30 - $title = Title::newFromText( $page );
31 - if ( $title ) {
32 - $article = new Article( $title );
33 - }
3430 $cform = new CiteForm( $title );
 31+ $cform->execute();
3532
36 - if ( !$title || ! $article->exists() ) {
37 - $cform->execute();
38 - } else {
39 - $cform->execute();
40 -
41 - $cout = new CiteOutput( $title, $article, $id );
 33+ if ( $title && $title->exists() ) {
 34+ $id = $wgRequest->getInt( 'id' );
 35+ $cout = new CiteOutput( $title, $id );
4236 $cout->execute();
4337 }
4438 }
@@ -117,11 +111,11 @@
118112
119113 var $mSpTitle;
120114
121 - function __construct( &$title, &$article, $id ) {
 115+ function __construct( $title, $id ) {
122116 global $wgHooks, $wgParser;
123117
124 - $this->mTitle =& $title;
125 - $this->mArticle =& $article;
 118+ $this->mTitle = $title;
 119+ $this->mArticle = new Article( $title );
126120 $this->mId = $id;
127121
128122 $wgHooks['ParserGetVariableValueVarCache'][] = array( $this, 'varCache' );
@@ -141,8 +135,7 @@
142136 if ( $msg == '' ) {
143137 $msg = $wgCiteDefaultText;
144138 }
145 - $this->mArticle->fetchContent( $this->mId, false );
146 - $ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->mArticle->getRevIdFetched() );
 139+ $ret = $wgParser->parse( $msg, $this->mTitle, $this->mParserOptions, false, true, $this->getRevId() );
147140 $wgOut->addHTML( $ret->getText() );
148141 }
149142
@@ -175,4 +168,12 @@
176169
177170 return true;
178171 }
 172+
 173+ function getRevId() {
 174+ if ( $this->mId ) {
 175+ return $this->mId;
 176+ } else {
 177+ return $this->mTitle->getLatestRevID();
 178+ }
 179+ }
179180 }

Status & tagging log