diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /includes/Wiki.php | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'includes/Wiki.php')
-rw-r--r-- | includes/Wiki.php | 145 |
1 files changed, 101 insertions, 44 deletions
diff --git a/includes/Wiki.php b/includes/Wiki.php index f8f699c9..ae75bf33 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -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' ); } @@ -126,7 +133,7 @@ class MediaWiki { * @return Title */ public function getTitle() { - if( $this->context->getTitle() === null ) { + if ( $this->context->getTitle() === null ) { $this->context->setTitle( $this->parseTitle() ); } return $this->context->getTitle(); @@ -227,7 +234,7 @@ class MediaWiki { if ( $title->getInterwiki() != '' ) { $rdfrom = $request->getVal( 'rdfrom' ); if ( $rdfrom ) { - $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) ); + $url = $title->getFullURL( array( 'rdfrom' => $rdfrom ) ); } else { $query = $request->getValues(); unset( $query['title'] ); @@ -307,7 +314,8 @@ class MediaWiki { $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 +435,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 && @@ -480,7 +489,7 @@ class MediaWiki { $resp->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) ); $resp->header( 'X-Database-Lag: ' . intval( $lag ) ); $resp->header( 'Content-Type: text/plain' ); - if( $wgShowHostnames ) { + if ( $wgShowHostnames ) { echo "Waiting for $host: $lag seconds lagged\n"; } else { echo "Waiting for a database server: $lag seconds lagged\n"; @@ -502,23 +511,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 +531,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->detectProtocol() == '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 ) ) { @@ -599,7 +636,7 @@ class MediaWiki { * Do a job from the job queue */ private function doJobs() { - global $wgJobRunRate; + global $wgJobRunRate, $wgPhpCli, $IP; if ( $wgJobRunRate <= 0 || wfReadOnly() ) { return; @@ -615,23 +652,43 @@ class MediaWiki { $n = intval( $wgJobRunRate ); } - $group = JobQueueGroup::singleton(); - do { - $job = $group->pop( JobQueueGroup::USE_CACHE ); // job from any queue - if ( $job ) { - $output = $job->toString() . "\n"; - $t = - microtime( true ); - $success = $job->run(); - $group->ack( $job ); // done - $t += microtime( true ); - $t = round( $t * 1000 ); - if ( !$success ) { - $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n"; - } else { - $output .= "Success, Time: $t ms\n"; - } - wfDebugLog( 'jobqueue', $output ); + if ( !wfShellExecDisabled() && is_executable( $wgPhpCli ) ) { + // Start a background process to run some of the jobs. + // This will be asynchronous on *nix though not on Windows. + wfProfileIn( __METHOD__ . '-exec' ); + $retVal = 1; + $cmd = wfShellWikiCmd( "$IP/maintenance/runJobs.php", array( '--maxjobs', $n ) ); + wfShellExec( "$cmd &", $retVal ); + wfProfileOut( __METHOD__ . '-exec' ); + } else { + try { + // Fallback to running the jobs here while the user waits + $group = JobQueueGroup::singleton(); + do { + $job = $group->pop( JobQueueGroup::USE_CACHE ); // job from any queue + if ( $job ) { + $output = $job->toString() . "\n"; + $t = - microtime( true ); + wfProfileIn( __METHOD__ . '-' . get_class( $job ) ); + $success = $job->run(); + wfProfileOut( __METHOD__ . '-' . get_class( $job ) ); + $group->ack( $job ); // done + $t += microtime( true ); + $t = round( $t * 1000 ); + if ( $success === false ) { + $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n"; + } else { + $output .= "Success, Time: $t ms\n"; + } + wfDebugLog( 'jobqueue', $output ); + } + } while ( --$n && $job ); + } catch ( MWException $e ) { + // 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. + MWExceptionHandler::logException( $e ); } - } while ( --$n && $job ); + } } } |