Example #1
0
 /**
  * Main execution function
  * @param $par unused
  */
 function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser, $wgScriptPath;
     if (!$wgUser->isAllowed('grouppermissions')) {
         $wgOut->permissionRequired('grouppermissions');
         return;
     }
     $wgOut->addHTML('<noscript><strong>' . wfMsg('grouppermissions-needjs') . '</strong></noscript>');
     $this->setHeaders();
     $wgOut->addWikiText(wfMsg('grouppermissions-sp-header'));
     $dir = dirname(__FILE__);
     if (!empty($wgScriptPath)) {
         $pos = strpos($dir, $wgScriptPath);
         $dir = substr($dir, $pos);
     }
     addScriptFile("{$dir}/scripts/permsort.js");
     //if we posted, try to write the file
     if ($wgRequest->wasPosted()) {
         $success = $this->writeFile();
         if ($success) {
             $wgOut->addWikiText(wfMsg('grouppermissions-sp-success'));
             global $wgGroupPermissions, $wgGPManagerSortTypes, $wgGPManagerSort;
             require dirname(__FILE__) . '/config/SortPermissions.php';
         }
     }
     $this->makeForm();
 }
 /**
  * Main execution function
  * @param $par the target group to act upon
  */
 function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser;
     if (!$wgUser->isAllowed('grouppermissions')) {
         $wgOut->permissionRequired('grouppermissions');
         return;
     }
     $this->setHeaders();
     $wgOut->addWikiText(wfMsg('grouppermissions-header'));
     //display the search form and define an array of the usergroups and an array of all current permissions
     global $wgGroupPermissions, $wgGPManagerNeverGrant;
     $this->target = $par ? $par : $wgRequest->getText('groupsearch', '');
     foreach ($wgGroupPermissions as $group => $permissions) {
         $this->groupslist[] = $group;
         foreach ($permissions as $right => $value) {
             if (!in_array($right, $this->permissionslist)) {
                 $this->permissionslist[] = $right;
             }
         }
     }
     //sort the array in alphabetical order for ease of finding things
     sort($this->permissionslist);
     $wgOut->addHTML($this->makeSearchForm());
     //test if we have a valid target to act upon
     if ($this->target != '') {
         //ok, we do. Now, what action was just being performed?
         if ($wgRequest->getCheck('dosearch') || !$wgRequest->wasPosted()) {
             addScriptFile('prefs.js');
             //it was a search, check the group
             if (in_array($this->target, $this->groupslist)) {
                 global $wgImplicitGroups;
                 //group exists, so we can change it, can't delete it if it's an implicit group
                 if (in_array($this->target, $wgImplicitGroups)) {
                     //cannot delete group, show just show the change form
                     $wgOut->addHTML($this->makeChangeForm());
                 } else {
                     //can delete group, so show that form as well
                     $wgOut->addHTML($this->makeDeleteForm());
                     $wgOut->addHTML($this->makeChangeForm());
                 }
             } else {
                 //group doesn't exist, let's make it and assign some rights
                 $wgOut->addHTML($this->makeAddForm());
             }
         } elseif ($wgRequest->wasPosted() && $wgRequest->getVal('doadd') == '1') {
             //we just added a new group!
             $success = $this->writeFile('add');
             if ($success) {
                 $this->addLogItem('add', trim($wgRequest->getText('addcomment')));
                 $wgOut->addWikiText(wfMsg('grouppermissions-addsuccess', $this->target));
                 $this->listsmade = false;
                 require dirname(__FILE__) . '/config/GroupPermissions.php';
             }
         } elseif ($wgRequest->wasPosted() && $wgRequest->getVal('dodelete') == '1') {
             //we just deleted a user group. don't remove users from the group just in case we want to make it again
             $success = $this->writeFile('delete');
             if ($success) {
                 $this->addLogItem('delete', trim($wgRequest->getText('deletecomment')));
                 $wgOut->addWikiText(wfMsg('grouppermissions-deletesuccess', $this->target));
                 $this->listsmade = false;
                 require dirname(__FILE__) . '/config/GroupPermissions.php';
             }
         } elseif ($wgRequest->wasPosted() && $wgRequest->getVal('dochange') == '1') {
             //we modified the permissions of an existing group
             $success = $this->writeFile('change');
             if ($success) {
                 $this->addLogItem('change', trim($wgRequest->getText('comment')));
                 $wgOut->addWikiText(wfMsg('grouppermissions-changesuccess', $this->target));
                 $this->listsmade = false;
                 require dirname(__FILE__) . '/config/GroupPermissions.php';
             }
         }
     }
 }