From: Umherirrender Date: Mon, 19 Aug 2019 20:45:43 +0000 (+0200) Subject: Avoid multiply calls to MediaWikiServices::getInstance() in one function X-Git-Tag: 1.34.0-rc.0~443^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=6b8a2a75ee4a0b5c9b77e47123cf11475107c15e;p=lhc%2Fweb%2Fwiklou.git Avoid multiply calls to MediaWikiServices::getInstance() in one function RepoGroup::singleton() results in MediaWikiServices::getInstance()->getRepoGroup() Also avoid getting the service in loops, doing it once before the loop is cheaper Change-Id: I29e0c7487e3e498559ff16a567e2fad0c0f8bb69 --- diff --git a/includes/Linker.php b/includes/Linker.php index e748b3a045..1a5058d6f4 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -688,13 +688,14 @@ class Linker { if ( $label == '' ) { $label = $title->getPrefixedText(); } + $repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); $currentExists = $time - && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ) !== false; + && $repoGroup->findFile( $title ) !== false; if ( ( $wgUploadMissingFileUrl || $wgUploadNavigationUrl || $wgEnableUploads ) && !$currentExists ) { - if ( RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title ) ) { + if ( $repoGroup->getLocalRepo()->checkRedirect( $title ) ) { // We already know it's a redirect, so mark it accordingly return self::link( $title, diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 4cbed21394..74c6f8fccd 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -59,9 +59,10 @@ class ApiMove extends ApiBase { } $toTalk = $toTitle->getTalkPageIfDefined(); + $repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); if ( $toTitle->getNamespace() == NS_FILE - && !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle ) - && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $toTitle ) + && !$repoGroup->getLocalRepo()->findFile( $toTitle ) + && $repoGroup->findFile( $toTitle ) ) { if ( !$params['ignorewarnings'] && $this->getPermissionManager()->userHasRight( $user, 'reupload-shared' ) ) { diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 941d1083e9..6da362dd1b 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -305,8 +305,9 @@ class MovePageForm extends UnlistedSpecialPage { // mediawiki.special.movePage module $immovableNamespaces = []; + $namespaceInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) { - if ( !MediaWikiServices::getInstance()->getNamespaceInfo()->isMovable( $nsId ) ) { + if ( !$namespaceInfo->isMovable( $nsId ) ) { $immovableNamespaces[] = $nsId; } } @@ -534,11 +535,14 @@ class MovePageForm extends UnlistedSpecialPage { return; } + $services = MediaWikiServices::getInstance(); + # Show a warning if the target file exists on a shared repo + $repoGroup = $services->getRepoGroup(); if ( $nt->getNamespace() == NS_FILE && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) ) - && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt ) - && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $nt ) + && !$repoGroup->getLocalRepo()->findFile( $nt ) + && $repoGroup->findFile( $nt ) ) { $this->showForm( [ [ 'file-exists-sharedrepo' ] ] ); @@ -568,8 +572,7 @@ class MovePageForm extends UnlistedSpecialPage { // Delete an associated image if there is if ( $nt->getNamespace() == NS_FILE ) { - $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() - ->newFile( $nt ); + $file = $repoGroup->getLocalRepo()->newFile( $nt ); $file->load( File::READ_LATEST ); if ( $file->exists() ) { $file->delete( $reason, false, $user ); @@ -604,7 +607,7 @@ class MovePageForm extends UnlistedSpecialPage { $this->moveTalk = false; } if ( $this->moveSubpages ) { - $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); + $permissionManager = $services->getPermissionManager(); $this->moveSubpages = $permissionManager->userCan( 'move-subpages', $user, $ot ); } @@ -670,7 +673,7 @@ class MovePageForm extends UnlistedSpecialPage { */ // @todo FIXME: Use Title::moveSubpages() here - $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + $nsInfo = $services->getNamespaceInfo(); $dbr = wfGetDB( DB_MASTER ); if ( $this->moveSubpages && ( $nsInfo->hasSubpages( $nt->getNamespace() ) || (