Remove the deprecated MWGrants class

Bug: T253077
Change-Id: I95c3e0668799e20e7e0abe5346e6d884502a5fb2
This commit is contained in:
Alexander Vorwerk 2022-09-16 17:07:20 +02:00
parent 8d361d665b
commit 6b196b660d
4 changed files with 1 additions and 285 deletions

View file

@ -72,6 +72,7 @@ because of Phabricator reports.
=== Breaking changes in 1.40 ===
* BagOStuff::makeKeyInternal(), deprecated for public use in 1.36, is now a
protected method of MediumSpecificBagOStuff.
* The MWGrants class, deprecated since 1.38, has been removed.
* …
=== Deprecations in 1.40 ===

View file

@ -804,7 +804,6 @@ $wgAutoloadLocalClasses = [
'MWExceptionHandler' => __DIR__ . '/includes/exception/MWExceptionHandler.php',
'MWExceptionRenderer' => __DIR__ . '/includes/exception/MWExceptionRenderer.php',
'MWFileProps' => __DIR__ . '/includes/utils/MWFileProps.php',
'MWGrants' => __DIR__ . '/includes/MWGrants.php',
'MWHttpRequest' => __DIR__ . '/includes/http/MWHttpRequest.php',
'MWLBFactory' => __DIR__ . '/includes/db/MWLBFactory.php',
'MWOldPassword' => __DIR__ . '/includes/password/MWOldPassword.php',

View file

@ -1,158 +0,0 @@
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use MediaWiki\MediaWikiServices;
/**
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsInfo and GrantsLocalization instead
*
* A collection of public static functions to deal with grants.
*/
class MWGrants {
/**
* List all known grants.
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsInfo::getValidGrants() instead
* @return array
*/
public static function getValidGrants() {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsInfo()->getValidGrants();
}
/**
* Map all grants to corresponding user rights.
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsInfo::getRightsByGrant() instead
* @return array grant => array of rights
*/
public static function getRightsByGrant() {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsInfo()->getRightsByGrant();
}
/**
* Fetch the description of the grant
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsLocalization::getGrantDescription() instead
* @param string $grant
* @param Language|string|null $lang
* @return string Grant description
*/
public static function grantName( $grant, $lang = null ) {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsLocalization()->getGrantDescription( $grant, $lang );
}
/**
* Fetch the descriptions for the grants.
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsLocalization::getGrantDescriptions() instead
* @param string[] $grants
* @param Language|string|null $lang
* @return string[] Corresponding grant descriptions
*/
public static function grantNames( array $grants, $lang = null ) {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsLocalization()->getGrantDescriptions( $grants, $lang );
}
/**
* Fetch the rights allowed by a set of grants.
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsInfo::getGrantRights() instead
* @param string[]|string $grants
* @return string[]
*/
public static function getGrantRights( $grants ) {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsInfo()->getGrantRights( $grants );
}
/**
* Test that all grants in the list are known.
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsInfo::grantsAreValid() instead
* @param string[] $grants
* @return bool
*/
public static function grantsAreValid( array $grants ) {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsInfo()->grantsAreValid( $grants );
}
/**
* Divide the grants into groups.
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsInfo::getGrantGroups() instead
* @param string[]|null $grantsFilter
* @return array Map of (group => (grant list))
*/
public static function getGrantGroups( $grantsFilter = null ) {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsInfo()->getGrantGroups( $grantsFilter );
}
/**
* Get the list of grants that are hidden and should always be granted
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsInfo::getHiddenGrants() instead
* @return string[]
*/
public static function getHiddenGrants() {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsInfo()->getHiddenGrants();
}
/**
* Generate a link to Special:ListGrants for a particular grant name.
*
* This should be used to link end users to a full description of what
* rights they are giving when they authorize a grant.
*
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsLocalization::getGrantsLink() instead
*
* @param string $grant the grant name
* @param Language|string|null $lang
* @return string (proto-relative) HTML link
*/
public static function getGrantsLink( $grant, $lang = null ) {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsLocalization()->getGrantsLink( $grant, $lang );
}
/**
* Generate wikitext to display a list of grants
* @deprecated since 1.38, hard deprecated since 1.39
* Use GrantsLocalization::getGrantsWikiText() instead
*
* @param string[]|null $grantsFilter If non-null, only display these grants.
* @param Language|string|null $lang
* @return string Wikitext
*/
public static function getGrantsWikiText( $grantsFilter, $lang = null ) {
wfDeprecated( __METHOD__, '1.38' );
return MediaWikiServices::getInstance()->getGrantsLocalization()->getGrantsWikiText( $grantsFilter, $lang );
}
}

View file

@ -1,126 +0,0 @@
<?php
use MediaWiki\MainConfigNames;
class MWGrantsTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->overrideConfigValues( [
MainConfigNames::GrantPermissions => [
'hidden1' => [ 'read' => true, 'autoconfirmed' => false ],
'hidden2' => [ 'autoconfirmed' => true ],
'normal' => [ 'edit' => true ],
'normal2' => [ 'edit' => true, 'create' => true ],
'admin' => [ 'protect' => true, 'delete' => true ],
],
MainConfigNames::GrantPermissionGroups => [
'hidden1' => 'hidden',
'hidden2' => 'hidden',
'normal' => 'normal-group',
'admin' => 'admin',
],
] );
}
/**
* @covers MWGrants::getValidGrants
*/
public function testGetValidGrants() {
$this->hideDeprecated( 'MWGrants::getValidGrants' );
$this->assertSame(
[ 'hidden1', 'hidden2', 'normal', 'normal2', 'admin' ],
MWGrants::getValidGrants()
);
}
/**
* @covers MWGrants::getRightsByGrant
*/
public function testGetRightsByGrant() {
$this->hideDeprecated( 'MWGrants::getRightsByGrant' );
$this->assertSame(
[
'hidden1' => [ 'read' ],
'hidden2' => [ 'autoconfirmed' ],
'normal' => [ 'edit' ],
'normal2' => [ 'edit', 'create' ],
'admin' => [ 'protect', 'delete' ],
],
MWGrants::getRightsByGrant()
);
}
/**
* @dataProvider provideGetGrantRights
* @covers MWGrants::getGrantRights
* @param array|string $grants
* @param array $rights
*/
public function testGetGrantRights( $grants, $rights ) {
$this->hideDeprecated( 'MWGrants::getGrantRights' );
$this->assertSame( $rights, MWGrants::getGrantRights( $grants ) );
}
public static function provideGetGrantRights() {
return [
[ 'hidden1', [ 'read' ] ],
[ [ 'hidden1', 'hidden2', 'hidden3' ], [ 'read', 'autoconfirmed' ] ],
[ [ 'normal1', 'normal2' ], [ 'edit', 'create' ] ],
];
}
/**
* @dataProvider provideGrantsAreValid
* @covers MWGrants::grantsAreValid
* @param array $grants
* @param bool $valid
*/
public function testGrantsAreValid( $grants, $valid ) {
$this->hideDeprecated( 'MWGrants::grantsAreValid' );
$this->assertSame( $valid, MWGrants::grantsAreValid( $grants ) );
}
public static function provideGrantsAreValid() {
return [
[ [ 'hidden1', 'hidden2' ], true ],
[ [ 'hidden1', 'hidden3' ], false ],
];
}
/**
* @dataProvider provideGetGrantGroups
* @covers MWGrants::getGrantGroups
* @param array|null $grants
* @param array $expect
*/
public function testGetGrantGroups( $grants, $expect ) {
$this->hideDeprecated( 'MWGrants::getGrantGroups' );
$this->assertSame( $expect, MWGrants::getGrantGroups( $grants ) );
}
public static function provideGetGrantGroups() {
return [
[ null, [
'hidden' => [ 'hidden1', 'hidden2' ],
'normal-group' => [ 'normal' ],
'other' => [ 'normal2' ],
'admin' => [ 'admin' ],
] ],
[ [ 'hidden1', 'normal' ], [
'hidden' => [ 'hidden1' ],
'normal-group' => [ 'normal' ],
] ],
];
}
/**
* @covers MWGrants::getHiddenGrants
*/
public function testGetHiddenGrants() {
$this->hideDeprecated( 'MWGrants::getHiddenGrants' );
$this->assertSame( [ 'hidden1', 'hidden2' ], MWGrants::getHiddenGrants() );
}
}