2011-05-04 17:23:14 +00:00
|
|
|
<?php
|
2006-01-11 09:24:34 +00:00
|
|
|
/**
|
2011-06-28 17:20:16 +00:00
|
|
|
* Helper class for the index.php entry point.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2015-03-23 00:53:24 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2016-08-08 21:55:56 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2015-03-23 00:53:24 +00:00
|
|
|
|
2011-06-28 17:20:16 +00:00
|
|
|
/**
|
|
|
|
|
* The MediaWiki class is the helper class for the index.php entry point.
|
2006-01-11 09:24:34 +00:00
|
|
|
*/
|
Provisional revert of r89406, r89414: reference-related warnings need cleanup before applying code like this
Per CR http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89406#c17545 :
'Here is a third one: Strict Standards: Only variables should be passed by reference in /www/sandwiki/includes/Wiki.php on line 177 '
Offending bit is this:
- SpecialPageFactory::executePath( $this->context->title, $this->context );
+ SpecialPageFactory::executePath( $this->getTitle(), $this->getContext() );
That function demands reference paramters for $title and $context, which is being violated here where we now pass function return values:
public static function executePath( Title &$title, RequestContext &$context, $including = false ) {
The $title does sometimes get replaced within the function body, but $context does not appear to ever be replaced (its *contents* are modified, which does not require passing by reference)
If replacing it is something it should be doing, then we need to be able to replace it upstream presumably, so $this->getTitle() probably isn't appropriate.
The $context probably should have the reference simply removed.
2011-06-03 18:48:59 +00:00
|
|
|
class MediaWiki {
|
|
|
|
|
/**
|
2011-09-15 15:19:49 +00:00
|
|
|
* @var IContextSource
|
Provisional revert of r89406, r89414: reference-related warnings need cleanup before applying code like this
Per CR http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89406#c17545 :
'Here is a third one: Strict Standards: Only variables should be passed by reference in /www/sandwiki/includes/Wiki.php on line 177 '
Offending bit is this:
- SpecialPageFactory::executePath( $this->context->title, $this->context );
+ SpecialPageFactory::executePath( $this->getTitle(), $this->getContext() );
That function demands reference paramters for $title and $context, which is being violated here where we now pass function return values:
public static function executePath( Title &$title, RequestContext &$context, $including = false ) {
The $title does sometimes get replaced within the function body, but $context does not appear to ever be replaced (its *contents* are modified, which does not require passing by reference)
If replacing it is something it should be doing, then we need to be able to replace it upstream presumably, so $this->getTitle() probably isn't appropriate.
The $context probably should have the reference simply removed.
2011-06-03 18:48:59 +00:00
|
|
|
*/
|
|
|
|
|
private $context;
|
2011-04-03 21:32:50 +00:00
|
|
|
|
2014-08-07 20:38:09 +00:00
|
|
|
/**
|
|
|
|
|
* @var Config
|
|
|
|
|
*/
|
|
|
|
|
private $config;
|
|
|
|
|
|
2015-10-05 23:58:42 +00:00
|
|
|
/**
|
|
|
|
|
* @var String Cache what action this request is
|
|
|
|
|
*/
|
|
|
|
|
private $action;
|
|
|
|
|
|
2012-01-12 19:03:32 +00:00
|
|
|
/**
|
|
|
|
|
* @param IContextSource|null $context
|
|
|
|
|
*/
|
2011-09-15 15:19:49 +00:00
|
|
|
public function __construct( IContextSource $context = null ) {
|
2011-06-18 14:50:26 +00:00
|
|
|
if ( !$context ) {
|
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
|
}
|
2011-06-21 23:28:50 +00:00
|
|
|
|
Provisional revert of r89406, r89414: reference-related warnings need cleanup before applying code like this
Per CR http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89406#c17545 :
'Here is a third one: Strict Standards: Only variables should be passed by reference in /www/sandwiki/includes/Wiki.php on line 177 '
Offending bit is this:
- SpecialPageFactory::executePath( $this->context->title, $this->context );
+ SpecialPageFactory::executePath( $this->getTitle(), $this->getContext() );
That function demands reference paramters for $title and $context, which is being violated here where we now pass function return values:
public static function executePath( Title &$title, RequestContext &$context, $including = false ) {
The $title does sometimes get replaced within the function body, but $context does not appear to ever be replaced (its *contents* are modified, which does not require passing by reference)
If replacing it is something it should be doing, then we need to be able to replace it upstream presumably, so $this->getTitle() probably isn't appropriate.
The $context probably should have the reference simply removed.
2011-06-03 18:48:59 +00:00
|
|
|
$this->context = $context;
|
2014-08-07 20:38:09 +00:00
|
|
|
$this->config = $context->getConfig();
|
2011-04-03 19:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 19:33:15 +00:00
|
|
|
/**
|
2011-06-28 17:20:16 +00:00
|
|
|
* Parse the request to get the Title object
|
2008-03-19 19:55:26 +00:00
|
|
|
*
|
2015-04-25 22:43:37 +00:00
|
|
|
* @throws MalformedTitleException If a title has been provided by the user, but is invalid.
|
2014-04-20 19:16:57 +00:00
|
|
|
* @return Title Title object to be $wgTitle
|
2006-01-11 19:33:15 +00:00
|
|
|
*/
|
2011-04-03 21:32:50 +00:00
|
|
|
private function parseTitle() {
|
2010-12-16 20:11:53 +00:00
|
|
|
global $wgContLang;
|
|
|
|
|
|
2011-06-17 10:07:40 +00:00
|
|
|
$request = $this->context->getRequest();
|
|
|
|
|
$curid = $request->getInt( 'curid' );
|
|
|
|
|
$title = $request->getVal( 'title' );
|
2014-10-27 14:35:41 +00:00
|
|
|
$action = $request->getVal( 'action' );
|
2010-11-30 18:44:50 +00:00
|
|
|
|
2011-06-17 10:07:40 +00:00
|
|
|
if ( $request->getCheck( 'search' ) ) {
|
2010-12-06 17:42:14 +00:00
|
|
|
// 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).
|
|
|
|
|
$ret = SpecialPage::getTitleFor( 'Search' );
|
2011-04-03 15:56:29 +00:00
|
|
|
} elseif ( $curid ) {
|
2010-06-30 15:50:37 +00:00
|
|
|
// URLs like this are generated by RC, because rc_title isn't always accurate
|
2006-01-11 19:33:15 +00:00
|
|
|
$ret = Title::newFromID( $curid );
|
|
|
|
|
} else {
|
|
|
|
|
$ret = Title::newFromURL( $title );
|
2011-11-02 18:47:04 +00:00
|
|
|
// Alias NS_MEDIA page URLs to NS_FILE...we only use NS_MEDIA
|
|
|
|
|
// in wikitext links to tell Parser to make a direct file link
|
|
|
|
|
if ( !is_null( $ret ) && $ret->getNamespace() == NS_MEDIA ) {
|
|
|
|
|
$ret = Title::makeTitle( NS_FILE, $ret->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
// Check variant links so that interwiki links don't have to worry
|
2008-03-19 19:55:26 +00:00
|
|
|
// about the possible different language variants
|
2011-07-13 18:05:44 +00:00
|
|
|
if ( count( $wgContLang->getVariants() ) > 1
|
2013-12-01 20:39:00 +00:00
|
|
|
&& !is_null( $ret ) && $ret->getArticleID() == 0
|
|
|
|
|
) {
|
2008-03-26 18:57:37 +00:00
|
|
|
$wgContLang->findVariantLink( $title, $ret );
|
2011-04-04 23:09:21 +00:00
|
|
|
}
|
2006-01-11 19:33:15 +00:00
|
|
|
}
|
2013-09-28 16:57:23 +00:00
|
|
|
|
|
|
|
|
// 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() ) {
|
2009-01-07 13:23:12 +00:00
|
|
|
// We can have urls with just ?diff=,?oldid= or even just ?diff=
|
2011-06-17 10:07:40 +00:00
|
|
|
$oldid = $request->getInt( 'oldid' );
|
|
|
|
|
$oldid = $oldid ? $oldid : $request->getInt( 'diff' );
|
2009-01-07 13:23:12 +00:00
|
|
|
// Allow oldid to override a changed or missing title
|
2011-04-03 15:56:29 +00:00
|
|
|
if ( $oldid ) {
|
2009-01-07 13:23:12 +00:00
|
|
|
$rev = Revision::newFromId( $oldid );
|
|
|
|
|
$ret = $rev ? $rev->getTitle() : $ret;
|
2007-06-27 15:30:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-04-04 23:09:21 +00:00
|
|
|
|
2013-09-28 16:57:23 +00:00
|
|
|
// Use the main page as default title if nothing else has been provided
|
2014-05-11 15:34:55 +00:00
|
|
|
if ( $ret === null
|
|
|
|
|
&& strval( $title ) === ''
|
|
|
|
|
&& !$request->getCheck( 'curid' )
|
|
|
|
|
&& $action !== 'delete'
|
|
|
|
|
) {
|
2013-09-28 16:57:23 +00:00
|
|
|
$ret = Title::newMainPage();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-02 10:59:10 +00:00
|
|
|
if ( $ret === null || ( $ret->getDBkey() == '' && !$ret->isExternal() ) ) {
|
2015-04-25 22:43:37 +00:00
|
|
|
// If we get here, we definitely don't have a valid title; throw an exception.
|
|
|
|
|
// Try to get detailed invalid title exception first, fall back to MalformedTitleException.
|
|
|
|
|
Title::newFromTextThrow( $title );
|
2015-05-20 19:44:01 +00:00
|
|
|
throw new MalformedTitleException( 'badtitletext', $title );
|
2011-04-04 23:09:21 +00:00
|
|
|
}
|
2011-07-13 18:30:47 +00:00
|
|
|
|
2008-03-19 19:55:26 +00:00
|
|
|
return $ret;
|
2006-01-11 19:33:15 +00:00
|
|
|
}
|
2007-01-20 12:59:34 +00:00
|
|
|
|
2011-04-03 21:32:50 +00:00
|
|
|
/**
|
|
|
|
|
* Get the Title object that we'll be acting on, as specified in the WebRequest
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
2012-01-11 19:47:21 +00:00
|
|
|
public function getTitle() {
|
2014-09-26 17:18:43 +00:00
|
|
|
if ( !$this->context->hasTitle() ) {
|
2015-04-25 22:43:37 +00:00
|
|
|
try {
|
|
|
|
|
$this->context->setTitle( $this->parseTitle() );
|
|
|
|
|
} catch ( MalformedTitleException $ex ) {
|
|
|
|
|
$this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
|
|
|
|
|
}
|
2011-04-03 21:32:50 +00:00
|
|
|
}
|
2011-06-17 10:29:39 +00:00
|
|
|
return $this->context->getTitle();
|
2011-04-03 21:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-21 20:35:05 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the name of the action that will be executed.
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @return string Action
|
2012-07-21 20:35:05 +00:00
|
|
|
*/
|
|
|
|
|
public function getAction() {
|
2015-10-05 23:58:42 +00:00
|
|
|
if ( $this->action === null ) {
|
|
|
|
|
$this->action = Action::getActionName( $this->context );
|
2012-07-21 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-05 23:58:42 +00:00
|
|
|
return $this->action;
|
2012-07-21 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 12:25:41 +00:00
|
|
|
/**
|
2011-05-26 16:41:11 +00:00
|
|
|
* Performs the request.
|
2008-03-19 19:55:26 +00:00
|
|
|
* - bad titles
|
2011-05-26 16:41:11 +00:00
|
|
|
* - read restriction
|
2008-03-19 19:55:26 +00:00
|
|
|
* - local interwiki redirects
|
|
|
|
|
* - redirect loop
|
|
|
|
|
* - special pages
|
2011-05-26 16:41:11 +00:00
|
|
|
* - normal pages
|
2012-01-12 19:41:18 +00:00
|
|
|
*
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException|PermissionsError|BadTitleError|HttpError
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2006-01-11 12:25:41 +00:00
|
|
|
*/
|
2011-07-13 18:30:47 +00:00
|
|
|
private function performRequest() {
|
2014-08-07 20:38:09 +00:00
|
|
|
global $wgTitle;
|
2011-05-16 16:46:30 +00:00
|
|
|
|
2011-06-17 10:29:39 +00:00
|
|
|
$request = $this->context->getRequest();
|
2012-10-17 00:00:07 +00:00
|
|
|
$requestTitle = $title = $this->context->getTitle();
|
2011-06-17 10:29:39 +00:00
|
|
|
$output = $this->context->getOutput();
|
|
|
|
|
$user = $this->context->getUser();
|
|
|
|
|
|
|
|
|
|
if ( $request->getVal( 'printable' ) === 'yes' ) {
|
|
|
|
|
$output->setPrintable();
|
2011-05-26 16:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-18 14:48:23 +00:00
|
|
|
$unused = null; // To pass it by reference
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'BeforeInitialize', [ &$title, &$unused, &$output, &$user, $request, $this ] );
|
2011-12-18 14:48:23 +00:00
|
|
|
|
2009-12-07 18:28:25 +00:00
|
|
|
// Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
|
2014-01-02 10:59:10 +00:00
|
|
|
if ( is_null( $title ) || ( $title->getDBkey() == '' && !$title->isExternal() )
|
2013-12-01 20:39:00 +00:00
|
|
|
|| $title->isSpecial( 'Badtitle' )
|
|
|
|
|
) {
|
2011-10-03 14:04:43 +00:00
|
|
|
$this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
|
2015-04-25 22:43:37 +00:00
|
|
|
try {
|
|
|
|
|
$this->parseTitle();
|
|
|
|
|
} catch ( MalformedTitleException $ex ) {
|
|
|
|
|
throw new BadTitleError( $ex );
|
|
|
|
|
}
|
2012-01-25 10:51:37 +00:00
|
|
|
throw new BadTitleError();
|
2011-11-06 19:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check user's permissions to read this page.
|
|
|
|
|
// We have to check here to catch special pages etc.
|
|
|
|
|
// We will check again in Article::view().
|
2014-07-24 20:07:08 +00:00
|
|
|
$permErrors = $title->isSpecial( 'RunJobs' )
|
2016-02-17 09:09:32 +00:00
|
|
|
? [] // relies on HMAC key signature alone
|
2014-07-24 20:07:08 +00:00
|
|
|
: $title->getUserPermissionsErrors( 'read', $user );
|
2011-11-06 19:59:46 +00:00
|
|
|
if ( count( $permErrors ) ) {
|
2011-12-18 01:32:11 +00:00
|
|
|
// Bug 32276: 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
|
|
|
|
|
// when they are not guessable. So we reset the title to Special:Badtitle before the
|
2011-11-28 23:18:55 +00:00
|
|
|
// permissions error is displayed.
|
2015-10-14 07:46:44 +00:00
|
|
|
|
2011-12-18 01:32:11 +00:00
|
|
|
// The skin mostly uses $this->context->getTitle() these days, but some extensions
|
2011-11-28 23:18:55 +00:00
|
|
|
// still use $wgTitle.
|
|
|
|
|
$badTitle = SpecialPage::getTitleFor( 'Badtitle' );
|
|
|
|
|
$this->context->setTitle( $badTitle );
|
|
|
|
|
$wgTitle = $badTitle;
|
|
|
|
|
|
2011-11-06 19:59:46 +00:00
|
|
|
throw new PermissionsError( 'read', $permErrors );
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-28 03:43:07 +00:00
|
|
|
// Interwiki redirects
|
2014-01-02 10:59:10 +00:00
|
|
|
if ( $title->isExternal() ) {
|
2011-06-17 10:29:39 +00:00
|
|
|
$rdfrom = $request->getVal( 'rdfrom' );
|
2011-04-03 15:56:29 +00:00
|
|
|
if ( $rdfrom ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$url = $title->getFullURL( [ 'rdfrom' => $rdfrom ] );
|
2006-01-11 13:28:23 +00:00
|
|
|
} else {
|
2011-06-17 10:29:39 +00:00
|
|
|
$query = $request->getValues();
|
2009-08-04 16:31:19 +00:00
|
|
|
unset( $query['title'] );
|
2011-06-17 10:29:39 +00:00
|
|
|
$url = $title->getFullURL( $query );
|
2006-01-11 13:28:23 +00:00
|
|
|
}
|
2011-04-04 23:09:21 +00:00
|
|
|
// Check for a redirect loop
|
2014-08-07 20:38:09 +00:00
|
|
|
if ( !preg_match( '/^' . preg_quote( $this->config->get( 'Server' ), '/' ) . '/', $url )
|
2013-12-01 20:39:00 +00:00
|
|
|
&& $title->isLocal()
|
|
|
|
|
) {
|
2011-03-26 21:06:37 +00:00
|
|
|
// 301 so google et al report the target as the actual url.
|
2011-06-17 10:29:39 +00:00
|
|
|
$output->redirect( $url, 301 );
|
2006-01-11 13:28:23 +00:00
|
|
|
} else {
|
2011-08-25 21:03:52 +00:00
|
|
|
$this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
|
2015-04-25 22:43:37 +00:00
|
|
|
try {
|
|
|
|
|
$this->parseTitle();
|
|
|
|
|
} catch ( MalformedTitleException $ex ) {
|
|
|
|
|
throw new BadTitleError( $ex );
|
|
|
|
|
}
|
2012-01-25 10:51:37 +00:00
|
|
|
throw new BadTitleError();
|
2006-01-11 13:28:23 +00:00
|
|
|
}
|
2015-06-19 19:56:36 +00:00
|
|
|
// Handle any other redirects.
|
|
|
|
|
// Redirect loops, titleless URL, $wgUsePathInfo URLs, and URLs with a variant
|
|
|
|
|
} elseif ( !$this->tryNormaliseRedirect( $title ) ) {
|
2015-10-05 23:58:42 +00:00
|
|
|
// Prevent information leak via Special:MyPage et al (T109724)
|
|
|
|
|
if ( $title->isSpecialPage() ) {
|
2016-03-19 00:08:06 +00:00
|
|
|
$specialPage = SpecialPageFactory::getPage( $title->getDBkey() );
|
2016-02-02 19:56:25 +00:00
|
|
|
if ( $specialPage instanceof RedirectSpecialPage ) {
|
|
|
|
|
$specialPage->setContext( $this->context );
|
|
|
|
|
if ( $this->config->get( 'HideIdentifiableRedirects' )
|
|
|
|
|
&& $specialPage->personallyIdentifiableTarget()
|
|
|
|
|
) {
|
2016-03-19 00:08:06 +00:00
|
|
|
list( , $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
|
2016-02-02 19:56:25 +00:00
|
|
|
$target = $specialPage->getRedirect( $subpage );
|
|
|
|
|
// target can also be true. We let that case fall through to normal processing.
|
|
|
|
|
if ( $target instanceof Title ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$query = $specialPage->getRedirectQuery() ?: [];
|
2016-02-02 19:56:25 +00:00
|
|
|
$request = new DerivativeRequest( $this->context->getRequest(), $query );
|
|
|
|
|
$request->setRequestURL( $this->context->getRequest()->getRequestURL() );
|
|
|
|
|
$this->context->setRequest( $request );
|
|
|
|
|
// Do not varnish cache these. May vary even for anons
|
|
|
|
|
$this->context->getOutput()->lowerCdnMaxage( 0 );
|
|
|
|
|
$this->context->setTitle( $target );
|
|
|
|
|
$wgTitle = $target;
|
|
|
|
|
// Reset action type cache. (Special pages have only view)
|
|
|
|
|
$this->action = null;
|
|
|
|
|
$title = $target;
|
2016-02-17 09:09:32 +00:00
|
|
|
$output->addJsConfigVars( [
|
2016-02-02 19:56:25 +00:00
|
|
|
'wgInternalRedirectTargetUrl' => $target->getFullURL( $query ),
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2016-02-02 19:56:25 +00:00
|
|
|
$output->addModules( 'mediawiki.action.view.redirect' );
|
|
|
|
|
}
|
2015-10-05 23:58:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-01-20 12:59:34 +00:00
|
|
|
|
2015-10-05 23:58:42 +00:00
|
|
|
// Special pages ($title may have changed since if statement above)
|
2015-06-19 19:56:36 +00:00
|
|
|
if ( NS_SPECIAL == $title->getNamespace() ) {
|
|
|
|
|
// Actions that need to be made when we have a special pages
|
|
|
|
|
SpecialPageFactory::executePath( $title, $this->context );
|
|
|
|
|
} else {
|
|
|
|
|
// ...otherwise treat it as an article view. The article
|
|
|
|
|
// may still be a wikipage redirect to another article or URL.
|
|
|
|
|
$article = $this->initializeArticle();
|
|
|
|
|
if ( is_object( $article ) ) {
|
|
|
|
|
$this->performAction( $article, $requestTitle );
|
|
|
|
|
} elseif ( is_string( $article ) ) {
|
|
|
|
|
$output->redirect( $article );
|
2007-01-03 09:15:11 +00:00
|
|
|
} else {
|
2015-06-19 19:56:36 +00:00
|
|
|
throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle()"
|
|
|
|
|
. " returned neither an object nor a URL" );
|
2007-01-03 09:15:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-06-19 19:56:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle redirects for uncanonical title requests.
|
|
|
|
|
*
|
|
|
|
|
* Handles:
|
|
|
|
|
* - Redirect loops.
|
|
|
|
|
* - No title in URL.
|
|
|
|
|
* - $wgUsePathInfo URLs.
|
|
|
|
|
* - URLs with a variant.
|
|
|
|
|
* - Other non-standard URLs (as long as they have no extra query parameters).
|
|
|
|
|
*
|
|
|
|
|
* Behaviour:
|
|
|
|
|
* - Normalise title values:
|
|
|
|
|
* /wiki/Foo%20Bar -> /wiki/Foo_Bar
|
|
|
|
|
* - Normalise empty title:
|
|
|
|
|
* /wiki/ -> /wiki/Main
|
|
|
|
|
* /w/index.php?title= -> /wiki/Main
|
2015-06-19 20:07:24 +00:00
|
|
|
* - Normalise non-standard title urls:
|
|
|
|
|
* /w/index.php?title=Foo_Bar -> /wiki/Foo_Bar
|
2015-06-19 19:56:36 +00:00
|
|
|
* - Don't redirect anything with query parameters other than 'title' or 'action=view'.
|
|
|
|
|
*
|
2015-08-24 20:00:23 +00:00
|
|
|
* @param Title $title
|
2015-06-19 19:56:36 +00:00
|
|
|
* @return bool True if a redirect was set.
|
2015-08-24 20:00:23 +00:00
|
|
|
* @throws HttpError
|
2015-06-19 19:56:36 +00:00
|
|
|
*/
|
2015-08-24 20:00:23 +00:00
|
|
|
private function tryNormaliseRedirect( Title $title ) {
|
2015-06-19 19:56:36 +00:00
|
|
|
$request = $this->context->getRequest();
|
|
|
|
|
$output = $this->context->getOutput();
|
|
|
|
|
|
|
|
|
|
if ( $request->getVal( 'action', 'view' ) != 'view'
|
|
|
|
|
|| $request->wasPosted()
|
2016-02-17 09:09:32 +00:00
|
|
|
|| count( $request->getValueNames( [ 'action', 'title' ] ) )
|
|
|
|
|
|| !Hooks::run( 'TestCanonicalRedirect', [ $request, $title, $output ] )
|
2015-06-19 19:56:36 +00:00
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $title->isSpecialPage() ) {
|
|
|
|
|
list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
|
|
|
|
|
if ( $name ) {
|
|
|
|
|
$title = SpecialPage::getTitleFor( $name, $subpage );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Redirect to canonical url, make it a 301 to allow caching
|
|
|
|
|
$targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
|
2015-06-19 20:07:24 +00:00
|
|
|
|
|
|
|
|
if ( $targetUrl != $request->getFullRequestURL() ) {
|
2015-12-10 01:07:05 +00:00
|
|
|
$output->setCdnMaxage( 1200 );
|
2015-06-19 20:07:24 +00:00
|
|
|
$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' )
|
|
|
|
|
) {
|
2015-06-19 19:56:36 +00:00
|
|
|
$message = "Redirect loop detected!\n\n" .
|
|
|
|
|
"This means the wiki got confused about what page was " .
|
|
|
|
|
"requested; this sometimes happens when moving a wiki " .
|
|
|
|
|
"to a new server or changing the server configuration.\n\n";
|
|
|
|
|
|
|
|
|
|
if ( $this->config->get( 'UsePathInfo' ) ) {
|
|
|
|
|
$message .= "The wiki is trying to interpret the page " .
|
|
|
|
|
"title from the URL path portion (PATH_INFO), which " .
|
|
|
|
|
"sometimes fails depending on the web server. Try " .
|
|
|
|
|
"setting \"\$wgUsePathInfo = false;\" in your " .
|
|
|
|
|
"LocalSettings.php, or check that \$wgArticlePath " .
|
|
|
|
|
"is correct.";
|
2011-05-26 16:41:11 +00:00
|
|
|
} else {
|
2015-06-19 19:56:36 +00:00
|
|
|
$message .= "Your web server was detected as possibly not " .
|
|
|
|
|
"supporting URL path components (PATH_INFO) correctly; " .
|
|
|
|
|
"check your LocalSettings.php for a customized " .
|
|
|
|
|
"\$wgArticlePath setting and/or toggle \$wgUsePathInfo " .
|
|
|
|
|
"to true.";
|
2011-05-26 16:41:11 +00:00
|
|
|
}
|
2015-06-19 19:56:36 +00:00
|
|
|
throw new HttpError( 500, $message );
|
2006-01-11 12:25:41 +00:00
|
|
|
}
|
2015-06-19 20:07:24 +00:00
|
|
|
return false;
|
2006-01-11 12:25:41 +00:00
|
|
|
}
|
2006-01-10 14:58:06 +00:00
|
|
|
|
2006-01-13 00:29:20 +00:00
|
|
|
/**
|
2011-05-22 17:59:47 +00:00
|
|
|
* Initialize the main Article object for "standard" actions (view, etc)
|
2006-01-13 00:29:20 +00:00
|
|
|
* Create an Article object for the page, following redirects if needed.
|
2008-03-19 19:55:26 +00:00
|
|
|
*
|
2015-12-23 20:19:13 +00:00
|
|
|
* @return Article|string An Article, or a string to redirect to another URL
|
2006-01-13 00:29:20 +00:00
|
|
|
*/
|
2011-04-03 21:32:50 +00:00
|
|
|
private function initializeArticle() {
|
2011-06-17 10:29:39 +00:00
|
|
|
$title = $this->context->getTitle();
|
2013-01-04 09:11:13 +00:00
|
|
|
if ( $this->context->canUseWikiPage() ) {
|
|
|
|
|
// Try to use request context wiki page, as there
|
|
|
|
|
// is already data from db saved in per process
|
|
|
|
|
// cache there from this->getAction() call.
|
|
|
|
|
$page = $this->context->getWikiPage();
|
|
|
|
|
} else {
|
|
|
|
|
// This case should not happen, but just in case.
|
2015-12-23 20:19:13 +00:00
|
|
|
// @TODO: remove this or use an exception
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$this->context->setWikiPage( $page );
|
|
|
|
|
wfWarn( "RequestContext::canUseWikiPage() returned false" );
|
2013-01-04 09:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-23 20:19:13 +00:00
|
|
|
// Make GUI wrapper for the WikiPage
|
|
|
|
|
$article = Article::newFromWikiPage( $page, $this->context );
|
|
|
|
|
|
2014-09-23 22:41:03 +00:00
|
|
|
// Skip some unnecessary code if the content model doesn't support redirects
|
|
|
|
|
if ( !ContentHandler::getForTitle( $title )->supportsRedirects() ) {
|
2008-12-23 22:48:44 +00:00
|
|
|
return $article;
|
|
|
|
|
}
|
2012-01-06 20:00:04 +00:00
|
|
|
|
|
|
|
|
$request = $this->context->getRequest();
|
|
|
|
|
|
2006-01-13 00:29:20 +00:00
|
|
|
// Namespace might change when using redirects
|
2008-05-08 20:15:09 +00:00
|
|
|
// Check for redirects ...
|
2014-10-11 17:15:49 +00:00
|
|
|
$action = $request->getVal( 'action', 'view' );
|
2015-12-23 20:19:13 +00:00
|
|
|
$file = ( $page instanceof WikiFilePage ) ? $page->getFile() : null;
|
2013-03-07 16:50:43 +00:00
|
|
|
if ( ( $action == 'view' || $action == 'render' ) // ... for actions that show content
|
2013-12-01 20:39:00 +00:00
|
|
|
&& !$request->getVal( 'oldid' ) // ... and are not old revisions
|
|
|
|
|
&& !$request->getVal( 'diff' ) // ... and not when showing diff
|
|
|
|
|
&& $request->getVal( 'redirect' ) != 'no' // ... unless explicitly told not to
|
2008-12-09 03:25:02 +00:00
|
|
|
// ... and the article is not a non-redirect image page with associated file
|
2013-12-01 20:39:00 +00:00
|
|
|
&& !( is_object( $file ) && $file->exists() && !$file->getRedirected() )
|
|
|
|
|
) {
|
2010-06-30 15:50:37 +00:00
|
|
|
// Give extensions a change to ignore/handle redirects as needed
|
2008-07-04 09:38:12 +00:00
|
|
|
$ignoreRedirect = $target = false;
|
2010-12-01 20:22:45 +00:00
|
|
|
|
2014-12-09 07:23:30 +00:00
|
|
|
Hooks::run( 'InitializeArticleMaybeRedirect',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ &$title, &$request, &$ignoreRedirect, &$target, &$article ] );
|
2015-12-23 20:19:13 +00:00
|
|
|
$page = $article->getPage(); // reflect any hook changes
|
2008-12-09 03:25:02 +00:00
|
|
|
|
2009-09-06 10:09:45 +00:00
|
|
|
// Follow redirects only for... redirects.
|
|
|
|
|
// If $target is set, then a hook wanted to redirect.
|
2015-12-23 20:19:13 +00:00
|
|
|
if ( !$ignoreRedirect && ( $target || $page->isRedirect() ) ) {
|
2010-06-30 15:50:37 +00:00
|
|
|
// Is the target already set by an extension?
|
2015-12-23 20:19:13 +00:00
|
|
|
$target = $target ? $target : $page->followRedirect();
|
2011-04-03 15:56:29 +00:00
|
|
|
if ( is_string( $target ) ) {
|
2014-08-07 20:38:09 +00:00
|
|
|
if ( !$this->config->get( 'DisableHardRedirects' ) ) {
|
2006-01-14 21:19:17 +00:00
|
|
|
// we'll need to redirect
|
|
|
|
|
return $target;
|
|
|
|
|
}
|
2006-01-11 09:24:34 +00:00
|
|
|
}
|
2011-04-03 15:56:29 +00:00
|
|
|
if ( is_object( $target ) ) {
|
2008-03-19 19:55:26 +00:00
|
|
|
// Rewrite environment to redirected article
|
2015-12-23 20:19:13 +00:00
|
|
|
$rpage = WikiPage::factory( $target );
|
|
|
|
|
$rpage->loadPageData();
|
|
|
|
|
if ( $rpage->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
|
|
|
|
|
$rarticle = Article::newFromWikiPage( $rpage, $this->context );
|
2011-06-17 10:29:39 +00:00
|
|
|
$rarticle->setRedirectedFrom( $title );
|
2015-12-23 20:19:13 +00:00
|
|
|
|
2006-01-14 21:19:17 +00:00
|
|
|
$article = $rarticle;
|
2011-06-17 10:29:39 +00:00
|
|
|
$this->context->setTitle( $target );
|
2012-01-06 20:00:04 +00:00
|
|
|
$this->context->setWikiPage( $article->getPage() );
|
2006-01-14 21:19:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-12-23 20:19:13 +00:00
|
|
|
// Article may have been changed by hook
|
2011-06-17 10:29:39 +00:00
|
|
|
$this->context->setTitle( $article->getTitle() );
|
2012-01-06 20:00:04 +00:00
|
|
|
$this->context->setWikiPage( $article->getPage() );
|
2006-01-13 00:29:20 +00:00
|
|
|
}
|
2006-01-10 18:41:23 +00:00
|
|
|
}
|
2011-07-13 18:30:47 +00:00
|
|
|
|
2006-01-10 21:45:56 +00:00
|
|
|
return $article;
|
2006-01-10 18:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 12:25:41 +00:00
|
|
|
/**
|
|
|
|
|
* Perform one of the "standard" actions
|
2008-03-19 19:55:26 +00:00
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param Page $page
|
|
|
|
|
* @param Title $requestTitle The original title, before any redirects were applied
|
2006-01-11 12:25:41 +00:00
|
|
|
*/
|
2012-10-17 00:00:07 +00:00
|
|
|
private function performAction( Page $page, Title $requestTitle ) {
|
2011-06-17 10:29:39 +00:00
|
|
|
$request = $this->context->getRequest();
|
|
|
|
|
$output = $this->context->getOutput();
|
|
|
|
|
$title = $this->context->getTitle();
|
|
|
|
|
$user = $this->context->getUser();
|
|
|
|
|
|
2014-12-09 07:23:30 +00:00
|
|
|
if ( !Hooks::run( 'MediaWikiPerformAction',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $output, $page, $title, $user, $request, $this ] )
|
2013-12-01 20:39:00 +00:00
|
|
|
) {
|
2007-11-06 01:16:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:38:29 +00:00
|
|
|
$act = $this->getAction();
|
2013-09-19 19:06:10 +00:00
|
|
|
$action = Action::factory( $act, $page, $this->context );
|
|
|
|
|
|
2011-07-13 22:11:53 +00:00
|
|
|
if ( $action instanceof Action ) {
|
2016-01-14 00:06:06 +00:00
|
|
|
// Narrow DB query expectations for this HTTP request
|
|
|
|
|
$trxLimits = $this->config->get( 'TrxProfilerLimits' );
|
|
|
|
|
$trxProfiler = Profiler::instance()->getTransactionProfiler();
|
|
|
|
|
if ( $request->wasPosted() && !$action->doesWrites() ) {
|
|
|
|
|
$trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ );
|
2016-05-06 22:25:36 +00:00
|
|
|
$request->markAsSafeRequest();
|
2016-01-14 00:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-10 01:30:47 +00:00
|
|
|
# Let CDN cache things if we can purge them.
|
2014-08-07 20:38:09 +00:00
|
|
|
if ( $this->config->get( 'UseSquid' ) &&
|
2015-02-16 20:20:21 +00:00
|
|
|
in_array(
|
2015-12-12 00:40:35 +00:00
|
|
|
// Use PROTO_INTERNAL because that's what getCdnUrls() uses
|
2015-02-16 20:20:21 +00:00
|
|
|
wfExpandUrl( $request->getRequestURL(), PROTO_INTERNAL ),
|
2015-12-12 00:40:35 +00:00
|
|
|
$requestTitle->getCdnUrls()
|
2015-02-16 20:20:21 +00:00
|
|
|
)
|
2012-06-05 22:58:54 +00:00
|
|
|
) {
|
2015-12-10 01:07:05 +00:00
|
|
|
$output->setCdnMaxage( $this->config->get( 'SquidMaxage' ) );
|
2012-06-05 22:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:38:29 +00:00
|
|
|
$action->show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( Hooks::run( 'UnknownAction', [ $request->getVal( 'action', 'view' ), $page ] ) ) {
|
2014-05-22 22:17:23 +00:00
|
|
|
$output->setStatusCode( 404 );
|
2012-01-17 19:56:08 +00:00
|
|
|
$output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
|
2006-02-24 07:49:36 +00:00
|
|
|
}
|
2005-12-30 12:25:54 +00:00
|
|
|
}
|
2011-06-18 14:50:26 +00:00
|
|
|
|
|
|
|
|
/**
|
2015-05-15 23:23:51 +00:00
|
|
|
* Run the current MediaWiki instance; index.php just calls this
|
2011-06-21 23:28:50 +00:00
|
|
|
*/
|
2011-07-13 18:30:47 +00:00
|
|
|
public function run() {
|
2011-06-18 14:50:26 +00:00
|
|
|
try {
|
2014-03-03 21:12:11 +00:00
|
|
|
try {
|
|
|
|
|
$this->main();
|
|
|
|
|
} catch ( ErrorPageError $e ) {
|
|
|
|
|
// Bug 62091: 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.
|
2015-05-20 23:32:20 +00:00
|
|
|
$this->doPreOutputCommit();
|
2014-03-03 21:12:11 +00:00
|
|
|
$e->report(); // display the GUI error
|
|
|
|
|
}
|
2015-05-15 23:23:51 +00:00
|
|
|
} catch ( Exception $e ) {
|
|
|
|
|
MWExceptionHandler::handleException( $e );
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-20 23:32:20 +00:00
|
|
|
$this->doPostOutputShutdown( 'normal' );
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 06:57:00 +00:00
|
|
|
/**
|
|
|
|
|
* @see MediaWiki::preOutputCommit()
|
|
|
|
|
* @since 1.26
|
|
|
|
|
*/
|
|
|
|
|
public function doPreOutputCommit() {
|
|
|
|
|
self::preOutputCommit( $this->context );
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-20 23:32:20 +00:00
|
|
|
/**
|
|
|
|
|
* This function commits all DB changes as needed before
|
|
|
|
|
* the user can receive a response (in case commit fails)
|
|
|
|
|
*
|
2015-11-10 06:57:00 +00:00
|
|
|
* @param IContextSource $context
|
|
|
|
|
* @since 1.27
|
2015-05-20 23:32:20 +00:00
|
|
|
*/
|
2015-11-10 06:57:00 +00:00
|
|
|
public static function preOutputCommit( IContextSource $context ) {
|
2015-05-20 23:32:20 +00:00
|
|
|
// Either all DBs should commit or none
|
|
|
|
|
ignore_user_abort( true );
|
2015-08-24 21:46:19 +00:00
|
|
|
|
2015-10-24 10:22:41 +00:00
|
|
|
$config = $context->getConfig();
|
|
|
|
|
|
2016-09-07 15:40:39 +00:00
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
2015-10-24 10:22:41 +00:00
|
|
|
// Commit all changes
|
2016-09-07 15:40:39 +00:00
|
|
|
$lbFactory->commitMasterChanges(
|
2015-12-27 23:41:14 +00:00
|
|
|
__METHOD__,
|
|
|
|
|
// Abort if any transaction was too big
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'maxWriteDuration' => $config->get( 'MaxUserDBWriteDuration' ) ]
|
2015-12-27 23:41:14 +00:00
|
|
|
);
|
2015-08-24 21:46:19 +00:00
|
|
|
|
2015-11-30 22:02:53 +00:00
|
|
|
DeferredUpdates::doUpdates( 'enqueue', DeferredUpdates::PRESEND );
|
|
|
|
|
wfDebug( __METHOD__ . ': pre-send deferred updates completed' );
|
2015-08-19 23:33:03 +00:00
|
|
|
|
2016-08-29 00:01:55 +00:00
|
|
|
// Record ChronologyProtector positions
|
2016-09-07 15:40:39 +00:00
|
|
|
$lbFactory->shutdown();
|
2016-08-29 00:01:55 +00:00
|
|
|
wfDebug( __METHOD__ . ': all transactions committed' );
|
|
|
|
|
|
2016-01-13 17:31:39 +00:00
|
|
|
// Set a cookie to tell all CDN edge nodes to "stick" the user to the DC that handles this
|
|
|
|
|
// POST request (e.g. the "master" data center). Also have the user briefly bypass CDN so
|
|
|
|
|
// ChronologyProtector works for cacheable URLs.
|
2015-11-10 06:57:00 +00:00
|
|
|
$request = $context->getRequest();
|
2016-09-07 15:40:39 +00:00
|
|
|
if ( $request->wasPosted() && $lbFactory->hasOrMadeRecentMasterChanges() ) {
|
2015-11-10 06:57:00 +00:00
|
|
|
$expires = time() + $config->get( 'DataCenterUpdateStickTTL' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$options = [ 'prefix' => '' ];
|
2015-12-23 20:50:59 +00:00
|
|
|
$request->response()->setCookie( 'UseDC', 'master', $expires, $options );
|
|
|
|
|
$request->response()->setCookie( 'UseCDNCache', 'false', $expires, $options );
|
2015-08-19 23:33:03 +00:00
|
|
|
}
|
2015-10-01 07:24:18 +00:00
|
|
|
|
2016-09-05 20:21:26 +00:00
|
|
|
// Avoid letting a few seconds of replica DB lag cause a month of stale data. This logic is
|
2016-01-13 17:31:39 +00:00
|
|
|
// also intimately related to the value of $wgCdnReboundPurgeDelay.
|
2016-09-07 15:40:39 +00:00
|
|
|
if ( $lbFactory->laggedReplicaUsed() ) {
|
2015-11-10 06:57:00 +00:00
|
|
|
$maxAge = $config->get( 'CdnMaxageLagged' );
|
|
|
|
|
$context->getOutput()->lowerCdnMaxage( $maxAge );
|
2015-10-21 00:27:27 +00:00
|
|
|
$request->response()->header( "X-Database-Lagged: true" );
|
2015-10-01 07:24:18 +00:00
|
|
|
wfDebugLog( 'replication', "Lagged DB used; CDN cache TTL limited to $maxAge seconds" );
|
|
|
|
|
}
|
2016-04-20 19:37:00 +00:00
|
|
|
|
|
|
|
|
// Avoid long-term cache pollution due to message cache rebuild timeouts (T133069)
|
|
|
|
|
if ( MessageCache::singleton()->isDisabled() ) {
|
|
|
|
|
$maxAge = $config->get( 'CdnMaxageSubstitute' );
|
|
|
|
|
$context->getOutput()->lowerCdnMaxage( $maxAge );
|
|
|
|
|
$request->response()->header( "X-Response-Substitute: true" );
|
|
|
|
|
}
|
2015-05-15 23:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function does work that can be done *after* the
|
|
|
|
|
* user gets the HTTP response so they don't block on it
|
|
|
|
|
*
|
2015-08-24 21:31:06 +00:00
|
|
|
* This manages deferred updates, job insertion,
|
|
|
|
|
* final commit, and the logging of profiling data
|
|
|
|
|
*
|
2015-05-20 23:32:20 +00:00
|
|
|
* @param string $mode Use 'fast' to always skip job running
|
2015-05-15 23:23:51 +00:00
|
|
|
* @since 1.26
|
|
|
|
|
*/
|
2015-05-20 23:32:20 +00:00
|
|
|
public function doPostOutputShutdown( $mode = 'normal' ) {
|
2015-11-03 02:26:07 +00:00
|
|
|
$timing = $this->context->getTiming();
|
|
|
|
|
$timing->mark( 'requestShutdown' );
|
|
|
|
|
|
2015-08-24 21:31:06 +00:00
|
|
|
// Show visible profiling data if enabled (which cannot be post-send)
|
2015-05-20 23:32:20 +00:00
|
|
|
Profiler::instance()->logDataPageOutputOnly();
|
|
|
|
|
|
|
|
|
|
$that = $this;
|
|
|
|
|
$callback = function () use ( $that, $mode ) {
|
|
|
|
|
try {
|
2015-08-24 21:31:06 +00:00
|
|
|
$that->restInPeace( $mode );
|
2015-05-20 23:32:20 +00:00
|
|
|
} catch ( Exception $e ) {
|
|
|
|
|
MWExceptionHandler::handleException( $e );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-08-24 21:31:06 +00:00
|
|
|
// Defer everything else...
|
2015-05-20 23:32:20 +00:00
|
|
|
if ( function_exists( 'register_postsend_function' ) ) {
|
|
|
|
|
// https://github.com/facebook/hhvm/issues/1230
|
|
|
|
|
register_postsend_function( $callback );
|
|
|
|
|
} else {
|
|
|
|
|
if ( function_exists( 'fastcgi_finish_request' ) ) {
|
|
|
|
|
fastcgi_finish_request();
|
|
|
|
|
} else {
|
|
|
|
|
// Either all DB and deferred updates should happen or none.
|
2016-09-07 20:12:38 +00:00
|
|
|
// The latter should not be cancelled due to client disconnect.
|
2015-05-20 23:32:20 +00:00
|
|
|
ignore_user_abort( true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$callback();
|
2011-06-18 14:50:26 +00:00
|
|
|
}
|
2011-06-21 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-13 18:30:47 +00:00
|
|
|
private function main() {
|
2016-01-14 00:06:06 +00:00
|
|
|
global $wgTitle;
|
2011-06-21 23:28:50 +00:00
|
|
|
|
2012-01-21 20:13:57 +00:00
|
|
|
$request = $this->context->getRequest();
|
2011-06-21 23:28:50 +00:00
|
|
|
|
2013-10-07 19:47:43 +00:00
|
|
|
// Send Ajax requests to the Ajax dispatcher.
|
2014-10-27 14:35:41 +00:00
|
|
|
if ( $this->config->get( 'UseAjax' ) && $request->getVal( 'action' ) === 'ajax' ) {
|
2013-10-07 19:47:43 +00:00
|
|
|
// Set a dummy title, because $wgTitle == null might break things
|
2015-04-03 08:33:38 +00:00
|
|
|
$title = Title::makeTitle( NS_SPECIAL, 'Badtitle/performing an AJAX call in '
|
|
|
|
|
. __METHOD__
|
|
|
|
|
);
|
2013-10-07 19:47:43 +00:00
|
|
|
$this->context->setTitle( $title );
|
|
|
|
|
$wgTitle = $title;
|
|
|
|
|
|
2014-08-26 02:14:41 +00:00
|
|
|
$dispatcher = new AjaxDispatcher( $this->config );
|
|
|
|
|
$dispatcher->performAction( $this->context->getUser() );
|
2013-10-07 19:47:43 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get title from request parameters,
|
|
|
|
|
// is set on the fly by parseTitle the first time.
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
$action = $this->getAction();
|
|
|
|
|
$wgTitle = $title;
|
|
|
|
|
|
2016-01-14 00:06:06 +00:00
|
|
|
// Set DB query expectations for this HTTP request
|
|
|
|
|
$trxLimits = $this->config->get( 'TrxProfilerLimits' );
|
2015-02-27 14:02:24 +00:00
|
|
|
$trxProfiler = Profiler::instance()->getTransactionProfiler();
|
2015-03-23 00:53:24 +00:00
|
|
|
$trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) );
|
2016-05-20 03:31:19 +00:00
|
|
|
if ( $request->hasSafeMethod() ) {
|
2016-01-14 00:06:06 +00:00
|
|
|
$trxProfiler->setExpectations( $trxLimits['GET'], __METHOD__ );
|
2016-05-20 03:31:19 +00:00
|
|
|
} else {
|
|
|
|
|
$trxProfiler->setExpectations( $trxLimits['POST'], __METHOD__ );
|
2015-01-15 23:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-01 17:25:53 +00:00
|
|
|
// 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.
|
2013-10-07 19:47:43 +00:00
|
|
|
// Note: Do this after $wgTitle is setup, otherwise the hooks run from
|
|
|
|
|
// isLoggedIn() will do all sorts of weird stuff.
|
2013-02-01 17:25:53 +00:00
|
|
|
if (
|
2014-05-12 20:05:00 +00:00
|
|
|
$request->getProtocol() == 'http' &&
|
2016-05-26 18:04:02 +00:00
|
|
|
// switch to HTTPS only when supported by the server
|
|
|
|
|
preg_match( '#^https://#', wfExpandUrl( $request->getRequestURL(), PROTO_HTTPS ) ) &&
|
2013-02-01 17:25:53 +00:00
|
|
|
(
|
2016-02-01 20:44:03 +00:00
|
|
|
$request->getSession()->shouldForceHTTPS() ||
|
|
|
|
|
// Check the cookie manually, for paranoia
|
2013-08-29 20:40:07 +00:00
|
|
|
$request->getCookie( 'forceHTTPS', '' ) ||
|
2016-02-01 20:44:03 +00:00
|
|
|
// check for prefixed version that was used for a time in older MW versions
|
2013-08-31 00:00:03 +00:00
|
|
|
$request->getCookie( 'forceHTTPS' ) ||
|
2013-02-01 17:25:53 +00:00
|
|
|
// Avoid checking the user and groups unless it's enabled.
|
2013-08-21 01:39:45 +00:00
|
|
|
(
|
|
|
|
|
$this->context->getUser()->isLoggedIn()
|
|
|
|
|
&& $this->context->getUser()->requiresHTTPS()
|
|
|
|
|
)
|
2014-05-12 20:05:00 +00:00
|
|
|
)
|
2012-09-17 18:10:30 +00:00
|
|
|
) {
|
2013-08-20 00:29:43 +00:00
|
|
|
$oldUrl = $request->getFullRequestURL();
|
2014-04-26 20:34:21 +00:00
|
|
|
$redirUrl = preg_replace( '#^http://#', 'https://', $oldUrl );
|
2013-08-20 00:29:43 +00:00
|
|
|
|
2014-05-12 20:05:00 +00:00
|
|
|
// ATTENTION: This hook is likely to be removed soon due to overall design of the system.
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( Hooks::run( 'BeforeHttpsRedirect', [ $this->context, &$redirUrl ] ) ) {
|
2014-05-12 20:05:00 +00:00
|
|
|
|
|
|
|
|
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.
|
2015-10-14 07:46:44 +00:00
|
|
|
|
2014-07-23 20:04:48 +00:00
|
|
|
// @todo FIXME: See if we could issue a 307 or 308 here, need
|
2014-05-12 20:05:00 +00:00
|
|
|
// 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
|
2015-04-07 01:01:45 +00:00
|
|
|
$title = Title::newFromText( 'REDIR', NS_MAIN );
|
2014-05-12 20:05:00 +00:00
|
|
|
$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();
|
|
|
|
|
return;
|
2013-08-20 00:29:43 +00:00
|
|
|
}
|
2012-09-17 18:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-07 20:38:09 +00:00
|
|
|
if ( $this->config->get( 'UseFileCache' ) && $title->getNamespace() >= 0 ) {
|
2011-09-29 08:18:20 +00:00
|
|
|
if ( HTMLFileCache::useFileCache( $this->context ) ) {
|
2012-01-21 20:10:35 +00:00
|
|
|
// Try low-level file cache hit
|
2014-09-15 22:47:30 +00:00
|
|
|
$cache = new HTMLFileCache( $title, $action );
|
2011-09-29 08:18:20 +00:00
|
|
|
if ( $cache->isCacheGood( /* Assume up to date */ ) ) {
|
2012-01-21 20:10:35 +00:00
|
|
|
// Check incoming headers to see if client has this cached
|
2011-09-29 08:18:20 +00:00
|
|
|
$timestamp = $cache->cacheTimestamp();
|
2011-07-13 18:05:44 +00:00
|
|
|
if ( !$this->context->getOutput()->checkLastModified( $timestamp ) ) {
|
2011-09-29 08:18:20 +00:00
|
|
|
$cache->loadFromFileCache( $this->context );
|
2011-06-18 14:50:26 +00:00
|
|
|
}
|
2012-01-21 20:10:35 +00:00
|
|
|
// Do any stats increment/watchlist stuff
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
// Assume we're viewing the latest revision (this should always be the case with file cache)
|
2012-01-06 20:00:04 +00:00
|
|
|
$this->context->getWikiPage()->doViewUpdates( $this->context->getUser() );
|
2012-01-21 20:10:35 +00:00
|
|
|
// Tell OutputPage that output is taken care of
|
2011-06-18 14:50:26 +00:00
|
|
|
$this->context->getOutput()->disable();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-21 23:28:50 +00:00
|
|
|
|
2014-02-12 22:43:14 +00:00
|
|
|
// Actually do the work of the request and build up any output
|
2011-06-18 14:50:26 +00:00
|
|
|
$this->performRequest();
|
2012-07-20 20:38:24 +00:00
|
|
|
|
|
|
|
|
// Now commit any transactions, so that unreported errors after
|
2015-05-20 23:32:20 +00:00
|
|
|
// output() don't roll back the whole DB transaction and so that
|
|
|
|
|
// we avoid having both success and error text in the response
|
|
|
|
|
$this->doPreOutputCommit();
|
2012-07-20 20:38:24 +00:00
|
|
|
|
|
|
|
|
// Output everything!
|
|
|
|
|
$this->context->getOutput()->output();
|
2011-06-18 14:50:26 +00:00
|
|
|
}
|
2012-07-21 20:35:05 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ends this task peacefully
|
2015-08-24 21:31:06 +00:00
|
|
|
* @param string $mode Use 'fast' to always skip job running
|
2012-07-21 20:35:05 +00:00
|
|
|
*/
|
2015-08-24 21:31:06 +00:00
|
|
|
public function restInPeace( $mode = 'fast' ) {
|
2016-09-07 15:40:39 +00:00
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
2015-08-24 21:31:06 +00:00
|
|
|
// Assure deferred updates are not in the main transaction
|
2016-09-07 15:40:39 +00:00
|
|
|
$lbFactory->commitMasterChanges( __METHOD__ );
|
2015-08-24 21:31:06 +00:00
|
|
|
|
2016-06-08 17:47:53 +00:00
|
|
|
// Loosen DB query expectations since the HTTP client is unblocked
|
|
|
|
|
$trxProfiler = Profiler::instance()->getTransactionProfiler();
|
|
|
|
|
$trxProfiler->resetExpectations();
|
|
|
|
|
$trxProfiler->setExpectations(
|
|
|
|
|
$this->config->get( 'TrxProfilerLimits' )['PostSend'],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2015-01-15 23:55:17 +00:00
|
|
|
|
2012-07-21 20:35:05 +00:00
|
|
|
// Do any deferred jobs
|
2015-10-08 07:09:08 +00:00
|
|
|
DeferredUpdates::doUpdates( 'enqueue' );
|
2012-07-21 20:35:05 +00:00
|
|
|
|
2015-05-15 23:23:51 +00:00
|
|
|
// Make sure any lazy jobs are pushed
|
2015-05-19 02:06:49 +00:00
|
|
|
JobQueueGroup::pushLazyJobs();
|
2015-05-15 23:23:51 +00:00
|
|
|
|
2015-08-24 21:31:06 +00:00
|
|
|
// Now that everything specific to this request is done,
|
|
|
|
|
// try to occasionally run jobs (if enabled) from the queues
|
|
|
|
|
if ( $mode === 'normal' ) {
|
|
|
|
|
$this->triggerJobs();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-21 20:35:05 +00:00
|
|
|
// Log profiling data, e.g. in the database or UDP
|
|
|
|
|
wfLogProfilingData();
|
|
|
|
|
|
|
|
|
|
// Commit and close up!
|
2016-09-07 15:40:39 +00:00
|
|
|
$lbFactory->commitMasterChanges( __METHOD__ );
|
|
|
|
|
$lbFactory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT );
|
2012-07-21 20:35:05 +00:00
|
|
|
|
|
|
|
|
wfDebug( "Request ended normally\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-12 22:43:14 +00:00
|
|
|
* Potentially open a socket and sent an HTTP request back to the server
|
|
|
|
|
* to run a specified number of jobs. This registers a callback to cleanup
|
|
|
|
|
* the socket once it's done.
|
2012-07-21 20:35:05 +00:00
|
|
|
*/
|
2015-05-20 23:32:20 +00:00
|
|
|
public function triggerJobs() {
|
2014-08-07 20:38:09 +00:00
|
|
|
$jobRunRate = $this->config->get( 'JobRunRate' );
|
2016-08-23 06:04:36 +00:00
|
|
|
if ( $this->getTitle()->isSpecial( 'RunJobs' ) ) {
|
2014-03-12 19:19:27 +00:00
|
|
|
return; // recursion guard
|
2016-08-23 06:04:36 +00:00
|
|
|
} elseif ( $jobRunRate <= 0 || wfReadOnly() ) {
|
|
|
|
|
return;
|
2012-07-21 20:35:05 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2014-08-07 20:38:09 +00:00
|
|
|
if ( $jobRunRate < 1 ) {
|
2012-07-21 20:35:05 +00:00
|
|
|
$max = mt_getrandmax();
|
2014-08-07 20:38:09 +00:00
|
|
|
if ( mt_rand( 0, $max ) > $max * $jobRunRate ) {
|
|
|
|
|
return; // the higher the job run rate, the less likely we return here
|
2012-07-21 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
$n = 1;
|
|
|
|
|
} else {
|
2014-08-07 20:38:09 +00:00
|
|
|
$n = intval( $jobRunRate );
|
2012-07-21 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-23 00:53:24 +00:00
|
|
|
$runJobsLogger = LoggerFactory::getInstance( 'runJobs' );
|
2015-01-26 23:04:12 +00:00
|
|
|
|
2016-08-31 12:24:02 +00:00
|
|
|
// Fall back to running the job(s) while the user waits if needed
|
2014-08-07 20:38:09 +00:00
|
|
|
if ( !$this->config->get( 'RunJobsAsync' ) ) {
|
2015-01-26 23:04:12 +00:00
|
|
|
$runner = new JobRunner( $runJobsLogger );
|
2016-08-31 12:24:02 +00:00
|
|
|
$runner->run( [ 'maxJobs' => $n ] );
|
Added $wgRunJobsAsync to allow running jobs the old way
Adding a new global variable (DefaultSettings.php) named $wgRunJobsAsync, that
defaults to true, to allow installations to force the old synchronous job
execution on page requests instead of the new asynchonous one.
The asynchronous job queue execution was added in 1.22, executing a new shell
script, and it caused major problems for third party installations with restricted
environments or limited system resources, and also because a lot of bugs that went
unnoticed because WMF wikis do not use the on-request job queue.
In 1.23 it was changed to use a new internal HTTP request to a MediaWiki entry point
to perform the request, While some of the bugs were solved, it could still have
performance problems for opening a new process and loading a lot of MediaWiki PHP
objects on it, just to perform a request to see if there are pending jobs and execute
them (it doesn't check if there are jobs to execute). While this may improve speed
on single page requests, because it does not block the execution of the current page,
it has't been thoroughly tested on third party installations. And what is more
important, now there's no way to revert back to the old way of handling those jobs,
as it was done in 1.22 (setting $wgPhpCli = false). This means, in case of major
bugs on the job queue execution due to the new request, there's no way to fix it
other than editing MediaWiki PHP files directly, or completely disable the
on-request job queue handling (some hosts can't set up a cron job for that)
This situation makes it critical to have a safe way to revert to the old job queue
handling, at least until testing that the current implementation doesn't break a lot
of installations.
Bug: 61387
Change-Id: I892a3608228ec0a1c63268fb6180ec679c315980
2014-04-07 21:13:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-31 12:24:02 +00:00
|
|
|
// Do not send request if there are probably no jobs
|
2014-04-11 22:00:12 +00:00
|
|
|
try {
|
2016-08-31 12:24:02 +00:00
|
|
|
$group = JobQueueGroup::singleton();
|
|
|
|
|
if ( !$group->queuesHaveJobs( JobQueueGroup::TYPE_DEFAULT ) ) {
|
|
|
|
|
return;
|
2014-04-11 22:00:12 +00:00
|
|
|
}
|
|
|
|
|
} catch ( JobQueueError $e ) {
|
|
|
|
|
MWExceptionHandler::logException( $e );
|
|
|
|
|
return; // do not make the site unavailable
|
2014-04-08 16:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$query = [ 'title' => 'Special:RunJobs',
|
|
|
|
|
'tasks' => 'jobs', 'maxjobs' => $n, 'sigexpiry' => time() + 5 ];
|
2014-08-01 13:55:16 +00:00
|
|
|
$query['signature'] = SpecialRunJobs::getQuerySignature(
|
|
|
|
|
$query, $this->config->get( 'SecretKey' ) );
|
2014-02-28 05:35:30 +00:00
|
|
|
|
2014-02-12 22:43:14 +00:00
|
|
|
$errno = $errstr = null;
|
2016-08-23 06:04:36 +00:00
|
|
|
$info = wfParseUrl( $this->config->get( 'CanonicalServer' ) );
|
2016-08-31 12:24:02 +00:00
|
|
|
$host = $info ? $info['host'] : null;
|
2016-03-14 16:04:40 +00:00
|
|
|
$port = 80;
|
|
|
|
|
if ( isset( $info['scheme'] ) && $info['scheme'] == 'https' ) {
|
|
|
|
|
$host = "tls://" . $host;
|
|
|
|
|
$port = 443;
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $info['port'] ) ) {
|
|
|
|
|
$port = $info['port'];
|
|
|
|
|
}
|
2016-08-31 12:24:02 +00:00
|
|
|
|
|
|
|
|
MediaWiki\suppressWarnings();
|
|
|
|
|
$sock = $host ? fsockopen(
|
2016-03-14 16:04:40 +00:00
|
|
|
$host,
|
|
|
|
|
$port,
|
2014-02-12 22:43:14 +00:00
|
|
|
$errno,
|
2014-03-25 22:31:56 +00:00
|
|
|
$errstr,
|
2016-08-31 12:24:02 +00:00
|
|
|
// If it takes more than 100ms to connect to ourselves there is a problem...
|
|
|
|
|
0.100
|
|
|
|
|
) : false;
|
2015-06-10 18:29:05 +00:00
|
|
|
MediaWiki\restoreWarnings();
|
2016-08-31 12:24:02 +00:00
|
|
|
|
|
|
|
|
$invokedWithSuccess = true;
|
|
|
|
|
if ( $sock ) {
|
|
|
|
|
$special = SpecialPageFactory::getPage( 'RunJobs' );
|
|
|
|
|
$url = $special->getPageTitle()->getCanonicalURL( $query );
|
|
|
|
|
$req = (
|
|
|
|
|
"POST $url HTTP/1.1\r\n" .
|
|
|
|
|
"Host: {$info['host']}\r\n" .
|
|
|
|
|
"Connection: Close\r\n" .
|
|
|
|
|
"Content-Length: 0\r\n\r\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$runJobsLogger->info( "Running $n job(s) via '$url'" );
|
|
|
|
|
// Send a cron API request to be performed in the background.
|
|
|
|
|
// Give up if this takes too long to send (which should be rare).
|
|
|
|
|
stream_set_timeout( $sock, 2 );
|
|
|
|
|
$bytes = fwrite( $sock, $req );
|
|
|
|
|
if ( $bytes !== strlen( $req ) ) {
|
|
|
|
|
$invokedWithSuccess = false;
|
|
|
|
|
$runJobsLogger->error( "Failed to start cron API (socket write error)" );
|
|
|
|
|
} else {
|
|
|
|
|
// Do not wait for the response (the script should handle client aborts).
|
|
|
|
|
// Make sure that we don't close before that script reaches ignore_user_abort().
|
|
|
|
|
$start = microtime( true );
|
|
|
|
|
$status = fgets( $sock );
|
|
|
|
|
$sec = microtime( true ) - $start;
|
|
|
|
|
if ( !preg_match( '#^HTTP/\d\.\d 202 #', $status ) ) {
|
|
|
|
|
$invokedWithSuccess = false;
|
|
|
|
|
$runJobsLogger->error( "Failed to start cron API: received '$status' ($sec)" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose( $sock );
|
|
|
|
|
} else {
|
|
|
|
|
$invokedWithSuccess = false;
|
2015-01-26 23:04:12 +00:00
|
|
|
$runJobsLogger->error( "Failed to start cron API (socket error $errno): $errstr" );
|
2014-02-12 22:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-31 12:24:02 +00:00
|
|
|
// Fall back to running the job(s) while the user waits if needed
|
|
|
|
|
if ( !$invokedWithSuccess ) {
|
|
|
|
|
$runJobsLogger->warning( "Jobs switched to blocking; Special:RunJobs disabled" );
|
2014-02-12 22:43:14 +00:00
|
|
|
|
2016-08-31 12:24:02 +00:00
|
|
|
$runner = new JobRunner( $runJobsLogger );
|
|
|
|
|
$runner->run( [ 'maxJobs' => $n ] );
|
2013-04-18 05:05:47 +00:00
|
|
|
}
|
2012-07-21 20:35:05 +00:00
|
|
|
}
|
2010-08-09 18:54:43 +00:00
|
|
|
}
|