From 543b0637736aebb1f22cf252d452d5a66a049562 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 13 Jan 2016 16:06:06 -0800 Subject: [PATCH] Distinguish read vs write mode Action classes Bug: T123589 Change-Id: I3c8fab646d3bb8cd468e5b60c27f3c5d43f9f97c --- includes/MediaWiki.php | 19 ++++++++++++------- includes/actions/Action.php | 9 +++++++++ includes/actions/DeleteAction.php | 4 ++++ includes/actions/EditAction.php | 4 ++++ includes/actions/FormAction.php | 4 ++++ includes/actions/MarkpatrolledAction.php | 4 ++++ includes/actions/ProtectAction.php | 4 ++++ includes/actions/PurgeAction.php | 4 ++++ includes/actions/RevertAction.php | 4 ++++ includes/actions/RevisiondeleteAction.php | 4 ++++ includes/actions/RollbackAction.php | 4 ++++ includes/actions/UnprotectAction.php | 4 ++++ includes/actions/UnwatchAction.php | 4 ++++ includes/actions/WatchAction.php | 4 ++++ 14 files changed, 69 insertions(+), 7 deletions(-) diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 6a57d3943a..ab02ba75b5 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -458,7 +458,6 @@ class MediaWiki { * @param Title $requestTitle The original title, before any redirects were applied */ private function performAction( Page $page, Title $requestTitle ) { - $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); @@ -471,10 +470,16 @@ class MediaWiki { } $act = $this->getAction(); - $action = Action::factory( $act, $page, $this->context ); if ( $action instanceof Action ) { + // 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__ ); + } + # Let CDN cache things if we can purge them. if ( $this->config->get( 'UseSquid' ) && in_array( @@ -494,7 +499,6 @@ class MediaWiki { $output->setStatusCode( 404 ); $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); } - } /** @@ -625,7 +629,7 @@ class MediaWiki { } private function main() { - global $wgTitle, $wgTrxProfilerLimits; + global $wgTitle; $request = $this->context->getRequest(); @@ -649,13 +653,14 @@ class MediaWiki { $action = $this->getAction(); $wgTitle = $title; + // Set DB query expectations for this HTTP request + $trxLimits = $this->config->get( 'TrxProfilerLimits' ); $trxProfiler = Profiler::instance()->getTransactionProfiler(); $trxProfiler->setLogger( LoggerFactory::getInstance( 'DBPerformance' ) ); - if ( $request->wasPosted() ) { - $trxProfiler->setExpectations( $wgTrxProfilerLimits['POST'], __METHOD__ ); + $trxProfiler->setExpectations( $trxLimits['POST'], __METHOD__ ); } else { - $trxProfiler->setExpectations( $wgTrxProfilerLimits['GET'], __METHOD__ ); + $trxProfiler->setExpectations( $trxLimits['GET'], __METHOD__ ); } // If the user has forceHTTPS set to true, or if the user diff --git a/includes/actions/Action.php b/includes/actions/Action.php index 6ddc596b9d..97d7132fe3 100644 --- a/includes/actions/Action.php +++ b/includes/actions/Action.php @@ -417,4 +417,13 @@ abstract class Action { wfTransactionalTimeLimit(); } } + + /** + * Indicates whether this action may perform database writes + * @return bool + * @since 1.27 + */ + public function doesWrites() { + return false; + } } diff --git a/includes/actions/DeleteAction.php b/includes/actions/DeleteAction.php index 841a94df03..cb57d3ed81 100644 --- a/includes/actions/DeleteAction.php +++ b/includes/actions/DeleteAction.php @@ -53,4 +53,8 @@ class DeleteAction extends FormlessAction { $this->addHelpLink( 'Help:Sysop deleting and undeleting' ); $this->page->delete(); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/EditAction.php b/includes/actions/EditAction.php index eb53f19ae3..643d1c4d1c 100644 --- a/includes/actions/EditAction.php +++ b/includes/actions/EditAction.php @@ -58,4 +58,8 @@ class EditAction extends FormlessAction { $editor->edit(); } } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/FormAction.php b/includes/actions/FormAction.php index aa201d7be1..55b9b991ee 100644 --- a/includes/actions/FormAction.php +++ b/includes/actions/FormAction.php @@ -127,4 +127,8 @@ abstract class FormAction extends Action { $this->onSuccess(); } } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/MarkpatrolledAction.php b/includes/actions/MarkpatrolledAction.php index 34067f119e..b8a7616902 100644 --- a/includes/actions/MarkpatrolledAction.php +++ b/includes/actions/MarkpatrolledAction.php @@ -89,4 +89,8 @@ class MarkpatrolledAction extends FormlessAction { $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() ); $this->getOutput()->returnToMain( null, $return ); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/ProtectAction.php b/includes/actions/ProtectAction.php index 48909cfd72..126daa069f 100644 --- a/includes/actions/ProtectAction.php +++ b/includes/actions/ProtectAction.php @@ -51,4 +51,8 @@ class ProtectAction extends FormlessAction { $this->page->protect(); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/PurgeAction.php b/includes/actions/PurgeAction.php index 7e77846884..183c3b92e5 100644 --- a/includes/actions/PurgeAction.php +++ b/includes/actions/PurgeAction.php @@ -97,4 +97,8 @@ class PurgeAction extends FormAction { public function onSuccess() { $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) ); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php index 4885a31ec1..8a54c3944d 100644 --- a/includes/actions/RevertAction.php +++ b/includes/actions/RevertAction.php @@ -151,4 +151,8 @@ class RevertAction extends FormAction { protected function getDescription() { return OutputPage::buildBacklinkSubtitle( $this->getTitle() ); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/RevisiondeleteAction.php b/includes/actions/RevisiondeleteAction.php index dbcb8485ed..7df42b3317 100644 --- a/includes/actions/RevisiondeleteAction.php +++ b/includes/actions/RevisiondeleteAction.php @@ -58,4 +58,8 @@ class RevisiondeleteAction extends FormlessAction { $special->getContext()->setTitle( $special->getPageTitle() ); $special->run( '' ); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/RollbackAction.php b/includes/actions/RollbackAction.php index 040485637d..cc94fd37f2 100644 --- a/includes/actions/RollbackAction.php +++ b/includes/actions/RollbackAction.php @@ -126,4 +126,8 @@ class RollbackAction extends FormlessAction { protected function getDescription() { return ''; } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/UnprotectAction.php b/includes/actions/UnprotectAction.php index 559cfaf7ca..0757e88cee 100644 --- a/includes/actions/UnprotectAction.php +++ b/includes/actions/UnprotectAction.php @@ -39,4 +39,8 @@ class UnprotectAction extends ProtectAction { public function show() { $this->page->unprotect(); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/UnwatchAction.php b/includes/actions/UnwatchAction.php index 0a8628dd26..f8f1dc1f44 100644 --- a/includes/actions/UnwatchAction.php +++ b/includes/actions/UnwatchAction.php @@ -52,4 +52,8 @@ class UnwatchAction extends WatchAction { public function onSuccess() { $this->getOutput()->addWikiMsg( 'removedwatchtext', $this->getTitle()->getPrefixedText() ); } + + public function doesWrites() { + return true; + } } diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php index 30b83d70f4..547fd9b6e3 100644 --- a/includes/actions/WatchAction.php +++ b/includes/actions/WatchAction.php @@ -178,4 +178,8 @@ class WatchAction extends FormAction { public static function getUnwatchToken( Title $title, User $user, $action = 'unwatch' ) { return self::getWatchToken( $title, $user, $action ); } + + public function doesWrites() { + return true; + } } -- 2.20.1