r88588 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88587‎ | r88588 | r88589 >
Date:17:59, 22 May 2011
Author:demon
Status:resolved (Comments)
Tags:
Comment:
$wgArticle is deprecated! Possible removal in 1.20 or 1.21!
* Encapsulate index.php in wfIndexMain() (similar to r77873)
* Kill $wgArticle check in Exception, not necessary anymore
* Kill $wgArticle in Setup, also not necessary
* Add angry note about $wgArticle to rebuildFileCache.
* Remove note about $wgArticle in Parser since it's dying anyway
Modified paths:
  • /trunk/phase3/docs/globals.txt (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildFileCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Wiki.php
@@ -150,7 +150,6 @@
151151
152152 // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
153153 if ( $this->context->title instanceof BadTitle ) {
154 - // Die now before we mess up $wgArticle and the skin stops working
155154 throw new ErrorPageError( 'badtitle', 'badtitletext' );
156155
157156 // Interwiki redirects
@@ -292,7 +291,7 @@
293292 }
294293
295294 /**
296 - * Initialize the object to be known as $wgArticle for "standard" actions
 295+ * Initialize the main Article object for "standard" actions (view, etc)
297296 * Create an Article object for the page, following redirects if needed.
298297 *
299298 * @return mixed an Article, or a string to redirect to another URL
Index: trunk/phase3/includes/Setup.php
@@ -443,11 +443,10 @@
444444
445445 # Placeholders in case of DB error
446446 $wgTitle = null;
447 -$wgArticle = null;
448447
449448 $wgDeferredUpdateList = array();
450449
451 -// We need to check for safe_mode, because mail() willl throws an E_NOTICE
 450+// We need to check for safe_mode, because mail() will throw an E_NOTICE
452451 // on additional parameters
453452 if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
454453 $wgAdditionalMailParams = null;
Index: trunk/phase3/includes/parser/Parser.php
@@ -34,7 +34,7 @@
3535 * Globals used:
3636 * objects: $wgLang, $wgContLang
3737 *
38 - * NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
 38+ * NOT $wgUser or $wgTitle. Keep them away!
3939 *
4040 * settings:
4141 * $wgUseDynamicDates*, $wgInterwikiMagic*,
Index: trunk/phase3/includes/Exception.php
@@ -22,7 +22,8 @@
2323 function useOutputPage() {
2424 return $this->useMessageCache() &&
2525 !empty( $GLOBALS['wgFullyInitialised'] ) &&
26 - ( !empty( $GLOBALS['wgArticle'] ) || ( !empty( $GLOBALS['wgOut'] ) && !$GLOBALS['wgOut']->isArticleRelated() ) ) &&
 26+ !empty( $GLOBALS['wgOut'] ) &&
 27+ !$GLOBALS['wgOut']->isArticleRelated() &&
2728 !empty( $GLOBALS['wgTitle'] );
2829 }
2930
Index: trunk/phase3/index.php
@@ -63,83 +63,98 @@
6464
6565 # Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and
6666 # the globals $wgRequest, $wgOut, $wgUser, $wgLang and $wgContLang, amongst others; it
67 -# does *not* load $wgTitle or $wgArticle
 67+# does *not* load $wgTitle
6868 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
6969
70 -wfProfileIn( 'index.php' );
71 -wfProfileIn( 'index.php-setup' );
 70+wfIndexMain();
7271
73 -$maxLag = $wgRequest->getVal( 'maxlag' );
74 -if ( !is_null( $maxLag ) ) {
75 - $lb = wfGetLB(); // foo()->bar() is not supported in PHP4
76 - list( $host, $lag ) = $lb->getMaxLag();
77 - if ( $lag > $maxLag ) {
78 - header( 'HTTP/1.1 503 Service Unavailable' );
79 - header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
80 - header( 'X-Database-Lag: ' . intval( $lag ) );
81 - header( 'Content-Type: text/plain' );
82 - if( $wgShowHostnames ) {
83 - echo "Waiting for $host: $lag seconds lagged\n";
84 - } else {
85 - echo "Waiting for a database server: $lag seconds lagged\n";
 72+function wfIndexMain() {
 73+ global $wgRequest, $wgShowHostnames, $mediaWiki, $wgTitle, $wgUseAjax, $wgUseFileCache;
 74+
 75+ wfProfileIn( 'index.php' );
 76+ wfProfileIn( 'index.php-setup' );
 77+
 78+ $maxLag = $wgRequest->getVal( 'maxlag' );
 79+ if ( !is_null( $maxLag ) ) {
 80+ $lb = wfGetLB(); // foo()->bar() is not supported in PHP4
 81+ list( $host, $lag ) = $lb->getMaxLag();
 82+ if ( $lag > $maxLag ) {
 83+ header( 'HTTP/1.1 503 Service Unavailable' );
 84+ header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
 85+ header( 'X-Database-Lag: ' . intval( $lag ) );
 86+ header( 'Content-Type: text/plain' );
 87+ if( $wgShowHostnames ) {
 88+ echo "Waiting for $host: $lag seconds lagged\n";
 89+ } else {
 90+ echo "Waiting for a database server: $lag seconds lagged\n";
 91+ }
 92+ exit;
8693 }
87 - exit;
8894 }
89 -}
9095
91 -# Initialize MediaWiki base class
92 -$context = RequestContext::getMain();
93 -$mediaWiki = new MediaWiki( $context );
 96+ # Initialize MediaWiki base class
 97+ $context = RequestContext::getMain();
 98+ $mediaWiki = new MediaWiki( $context );
9499
95 -# Set title from request parameters
96 -$wgTitle = $mediaWiki->getTitle();
97 -$action = $wgRequest->getVal( 'action', 'view' );
 100+ # Set title from request parameters
 101+ $wgTitle = $mediaWiki->getTitle();
 102+ $action = $wgRequest->getVal( 'action', 'view' );
98103
99 -wfProfileOut( 'index.php-setup' );
 104+ wfProfileOut( 'index.php-setup' );
100105
101 -# Send Ajax requests to the Ajax dispatcher.
102 -if ( $wgUseAjax && $action == 'ajax' ) {
103 - $dispatcher = new AjaxDispatcher();
104 - $dispatcher->performAction();
105 - wfProfileOut( 'index.php' );
106 - $mediaWiki->restInPeace();
107 - exit;
108 -}
 106+ # Send Ajax requests to the Ajax dispatcher.
 107+ if ( $wgUseAjax && $action == 'ajax' ) {
 108+ $dispatcher = new AjaxDispatcher();
 109+ $dispatcher->performAction();
 110+ wfProfileOut( 'index.php' );
 111+ $mediaWiki->restInPeace();
 112+ exit;
 113+ }
109114
110 -if ( $wgUseFileCache && $wgTitle !== null ) {
111 - wfProfileIn( 'index.php-filecache' );
112 - // Raw pages should handle cache control on their own,
113 - // even when using file cache. This reduces hits from clients.
114 - if ( $action != 'raw' && HTMLFileCache::useFileCache() ) {
115 - /* Try low-level file cache hit */
116 - $cache = new HTMLFileCache( $wgTitle, $action );
117 - if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
118 - /* Check incoming headers to see if client has this cached */
119 - if ( !$context->output->checkLastModified( $cache->fileCacheTime() ) ) {
120 - $cache->loadFromFileCache();
 115+ if ( $wgUseFileCache && $wgTitle !== null ) {
 116+ wfProfileIn( 'index.php-filecache' );
 117+ // Raw pages should handle cache control on their own,
 118+ // even when using file cache. This reduces hits from clients.
 119+ if ( $action != 'raw' && HTMLFileCache::useFileCache() ) {
 120+ /* Try low-level file cache hit */
 121+ $cache = new HTMLFileCache( $wgTitle, $action );
 122+ if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
 123+ /* Check incoming headers to see if client has this cached */
 124+ if ( !$context->output->checkLastModified( $cache->fileCacheTime() ) ) {
 125+ $cache->loadFromFileCache();
 126+ }
 127+ # Do any stats increment/watchlist stuff
 128+ $article = MediaWiki::articleFromTitle( $wgTitle, $context );
 129+ $article->viewUpdates();
 130+ # Tell OutputPage that output is taken care of
 131+ $context->output->disable();
 132+ wfProfileOut( 'index.php-filecache' );
 133+ $mediaWiki->finalCleanup();
 134+ wfProfileOut( 'index.php' );
 135+ $mediaWiki->restInPeace();
 136+ exit;
121137 }
122 - # Do any stats increment/watchlist stuff
123 - $wgArticle = MediaWiki::articleFromTitle( $wgTitle, $context );
124 - $wgArticle->viewUpdates();
125 - # Tell OutputPage that output is taken care of
126 - $context->output->disable();
127 - wfProfileOut( 'index.php-filecache' );
128 - $mediaWiki->finalCleanup();
129 - wfProfileOut( 'index.php' );
130 - $mediaWiki->restInPeace();
131 - exit;
132138 }
 139+ wfProfileOut( 'index.php-filecache' );
133140 }
134 - wfProfileOut( 'index.php-filecache' );
135 -}
136141
137 -$mediaWiki->performRequestForTitle( $wgArticle );
138 -$mediaWiki->finalCleanup();
 142+ $mediaWiki->performRequestForTitle( $article );
