Aashaka has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277723
Change subject: Use RequestContext::getMain()->getUser() instead of $wgUser in
Title.php
......................................................................
Use RequestContext::getMain()->getUser() instead of $wgUser in Title.php
$wgUser is a global and its use is deprecated.
RequestContext::getMain()->getUser() has been used in place of $wgUser
in functions: userCan, isValidMoveOperation, validateFileMoveOperation,
moveTo and getNotificationTimestamp.
Bug: T51086
Change-Id: Iebc81afdbd8d1adc7dbf4cd98f710f370c200cc3
---
M includes/Title.php
1 file changed, 16 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/23/277723/1
diff --git a/includes/Title.php b/includes/Title.php
index 0ac3e46..54e6536 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -1899,7 +1899,8 @@
* May provide false positives, but should never provide a false
negative.
*
* @param string $action Action that permission needs to be checked for
- * @param User $user User to check (since 1.19); $wgUser will be used
if not provided.
+ * @param User $user User to check (since 1.19);
+ * RequestContext::getMain()->getUser() will be used if not provided.
* @return bool
*/
public function quickUserCan( $action, $user = null ) {
@@ -1910,15 +1911,14 @@
* Can $user perform $action on this page?
*
* @param string $action Action that permission needs to be checked for
- * @param User $user User to check (since 1.19); $wgUser will be used
if not
- * provided.
+ * @param User $user User to check (since 1.19);
+ * RequestContext::getMain()->getUser() will be used if not provided.
* @param string $rigor Same format as Title::getUserPermissionsErrors()
* @return bool
*/
public function userCan( $action, $user = null, $rigor = 'secure' ) {
if ( !$user instanceof User ) {
- global $wgUser;
- $user = $wgUser;
+ $user = RequestContext::getMain()->getUser();
}
return !count( $this->getUserPermissionsErrorsInternal(
$action, $user, $rigor, true ) );
@@ -3614,12 +3614,11 @@
*
* @deprecated since 1.25, use MovePage's methods instead
* @param Title $nt The new title
- * @param bool $auth Whether to check user permissions (uses $wgUser)
+ * @param bool $auth Whether to check user permissions (uses
RequestContext::getMain()->getUser())
* @param string $reason Is the log summary of the move, used for spam
checking
* @return array|bool True on success, getUserPermissionsErrors()-like
array on failure
*/
public function isValidMoveOperation( &$nt, $auth = true, $reason = ''
) {
- global $wgUser;
if ( !( $nt instanceof Title ) ) {
// Normally we'd add this to $errors, but we'll get
@@ -3632,7 +3631,7 @@
if ( $auth ) {
$errors = wfMergeErrorArrays(
$errors,
- $mp->checkPermissions( $wgUser, $reason
)->getErrorsArray()
+ $mp->checkPermissions(
RequestContext::getMain()->getUser(), $reason )->getErrorsArray()
);
}
@@ -3646,13 +3645,13 @@
* @return array List of errors
*/
protected function validateFileMoveOperation( $nt ) {
- global $wgUser;
+ $user = RequestContext::getMain()->getUser();
$errors = [];
$destFile = wfLocalFile( $nt );
$destFile->load( File::READ_LATEST );
- if ( !$wgUser->isAllowed( 'reupload-shared' )
+ if ( !$user->isAllowed( 'reupload-shared' )
&& !$destFile->exists() && wfFindFile( $nt )
) {
$errors[] = [ 'file-exists-sharedrepo' ];
@@ -3666,7 +3665,7 @@
*
* @deprecated since 1.25, use the MovePage class instead
* @param Title $nt The new title
- * @param bool $auth Indicates whether $wgUser's permissions
+ * @param bool $auth Indicates whether $user's permissions
* should be checked
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to create a redirect from the
old title to the new title.
@@ -3674,20 +3673,20 @@
* @return array|bool True on success, getUserPermissionsErrors()-like
array on failure
*/
public function moveTo( &$nt, $auth = true, $reason = '',
$createRedirect = true ) {
- global $wgUser;
+ $user = RequestContext::getMain()->getUser();
$err = $this->isValidMoveOperation( $nt, $auth, $reason );
if ( is_array( $err ) ) {
// Auto-block user's IP if the account was "hard"
blocked
- $wgUser->spreadAnyEditBlock();
+ $user->spreadAnyEditBlock();
return $err;
}
// Check suppressredirect permission
- if ( $auth && !$wgUser->isAllowed( 'suppressredirect' ) ) {
+ if ( $auth && !$user->isAllowed( 'suppressredirect' ) ) {
$createRedirect = true;
}
$mp = new MovePage( $this, $nt );
- $status = $mp->move( $wgUser, $reason, $createRedirect );
+ $status = $mp->move( $user, $reason, $createRedirect );
if ( $status->isOK() ) {
return true;
} else {
@@ -3699,7 +3698,7 @@
* Move this page's subpages to be subpages of $nt
*
* @param Title $nt Move target
- * @param bool $auth Whether $wgUser's permissions should be checked
+ * @param bool $auth Whether $user's permissions should be checked
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to create redirects from the old
subpages to
* the new ones Ignored if the user doesn't have the
'suppressredirect' right
@@ -4446,11 +4445,10 @@
* @return string|null
*/
public function getNotificationTimestamp( $user = null ) {
- global $wgUser;
// Assume current user if none given
if ( !$user ) {
- $user = $wgUser;
+ $user = RequestContext::getMain()->getUser();
}
// Check cache first
$uid = $user->getId();
--
To view, visit https://gerrit.wikimedia.org/r/277723
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebc81afdbd8d1adc7dbf4cd98f710f370c200cc3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aashaka <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits