Nikerabbit has uploaded a new change for review.
https://gerrit.wikimedia.org/r/179100
Change subject: Add User::equals
......................................................................
Add User::equals
Seems stupid omission. Title has one. Why do I need to think how
to determine how to users objects point to the same user. Allows
more expressive code.
Also fixes a bug in multiple places where users "0" and "00" were
considered equal.
Change-Id: I682392e564b332b77ab489f2ad394fa2d28098a5
---
M includes/User.php
M includes/changes/RecentChange.php
M includes/diff/DifferenceEngine.php
M includes/page/Article.php
M includes/specials/SpecialUserrights.php
5 files changed, 17 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/00/179100/1
diff --git a/includes/User.php b/includes/User.php
index bda825f..f0a5037 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -4764,7 +4764,7 @@
if ( $action === true ) {
$action = 'byemail';
} elseif ( $action === false ) {
- if ( $this->getName() == $wgUser->getName() ) {
+ if ( $this->equals( $wgUser ) ) {
$action = 'create';
} else {
$action = 'create2';
@@ -5049,4 +5049,15 @@
return Status::newFatal( 'badaccess-group0' );
}
}
+
+ /**
+ * Checks if two user objects point to the same user.
+ *
+ * @since 1.25
+ * @param User $user
+ * @return bool
+ */
+ public function equals( User $user ) {
+ return $this->getName() === $user->getName();
+ }
}
diff --git a/includes/changes/RecentChange.php
b/includes/changes/RecentChange.php
index c719d8d..86cd1d7 100644
--- a/includes/changes/RecentChange.php
+++ b/includes/changes/RecentChange.php
@@ -450,7 +450,7 @@
}
// Users without the 'autopatrol' right can't patrol their
// own revisions
- if ( $user->getName() == $this->getAttribute( 'rc_user_text' )
+ if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
&& !$user->isAllowed( 'autopatrol' )
) {
$errors[] = array(
'markedaspatrollederror-noautopatrol' );
diff --git a/includes/diff/DifferenceEngine.php
b/includes/diff/DifferenceEngine.php
index c887193..dcff557 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -491,7 +491,7 @@
array( 'USE INDEX' => 'rc_timestamp' )
);
- if ( $change &&
$change->getPerformer()->getName() !== $user->getName() ) {
+ if ( $change &&
!$change->getPerformer()->equals( $user ) ) {
$rcid = $change->getAttribute( 'rc_id'
);
} else {
// None found or the page has been
created by the current user.
diff --git a/includes/page/Article.php b/includes/page/Article.php
index 0318f65..25205ab 100644
--- a/includes/page/Article.php
+++ b/includes/page/Article.php
@@ -1159,7 +1159,7 @@
return false;
}
- if ( $rc->getPerformer()->getName() == $user->getName() ) {
+ if ( $rc->getPerformer()->equals( $user ) ) {
// Don't show a patrol link for own creations. If the
user could
// patrol them, they already would be patrolled
wfProfileOut( __METHOD__ );
diff --git a/includes/specials/SpecialUserrights.php
b/includes/specials/SpecialUserrights.php
index 3e9313c..e4a54ca 100644
--- a/includes/specials/SpecialUserrights.php
+++ b/includes/specials/SpecialUserrights.php
@@ -106,7 +106,7 @@
}
}
- if ( User::getCanonicalName( $this->mTarget ) ==
$user->getName() ) {
+ if ( User::getCanonicalName( $this->mTarget ) ===
$user->getName() ) {
$this->isself = true;
}
@@ -228,7 +228,7 @@
global $wgAuth;
// Validate input set...
- $isself = ( $user->getName() == $this->getUser()->getName() );
+ $isself = $user->equals( $this->getUser() );
$groups = $user->getGroups();
$changeable = $this->changeableGroups();
$addable = array_merge( $changeable['add'], $isself ?
$changeable['add-self'] : array() );
--
To view, visit https://gerrit.wikimedia.org/r/179100
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I682392e564b332b77ab489f2ad394fa2d28098a5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits