Jeroen De Dauw has submitted this change and it was merged.

Change subject: Use Title::quickUserCan in EntityPermissionChecker
......................................................................


Use Title::quickUserCan in EntityPermissionChecker

Change-Id: If3b94a329ed51c2881f383356d5f7d58bfa7da32
---
M repo/includes/actions/ViewEntityAction.php
M repo/includes/content/EntityContentFactory.php
M repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
3 files changed, 4 insertions(+), 65 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved



diff --git a/repo/includes/actions/ViewEntityAction.php 
b/repo/includes/actions/ViewEntityAction.php
index d65e40c..5dccc08 100644
--- a/repo/includes/actions/ViewEntityAction.php
+++ b/repo/includes/actions/ViewEntityAction.php
@@ -9,7 +9,6 @@
 use SpecialPage;
 use ViewAction;
 use Wikibase\Repo\Content\EntityHandler;
-use Wikibase\Repo\Store\EntityPermissionChecker;
 use Wikibase\Repo\WikibaseRepo;
 
 /**
@@ -27,11 +26,6 @@
         * @var LanguageFallbackChain
         */
        protected $languageFallbackChain;
-
-       /**
-        * @var EntityPermissionChecker
-        */
-       protected $permissionChecker;
 
        /**
         * Get the language fallback chain.
@@ -59,29 +53,6 @@
         */
        public function setLanguageFallbackChain( LanguageFallbackChain $chain 
) {
                $this->languageFallbackChain = $chain;
-       }
-
-       /**
-        * Get permission checker.
-        * Uses the default WikibaseRepo instance to get the service if it was 
not previously set.
-        *
-        * @return EntityPermissionChecker
-        */
-       public function getPermissionChecker() {
-               if ( $this->permissionChecker === null ) {
-                       $this->permissionChecker = 
WikibaseRepo::getDefaultInstance()->getEntityPermissionChecker();
-               }
-
-               return $this->permissionChecker;
-       }
-
-       /**
-        * Set permission checker.
-        *
-        * @param EntityPermissionChecker $permissionChecker
-        */
-       public function setPermissionChecker( EntityPermissionChecker 
$permissionChecker ) {
-               $this->permissionChecker = $permissionChecker;
        }
 
        /**
@@ -161,16 +132,13 @@
                // NOTE: page-wide property, independent of user permissions
                $outputPage->addJsConfigVars( 'wbIsEditView', $editable );
 
+               $user = $this->getContext()->getUser();
+
                if ( $editable && !$content->isRedirect() ) {
-                       $permissionChecker = $this->getPermissionChecker();
-                       $editable = 
$permissionChecker->getEditPermissionForTitle(
-                               $this->getArticle()->getTitle(),
-                               $content,
-                               $this->getUser()
-                       );
+                       $editable = 
$this->getArticle()->getTitle()->quickUserCan( 'edit', $user );
                }
 
-               $parserOptions = 
$this->getArticle()->getPage()->makeParserOptions( 
$this->getContext()->getUser() );
+               $parserOptions = 
$this->getArticle()->getPage()->makeParserOptions( $user );
 
                if ( !$editable ) {
                        // disable editing features ("sections" is a misnomer, 
it applies to the wikitext equivalent)
diff --git a/repo/includes/content/EntityContentFactory.php 
b/repo/includes/content/EntityContentFactory.php
index aefe580..1bc4454 100644
--- a/repo/includes/content/EntityContentFactory.php
+++ b/repo/includes/content/EntityContentFactory.php
@@ -311,24 +311,4 @@
                return $status;
        }
 
-       /**
-        * @param Title $title
-        * @param EntityContent $content
-        * @param User $user
-        *
-        * @return boolean
-        */
-       public function getEditPermissionForTitle( Title $title, EntityContent 
$content, User $user ) {
-               $entityContentTitle = $this->getTitleForId( 
$content->getEntity()->getId() );
-
-               if ( $entityContentTitle->getFullText() !== 
$title->getFullText() ) {
-                       throw new MWException( '$title does not match content' 
);
-               }
-
-               $errors = $title->getUserPermissionsErrors( 'edit', $user, 
'quick' );
-               $permissionStatus = $this->getStatusForPermissionErrors( 
$errors );
-
-               return $permissionStatus->isOK();
-       }
-
 }
diff --git a/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php 
b/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
index 40f4c2b..460cb3f 100644
--- a/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
+++ b/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
@@ -151,7 +151,6 @@
                                        'getPermissionStatusForEntity' => true,
                                        'getPermissionStatusForEntityType' => 
true,
                                        'getPermissionStatusForEntityId' => 
true,
-                                       'getEditPermissionForTitle' => true,
                                ),
                        ),
                        'edit not allowed' => array(
@@ -162,7 +161,6 @@
                                        'getPermissionStatusForEntity' => false,
                                        'getPermissionStatusForEntityType' => 
false,
                                        'getPermissionStatusForEntityId' => 
false,
-                                       'getEditPermissionForTitle' => false,
                                ),
                        ),
                        'delete not allowed' => array(
@@ -217,13 +215,6 @@
                if ( isset( $expectations['getPermissionStatusForEntityId'] ) ) 
{
                        $status = $factory->getPermissionStatusForEntityId( 
$wgUser, $action, $entity->getId() );
                        $this->assertEquals( 
$expectations['getPermissionStatusForEntityId'], $status->isOK() );
-               }
-
-               if ( isset( $expectations['getPermissionForTitle'] ) ) {
-                       $title = $factory->getTitleForId( $entity->getId() );
-                       $content = new \Wikibase\ItemContent( $entity );
-                       $hasPermission = $factory->getPermissionForTitle( 
$title, $content, $wgUser, $action );
-                       $this->assertEquals( 
$expectations['getPermissionForTitle'], $hasPermission );
                }
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If3b94a329ed51c2881f383356d5f7d58bfa7da32
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to