Big oops - merged to wrong branch.
[lhc/web/wiklou.git] / includes / Wiki.php
index eaa3996..08e06ea 100644 (file)
@@ -167,7 +167,7 @@ class MediaWiki {
                {
                        $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
                        wfProfileOut( __METHOD__ );
-                       throw new ErrorPageError( 'badtitle', 'badtitletext' );
+                       throw new BadTitleError();
                }
 
                // Check user's permissions to read this page.
@@ -214,7 +214,7 @@ class MediaWiki {
                        } else {
                                $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
                                wfProfileOut( __METHOD__ );
-                               throw new ErrorPageError( 'badtitle', 'badtitletext' );
+                               throw new BadTitleError();
                        }
                // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
                } elseif ( $request->getVal( 'action', 'view' ) == 'view' && !$request->wasPosted()
@@ -269,11 +269,10 @@ class MediaWiki {
                                $pageView = true;
                                /**
                                 * $wgArticle is deprecated, do not use it.
-                                * This will be removed entirely in 1.20.
                                 * @deprecated since 1.18
                                 */
                                global $wgArticle;
-                               $wgArticle = $article;
+                               $wgArticle = new DeprecatedGlobal( 'wgArticle', $article, '1.18' );
 
                                $this->performAction( $article );
                        } elseif ( is_string( $article ) ) {
@@ -431,9 +430,9 @@ class MediaWiki {
 
                while ( $n-- && false != ( $job = Job::pop() ) ) {
                        $output = $job->toString() . "\n";
-                       $t = -wfTime();
+                       $t = - microtime( true );
                        $success = $job->run();
-                       $t += wfTime();
+                       $t += microtime( true );
                        $t = round( $t * 1000 );
                        if ( !$success ) {
                                $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n";
@@ -460,10 +459,10 @@ class MediaWiki {
        /**
         * Perform one of the "standard" actions
         *
-        * @param $article Article
+        * @param $page Page
         */
-       private function performAction( Page $article ) {
-               global $wgSquidMaxage;
+       private function performAction( Page $page ) {
+               global $wgUseSquid, $wgSquidMaxage;
 
                wfProfileIn( __METHOD__ );
 
@@ -473,7 +472,7 @@ class MediaWiki {
                $user = $this->context->getUser();
 
                if ( !wfRunHooks( 'MediaWikiPerformAction',
-                       array( $output, $article, $title, $user, $request, $this ) ) )
+                       array( $output, $page, $title, $user, $request, $this ) ) )
                {
                        wfProfileOut( __METHOD__ );
                        return;
@@ -481,14 +480,23 @@ class MediaWiki {
 
                $act = $this->getAction();
 
-               $action = Action::factory( $act, $article );
+               $action = Action::factory( $act, $page );
                if ( $action instanceof Action ) {
+                       # When it's a known action, let Squid cache things if we can purge them.
+                       # If the action is unknown, we don't know what may happen in an extension,
+                       # but not caching can be always safe.
+                       if ( $wgUseSquid &&
+                               in_array( $request->getFullRequestURL(), $title->getSquidURLs() )
+                       ) {
+                               $output->setSquidMaxage( $wgSquidMaxage );
+                       }
+
                        $action->show();
                        wfProfileOut( __METHOD__ );
                        return;
                }
 
-               if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
+               if ( wfRunHooks( 'UnknownAction', array( $request->getVal( 'action', 'view' ), $page ) ) ) {
                        $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
                }
 
@@ -547,20 +555,28 @@ class MediaWiki {
 
                wfProfileIn( __METHOD__ );
 
-               // Get title from request parameters,
-               // is set on the fly by parseTitle the first time.
-               $title = $this->getTitle();
-               $action = $this->getAction();
-               $wgTitle = $title;
+               $request = $this->context->getRequest();
 
                // Send Ajax requests to the Ajax dispatcher.
-               if ( $wgUseAjax && true ) {
+               if ( $wgUseAjax && $request->getVal( 'action', 'view' ) == 'ajax' ) {
+
+                       // Set a dummy title, because $wgTitle == null might break things
+                       $title = Title::makeTitle( NS_MAIN, 'AJAX' );
+                       $this->context->setTitle( $title );
+                       $wgTitle = $title;
+
                        $dispatcher = new AjaxDispatcher();
                        $dispatcher->performAction();
                        wfProfileOut( __METHOD__ );
                        return;
                }
 
+               // Get title from request parameters,
+               // is set on the fly by parseTitle the first time.
+               $title = $this->getTitle();
+               $action = $this->getAction();
+               $wgTitle = $title;
+
                if ( $wgUseFileCache && $title->getNamespace() >= 0 ) {
                        wfProfileIn( 'main-try-filecache' );
                        if ( HTMLFileCache::useFileCache( $this->context ) ) {