Thiemo Kreuz (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/398794 )
Change subject: Replace class_exists with proper extension registration checks
......................................................................
Replace class_exists with proper extension registration checks
class_exists calls with a string are especially dangerous, because they
do not fail when the class gets renamed or moved to an other namespace.
Bug: T183096
Change-Id: I5c0b61b9f5785085c85bd9dd27187aafca314e92
---
M includes/CentralAuthHooks.php
M includes/CentralAuthPrimaryAuthenticationProvider.php
M includes/CentralAuthUser.php
M includes/GlobalRename/GlobalRenameUser.php
M includes/LocalRenameJob/LocalRenameUserJob.php
M includes/LocalRenameJob/LocalUserMergeJob.php
M includes/specials/SpecialCentralAutoLogin.php
M includes/specials/SpecialGlobalRenameQueue.php
M includes/specials/SpecialGlobalRenameUser.php
M includes/specials/SpecialGlobalUserMerge.php
M maintenance/createLocalAccount.php
M maintenance/forceRenameUsers.php
M maintenance/sendForceRenameNotification.php
13 files changed, 24 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth
refs/changes/94/398794/1
diff --git a/includes/CentralAuthHooks.php b/includes/CentralAuthHooks.php
index a24917e..43a1e05 100644
--- a/includes/CentralAuthHooks.php
+++ b/includes/CentralAuthHooks.php
@@ -47,7 +47,7 @@
global $wgDisableAuthManager;
$caBase = __DIR__ . '/..';
- if ( class_exists( 'RenameuserSQL' ) ) {
+ if ( ExtensionRegistry::getInstance()->isLoaded( 'Renameuser' )
) {
// Credits should only appear on wikis with
Extension:Renameuser
// installed
$wgExtensionCredits['specialpage'][] = [
@@ -60,7 +60,7 @@
];
}
- if ( class_exists( 'AntiSpoof' ) ) {
+ if ( ExtensionRegistry::getInstance()->isLoaded( 'AntiSpoof' )
) {
// If AntiSpoof is installed, we can do some AntiSpoof
stuff for CA
$wgExtensionCredits['antispam'][] = [
'path' => "{$caBase}/CentralAuth.php",
@@ -584,7 +584,7 @@
}
private static function isMobileDomain() {
- return class_exists( 'MobileContext' )
+ return class_exists( MobileContext::class )
&& MobileContext::singleton()->usingMobileDomain();
}
diff --git a/includes/CentralAuthPrimaryAuthenticationProvider.php
b/includes/CentralAuthPrimaryAuthenticationProvider.php
index 9d96793..451342e 100644
--- a/includes/CentralAuthPrimaryAuthenticationProvider.php
+++ b/includes/CentralAuthPrimaryAuthenticationProvider.php
@@ -90,7 +90,7 @@
$ret = parent::getAuthenticationRequests( $action, $options );
if ( $this->antiSpoofAccounts && $action ===
AuthManager::ACTION_CREATE &&
- class_exists( 'AntiSpoofAuthenticationRequest' )
+ class_exists( AntiSpoofAuthenticationRequest::class )
) {
$user = User::newFromName( $options['username'] ) ?:
new User();
if ( $user->isAllowed( 'override-antispoof' ) ) {
@@ -432,7 +432,7 @@
}
// Check CentralAuthAntiSpoof, if applicable. Assume the user
will override if they can.
- if ( $this->antiSpoofAccounts && class_exists(
'AntiSpoofAuthenticationRequest' ) &&
+ if ( $this->antiSpoofAccounts && class_exists(
AntiSpoofAuthenticationRequest::class ) &&
empty( $options['creating'] ) &&
!RequestContext::getMain()->getUser()->isAllowed(
'override-antispoof' )
) {
@@ -461,7 +461,7 @@
}
// Check CentralAuthAntiSpoof, if applicable
- if ( class_exists( 'AntiSpoofAuthenticationRequest' ) ) {
+ if ( class_exists( AntiSpoofAuthenticationRequest::class ) ) {
$antiSpoofReq =
AuthenticationRequest::getRequestByClass(
$reqs, AntiSpoofAuthenticationRequest::class
);
diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index c363eb6..a5caca2 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -888,7 +888,7 @@
* if that feature is enabled
*/
protected function recordAntiSpoof() {
- if ( class_exists( 'CentralAuthSpoofUser' ) ) {
+ if ( class_exists( CentralAuthSpoofUser::class ) ) {
$spoof = new CentralAuthSpoofUser( $this->mName );
$spoof->record();
}
@@ -899,7 +899,7 @@
* if that feature is enabled
*/
public function removeAntiSpoof() {
- if ( class_exists( 'CentralAuthSpoofUser' ) ) {
+ if ( class_exists( CentralAuthSpoofUser::class ) ) {
$spoof = new CentralAuthSpoofUser( $this->mName );
$spoof->remove();
}
diff --git a/includes/GlobalRename/GlobalRenameUser.php
b/includes/GlobalRename/GlobalRenameUser.php
index dc842a6..5469d58 100644
--- a/includes/GlobalRename/GlobalRenameUser.php
+++ b/includes/GlobalRename/GlobalRenameUser.php
@@ -125,7 +125,7 @@
);
// Update CA's AntiSpoof if enabled
- if ( class_exists( 'CentralAuthSpoofUser' ) ) {
+ if ( class_exists( CentralAuthSpoofUser::class ) ) {
$spoof = new CentralAuthSpoofUser(
$this->newUser->getName() );
$spoof->update( $this->oldUser->getName() );
}
diff --git a/includes/LocalRenameJob/LocalRenameUserJob.php
b/includes/LocalRenameJob/LocalRenameUserJob.php
index 56c5a77..3a1cb8b 100644
--- a/includes/LocalRenameJob/LocalRenameUserJob.php
+++ b/includes/LocalRenameJob/LocalRenameUserJob.php
@@ -43,9 +43,10 @@
}
public function doRun( $fnameTrxOwner ) {
- if ( !class_exists( 'RenameuserSQL' ) ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded( 'Renameuser'
) ) {
throw new Exception( 'Extension:Renameuser is not
installed' );
}
+
$from = $this->params['from'];
$to = $this->params['to'];
diff --git a/includes/LocalRenameJob/LocalUserMergeJob.php
b/includes/LocalRenameJob/LocalUserMergeJob.php
index 969487b..0652a12 100644
--- a/includes/LocalRenameJob/LocalUserMergeJob.php
+++ b/includes/LocalRenameJob/LocalUserMergeJob.php
@@ -14,9 +14,10 @@
}
public function doRun( $fnameTrxOwner ) {
- if ( !class_exists( 'MergeUser' ) ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded( 'UserMerge' )
) {
throw new Exception( 'Extension:UserMerge is not
installed' );
}
+
$from = $this->params['from'];
$to = $this->params['to'];
diff --git a/includes/specials/SpecialCentralAutoLogin.php
b/includes/specials/SpecialCentralAutoLogin.php
index 6b93784..1c4d254 100644
--- a/includes/specials/SpecialCentralAutoLogin.php
+++ b/includes/specials/SpecialCentralAutoLogin.php
@@ -604,7 +604,7 @@
private function do302Redirect( $target, $state, $params ) {
$url = WikiMap::getForeignURL( $target,
"Special:CentralAutoLogin/$state" );
if ( wfWikiID() == $this->loginWiki
- && class_exists( 'MobileContext' )
+ && class_exists( MobileContext::class )
&& isset( $params['mobile'] )
&& $params['mobile']
) {
diff --git a/includes/specials/SpecialGlobalRenameQueue.php
b/includes/specials/SpecialGlobalRenameQueue.php
index bf05d5a..b1b850f 100644
--- a/includes/specials/SpecialGlobalRenameQueue.php
+++ b/includes/specials/SpecialGlobalRenameQueue.php
@@ -408,7 +408,7 @@
$form->addHeaderText( $infoMsg->parseAsBlock() );
- if ( class_exists( 'CentralAuthSpoofUser' ) ) {
+ if ( class_exists( CentralAuthSpoofUser::class ) ) {
$spoofUser = new CentralAuthSpoofUser(
$req->getNewName() );
// @todo move this code somewhere else
$specialGblRename = new SpecialGlobalRenameUser();
@@ -426,7 +426,7 @@
}
// Show a message if the new username matches the title
blacklist.
- if ( class_exists( 'TitleBlacklist' ) ) {
+ if ( class_exists( TitleBlacklist::class ) ) {
$titleBlacklist =
TitleBlacklist::singleton()->isBlacklisted(
Title::makeTitleSafe( NS_USER,
$req->getNewName() ),
'new-account'
diff --git a/includes/specials/SpecialGlobalRenameUser.php
b/includes/specials/SpecialGlobalRenameUser.php
index 4df7ae6..60515c5 100644
--- a/includes/specials/SpecialGlobalRenameUser.php
+++ b/includes/specials/SpecialGlobalRenameUser.php
@@ -136,7 +136,7 @@
* @return Status
*/
function validate( array $data ) {
- if ( !class_exists( 'RenameuserSQL' ) ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded( 'Renameuser'
) ) {
return Status::newFatal(
'centralauth-rename-notinstalled' );
}
@@ -154,7 +154,7 @@
return Status::newFatal(
'centralauth-rename-badusername' );
}
- if ( !$this->overrideAntiSpoof && class_exists(
'CentralAuthSpoofUser' ) ) {
+ if ( !$this->overrideAntiSpoof && class_exists(
CentralAuthSpoofUser::class ) ) {
$spoofUser = new CentralAuthSpoofUser(
$newUser->getName() );
$conflicts = $this->processAntiSpoofConflicts(
$oldUser->getName(),
@@ -183,7 +183,7 @@
}
// Ask for confirmation if the new username matches the title
blacklist.
- if ( !$this->overrideTitleBlacklist && class_exists(
'TitleBlacklist' ) ) {
+ if ( !$this->overrideTitleBlacklist && class_exists(
TitleBlacklist::class ) ) {
$titleBlacklist =
TitleBlacklist::singleton()->isBlacklisted(
Title::makeTitleSafe( NS_USER,
$newUser->getName() ),
'new-account'
diff --git a/includes/specials/SpecialGlobalUserMerge.php
b/includes/specials/SpecialGlobalUserMerge.php
index 86d8ed9..56b91de 100644
--- a/includes/specials/SpecialGlobalUserMerge.php
+++ b/includes/specials/SpecialGlobalUserMerge.php
@@ -28,7 +28,7 @@
public function execute( $par ) {
global $wgCentralAuthEnableUserMerge;
- if ( !class_exists( 'SpecialUserMerge' ) ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded( 'UserMerge' )
) {
$this->setHeaders();
throw new ErrorPageError( 'error',
'centralauth-usermerge-notinstalled' );
}
diff --git a/maintenance/createLocalAccount.php
b/maintenance/createLocalAccount.php
index 7b82344..0385c43 100644
--- a/maintenance/createLocalAccount.php
+++ b/maintenance/createLocalAccount.php
@@ -15,7 +15,7 @@
}
public function execute() {
- if ( !class_exists( 'CentralAuthUser' ) ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded( 'CentralAuth'
) ) {
$this->error( "CentralAuth isn't enabled on this
wiki\n", 1 );
}
diff --git a/maintenance/forceRenameUsers.php b/maintenance/forceRenameUsers.php
index c9c9805..c92893e 100644
--- a/maintenance/forceRenameUsers.php
+++ b/maintenance/forceRenameUsers.php
@@ -30,7 +30,7 @@
}
public function execute() {
- if ( !class_exists( 'CentralAuthUser' ) ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded( 'CentralAuth'
) ) {
$this->error( 'CentralAuth is not installed on this
wiki.', 1 );
}
$dbw = CentralAuthUtils::getCentralDB();
diff --git a/maintenance/sendForceRenameNotification.php
b/maintenance/sendForceRenameNotification.php
index a33c9df..cab4088 100644
--- a/maintenance/sendForceRenameNotification.php
+++ b/maintenance/sendForceRenameNotification.php
@@ -27,9 +27,10 @@
}
public function execute() {
- if ( !class_exists( 'MassMessageServerSideJob' ) ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded( 'MassMessage'
) ) {
$this->error( 'This script requires the MassMessage
extension', 1 );
}
+
$message = $this->getLocalizedText( $this->getOption( 'message'
) );
$message = str_replace( '{{WIKI}}', wfWikiID(), $message );
$message .= " ~~~~~\n<!-- SUL finalisation notification -->";
--
To view, visit https://gerrit.wikimedia.org/r/398794
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c0b61b9f5785085c85bd9dd27187aafca314e92
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Thiemo Kreuz (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits