aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDannyS712 <DannyS712.enwiki@gmail.com>2020-02-26 04:26:00 +0000
committerDannyS712 <DannyS712.enwiki@gmail.com>2020-02-26 05:09:55 +0000
commit7186b63f825722472c99b1fd5224efd50133769c (patch)
tree0cb27c499b9b1c8d9b4237bd6b7b3621aa9429cc
parentdec8ddddcfe062bd4aa3a5bb1ab8cb5d988348f5 (diff)
downloadmediawikicore-7186b63f825722472c99b1fd5224efd50133769c.tar.gz
mediawikicore-7186b63f825722472c99b1fd5224efd50133769c.zip
Hard deprecate Title::getUserPermissionsErrors
Remove final uses as well Bug: T244929 Change-Id: I65e937c7b9904b1e93f649508b14148849589f82
-rw-r--r--RELEASE-NOTES-1.355
-rw-r--r--includes/GlobalFunctions.php2
-rw-r--r--includes/OutputPage.php2
-rw-r--r--includes/ProtectionForm.php12
-rw-r--r--includes/Title.php2
-rw-r--r--includes/api/IApiMessage.php2
-rw-r--r--includes/changes/RecentChange.php12
-rw-r--r--includes/page/WikiPage.php5
-rw-r--r--includes/specials/SpecialChangeContentModel.php9
-rw-r--r--includes/upload/UploadBase.php4
-rw-r--r--tests/phpunit/includes/TitlePermissionTest.php11
11 files changed, 46 insertions, 20 deletions
diff --git a/RELEASE-NOTES-1.35 b/RELEASE-NOTES-1.35
index 8ec75cdecdc4..16a11b19fea8 100644
--- a/RELEASE-NOTES-1.35
+++ b/RELEASE-NOTES-1.35
@@ -516,8 +516,9 @@ because of Phabricator reports.
* The SpecialPageFactory class was moved from the MediaWiki\Special namespace
to the MediaWiki\SpecialPage namespace. The old location remains as a
deprecated alias.
-* Title::userCan and ::quickUserCan, deprecated in 1.33, were hard deprecated.
- Instead, use PermissionManager::userCan and ::quickUserCan.
+* Title::userCan, ::quickUserCan, and ::getUserPermissionsErrors, which
+ were deprecated in 1.33, were hard deprecated. Instead, use
+ PermissionManager::userCan, ::quickUserCan, and ::getPermissionErrors.
* All methods of the old SpecialPageFactory, deprecated in 1.32, were hard
deprecated. Instead, get a SpecialPageFactory from MediaWikiServices and
use its methods.
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 624360723a58..386ffa6f6f14 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -160,7 +160,7 @@ function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) {
}
/**
- * Merge arrays in the style of getUserPermissionsErrors, with duplicate removal
+ * Merge arrays in the style of PermissionManager::getPermissionErrors, with duplicate removal
* e.g.
* wfMergeErrorArrays(
* [ [ 'x' ] ],
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index da732874f29b..314af5fb47b8 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -2772,7 +2772,7 @@ class OutputPage extends ContextSource {
/**
* Format a list of error messages
*
- * @param array $errors Array of arrays returned by Title::getUserPermissionsErrors
+ * @param array $errors Array of arrays returned by PermissionManager::getPermissionErrors
* @param string|null $action Action that was denied or null if unknown
* @return string The wikitext error-messages, formatted into a list.
*/
diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php
index 9bdd45788e63..0e10c1ef664d 100644
--- a/includes/ProtectionForm.php
+++ b/includes/ProtectionForm.php
@@ -74,6 +74,9 @@ class ProtectionForm {
/** @var IContextSource */
private $mContext;
+ /** @var PermissionManager */
+ private $permManager;
+
public function __construct( Article $article ) {
// Set instance variables.
$this->mArticle = $article;
@@ -81,11 +84,14 @@ class ProtectionForm {
$this->mApplicableTypes = $this->mTitle->getRestrictionTypes();
$this->mContext = $article->getContext();
+ $this->permManager = MediaWikiServices::getInstance()->getPermissionManager();
+
// Check if the form should be disabled.
// If it is, the form will be available in read-only to show levels.
- $this->mPermErrors = $this->mTitle->getUserPermissionsErrors(
+ $this->mPermErrors = $this->permManager->getPermissionErrors(
'protect',
$this->mContext->getUser(),
+ $this->mTitle,
$this->mContext->getRequest()->wasPosted()
? PermissionManager::RIGOR_SECURE
: PermissionManager::RIGOR_FULL // T92357
@@ -105,7 +111,7 @@ class ProtectionForm {
* Loads the current state of protection into the object.
*/
function loadData() {
- $levels = MediaWikiServices::getInstance()->getPermissionManager()->getNamespaceRestrictionLevels(
+ $levels = $this->permManager->getNamespaceRestrictionLevels(
$this->mTitle->getNamespace(), $this->mContext->getUser()
);
$this->mCascade = $this->mTitle->areRestrictionsCascading();
@@ -195,7 +201,7 @@ class ProtectionForm {
*/
function execute() {
if (
- MediaWikiServices::getInstance()->getPermissionManager()->getNamespaceRestrictionLevels(
+ $this->permManager->getNamespaceRestrictionLevels(
$this->mTitle->getNamespace()
) === [ '' ]
) {
diff --git a/includes/Title.php b/includes/Title.php
index a48977cce0e8..dc557021f26d 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -2452,6 +2452,8 @@ class Title implements LinkTarget, IDBAccessObject {
public function getUserPermissionsErrors(
$action, $user, $rigor = PermissionManager::RIGOR_SECURE, $ignoreErrors = []
) {
+ wfDeprecated( __METHOD__, '1.33' );
+
// TODO: this is for b/c, eventually will be removed
if ( $rigor === true ) {
$rigor = PermissionManager::RIGOR_SECURE; // b/c
diff --git a/includes/api/IApiMessage.php b/includes/api/IApiMessage.php
index fee62c5acb57..7ce996c0c0e9 100644
--- a/includes/api/IApiMessage.php
+++ b/includes/api/IApiMessage.php
@@ -24,7 +24,7 @@
* The idea is that it's a Message that has some extra data for the API to use when interpreting it
* as an error (or, in the future, as a warning). Internals of MediaWiki often use messages (or
* message keys, or Status objects containing messages) to pass information about errors to the user
- * (see e.g. Title::getUserPermissionsErrors()) and the API has to make do with that.
+ * (see e.g. PermssionManager::getPermissionErrors()) and the API has to make do with that.
*
* @since 1.25
* @note This interface exists to work around PHP's inheritance, so ApiMessage
diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php
index e3ec2e347118..0f1a3ec0c08c 100644
--- a/includes/changes/RecentChange.php
+++ b/includes/changes/RecentChange.php
@@ -536,11 +536,13 @@ class RecentChange implements Taggable {
* @param bool $auto For automatic patrol
* @param string|string[]|null $tags Change tags to add to the patrol log entry
* ($user should be able to add the specified tags before this is called)
- * @return array Array of permissions errors, see Title::getUserPermissionsErrors()
+ * @return array Array of permissions errors, see PermissionManager::getPermissionErrors()
*/
public function doMarkPatrolled( User $user, $auto = false, $tags = null ) {
global $wgUseRCPatrol, $wgUseNPPatrol, $wgUseFilePatrol;
+ $permManager = MediaWikiServices::getInstance()->getPermissionManager();
+
// Fix up $tags so that the MarkPatrolled hook below always gets an array
if ( $tags === null ) {
$tags = [];
@@ -558,7 +560,10 @@ class RecentChange implements Taggable {
}
// Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
$right = $auto ? 'autopatrol' : 'patrol';
- $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
+ $errors = array_merge(
+ $errors,
+ $permManager->getPermissionErrors( $right, $user, $this->getTitle() )
+ );
if ( !Hooks::run( 'MarkPatrolled',
[ $this->getAttribute( 'rc_id' ), &$user, false, $auto, &$tags ] )
) {
@@ -567,8 +572,7 @@ class RecentChange implements Taggable {
// Users without the 'autopatrol' right can't patrol their
// own revisions
if ( $user->getName() === $this->getAttribute( 'rc_user_text' ) &&
- !MediaWikiServices::getInstance()->getPermissionManager()
- ->userHasRight( $user, 'autopatrol' )
+ !$permManager->userHasRight( $user, 'autopatrol' )
) {
$errors[] = [ 'markedaspatrollederror-noautopatrol' ];
}
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 7e1f18687856..908797d59c89 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -3118,8 +3118,9 @@ class WikiPage implements Page, IDBAccessObject {
$resultDetails = null;
// Check permissions
- $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $user );
- $rollbackErrors = $this->mTitle->getUserPermissionsErrors( 'rollback', $user );
+ $permManager = MediaWikiServices::getInstance()->getPermissionManager();
+ $editErrors = $permManager->getPermissionErrors( 'edit', $user, $this->mTitle );
+ $rollbackErrors = $permManager->getPermissionErrors( 'rollback', $user, $this->mTitle );
$errors = array_merge( $editErrors, wfArrayDiff2( $rollbackErrors, $editErrors ) );
if ( !$user->matchEditToken( $token, 'rollback' ) ) {
diff --git a/includes/specials/SpecialChangeContentModel.php b/includes/specials/SpecialChangeContentModel.php
index cf62ff0c4132..96129cdba6ac 100644
--- a/includes/specials/SpecialChangeContentModel.php
+++ b/includes/specials/SpecialChangeContentModel.php
@@ -197,15 +197,16 @@ class SpecialChangeContentModel extends FormSpecialPage {
$titleWithNewContentModel->setContentModel( $data['model'] );
$user = $this->getUser();
// Check permissions and make sure the user has permission to:
+ $permManager = MediaWikiServices::getInstance()->getPermissionManager();
$errors = wfMergeErrorArrays(
// edit the contentmodel of the page
- $this->title->getUserPermissionsErrors( 'editcontentmodel', $user ),
+ $permManager->getPermissionErrors( 'editcontentmodel', $user, $this->title ),
// edit the page under the old content model
- $this->title->getUserPermissionsErrors( 'edit', $user ),
+ $permManager->getPermissionErrors( 'edit', $user, $this->title ),
// edit the contentmodel under the new content model
- $titleWithNewContentModel->getUserPermissionsErrors( 'editcontentmodel', $user ),
+ $permManager->getPermissionErrors( 'editcontentmodel', $user, $titleWithNewContentModel ),
// edit the page under the new content model
- $titleWithNewContentModel->getUserPermissionsErrors( 'edit', $user )
+ $permManager->getPermissionErrors( 'edit', $user, $titleWithNewContentModel )
);
if ( $errors ) {
$out = $this->getOutput();
diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php
index ecaad51f18c1..5dde7934c467 100644
--- a/includes/upload/UploadBase.php
+++ b/includes/upload/UploadBase.php
@@ -610,7 +610,7 @@ abstract class UploadBase {
* really checking the title + user combination.
*
* @param User $user User object to verify the permissions against
- * @return array|bool An array as returned by getUserPermissionsErrors or true
+ * @return array|bool An array as returned by getPermissionErrors or true
* in case the user has proper permissions.
*/
public function verifyPermissions( $user ) {
@@ -625,7 +625,7 @@ abstract class UploadBase {
* can-user-upload checking.
*
* @param User $user User object to verify the permissions against
- * @return array|bool An array as returned by getUserPermissionsErrors or true
+ * @return array|bool An array as returned by getPermissionErrors or true
* in case the user has proper permissions.
*/
public function verifyTitlePermissions( $user ) {
diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php
index 30dab8643237..489f68c91cff 100644
--- a/tests/phpunit/includes/TitlePermissionTest.php
+++ b/tests/phpunit/includes/TitlePermissionTest.php
@@ -101,6 +101,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
public function testQuickPermissions() {
$this->hideDeprecated( 'Title::userCan' );
$this->hideDeprecated( 'Title::quickUserCan' );
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
$prefix = MediaWikiServices::getInstance()->getContentLanguage()->
getFormattedNsText( NS_PROJECT );
@@ -367,6 +368,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
}
protected function runGroupPermissions( $action, $result, $result2 = null ) {
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
if ( $result2 === null ) {
$result2 = $result;
}
@@ -411,6 +413,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
*/
public function testSpecialsAndNSPermissions() {
$this->hideDeprecated( 'Title::userCan' );
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
$this->setUser( $this->userName );
@@ -657,6 +660,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
$resultUserJs,
$resultPatrol
) {
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
+
$this->overrideUserPermissions( $this->user );
$result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
$this->assertEquals( $resultNone, $result );
@@ -705,6 +710,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
*/
public function testPageRestrictions() {
$this->hideDeprecated( 'Title::quickUserCan' );
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
$prefix = MediaWikiServices::getInstance()->getContentLanguage()->
getFormattedNsText( NS_PROJECT );
@@ -799,6 +805,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
*/
public function testCascadingSourcesRestrictions() {
$this->hideDeprecated( 'Title::userCan' );
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
$this->setTitle( NS_MAIN, "test page" );
$this->overrideUserPermissions( $this->user, [ "edit", "bogus" ] );
@@ -831,6 +838,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
*/
public function testActionPermissions() {
$this->hideDeprecated( 'Title::userCan' );
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
$this->overrideUserPermissions( $this->user, [ "createpage" ] );
$this->setTitle( NS_MAIN, "test page" );
@@ -905,6 +913,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
public function testUserBlock() {
$this->hideDeprecated( 'Title::userCan' );
$this->hideDeprecated( 'Title::quickUserCan' );
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
$this->setMwGlobals( [
'wgEmailConfirmToEdit' => true,
@@ -1068,6 +1077,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
* an action of the same name.
*/
public function testUserBlockAction() {
+ $this->hideDeprecated( 'Title::getUserPermissionsErrors' );
+
global $wgLang;
$tester = $this->getMockBuilder( Action::class )