+ /**
+ * Checks if the request should abort due to a lagged server,
+ * for given maxlag parameter.
+ *
+ * @param boolean $abort True if this class should abort the
+ * script execution. False to return the result as a boolean.
+ * @return boolean True if we passed the check, false if we surpass the maxlag
+ */
+ private function checkMaxLag( $abort ) {
+ global $wgShowHostnames;
+
+ wfProfileIn( __METHOD__ );
+ $maxLag = $this->context->getRequest()->getVal( 'maxlag' );
+ if ( !is_null( $maxLag ) ) {
+ $lb = wfGetLB(); // foo()->bar() is not supported in PHP4
+ list( $host, $lag ) = $lb->getMaxLag();
+ if ( $lag > $maxLag ) {
+ if ( $abort ) {
+ $resp = $this->context->getRequest()->response();
+ $resp->header( 'HTTP/1.1 503 Service Unavailable' );
+ $resp->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
+ $resp->header( 'X-Database-Lag: ' . intval( $lag ) );
+ $resp->header( 'Content-Type: text/plain' );
+ if( $wgShowHostnames ) {
+ echo "Waiting for $host: $lag seconds lagged\n";
+ } else {
+ echo "Waiting for a database server: $lag seconds lagged\n";
+ }
+ }
+
+ wfProfileOut( __METHOD__ );
+
+ if ( !$abort ) {
+ return false;
+ }
+ exit;
+ }
+ }
+ wfProfileOut( __METHOD__ );
+ return true;
+ }
+
+ private function main() {
+ global $wgUseFileCache, $wgTitle, $wgUseAjax;
+
+ wfProfileIn( __METHOD__ );
+
+ # Set title from request parameters
+ $wgTitle = $this->getTitle();
+ $action = $this->getAction();
+ $user = $this->context->getUser();
+
+ # Send Ajax requests to the Ajax dispatcher.
+ if ( $wgUseAjax && $action == 'ajax' ) {
+ $dispatcher = new AjaxDispatcher();
+ $dispatcher->performAction();
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+
+ if ( $wgUseFileCache && $wgTitle->getNamespace() != NS_SPECIAL ) {
+ wfProfileIn( 'main-try-filecache' );
+ // Raw pages should handle cache control on their own,
+ // even when using file cache. This reduces hits from clients.
+ if ( HTMLFileCache::useFileCache() ) {
+ /* Try low-level file cache hit */
+ $cache = new HTMLFileCache( $wgTitle, $action );
+ if ( $cache->isFileCacheGood( /* Assume up to date */ ) ) {
+ /* Check incoming headers to see if client has this cached */
+ $timestamp = $cache->fileCacheTime();
+ if ( !$this->context->getOutput()->checkLastModified( $timestamp ) ) {
+ $cache->loadFromFileCache();
+ }
+ # Do any stats increment/watchlist stuff
+ $article = WikiPage::factory( $wgTitle );
+ $article->doViewUpdates( $user );
+ # Tell OutputPage that output is taken care of
+ $this->context->getOutput()->disable();
+ wfProfileOut( 'main-try-filecache' );
+ wfProfileOut( __METHOD__ );
+ return;
+ }
+ }
+ wfProfileOut( 'main-try-filecache' );
+ }
+
+ $this->performRequest();
+ $this->finalCleanup();
+
+ wfProfileOut( __METHOD__ );
+ }