Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -460,6 +460,8 @@ |
461 | 461 | * Cleanup and error checking on Special:Listredirects |
462 | 462 | * Clear up some instances of old OutputPage::sysopRequired() function usage |
463 | 463 | * 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 |
464 | 466 | |
465 | 467 | === Caveats === |
466 | 468 | |
Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -42,6 +42,7 @@ |
43 | 43 | */ |
44 | 44 | function initialize ( &$title, &$output, &$user, $request ) { |
45 | 45 | wfProfileIn( 'MediaWiki::initialize' ); |
| 46 | + $this->preliminaryChecks ( $title , $output , $request ) ; |
46 | 47 | $article = NULL; |
47 | 48 | if ( !$this->initializeSpecialCases( $title, $output, $request ) ) { |
48 | 49 | $article = $this->initializeArticle( $title, $request ); |
— | — | @@ -51,6 +52,30 @@ |
52 | 53 | return $article; |
53 | 54 | } |
54 | 55 | |
| 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 | + |
55 | 80 | /** |
56 | 81 | * Initialize the object to be known as $wgArticle for special cases |
57 | 82 | */ |
— | — | @@ -147,6 +172,42 @@ |
148 | 173 | } |
149 | 174 | |
150 | 175 | /** |
| 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 | + /** |
151 | 212 | * Perform one of the "standard" actions |
152 | 213 | */ |
153 | 214 | function performAction( &$output, &$article, &$title, &$user, &$request ) { |
— | — | @@ -243,8 +304,9 @@ |
244 | 305 | $output->errorpage( 'nosuchaction', 'nosuchactiontext' ); |
245 | 306 | } |
246 | 307 | wfProfileOut( 'MediaWiki::performAction' ); |
| 308 | + } |
247 | 309 | |
248 | | - } |
| 310 | + |
249 | 311 | } |
250 | 312 | |
251 | 313 | }; /* End of class MediaWiki */ |
Index: trunk/phase3/index.php |
— | — | @@ -98,34 +98,14 @@ |
99 | 99 | } |
100 | 100 | wfProfileOut( 'main-misc-setup' ); |
101 | 101 | |
102 | | -# Debug statement for user levels |
103 | | -// print_r($wgUser); |
104 | 102 | |
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 | | - |
123 | 103 | # Initialize MediaWiki base class |
124 | 104 | require_once( "includes/Wiki.php" ); |
125 | 105 | $mediaWiki = new MediaWiki(); |
126 | 106 | |
| 107 | +# Setting global variables in mediaWiki |
127 | 108 | $mediaWiki->setVal( "Server", $wgServer ); |
128 | 109 | $mediaWiki->setVal( "DisableInternalSearch", $wgDisableInternalSearch ); |
129 | | -$mediaWiki->setVal( "Search", $search ); |
130 | 110 | $mediaWiki->setVal( "action", $action ); |
131 | 111 | $mediaWiki->setVal( "SquidMaxage", $wgSquidMaxage ); |
132 | 112 | $mediaWiki->setVal( "EnableDublinCoreRdf", $wgEnableDublinCoreRdf ); |
— | — | @@ -135,34 +115,10 @@ |
136 | 116 | $mediaWiki->setVal( "DisabledActions", $wgDisabledActions ); |
137 | 117 | |
138 | 118 | $wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest ); |
| 119 | +$mediaWiki->finalCleanup ( $wgDeferredUpdateList , $wgLoadBalancer , $wgOut ) ; |
139 | 120 | |
140 | | -wfProfileOut( 'main-action' ); |
| 121 | +# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup |
| 122 | +$mediaWiki->doUpdates( $wgPostCommitUpdateList ); |
141 | 123 | |
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 ); |
169 | 125 | ?> |