MediaWiki.php: Reduce scope of variables
Some variables are set before early returns but used after - move that Some variables are set before an if, but only used inside the if - move the variables inside the if to skip the init of the variable Change-Id: I1da72bc7fae44316162ab96672fd6745e65341fc
This commit is contained in:
parent
0707d2f4ca
commit
338cd0fc6a
1 changed files with 19 additions and 19 deletions
|
|
@ -81,7 +81,6 @@ class MediaWiki {
|
|||
$request = $this->context->getRequest();
|
||||
$curid = $request->getInt( 'curid' );
|
||||
$title = $request->getText( 'title' );
|
||||
$action = $request->getRawVal( 'action' );
|
||||
|
||||
if ( $curid ) {
|
||||
// URLs like this are generated by RC, because rc_title isn't always accurate
|
||||
|
|
@ -138,7 +137,7 @@ class MediaWiki {
|
|||
if ( $ret === null
|
||||
&& strval( $title ) === ''
|
||||
&& !$request->getCheck( 'curid' )
|
||||
&& $action !== 'delete'
|
||||
&& $request->getRawVal( 'action' ) !== 'delete'
|
||||
) {
|
||||
$ret = Title::newMainPage();
|
||||
}
|
||||
|
|
@ -197,14 +196,15 @@ class MediaWiki {
|
|||
global $wgTitle;
|
||||
|
||||
$request = $this->context->getRequest();
|
||||
$requestTitle = $title = $this->context->getTitle();
|
||||
$output = $this->context->getOutput();
|
||||
$user = $this->context->getUser();
|
||||
|
||||
if ( $request->getRawVal( 'printable' ) === 'yes' ) {
|
||||
$output->setPrintable();
|
||||
}
|
||||
|
||||
$user = $this->context->getUser();
|
||||
$title = $this->context->getTitle();
|
||||
$requestTitle = $title;
|
||||
$this->getHookRunner()->onBeforeInitialize( $title, null, $output, $user, $request, $this );
|
||||
|
||||
// Invalid titles. T23776: The interwikis must redirect even if the page name is empty.
|
||||
|
|
@ -291,11 +291,11 @@ class MediaWiki {
|
|||
}
|
||||
|
||||
$query = $specialPage->getRedirectQuery( $subpage ) ?: [];
|
||||
$request = new DerivativeRequest( $this->context->getRequest(), $query );
|
||||
$request->setRequestURL( $this->context->getRequest()->getRequestURL() );
|
||||
$this->context->setRequest( $request );
|
||||
$derivateRequest = new DerivativeRequest( $request, $query );
|
||||
$derivateRequest->setRequestURL( $request->getRequestURL() );
|
||||
$this->context->setRequest( $derivateRequest );
|
||||
// Do not varnish cache these. May vary even for anons
|
||||
$this->context->getOutput()->lowerCdnMaxage( 0 );
|
||||
$output->lowerCdnMaxage( 0 );
|
||||
$this->context->setTitle( $target );
|
||||
$wgTitle = $target;
|
||||
// Reset action type cache. (Special pages have only view)
|
||||
|
|
@ -502,7 +502,6 @@ class MediaWiki {
|
|||
$output = $this->context->getOutput();
|
||||
$title = $this->context->getTitle();
|
||||
$user = $this->context->getUser();
|
||||
$services = MediaWikiServices::getInstance();
|
||||
|
||||
if ( !$this->getHookRunner()->onMediaWikiPerformAction(
|
||||
$output, $article, $title, $user, $request, $this )
|
||||
|
|
@ -512,6 +511,7 @@ class MediaWiki {
|
|||
|
||||
$t = microtime( true );
|
||||
$actionName = $this->getAction();
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$action = $services->getActionFactory()->getAction( $actionName, $article, $this->context );
|
||||
|
||||
if ( $action instanceof Action ) {
|
||||
|
|
@ -521,9 +521,9 @@ class MediaWiki {
|
|||
}
|
||||
|
||||
// Narrow DB query expectations for this HTTP request
|
||||
$trxLimits = $this->config->get( MainConfigNames::TrxProfilerLimits );
|
||||
$trxProfiler = Profiler::instance()->getTransactionProfiler();
|
||||
if ( $request->wasPosted() && !$action->doesWrites() ) {
|
||||
$trxProfiler = Profiler::instance()->getTransactionProfiler();
|
||||
$trxLimits = $this->config->get( MainConfigNames::TrxProfilerLimits );
|
||||
$trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ );
|
||||
$request->markAsSafeRequest();
|
||||
}
|
||||
|
|
@ -862,14 +862,12 @@ class MediaWiki {
|
|||
private function main() {
|
||||
global $wgTitle;
|
||||
|
||||
$output = $this->context->getOutput();
|
||||
$request = $this->context->getRequest();
|
||||
|
||||
// Get title from request parameters,
|
||||
// is set on the fly by parseTitle the first time.
|
||||
$title = $this->getTitle();
|
||||
$wgTitle = $title;
|
||||
|
||||
$request = $this->context->getRequest();
|
||||
// Set DB query expectations for this HTTP request
|
||||
$trxLimits = $this->config->get( MainConfigNames::TrxProfilerLimits );
|
||||
$trxProfiler = Profiler::instance()->getTransactionProfiler();
|
||||
|
|
@ -884,6 +882,7 @@ class MediaWiki {
|
|||
return;
|
||||
}
|
||||
|
||||
$output = $this->context->getOutput();
|
||||
if ( $title->canExist() && HTMLFileCache::useFileCache( $this->context ) ) {
|
||||
// getAction() may trigger DB queries, so avoid eagerly initializing it if possible.
|
||||
// This reduces the cost of requests that exit early due to tryNormaliseRedirect()
|
||||
|
|
@ -1106,12 +1105,14 @@ class MediaWiki {
|
|||
// The latter should not be cancelled due to client disconnect.
|
||||
ignore_user_abort( true );
|
||||
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$lbFactory = $services->getDBLoadBalancerFactory();
|
||||
// Assure deferred updates are not in the main transaction
|
||||
$lbFactory->commitPrimaryChanges( __METHOD__ );
|
||||
|
||||
// Loosen DB query expectations since the HTTP client is unblocked
|
||||
$trxProfiler = Profiler::instance()->getTransactionProfiler();
|
||||
$profiler = Profiler::instance();
|
||||
$trxProfiler = $profiler->getTransactionProfiler();
|
||||
$trxProfiler->redefineExpectations(
|
||||
$this->context->getRequest()->hasSafeMethod()
|
||||
? $this->config->get( MainConfigNames::TrxProfilerLimits )['PostSend-GET']
|
||||
|
|
@ -1124,16 +1125,15 @@ class MediaWiki {
|
|||
|
||||
// Handle external profiler outputs.
|
||||
// Any embedded profiler outputs were already processed in outputResponsePayload().
|
||||
$profiler = Profiler::instance();
|
||||
$profiler->logData();
|
||||
|
||||
self::emitBufferedStatsdData(
|
||||
MediaWikiServices::getInstance()->getStatsdDataFactory(),
|
||||
$services->getStatsdDataFactory(),
|
||||
$this->config
|
||||
);
|
||||
|
||||
// Send metrics gathered by MetricsFactory
|
||||
MediaWikiServices::getInstance()->getMetricsFactory()->flush();
|
||||
$services->getMetricsFactory()->flush();
|
||||
|
||||
// Commit and close up!
|
||||
$lbFactory->commitPrimaryChanges( __METHOD__ );
|
||||
|
|
|
|||
Loading…
Reference in a new issue