Beispiel #1
0
 /**
  * @covers MWGrants::getRightsByGrant
  */
 public function testGetRightsByGrant()
 {
     $this->assertSame(['hidden1' => ['read'], 'hidden2' => ['autoconfirmed'], 'normal' => ['edit'], 'normal2' => ['edit', 'create'], 'admin' => ['protect', 'delete']], MWGrants::getRightsByGrant());
 }
 protected function getFormFields()
 {
     $fields = [];
     if ($this->par !== null) {
         $this->botPassword = BotPassword::newFromCentralId($this->userId, $this->par);
         if (!$this->botPassword) {
             $this->botPassword = BotPassword::newUnsaved(['centralId' => $this->userId, 'appId' => $this->par]);
         }
         $sep = BotPassword::getSeparator();
         $fields[] = ['type' => 'info', 'label-message' => 'username', 'default' => $this->getUser()->getName() . $sep . $this->par];
         if ($this->botPassword->isSaved()) {
             $fields['resetPassword'] = ['type' => 'check', 'label-message' => 'botpasswords-label-resetpassword'];
         }
         $lang = $this->getLanguage();
         $showGrants = MWGrants::getValidGrants();
         $fields['grants'] = ['type' => 'checkmatrix', 'label-message' => 'botpasswords-label-grants', 'help-message' => 'botpasswords-help-grants', 'columns' => [$this->msg('botpasswords-label-grants-column')->escaped() => 'grant'], 'rows' => array_combine(array_map('MWGrants::getGrantsLink', $showGrants), $showGrants), 'default' => array_map(function ($g) {
             return "grant-{$g}";
         }, $this->botPassword->getGrants()), 'tooltips' => array_combine(array_map('MWGrants::getGrantsLink', $showGrants), array_map(function ($rights) use($lang) {
             return $lang->semicolonList(array_map('User::getRightDescription', $rights));
         }, array_intersect_key(MWGrants::getRightsByGrant(), array_flip($showGrants)))), 'force-options-on' => array_map(function ($g) {
             return "grant-{$g}";
         }, MWGrants::getHiddenGrants())];
         $fields['restrictions'] = ['type' => 'textarea', 'label-message' => 'botpasswords-label-restrictions', 'required' => true, 'default' => $this->botPassword->getRestrictions()->toJson(true), 'rows' => 5, 'validation-callback' => function ($v) {
             try {
                 MWRestrictions::newFromJson($v);
                 return true;
             } catch (InvalidArgumentException $ex) {
                 return $ex->getMessage();
             }
         }];
     } else {
         $dbr = BotPassword::getDB(DB_SLAVE);
         $res = $dbr->select('bot_passwords', ['bp_app_id'], ['bp_user' => $this->userId], __METHOD__);
         foreach ($res as $row) {
             $fields[] = ['section' => 'existing', 'type' => 'info', 'raw' => true, 'default' => Linker::link($this->getPageTitle($row->bp_app_id), htmlspecialchars($row->bp_app_id), [], [], ['known'])];
         }
         $fields['appId'] = ['section' => 'createnew', 'type' => 'textwithbutton', 'label-message' => 'botpasswords-label-appid', 'buttondefault' => $this->msg('botpasswords-label-create')->text(), 'buttonflags' => ['progressive', 'primary'], 'required' => true, 'size' => BotPassword::APPID_MAXLENGTH, 'maxlength' => BotPassword::APPID_MAXLENGTH, 'validation-callback' => function ($v) {
             $v = trim($v);
             return $v !== '' && strlen($v) <= BotPassword::APPID_MAXLENGTH;
         }];
         $fields[] = ['type' => 'hidden', 'default' => 'new', 'name' => 'op'];
     }
     return $fields;
 }
Beispiel #3
0
 /**
  * @covers MWGrants::getRightsByGrant
  */
 public function testGetRightsByGrant()
 {
     $this->assertSame(array('hidden1' => array('read'), 'hidden2' => array('autoconfirmed'), 'normal' => array('edit'), 'normal2' => array('edit', 'create'), 'admin' => array('protect', 'delete')), MWGrants::getRightsByGrant());
 }