Use cheaper getRawVal/getCheck instead of getVal where possible

getVal/getText can be expensive because they do Unicode normalization.
We can skip this when we know we aren't going to do anything meaningful
with the value anyway.

Change-Id: I9d939a44df6b67bcd8429096d89600ce1566ca39
This commit is contained in:
Thiemo Kreuz 2022-08-26 12:07:15 +02:00 committed by Bartosz Dziewoński
parent e680735d63
commit 62ddb8bceb
3 changed files with 9 additions and 9 deletions

View file

@ -445,12 +445,12 @@ class HookUtils {
return (
// ?title=...&action=edit&section=new
// ?title=...&veaction=editsource&section=new
( $req->getVal( 'action' ) === 'edit' || $req->getVal( 'veaction' ) === 'editsource' ) &&
$req->getVal( 'section' ) === 'new' &&
( $req->getRawVal( 'action' ) === 'edit' || $req->getRawVal( 'veaction' ) === 'editsource' ) &&
$req->getRawVal( 'section' ) === 'new' &&
// Adding a new topic with preloaded text is not supported yet (T269310)
!(
$req->getVal( 'editintro' ) || $req->getVal( 'preload' ) ||
$req->getVal( 'preloadparams' ) || $req->getVal( 'preloadtitle' )
$req->getCheck( 'editintro' ) || $req->getCheck( 'preload' ) ||
$req->getCheck( 'preloadparams' ) || $req->getCheck( 'preloadtitle' )
) &&
// User has new topic tool enabled (and not using &dtenable=0)
static::isFeatureEnabledForOutput( $out, static::NEWTOPICTOOL )
@ -475,14 +475,14 @@ class HookUtils {
(
// When following a red link from another page (but not when clicking the 'Edit' tab)
(
$req->getVal( 'action' ) === 'edit' && $req->getVal( 'redlink' ) === '1' &&
$req->getRawVal( 'action' ) === 'edit' && $req->getRawVal( 'redlink' ) === '1' &&
// …if not disabled by the user
$optionsLookup->getOption( $user, 'discussiontools-newtopictool-createpage' )
) ||
// When the new topic tool will be opened (usually when clicking the 'Add topic' tab)
static::shouldOpenNewTopicTool( $context ) ||
// In read mode (accessible for non-existent pages by clicking 'Cancel' in editor)
$req->getVal( 'action', 'view' ) === 'view'
$req->getRawVal( 'action', 'view' ) === 'view'
) &&
// Only in talk namespaces, not including other namespaces that isAvailableForTitle() allows
$title->isTalkPage() &&

View file

@ -442,7 +442,7 @@ class PageHooks implements
// Only show when following the link from the new topic tool, never on normal edit attempts.
// This can be called from within ApiVisualEditor, so we can't access most request parameters
// for the main request. However, we can access 'editintro', because it's passed to the API.
$context->getRequest()->getVal( 'editintro' ) === 'mw-dt-topic-hint'
$context->getRequest()->getRawVal( 'editintro' ) === 'mw-dt-topic-hint'
) {
$context->getOutput()->enableOOUI();

View file

@ -358,11 +358,11 @@ class EventDispatcher {
// might either be after an API request from DiscussionTools or a
// regular POST from WikiEditor. Both should have this value snuck
// into their request if their session is being logged.
if ( !$request->getVal( 'editingStatsId' ) ) {
if ( !$request->getCheck( 'editingStatsId' ) ) {
return false;
}
$editingStatsId = $request->getVal( 'editingStatsId' );
$isDiscussionTools = (bool)$request->getVal( 'dttags' );
$isDiscussionTools = $request->getCheck( 'dttags' );
$extensionRegistry = ExtensionRegistry::getInstance();
if ( !$extensionRegistry->isLoaded( 'EventLogging' ) ) {