Merge "Drop index oi_name_archive_name on table oldimage"
[lhc/web/wiklou.git] / includes / MediaWiki.php
index f7e57fc..521c02c 100644 (file)
@@ -22,6 +22,8 @@
 
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\ChronologyProtector;
+use Wikimedia\Rdbms\LBFactory;
 
 /**
  * The MediaWiki class is the helper class for the index.php entry point.
@@ -71,7 +73,7 @@ class MediaWiki {
                if ( $request->getCheck( 'search' ) ) {
                        // Compatibility with old search URLs which didn't use Special:Search
                        // Just check for presence here, so blank requests still
-                       // show the search page when using ugly URLs (bug 8054).
+                       // show the search page when using ugly URLs (T10054).
                        $ret = SpecialPage::getTitleFor( 'Search' );
                } elseif ( $curid ) {
                        // URLs like this are generated by RC, because rc_title isn't always accurate
@@ -181,7 +183,7 @@ class MediaWiki {
                $unused = null; // To pass it by reference
                Hooks::run( 'BeforeInitialize', [ &$title, &$unused, &$output, &$user, $request, $this ] );
 
-               // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
+               // Invalid titles. T23776: The interwikis must redirect even if the page name is empty.
                if ( is_null( $title ) || ( $title->getDBkey() == '' && !$title->isExternal() )
                        || $title->isSpecial( 'Badtitle' )
                ) {
@@ -201,7 +203,7 @@ class MediaWiki {
                        ? [] // relies on HMAC key signature alone
                        : $title->getUserPermissionsErrors( 'read', $user );
                if ( count( $permErrors ) ) {
-                       // Bug 32276: allowing the skin to generate output with $wgTitle or
+                       // T34276: allowing the skin to generate output with $wgTitle or
                        // $this->context->title set to the input title would allow anonymous users to
                        // determine whether a page exists, potentially leaking private data. In fact, the
                        // curid and oldid request  parameters would allow page titles to be enumerated even
@@ -313,8 +315,6 @@ class MediaWiki {
         * - Normalise empty title:
         *   /wiki/ -> /wiki/Main
         *   /w/index.php?title= -> /wiki/Main
-        * - Normalise non-standard title urls:
-        *   /w/index.php?title=Foo_Bar -> /wiki/Foo_Bar
         * - Don't redirect anything with query parameters other than 'title' or 'action=view'.
         *
         * @param Title $title
@@ -327,6 +327,8 @@ class MediaWiki {
 
                if ( $request->getVal( 'action', 'view' ) != 'view'
                        || $request->wasPosted()
+                       || ( $request->getVal( 'title' ) !== null
+                               && $title->getPrefixedDBkey() == $request->getVal( 'title' ) )
                        || count( $request->getValueNames( [ 'action', 'title' ] ) )
                        || !Hooks::run( 'TestCanonicalRedirect', [ $request, $title, $output ] )
                ) {
@@ -341,19 +343,7 @@ class MediaWiki {
                }
                // Redirect to canonical url, make it a 301 to allow caching
                $targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
-
-               if ( $targetUrl != $request->getFullRequestURL() ) {
-                       $output->setCdnMaxage( 1200 );
-                       $output->redirect( $targetUrl, '301' );
-                       return true;
-               }
-
-               // If there is no title, or the title is in a non-standard encoding, we demand
-               // a redirect. If cgi somehow changed the 'title' query to be non-standard while
-               // the url is standard, the server is misconfigured.
-               if ( $request->getVal( 'title' ) === null
-                       || $title->getPrefixedDBkey() != $request->getVal( 'title' )
-               ) {
+               if ( $targetUrl == $request->getFullRequestURL() ) {
                        $message = "Redirect loop detected!\n\n" .
                                "This means the wiki got confused about what page was " .
                                "requested; this sometimes happens when moving a wiki " .
@@ -375,7 +365,9 @@ class MediaWiki {
                        }
                        throw new HttpError( 500, $message );
                }
-               return false;
+               $output->setSquidMaxage( 1200 );
+               $output->redirect( $targetUrl, '301' );
+               return true;
        }
 
        /**
@@ -505,8 +497,15 @@ class MediaWiki {
                        $action->show();
                        return;
                }
-
-               if ( Hooks::run( 'UnknownAction', [ $request->getVal( 'action', 'view' ), $page ] ) ) {
+               // NOTE: deprecated hook. Add to $wgActions instead
+               if ( Hooks::run(
+                       'UnknownAction',
+                       [
+                               $request->getVal( 'action', 'view' ),
+                               $page
+                       ],
+                       '1.19'
+               ) ) {
                        $output->setStatusCode( 404 );
                        $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
                }
@@ -521,7 +520,7 @@ class MediaWiki {
                        try {
                                $this->main();
                        } catch ( ErrorPageError $e ) {
-                               // Bug 62091: while exceptions are convenient to bubble up GUI errors,
+                               // T64091: while exceptions are convenient to bubble up GUI errors,
                                // they are not internal application faults. As with normal requests, this
                                // should commit, print the output, do deferred updates, jobs, and profiling.
                                $this->doPreOutputCommit();