139143
140 -wfProfileOut( 'index.php' );
 144+ /**
 145+ * $wgArticle is deprecated, do not use it. This will possibly be removed
 146+ * entirely in 1.20 or 1.21
 147+ * @deprecated since 1.19
 148+ */
 149+ global $wgArticle;
 150+ $wgArticle = $article;
141151
142 -$mediaWiki->restInPeace();
 152+ $mediaWiki->finalCleanup();
143153
 154+ wfProfileOut( 'index.php' );
 155+
 156+ $mediaWiki->restInPeace();
 157+}
 158+
144159 /**
145160 * Display something vaguely comprehensible in the event of a totally unrecoverable error.
146161 * Does not assume access to *anything*; no globals, no autloader, no database, no localisation.
Index: trunk/phase3/maintenance/rebuildFileCache.php
@@ -31,6 +31,9 @@
3232 $this->setBatchSize( 100 );
3333 }
3434
 35+ /**
 36+ * @todo MAKE $wgArticle GO AWAY! This is the absolute LAST use in core
 37+ */
3538 public function execute() {
3639 global $wgUseFileCache, $wgDisableCounters, $wgContentNamespaces, $wgRequestTime;
3740 global $wgTitle, $wgArticle, $wgOut;
Index: trunk/phase3/docs/globals.txt
@@ -45,9 +45,6 @@
4646 $wgTitle
4747 Title object created from the request URL.
4848
49 -$wgArticle
50 - Article object corresponding to $wgTitle.
51 -
5249 $wgOut
5350 OutputPage object for HTTP response.
5451

Follow-up revisions

RevisionCommit summaryAuthorDate
r88589Followup r88588 ($wgArticle fixes)...demon18:00, 22 May 2011
r88590$wgArticle ain't needed here either ;) (followup r88588)demon18:05, 22 May 2011
r90339Add deprecated $wgArticle again. Fixes r88588.platonides14:55, 18 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77873* Made it possible to run multiple installer instances in the same cookie dom...tstarling13:20, 6 December 2010

Comments

#Comment by Platonides (talk | contribs)   23:47, 22 May 2011

$mediaWiki should be a local variable.

#Comment by 😂 (talk | contribs)   00:01, 23 May 2011

Eventually. I know there's a few callers out there that use it. See r88593 for one.

#Comment by Platonides (talk | contribs)   15:52, 2 June 2011

The $wgArticle code does nothing (other than being discoverable when grepping the codebase). Anything which relied on $wgArticle will already have run by that time. You should have done $wgArticle = &$article; before the $mediaWiki->performRequestForTitle() call (will be harder now after r88898 refactorization).

+	/**
+	 * $wgArticle is deprecated, do not use it. This will possibly be removed
+	 * entirely in 1.20 or 1.21
+	 * @deprecated since 1.19
+	 */
+	global $wgArticle;
+	$wgArticle = $article;
#Comment by 😂 (talk | contribs)   15:57, 2 June 2011

True. Especially since performRequest() only returns an Article in some scenarios.

#Comment by 😂 (talk | contribs)   21:53, 8 June 2011

Actually, why not just remove it completely? Leaving it around for a release encourages people to keep using it. It was never widely used outside of core, and I've already filed a bug for the remaining problems.

#Comment by Platonides (talk | contribs)   14:56, 18 June 2011

Marking resolved after r90338 and r90339

Status & tagging log