r88898 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88897‎ | r88898 | r88899 >
Date:16:41, 26 May 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
Merged MediaWiki::performRequestForTitle() and MediaWiki::handleSpecialCases() into MediaWiki::performRequest():
* this allows to perform tests in the correct order, i.e. first BadTitle check and then userCanRead()
* the Article object is now returned by the function instead of passed back in pass-by-reference parameter
* Removed the "return false;" when MediaWiki detects a redirect, was causing an useless full execution
Modified paths:
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Wiki.php
@@ -26,57 +26,6 @@
2727 }
2828
2929 /**
30 - * Initialization of ... everything
31 - * Performs the request too
32 - *
33 - * @param $article Article
34 - */
35 - public function performRequestForTitle( &$article ) {
36 - wfProfileIn( __METHOD__ );
37 -
38 - if ( $this->context->request->getVal( 'printable' ) === 'yes' ) {
39 - $this->context->output->setPrintable();
40 - }
41 -
42 - wfRunHooks( 'BeforeInitialize', array(
43 - &$this->context->title,
44 - &$article,
45 - &$this->context->output,
46 - &$this->context->user,
47 - $this->context->request,
48 - $this
49 - ) );
50 -
51 - // If the user is not logged in, the Namespace:title of the article must be in
52 - // the Read array in order for the user to see it. (We have to check here to
53 - // catch special pages etc. We check again in Article::view())
54 - if ( !is_null( $this->context->title ) && !$this->context->title->userCanRead() ) {
55 - $this->context->output->loginToUse();
56 - $this->finalCleanup();
57 - $this->context->output->disable();
58 - wfProfileOut( __METHOD__ );
59 - return false;
60 - }
61 -
62 - // Call handleSpecialCases() to deal with all special requests...
63 - if ( !$this->handleSpecialCases() ) {
64 - // ...otherwise treat it as an article view. The article
65 - // may be a redirect to another article or URL.
66 - $new_article = $this->initializeArticle();
67 - if ( is_object( $new_article ) ) {
68 - $article = $new_article;
69 - $this->performAction( $article );
70 - } elseif ( is_string( $new_article ) ) {
71 - $this->context->output->redirect( $new_article );
72 - } else {
73 - wfProfileOut( __METHOD__ );
74 - throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
75 - }
76 - }
77 - wfProfileOut( __METHOD__ );
78 - }
79 -
80 - /**
8130 * Parse $request to get the Title object
8231 *
8332 * @return Title object to be $wgTitle
@@ -135,23 +84,42 @@
13685 }
13786
13887 /**
139 - * Initialize some special cases:
 88+ * Performs the request.
14089 * - bad titles
 90+ * - read restriction
14191 * - local interwiki redirects
14292 * - redirect loop
14393 * - special pages
 94+ * - normal pages
14495 *
145 - * @return bool true if the request is already executed
 96+ * @return Article object
14697 */
147 - private function handleSpecialCases() {
 98+ public function performRequest() {
14899 global $wgServer, $wgUsePathInfo;
149100
150101 wfProfileIn( __METHOD__ );
151102
 103+ if ( $this->context->request->getVal( 'printable' ) === 'yes' ) {
 104+ $this->context->output->setPrintable();
 105+ }
 106+
 107+ wfRunHooks( 'BeforeInitialize', array(
 108+ &$this->context->title,
 109+ null,
 110+ &$this->context->output,
 111+ &$this->context->user,
 112+ $this->context->request,
 113+ $this
 114+ ) );
 115+
152116 // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
153117 if ( $this->context->title instanceof BadTitle ) {
154118 throw new ErrorPageError( 'badtitle', 'badtitletext' );
155 -
 119+ // If the user is not logged in, the Namespace:title of the article must be in
 120+ // the Read array in order for the user to see it. (We have to check here to
 121+ // catch special pages etc. We check again in Article::view())
 122+ } else if ( !$this->context->title->userCanRead() ) {
 123+ $this->context->output->loginToUse();
156124 // Interwiki redirects
157125 } else if ( $this->context->title->getInterwiki() != '' ) {
158126 $rdfrom = $this->context->request->getVal( 'rdfrom' );
@@ -205,8 +173,6 @@
206174 "to true.";
207175 }
208176 wfHttpError( 500, "Internal error", $message );
209 - wfProfileOut( __METHOD__ );
210 - return false;
211177 } else {
212178 $this->context->output->setSquidMaxage( 1200 );
213179 $this->context->output->redirect( $targetUrl, '301' );
@@ -216,13 +182,21 @@
217183 // actions that need to be made when we have a special pages
218184 SpecialPageFactory::executePath( $this->context->title, $this->context );
219185 } else {
220 - // No match to special cases
221 - wfProfileOut( __METHOD__ );
222 - return false;
 186+ // ...otherwise treat it as an article view. The article
 187+ // may be a redirect to another article or URL.
 188+ $article = $this->initializeArticle();
 189+ if ( is_object( $article ) ) {
 190+ $this->performAction( $article );
 191+ wfProfileOut( __METHOD__ );
 192+ return $article;
 193+ } elseif ( is_string( $new_article ) ) {
 194+ $this->context->output->redirect( $new_article );
 195+ } else {
 196+ wfProfileOut( __METHOD__ );
 197+ throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
 198+ }
223199 }
224 - // Did match a special case
225200 wfProfileOut( __METHOD__ );
226 - return true;
227201 }
228202
229203 /**
Index: trunk/phase3/index.php
@@ -138,16 +138,15 @@
139139 wfProfileOut( 'index.php-filecache' );
140140 }
141141
142 - $mediaWiki->performRequestForTitle( $article );
143 -
144142 /**
145143 * $wgArticle is deprecated, do not use it. This will possibly be removed
146144 * entirely in 1.20 or 1.21
147145 * @deprecated since 1.19
148146 */
149147 global $wgArticle;
150 - $wgArticle = $article;
151148
 149+ $wgArticle = $mediaWiki->performRequest();
 150+
152151 $mediaWiki->finalCleanup();
153152
154153 wfProfileOut( 'index.php' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r88921Fix for r88898: fix variable nameialex19:56, 26 May 2011
r106545followup r88898 -- move BeforeInitialize hook to where it can be...mah01:46, 18 December 2011
r106563Revert r106545 and pass a null variable by ref (also updated the documentatio...ialex14:48, 18 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   19:28, 26 May 2011

[26-May-2011 19:23:14] PHP Notice: Undefined variable: new_article in /www/w/includes/Wiki.php on line 192

[26-May-2011 19:23:14] /wiki/Translating:Languages: Exception: Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL

Status & tagging log