Rename mw.util.wikiGetlink to getUrl
[lhc/web/wiklou.git] / includes / Wiki.php
index cb0f60a..50bba7b 100644 (file)
@@ -85,8 +85,6 @@ class MediaWiki {
                } elseif ( $curid ) {
                        // URLs like this are generated by RC, because rc_title isn't always accurate
                        $ret = Title::newFromID( $curid );
-               } elseif ( $title == '' && $action != 'delete' ) {
-                       $ret = Title::newMainPage();
                } else {
                        $ret = Title::newFromURL( $title );
                        // Alias NS_MEDIA page URLs to NS_FILE...we only use NS_MEDIA
@@ -102,8 +100,12 @@ class MediaWiki {
                                $wgContLang->findVariantLink( $title, $ret );
                        }
                }
-               // For non-special titles, check for implicit titles
-               if ( is_null( $ret ) || !$ret->isSpecialPage() ) {
+
+               // If title is not provided, always allow oldid and diff to set the title.
+               // If title is provided, allow oldid and diff to override the title, unless
+               // we are talking about a special page which might use these parameters for
+               // other purposes.
+               if ( $ret === null || !$ret->isSpecialPage() ) {
                        // We can have urls with just ?diff=,?oldid= or even just ?diff=
                        $oldid = $request->getInt( 'oldid' );
                        $oldid = $oldid ? $oldid : $request->getInt( 'diff' );
@@ -114,6 +116,11 @@ class MediaWiki {
                        }
                }
 
+               // Use the main page as default title if nothing else has been provided
+               if ( $ret === null && strval( $title ) === '' && $action !== 'delete' ) {
+                       $ret = Title::newMainPage();
+               }
+
                if ( $ret === null || ( $ret->getDBkey() == '' && $ret->getInterwiki() == '' ) ) {
                        $ret = SpecialPage::getTitleFor( 'Badtitle' );
                }
@@ -295,19 +302,13 @@ class MediaWiki {
                        $article = $this->initializeArticle();
                        if ( is_object( $article ) ) {
                                $pageView = true;
-                               /**
-                                * $wgArticle is deprecated, do not use it.
-                                * @deprecated since 1.18
-                                */
-                               global $wgArticle;
-                               $wgArticle = new DeprecatedGlobal( 'wgArticle', $article, '1.18' );
-
                                $this->performAction( $article, $requestTitle );
                        } elseif ( is_string( $article ) ) {
                                $output->redirect( $article );
                        } else {
                                wfProfileOut( __METHOD__ );
-                               throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
+                               throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle()"
+                                       . " returned neither an object nor a URL" );
                        }
                }
 
@@ -427,7 +428,8 @@ class MediaWiki {
 
                $act = $this->getAction();
 
-               $action = Action::factory( $act, $page );
+               $action = Action::factory( $act, $page, $this->context );
+
                if ( $action instanceof Action ) {
                        # Let Squid cache things if we can purge them.
                        if ( $wgUseSquid &&
@@ -502,23 +504,6 @@ class MediaWiki {
 
                $request = $this->context->getRequest();
 
-               if ( $request->getCookie( 'forceHTTPS' )
-                       && $request->detectProtocol() == 'http'
-                       && $request->getMethod() == 'GET'
-               ) {
-                       $redirUrl = $request->getFullRequestURL();
-                       $redirUrl = str_replace( 'http://', 'https://', $redirUrl );
-
-                       // Setup dummy Title, otherwise OutputPage::redirect will fail
-                       $title = Title::newFromText( NS_MAIN, 'REDIR' );
-                       $this->context->setTitle( $title );
-                       $output = $this->context->getOutput();
-                       $output->redirect( $redirUrl );
-                       $output->output();
-                       wfProfileOut( __METHOD__ );
-                       return;
-               }
-
                // Send Ajax requests to the Ajax dispatcher.
                if ( $wgUseAjax && $request->getVal( 'action', 'view' ) == 'ajax' ) {
 
@@ -539,6 +524,51 @@ class MediaWiki {
                $action = $this->getAction();
                $wgTitle = $title;
 
+               // If the user has forceHTTPS set to true, or if the user
+               // is in a group requiring HTTPS, or if they have the HTTPS
+               // preference set, redirect them to HTTPS.
+               // Note: Do this after $wgTitle is setup, otherwise the hooks run from
+               // isLoggedIn() will do all sorts of weird stuff.
+               if (
+                       (
+                               $request->getCookie( 'forceHTTPS', '' ) ||
+                               // check for prefixed version for currently logged in users
+                               $request->getCookie( 'forceHTTPS' ) ||
+                               // Avoid checking the user and groups unless it's enabled.
+                               (
+                                       $this->context->getUser()->isLoggedIn()
+                                       && $this->context->getUser()->requiresHTTPS()
+                               )
+                       ) &&
+                       $request->getProtocol() == 'http'
+               ) {
+                       $oldUrl = $request->getFullRequestURL();
+                       $redirUrl = str_replace( 'http://', 'https://', $oldUrl );
+
+                       if ( $request->wasPosted() ) {
+                               // This is weird and we'd hope it almost never happens. This
+                               // means that a POST came in via HTTP and policy requires us
+                               // redirecting to HTTPS. It's likely such a request is going
+                               // to fail due to post data being lost, but let's try anyway
+                               // and just log the instance.
+                               //
+                               // @todo @fixme See if we could issue a 307 or 308 here, need
+                               // to see how clients (automated & browser) behave when we do
+                               wfDebugLog( 'RedirectedPosts', "Redirected from HTTP to HTTPS: $oldUrl" );
+                       }
+
+                       // Setup dummy Title, otherwise OutputPage::redirect will fail
+                       $title = Title::newFromText( NS_MAIN, 'REDIR' );
+                       $this->context->setTitle( $title );
+                       $output = $this->context->getOutput();
+                       // Since we only do this redir to change proto, always send a vary header
+                       $output->addVaryHeader( 'X-Forwarded-Proto' );
+                       $output->redirect( $redirUrl );
+                       $output->output();
+                       wfProfileOut( __METHOD__ );
+                       return;
+               }
+
                if ( $wgUseFileCache && $title->getNamespace() >= 0 ) {
                        wfProfileIn( 'main-try-filecache' );
                        if ( HTMLFileCache::useFileCache( $this->context ) ) {
@@ -551,6 +581,7 @@ class MediaWiki {
                                                $cache->loadFromFileCache( $this->context );
                                        }
                                        // Do any stats increment/watchlist stuff
+                                       // Assume we're viewing the latest revision (this should always be the case with file cache)
                                        $this->context->getWikiPage()->doViewUpdates( $this->context->getUser() );
                                        // Tell OutputPage that output is taken care of
                                        $this->context->getOutput()->disable();
@@ -650,7 +681,7 @@ class MediaWiki {
                                // We don't want exceptions thrown during job execution to
                                // be reported to the user since the output is already sent.
                                // Instead we just log them.
-                               wfDebugLog( 'exception', $e->getLogMessage() );
+                               MWExceptionHandler::logException( $e );
                        }
                }
        }