From 7ac4fec0ba987775786bca104991644050f71373 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Wed, 1 Oct 2014 13:06:10 +0100 Subject: [PATCH] User rights API: Abstract out some stuff about core's form into separate methods To we can make a CentralAuth API module for global user rights. Bug: 71495 Change-Id: I139c43e5eaa1fb63b75baddbafb7caa3c964d6b5 --- includes/api/ApiUserrights.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index c3ceb3457b..66af4c574c 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -32,12 +32,28 @@ class ApiUserrights extends ApiBase { private $mUser = null; + /** + * Get a UserrightsPage object, or subclass. + * @return UserrightsPage + */ + protected function getUserRightsPage() { + return new UserrightsPage; + } + + /** + * Get all available groups. + * @return array + */ + protected function getAllGroups() { + return User::getAllGroups(); + } + public function execute() { $params = $this->extractRequestParams(); $user = $this->getUrUser( $params ); - $form = new UserrightsPage; + $form = $this->getUserRightsPage(); $form->setContext( $this->getContext() ); $r['user'] = $user->getName(); $r['userid'] = $user->getId(); @@ -65,7 +81,7 @@ class ApiUserrights extends ApiBase { $user = isset( $params['user'] ) ? $params['user'] : '#' . $params['userid']; - $form = new UserrightsPage; + $form = $this->getUserRightsPage(); $form->setContext( $this->getContext() ); $status = $form->fetchUser( $user ); if ( !$status->isOK() ) { @@ -94,11 +110,11 @@ class ApiUserrights extends ApiBase { ApiBase::PARAM_TYPE => 'integer', ), 'add' => array( - ApiBase::PARAM_TYPE => User::getAllGroups(), + ApiBase::PARAM_TYPE => $this->getAllGroups(), ApiBase::PARAM_ISMULTI => true ), 'remove' => array( - ApiBase::PARAM_TYPE => User::getAllGroups(), + ApiBase::PARAM_TYPE => $this->getAllGroups(), ApiBase::PARAM_ISMULTI => true ), 'reason' => array( -- 2.20.1