Refactor deferrable updates into classes & interfaces, also add helper method for...
[lhc/web/wiklou.git] / includes / Wiki.php
index 11aeace..ca8584b 100644 (file)
@@ -99,7 +99,7 @@ class MediaWiki {
                }
 
                if ( $ret === null || ( $ret->getDBkey() == '' && $ret->getInterwiki() == '' ) ) {
-                       $ret = new BadTitle;
+                       $ret = SpecialPage::getTitleFor( 'Badtitle' );
                }
 
                return $ret;
@@ -147,7 +147,8 @@ class MediaWiki {
                        array( &$title, null, &$output, &$user, $request, $this ) );
 
                // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
-               if ( $title instanceof BadTitle ) {
+               if ( is_null( $title ) || ( ( $title->getDBkey() == '' ) && ( $title->getInterwiki() == '' ) ) ) {
+                       $this->context->title = SpecialPage::getTitleFor( 'Badtitle' );
                        throw new ErrorPageError( 'badtitle', 'badtitletext' );
                // If the user is not logged in, the Namespace:title of the article must be in
                // the Read array in order for the user to see it. (We have to check here to
@@ -171,7 +172,7 @@ class MediaWiki {
                                // 301 so google et al report the target as the actual url.
                                $output->redirect( $url, 301 );
                        } else {
-                               $this->context->setTitle( new BadTitle );
+                               $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
                                wfProfileOut( __METHOD__ );
                                throw new ErrorPageError( 'badtitle', 'badtitletext' );
                        }
@@ -187,7 +188,7 @@ class MediaWiki {
                                        $title = SpecialPage::getTitleFor( $name, $subpage );
                                }
                        }
-                       $targetUrl = $title->getFullURL();
+                       $targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
                        // Redirect to canonical url, make it a 301 to allow caching
                        if ( $targetUrl == $request->getFullRequestURL() ) {
                                $message = "Redirect loop detected!\n\n" .
@@ -228,7 +229,7 @@ class MediaWiki {
                                /**
                                 * $wgArticle is deprecated, do not use it. This will possibly be removed
                                 * entirely in 1.20 or 1.21
-                                * @deprecated since 1.19
+                                * @deprecated since 1.18
                                 */
                                global $wgArticle;
                                $wgArticle = $article;
@@ -253,7 +254,7 @@ class MediaWiki {
        /**
         * Create an Article object of the appropriate class for the given page.
         *
-        * @deprecated in 1.19; use Article::newFromTitle() instead
+        * @deprecated in 1.18; use Article::newFromTitle() instead
         * @param $title Title
         * @param $context RequestContext
         * @return Article object
@@ -277,21 +278,21 @@ class MediaWiki {
 
                // Check for disabled actions
                if ( in_array( $action, $wgDisabledActions ) ) {
-                       $action = 'nosuchaction';
-               } elseif ( $action === 'historysubmit' ) {
-                       // Workaround for bug #20966: inability of IE to provide an action dependent
-                       // on which submit button is clicked.
+                       return 'nosuchaction';
+               }
+
+               // Workaround for bug #20966: inability of IE to provide an action dependent
+               // on which submit button is clicked.
+               if ( $action === 'historysubmit' ) {
                        if ( $request->getBool( 'revisiondelete' ) ) {
-                               $action = 'revisiondelete';
+                               return 'revisiondelete';
                        } else {
-                               $action = 'view';
+                               return 'view';
                        }
                } elseif ( $action == 'editredlink' ) {
-                       $action = 'edit';
+                       return 'edit';
                }
-               
-               // Write back the executed action
-               $request->setVal( 'action', $action );
+
                return $action;
        }
 
@@ -376,7 +377,7 @@ class MediaWiki {
                // Output everything!
                $this->context->getOutput()->output();
                // Do any deferred jobs
-               wfDoUpdates( 'commit' );
+               DeferredUpdates::doUpdates( 'commit' );
                $this->doJobs();
                wfProfileOut( __METHOD__ );
        }
@@ -453,7 +454,7 @@ class MediaWiki {
                $act = $this->getAction();
 
                $action = Action::factory( $act, $article );
-               if( $action instanceof Action ){
+               if ( $action instanceof Action ) {
                        $action->show();
                        wfProfileOut( __METHOD__ );
                        return;
@@ -498,7 +499,7 @@ class MediaWiki {
                                                && ( $external || $user->getOption( 'externaleditor' ) ) )
                                        {
                                                $mode = $request->getVal( 'mode' );
-                                               $extedit = new ExternalEdit( $article, $mode );
+                                               $extedit = new ExternalEdit( $article->getTitle(), $mode );
                                                $extedit->edit();
                                        }
                                }
@@ -512,7 +513,6 @@ class MediaWiki {
                                break;
                        default:
                                if ( wfRunHooks( 'UnknownAction', array( $act, $article ) ) ) {
-                                       $request->setVal( 'action', 'nosuchaction' );
                                        $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
                                }
                }
@@ -551,10 +551,11 @@ class MediaWiki {
                        list( $host, $lag ) = $lb->getMaxLag();
                        if ( $lag > $maxLag ) {
                                if ( $abort ) {
-                                       header( 'HTTP/1.1 503 Service Unavailable' );
-                                       header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
-                                       header( 'X-Database-Lag: ' . intval( $lag ) );
-                                       header( 'Content-Type: text/plain' );
+                                       $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 {
@@ -564,8 +565,9 @@ class MediaWiki {
 
                                wfProfileOut( __METHOD__ );
 
-                               if ( !$abort )
+                               if ( !$abort ) {
                                        return false;
+                               }
                                exit;
                        }
                }