r12611 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12610‎ | r12611 | r12612 >
Date:15:46, 11 January 2006
Author:magnus_manske
Status:old
Tags:
Comment:
Most of index.php now in Wiki.php
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES
@@ -460,6 +460,8 @@
461461 * Cleanup and error checking on Special:Listredirects
462462 * Clear up some instances of old OutputPage::sysopRequired() function usage
463463 * Improve "upload disabled" notice
 464+* Move parts of index.php to include/Wiki.php in an attempt to both cleanup index.php
 465+ and create a MediaWiki-class mediaWiki base object
464466
465467 === Caveats ===
466468
Index: trunk/phase3/includes/Wiki.php
@@ -42,6 +42,7 @@
4343 */
4444 function initialize ( &$title, &$output, &$user, $request ) {
4545 wfProfileIn( 'MediaWiki::initialize' );
 46+ $this->preliminaryChecks ( $title , $output , $request ) ;
4647 $article = NULL;
4748 if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
4849 $article = $this->initializeArticle( $title, $request );
@@ -51,6 +52,30 @@
5253 return $article;
5354 }
5455
 56+ function preliminaryChecks ( &$title , &$output , $request ) {
 57+
 58+ # Debug statement for user levels
 59+ // print_r($wgUser);
 60+
 61+ $search = $request->getText( 'search' );
 62+ if( !is_null( $search ) && $search !== '' ) {
 63+ // Compatibility with old search URLs which didn't use Special:Search
 64+ // Do this above the read whitelist check for security...
 65+ $title = Title::makeTitle( NS_SPECIAL, 'Search' );
 66+ }
 67+ $this->setVal( "Search", $search );
 68+
 69+ # If the user is not logged in, the Namespace:title of the article must be in
 70+ # the Read array in order for the user to see it. (We have to check here to
 71+ # catch special pages etc. We check again in Article::view())
 72+ if ( !is_null( $title ) && !$title->userCanRead() ) {
 73+ $output->loginToUse();
 74+ $output->output();
 75+ exit;
 76+ }
 77+
 78+ }
 79+
5580 /**
5681 * Initialize the object to be known as $wgArticle for special cases
5782 */
@@ -147,6 +172,42 @@
148173 }
149174
150175 /**
 176+ * Cleaning up by doing deferred updates, calling loadbalancer and doing the output
 177+ */
 178+ function finalCleanup ( &$deferredUpdates , &$loadBalancer , &$output ) {
 179+ wfProfileIn( 'MediaWiki::finalCleanup' );
 180+ $this->doUpdates( $deferredUpdates );
 181+ $loadBalancer->saveMasterPos();
 182+ # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
 183+ $loadBalancer->commitAll();
 184+ $output->output();
 185+ wfProfileOut( 'MediaWiki::finalCleanup' );
 186+ }
 187+
 188+ /**
 189+ * Deferred updates aren't really deferred anymore. It's important to report errors to the
 190+ * user, and that means doing this before OutputPage::output(). Note that for page saves,
 191+ * the client will wait until the script exits anyway before following the redirect.
 192+ */
 193+ function doUpdates ( &$updates ) {
 194+ wfProfileIn( 'MediaWiki::doUpdates' );
 195+ foreach( $updates as $up ) {
 196+ $up->doUpdate();
 197+ }
 198+ wfProfileOut( 'MediaWiki::doUpdates' );
 199+ }
 200+
 201+ /**
 202+ * Ends this task peacefully
 203+ */
 204+ function restInPeace ( &$loadBalancer ) {
 205+ wfProfileClose();
 206+ logProfilingData();
 207+ $loadBalancer->closeAll();
 208+ wfDebug( "Request ended normally\n" );
 209+ }
 210+
 211+ /**
151212 * Perform one of the "standard" actions
152213 */
153214 function performAction( &$output, &$article, &$title, &$user, &$request ) {
@@ -243,8 +304,9 @@
244305 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
245306 }
246307 wfProfileOut( 'MediaWiki::performAction' );
 308+ }
247309
248 - }
 310+
249311 }
250312
251313 }; /* End of class MediaWiki */
Index: trunk/phase3/index.php
@@ -98,34 +98,14 @@
9999 }
100100 wfProfileOut( 'main-misc-setup' );
101101
102 -# Debug statement for user levels
103 -// print_r($wgUser);
104102
105 -$search = $wgRequest->getText( 'search' );
106 -if( !is_null( $search ) && $search !== '' ) {
107 - // Compatibility with old search URLs which didn't use Special:Search
108 - // Do this above the read whitelist check for security...
109 - $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
110 -}
111 -
112 -# If the user is not logged in, the Namespace:title of the article must be in
113 -# the Read array in order for the user to see it. (We have to check here to
114 -# catch special pages etc. We check again in Article::view())
115 -if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
116 - $wgOut->loginToUse();
117 - $wgOut->output();
118 - exit;
119 -}
120 -
121 -wfProfileIn( 'main-action' );
122 -
123103 # Initialize MediaWiki base class
124104 require_once( "includes/Wiki.php" );
125105 $mediaWiki = new MediaWiki();
126106
 107+# Setting global variables in mediaWiki
127108 $mediaWiki->setVal( "Server", $wgServer );
128109 $mediaWiki->setVal( "DisableInternalSearch", $wgDisableInternalSearch );
129 -$mediaWiki->setVal( "Search", $search );
130110 $mediaWiki->setVal( "action", $action );
131111 $mediaWiki->setVal( "SquidMaxage", $wgSquidMaxage );
132112 $mediaWiki->setVal( "EnableDublinCoreRdf", $wgEnableDublinCoreRdf );
@@ -135,34 +115,10 @@
136116 $mediaWiki->setVal( "DisabledActions", $wgDisabledActions );
137117
138118 $wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
 119+$mediaWiki->finalCleanup ( $wgDeferredUpdateList , $wgLoadBalancer , $wgOut ) ;
139120
140 -wfProfileOut( 'main-action' );
 121+# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup
 122+$mediaWiki->doUpdates( $wgPostCommitUpdateList );
141123
142 -# Deferred updates aren't really deferred anymore. It's important to report errors to the
143 -# user, and that means doing this before OutputPage::output(). Note that for page saves,
144 -# the client will wait until the script exits anyway before following the redirect.
145 -wfProfileIn( 'main-updates' );
146 -foreach( $wgDeferredUpdateList as $up ) {
147 - $up->doUpdate();
148 -}
149 -wfProfileOut( 'main-updates' );
150 -
151 -wfProfileIn( 'main-cleanup' );
152 -$wgLoadBalancer->saveMasterPos();
153 -
154 -# Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
155 -$wgLoadBalancer->commitAll();
156 -
157 -$wgOut->output();
158 -
159 -foreach( $wgPostCommitUpdateList as $up ) {
160 - $up->doUpdate();
161 -}
162 -
163 -wfProfileOut( 'main-cleanup' );
164 -
165 -wfProfileClose();
166 -logProfilingData();
167 -$wgLoadBalancer->closeAll();
168 -wfDebug( "Request ended normally\n" );
 124+$mediaWiki->restInPeace( $wgLoadBalancer );
169125 ?>

Status & tagging log