Jhernandez has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/200844

Change subject: Hygiene: Improve Collection::isOwner
......................................................................

Hygiene: Improve Collection::isOwner

Compare using the object equals method instead of doing it manually.

Actually use the method wherever possible around Special:Gather.

Bug: T94556
Change-Id: I562789a3d4831725673e581f28183326898cb8ad
---
M includes/models/CollectionBase.php
M includes/specials/SpecialGather.php
2 files changed, 10 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather 
refs/changes/44/200844/1

diff --git a/includes/models/CollectionBase.php 
b/includes/models/CollectionBase.php
index cf83b52..0632912 100644
--- a/includes/models/CollectionBase.php
+++ b/includes/models/CollectionBase.php
@@ -171,7 +171,7 @@
         * @return boolean
         */
        public function isOwner( User $user ) {
-               return $this->owner->getName() == $user->getName();
+               return $this->owner->equals( $user );
        }
 
 }
diff --git a/includes/specials/SpecialGather.php 
b/includes/specials/SpecialGather.php
index 7a53462..50c3184 100644
--- a/includes/specials/SpecialGather.php
+++ b/includes/specials/SpecialGather.php
@@ -115,8 +115,9 @@
                $collection = models\Collection::newFromApi( $id, $user );
 
                if ( $collection === null ||
-                       ( !$collection->isPublic() && !$this->isOwner( 
$collection->getOwner() ) ) ) {
+                       // If collection is private and current user doesn't 
own it
                        // FIXME: No permissions to visit this. Showing not 
found ATM.
+                       ( !$collection->isPublic() && !$collection->isOwner( 
$this->getUser() ) ) ) {
                        $this->renderError( new views\NotFound() );
                } else {
                        $this->getOutput()->addJsConfigVars( 
'wgGatherCollections', $collection->toArray() );
@@ -131,7 +132,9 @@
         * @param User $user owner of collections
         */
        public function renderUserCollectionsList( User $user ) {
-               $collectionsList = models\CollectionsList::newFromApi( $user, 
$this->isOwner( $user ) );
+               $collectionsList = models\CollectionsList::newFromApi(
+                       $user, $this->getUser()->equals( $user )
+               );
                if ( $collectionsList->getCount() > 0 ) {
                        $this->render( new views\CollectionsList( 
$collectionsList ) );
                } else {
@@ -152,25 +155,14 @@
                $view->render( $out );
        }
 
-       /**
-        * Returns if the user viewing the page is the owner of the 
collection/list
-        * we are viewing
-        *
-        * @param User $user user owner of the current page
-        *
-        * @return boolean
-        */
-       private function isOwner( User $user ) {
-               return $this->getUser()->equals( $user );
-       }
-
        // FIXME: Re-evaluate when UI supports editing image of collection.
        private function updateCollectionImage( $collection ) {
                $currentImage = $collection->getFile();
-               $user = $collection->getOwner();
                $suggestedImage = $collection->getSuggestedImage();
                $imageChanged = !$currentImage || 
$currentImage->getTitle()->getText() !== $suggestedImage;
-               if ( $imageChanged && $this->isOwner( $user ) && 
!$collection->isWatchlist() ) {
+               if ( $imageChanged &&
+                       $collection->isOwner( $this->getUser() ) &&
+                       !$collection->isWatchlist() ) {
                        // try to set the collection image to the first item in 
the collection.
                        try {
                                $api = new ApiMain( new DerivativeRequest(
@@ -179,7 +171,7 @@
                                                'action' => 'editlist',
                                                'id' => $collection->getId(),
                                                'image' => $suggestedImage,
-                                               'token' => $user->getEditToken( 
'watch' ),
+                                               'token' => 
$collection->getOwner()->getEditToken( 'watch' ),
                                        ),
                                        true
                                ), true );

-- 
To view, visit https://gerrit.wikimedia.org/r/200844
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I562789a3d4831725673e581f28183326898cb8ad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <jhernan...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to