Index: trunk/extensions/GroupPermissionsManager/GroupPermissionsManager_body.php |
— | — | @@ -20,10 +20,11 @@ |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Main execution function |
| 24 | + * @param $par the target group to act upon |
24 | 25 | */ |
25 | 26 | function execute( $par ) { |
26 | 27 | global $wgRequest, $wgOut, $wgUser; |
27 | | - |
| 28 | + |
28 | 29 | if( !$wgUser->isAllowed( 'grouppermissions' ) ) { |
29 | 30 | $wgOut->permissionRequired( 'grouppermissions' ); |
30 | 31 | return; |
— | — | @@ -35,7 +36,7 @@ |
36 | 37 | //display the search form and define an array of the usergroups and an array of all current permissions |
37 | 38 | global $wgGroupPermissions; |
38 | 39 | $this->target = $par ? $par : $wgRequest->getText( 'groupsearch', ''); |
39 | | - |
| 40 | + |
40 | 41 | foreach($wgGroupPermissions as $group => $permissions) { |
41 | 42 | $this->groupslist[] = $group; |
42 | 43 | foreach($permissions as $right => $value) { |
— | — | @@ -48,7 +49,7 @@ |
49 | 50 | sort($this->permissionslist); |
50 | 51 | |
51 | 52 | $wgOut->addHtml( $this->makeSearchForm() ); |
52 | | - |
| 53 | + |
53 | 54 | //test if we have a valid target to act upon |
54 | 55 | if( $this->target != '') { |
55 | 56 | //ok, we do. Now, what action was just being performed? |
— | — | @@ -100,6 +101,7 @@ |
101 | 102 | |
102 | 103 | /** |
103 | 104 | * Produce a form to search for a group |
| 105 | + * @return $form the HTML of the form |
104 | 106 | */ |
105 | 107 | function makeSearchForm() { |
106 | 108 | $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() ); |
— | — | @@ -114,6 +116,7 @@ |
115 | 117 | |
116 | 118 | /** |
117 | 119 | * Produce a form for changing group permissions |
| 120 | + * @return $form the HTML of the form |
118 | 121 | */ |
119 | 122 | function makeChangeForm() { |
120 | 123 | //Returns the checkbox toggles for the given group. |
— | — | @@ -121,7 +124,7 @@ |
122 | 125 | $form = "<br /><div>\n"; |
123 | 126 | $form .= "<form method=\"post\" action=\"".$thisTitle->getLocalUrl()."\" id=\"preferences\">\n"; |
124 | 127 | //get the rows of checkboxes, specify that we should get values for them as well |
125 | | - $form .= $this->createCheckboxes( $form, true ); |
| 128 | + $this->createCheckboxes( $form, true ); |
126 | 129 | $form .= "<br />\n"; |
127 | 130 | $form .= "<label for=\"comment\">".wfMsg('grouppermissions-comment')."</label> "; |
128 | 131 | $form .= "<input type=\"text\" name=\"comment\" id=\"comment\" size=\"45\" />\n"; |
— | — | @@ -131,9 +134,10 @@ |
132 | 135 | $form .= "</form>\n</div>\n"; |
133 | 136 | return $form; |
134 | 137 | } |
135 | | - |
| 138 | + |
136 | 139 | /** |
137 | 140 | * Produce a form to delete a group |
| 141 | + * @return $form the HTML of the form |
138 | 142 | */ |
139 | 143 | function makeDeleteForm() { |
140 | 144 | //sanity check, make sure that we aren't showing this for the automatic groups |
— | — | @@ -152,17 +156,18 @@ |
153 | 157 | $form .= "</form>\n</fieldset>\n"; |
154 | 158 | return $form; |
155 | 159 | } |
156 | | - |
| 160 | + |
157 | 161 | /** |
158 | 162 | * Produce a form to add a group |
| 163 | + * @return $form the HTML of the form |
159 | 164 | */ |
160 | 165 | function makeAddForm() { |
161 | 166 | //make a new group and return all toggles |
162 | 167 | $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() ); |
163 | 168 | $form = "<br /><div>\n"; |
164 | 169 | $form .= "<form method=\"post\" action=\"".$thisTitle->getLocalUrl()."\" id=\"preferences\">\n"; |
165 | | - //get the rows of checkboxes, specify that we should not get values for them |
166 | | - $form .= $this->createCheckboxes( $form, false ); |
| 170 | + //get the rows of checkboxes, specify that we should not get values for them |
| 171 | + $this->createCheckboxes( $form, false ); |
167 | 172 | $form .= "<br />\n"; |
168 | 173 | $form .= "<label for=\"addcomment\">".wfMsg('grouppermissions-comment')."</label> "; |
169 | 174 | $form .= "<input type=\"text\" name=\"addcomment\" id=\"addcomment\" size=\"45\" />\n"; |
— | — | @@ -174,7 +179,10 @@ |
175 | 180 | } |
176 | 181 | |
177 | 182 | /** |
178 | | - * Add logging entries for the specified action if logging is enabled |
| 183 | + * Add logging entries for the specified action |
| 184 | + * @param $type 'add', 'change', or 'delete', |
| 185 | + * @param $comment the log comment |
| 186 | + * @return bool $s the success of the operation |
179 | 187 | */ |
180 | 188 | function addLogItem( $type, $comment = '' ) { |
181 | 189 | $target = $this->target; |
— | — | @@ -189,8 +197,9 @@ |
190 | 198 | |
191 | 199 | /** |
192 | 200 | * Make the sorted tables of radio buttons and permissions |
193 | | - * @param form the form that it is adding the radio buttons to. |
194 | | - * @param getcurrentvalues is used for determining if it should set the radio buttons at the current permissions |
| 201 | + * @param $form the form that it is adding the radio buttons to. |
| 202 | + * @param $getcurrentvalues is used for determining if it should set the radio buttons at the current permissions |
| 203 | + * @return bool the success of the operation |
195 | 204 | */ |
196 | 205 | function createCheckboxes( &$form, $getcurrentvalues ) { |
197 | 206 | global $wgGroupPermissions, $wgGPManagerSortTypes, $wgGPManagerSort, $wgGPManagerNeverGrant; |
— | — | @@ -207,7 +216,7 @@ |
208 | 217 | foreach($wgGPManagerSortTypes as $type) { |
209 | 218 | $sort[$type] = array(); |
210 | 219 | } |
211 | | - |
| 220 | + |
212 | 221 | foreach($this->permissionslist as $right) { |
213 | 222 | $s = false; |
214 | 223 | foreach($wgGPManagerSortTypes as $type) { |
— | — | @@ -254,22 +263,25 @@ |
255 | 264 | } |
256 | 265 | $form .= "</td></tr>\n"; |
257 | 266 | } |
258 | | - $form .= "\n</table></fieldset>\n"; |
| 267 | + $form .= "</table></fieldset>\n"; |
259 | 268 | } |
| 269 | + return true; |
260 | 270 | } |
261 | | - |
| 271 | + |
262 | 272 | /** |
263 | 273 | * Write the php file |
| 274 | + * @param $type add, delete, or change - the type of the post |
| 275 | + * @return bool success of the write |
| 276 | + * @private |
264 | 277 | */ |
265 | | - function writeFile( $type ) { |
| 278 | + private function writeFile( $type ) { |
266 | 279 | //can we write the file? |
267 | 280 | if(!is_writable( dirname(__FILE__) . "/config" )) { |
268 | 281 | echo( "<h2>Cannot write config file, aborting</h2> |
269 | | - |
| 282 | + |
270 | 283 | <p>In order to use this extension, you need to make the /config subdirectory of this extension |
271 | | - writable by the webserver (eg, if you have this extension installed in /extensions/GPManager, |
272 | | - you need to make /extensions/GPManager/config writable by the webserver.</p> |
273 | | - |
| 284 | + writable by the webserver.</p> |
| 285 | + |
274 | 286 | <p>Make the necessary changes, then refresh this page to try again</p>" ); |
275 | 287 | die( 1 ); |
276 | 288 | } |
— | — | @@ -282,7 +294,7 @@ |
283 | 295 | } |
284 | 296 | } |
285 | 297 | $grouppermissions = '<?php |
286 | | -##### This file was automatically generated by Special:Grouppermissions. When changing group |
| 298 | +##### This file was automatically generated by Special:GroupPermissions. When changing group |
287 | 299 | ##### permissions, please do so HERE instead of LocalSettings.php or anywhere else. If you |
288 | 300 | ##### set permissions elsewhere, changing them here may not produce the desired results. |
289 | 301 | $wgGroupPermissions = array(); |
— | — | @@ -307,7 +319,7 @@ |
308 | 320 | } |
309 | 321 | } |
310 | 322 | } |
311 | | - |
| 323 | + |
312 | 324 | if($type == 'add') { |
313 | 325 | //add the new group and its permissions |
314 | 326 | foreach($_POST as $key => $value) { |
— | — | @@ -318,7 +330,7 @@ |
319 | 331 | } |
320 | 332 | } |
321 | 333 | } |
322 | | - |
| 334 | + |
323 | 335 | //let's iterate through the never grants now |
324 | 336 | if($wgGPManagerNeverGrant === array()) { |
325 | 337 | foreach($wgGroupPermissions as $group => $permissions) { |
— | — | @@ -376,7 +388,7 @@ |
377 | 389 | $grouppermissions .= "\n\$wgGPManagerNeverGrant['".$group."'] = ".$str.";"; |
378 | 390 | } |
379 | 391 | } |
380 | | - |
| 392 | + |
381 | 393 | $grouppermissions = str_replace( "\r\n", "\n", $grouppermissions ); |
382 | 394 | chdir( dirname(__FILE__) . "/config" ); |
383 | 395 | $f = fopen( "GroupPermissions.php", 'wt' ); |
— | — | @@ -390,7 +402,14 @@ |
391 | 403 | return false; |
392 | 404 | } |
393 | 405 | } |
394 | | - |
| 406 | + |
| 407 | + /** |
| 408 | + * Make a radio button with label |
| 409 | + * @param $right the permission to make the radio for |
| 410 | + * @param $value can be 'true', 'false' or 'never' |
| 411 | + * @param $checked whether to check this radio by default |
| 412 | + * @return $input the HTML of the input and label tags |
| 413 | + */ |
395 | 414 | function makeRadio( $right = '', $value = '', $checked = false ) { |
396 | 415 | if($checked) { |
397 | 416 | $input = "<input type=\"radio\" name=\"right-{$right}\" id=\"{$right}-{$value}\" class=\"{$value}\" value=\"{$value}\" checked=\"checked\" />"; |
— | — | @@ -400,4 +419,4 @@ |
401 | 420 | $input .= " <label for=\"{$right}-{$value}\">".wfMsgHtml('grouppermissions-'.$value)."</label> "; |
402 | 421 | return $input; |
403 | 422 | } |
404 | | -} |
| 423 | +} |
\ No newline at end of file |
Index: trunk/extensions/GroupPermissionsManager/GroupPermissionsManager.i18n.php |
— | — | @@ -6,12 +6,14 @@ |
7 | 7 | */ |
8 | 8 | |
9 | 9 | $messages = array(); |
10 | | - |
| 10 | + |
11 | 11 | /** English |
12 | 12 | * @author Ryan Schmidt |
13 | 13 | */ |
14 | 14 | $messages['en'] = array( |
15 | 15 | 'grouppermissions' => 'Manage Group Permissions', |
| 16 | + 'sortpermissions' => 'Sort Permissions', |
| 17 | + 'removeunusedgroups' => 'Remove Unused Groups', |
16 | 18 | 'grouppermissions-desc' => 'Manage group permissions via a special page', |
17 | 19 | 'grouppermissions-desc2' => 'Extended permissions system', |
18 | 20 | 'grouppermissions-header' => 'You may use this page to change the underlying permissions of the various usergroups', |
— | — | @@ -46,7 +48,14 @@ |
47 | 49 | 'grouppermissions-log-header' => 'This page tracks changes to the underlying permissions of user groups', |
48 | 50 | 'grouppermissions-needjs' => 'Warning: JavaScript is disabled on your browser. Some features may not work!', |
49 | 51 | 'grouppermissions-sp-header' => 'You may use this page to manage how permissions are sorted and add new permissions', |
50 | | - |
| 52 | + 'grouppermissions-sp-sort' => 'Sort Permissions', |
| 53 | + 'grouppermissions-sp-save' => 'Save', |
| 54 | + 'grouppermissions-sp-success' => 'Permissions have been successfully sorted', |
| 55 | + 'grouppermissions-sp-addtype' => 'Add Sort Type', |
| 56 | + 'grouppermissions-sp-addperm' => 'Add Permission', |
| 57 | + 'grouppermissions-rug-header' => 'You may use this page to remove users from unused (deleted) groups.', |
| 58 | + 'grouppermissions-rug-success' => 'Successfully removed users from unused groups!', |
| 59 | + 'grouppermissions-rug-confirm' => 'Remove users from unused groups', |
51 | 60 | 'right-viewsource' => 'View wiki source of protected pages', |
52 | 61 | 'right-raw' => 'View raw pages', |
53 | 62 | 'right-render' => 'View rendered pages without navigation', |
— | — | @@ -415,5 +424,4 @@ |
416 | 425 | 'grouppermissions-dosearch' => 'వెళ్ళు', |
417 | 426 | 'grouppermissions-comment' => 'వ్యాఖ్య:', |
418 | 427 | 'right-edit' => 'పేజీలను మార్చడం', |
419 | | -); |
420 | | - |
| 428 | +); |
\ No newline at end of file |
Index: trunk/extensions/GroupPermissionsManager/RemoveUnusedGroups.php |
— | — | @@ -0,0 +1,83 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | +* class definition for the special page |
| 6 | +*/ |
| 7 | +class RemoveUnusedGroups extends SpecialPage { |
| 8 | + |
| 9 | + /** |
| 10 | + * Constructor function |
| 11 | + * Registers the special page, restricts it to those with the 'userrights' right |
| 12 | + */ |
| 13 | + function RemoveUnusedGroups() { |
| 14 | + SpecialPage::SpecialPage( 'RemoveUnusedGroups', 'userrights' ); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * Main execution function |
| 19 | + * @param $par unused |
| 20 | + */ |
| 21 | + function execute($par) { |
| 22 | + global $wgUser, $wgRequest, $wgOut, $wgGPManagerRUGrequireConfirm; |
| 23 | + |
| 24 | + if( !$wgUser->isAllowed( 'userrights' ) ) { |
| 25 | + $wgOut->permissionRequired( 'userrights' ); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + wfLoadExtensionMessages('GroupPermissions'); |
| 30 | + $this->setHeaders(); |
| 31 | + $wgOut->addWikiText( wfMsg( 'grouppermissions-rug-header' ) ); |
| 32 | + if($wgRequest->wasPosted()) { |
| 33 | + $success = $this->removeUsers(); |
| 34 | + if($success) { |
| 35 | + $wgOut->addWikiText(wfMsg('grouppermissions-rug-success')); |
| 36 | + } |
| 37 | + } |
| 38 | + $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() ); |
| 39 | + $form = "<form method=\"post\" action=\"".$thisTitle->getLocalUrl()."\">\n<input type=\"submit\" name=\"wpConfirm\" value=\"".wfMsg('grouppermissions-rug-confirm')."\" />\n</form>"; |
| 40 | + $wgOut->addHTML($form); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Function to remove users from unused groups |
| 45 | + * @return bool the success of the operation |
| 46 | + * @private |
| 47 | + */ |
| 48 | + private function removeUsers() { |
| 49 | + global $wgDBprefix, $wgOut; |
| 50 | + //just use the master for everything, since we're reading and writing in the same link |
| 51 | + $db = wfGetDB(DB_MASTER); |
| 52 | + $db->begin(); |
| 53 | + $query = "SELECT DISTINCT `ug_group` FROM `{$wgDBprefix}user_groups`"; |
| 54 | + $res = $db->query($query, 'RemoveUnusedGroups::removeUsers:select'); |
| 55 | + if($res === false) { |
| 56 | + return false; |
| 57 | + } |
| 58 | + $nr = $db->numRows($res); |
| 59 | + $i = 0; |
| 60 | + $dbgroups = array(); |
| 61 | + while($i < $nr) { |
| 62 | + $row = $db->fetchRow($res); |
| 63 | + $dbgroups[] = $row['ug_group']; |
| 64 | + $i++; |
| 65 | + } |
| 66 | + $db->freeResult($res); |
| 67 | + global $wgGroupPermissions; |
| 68 | + $defgroups = array(); |
| 69 | + foreach($wgGroupPermissions as $group => $perms) { |
| 70 | + $defgroups[] = $group; |
| 71 | + } |
| 72 | + //todo: could this in any way be optimized? |
| 73 | + $diff = array_diff($dbgroups, $defgroups); |
| 74 | + foreach($diff as $group) { |
| 75 | + $query = "DELETE FROM `{$wgDBprefix}user_groups` WHERE ug_group='{$group}'"; |
| 76 | + $s = $db->query($query, 'RemoveUnusedGroups::removeUsers:delete'); |
| 77 | + if(!$s) { |
| 78 | + return false; |
| 79 | + } |
| 80 | + } |
| 81 | + $db->commit(); |
| 82 | + return true; |
| 83 | + } |
| 84 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/GroupPermissionsManager/RemoveUnusedGroups.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 85 | + native |
Index: trunk/extensions/GroupPermissionsManager/scripts/permsort.js |
— | — | @@ -0,0 +1,61 @@ |
| 2 | +//for the Special:SortPermissions page |
| 3 | + |
| 4 | +//Adds a new column (sort type) to the table |
| 5 | +function addColumn() { |
| 6 | + var table = document.getElementById('sorttable'); |
| 7 | + var ste = document.getElementById('sorttypes'); |
| 8 | + var colname = document.getElementById('wpNewType').value; |
| 9 | + if(!colname || colname == '') return false; |
| 10 | + types[numtypes] = colname; |
| 11 | + numtypes++; |
| 12 | + var rows = table.getElementsByTagName('tr'); |
| 13 | + for(var i=0;i<rows.length;i++) { |
| 14 | + var td = document.createElement('td'); |
| 15 | + var btn = document.createElement('input'); |
| 16 | + var rowname = rows[i].id; |
| 17 | + btn.type = 'radio'; |
| 18 | + btn.name = 'right-' + rowname; |
| 19 | + btn.id = rowname + '-' + colname; |
| 20 | + btn.value = colname; |
| 21 | + var lbl = document.createElement('label'); |
| 22 | + lbl.htmlFor = rowname + '-' + colname; |
| 23 | + var text = document.createTextNode(colname); |
| 24 | + lbl.appendChild(text); |
| 25 | + td.appendChild(btn); |
| 26 | + td.appendChild(lbl); |
| 27 | + rows[i].appendChild(td); |
| 28 | + } |
| 29 | + ste.value = ste.value + '|' + colname; |
| 30 | + return true; |
| 31 | +} |
| 32 | + |
| 33 | +//Adds a new row (permission) to the table |
| 34 | +function addRow() { |
| 35 | + var table = document.getElementById('sorttable'); |
| 36 | + var rowname = document.getElementById('wpNewPerm').value; |
| 37 | + if(!rowname || rowname == '') return false; |
| 38 | + var tr = document.createElement('tr'); |
| 39 | + tr.id = rowname; |
| 40 | + var td = []; |
| 41 | + td[0] = document.createElement('td'); |
| 42 | + var text = document.createTextNode(rowname); |
| 43 | + td[0].appendChild(text); |
| 44 | + tr.appendChild(td[0]); |
| 45 | + for(var i=1;i<=numtypes;i++) { |
| 46 | + td[i] = document.createElement('td'); |
| 47 | + var btn = document.createElement('input'); |
| 48 | + btn.type = 'radio'; |
| 49 | + btn.name = 'right-' + rowname; |
| 50 | + btn.id = rowname + '-' + types[i-1]; |
| 51 | + btn.value = types[i-1]; |
| 52 | + var lbl = document.createElement('label'); |
| 53 | + lbl.htmlFor = rowname + '-' + types[i-1]; |
| 54 | + var text = document.createTextNode(types[i-1]); |
| 55 | + lbl.appendChild(text); |
| 56 | + td[i].appendChild(btn); |
| 57 | + td[i].appendChild(lbl); |
| 58 | + tr.appendChild(td[i]); |
| 59 | + } |
| 60 | + table.appendChild(tr); |
| 61 | + return true; |
| 62 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/GroupPermissionsManager/scripts/permsort.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 63 | + native |
Index: trunk/extensions/GroupPermissionsManager/GroupPermissionsManager.php |
— | — | @@ -14,16 +14,16 @@ |
15 | 15 | 'name' => 'GroupPermissions Manager', |
16 | 16 | 'author' => 'Ryan Schmidt', |
17 | 17 | 'url' => 'http://www.mediawiki.org/wiki/Extension:GroupPermissions_Manager', |
18 | | - 'version' => '3.0', |
| 18 | + 'version' => '3.1', |
19 | 19 | 'description' => 'Manage group permissions via a special page', |
20 | 20 | 'descriptionmsg' => 'grouppermissions-desc', |
21 | 21 | ); |
22 | 22 | $wgAutoloadClasses['GroupPermissions'] = dirname(__FILE__) . '/GroupPermissionsManager_body.php'; |
23 | | -#$wgAutoloadClasses['RemoveUnusedGroups'] = dirname(__FILE__) . '/RemoveUnusedGroups.php'; |
24 | | -#$wgAutoloadClasses['SortPermissions'] = dirname(__FILE__) . '/SortPermissions.php'; |
| 23 | +$wgAutoloadClasses['RemoveUnusedGroups'] = dirname(__FILE__) . '/RemoveUnusedGroups.php'; |
| 24 | +$wgAutoloadClasses['SortPermissions'] = dirname(__FILE__) . '/SortPermissions.php'; |
25 | 25 | $wgSpecialPages['GroupPermissions'] = 'GroupPermissions'; |
26 | | -#$wgSpecialPages['RemoveUnusedGroups'] = 'RemoveUnusedGroups'; |
27 | | -#$wgSpecialPages['SortPermissions'] = 'SortPermissions'; |
| 26 | +$wgSpecialPages['RemoveUnusedGroups'] = 'RemoveUnusedGroups'; |
| 27 | +$wgSpecialPages['SortPermissions'] = 'SortPermissions'; |
28 | 28 | $wgExtensionMessagesFiles['GroupPermissions'] = dirname(__FILE__) . '/GroupPermissionsManager.i18n.php'; |
29 | 29 | |
30 | 30 | $wgLogTypes[] = 'gpmanager'; |
— | — | @@ -34,8 +34,8 @@ |
35 | 35 | $wgLogHeaders['gpmanager'] = 'grouppermissions-log-header'; |
36 | 36 | $wgLogNames['gpmanager'] = 'grouppermissions-log-name'; |
37 | 37 | $wgSpecialPageGroups['GroupPermissions'] = 'wiki'; |
38 | | -#$wgSpecialPageGroups['RemoveUnusedGroups'] = 'user'; |
39 | | -#$wgSpecialPageGroups['SortPermissions'] = 'wiki'; |
| 38 | +$wgSpecialPageGroups['RemoveUnusedGroups'] = 'users'; |
| 39 | +$wgSpecialPageGroups['SortPermissions'] = 'wiki'; |
40 | 40 | |
41 | 41 | ##Permission required to use the 'GroupPermissions' and 'SortPermissions' special page |
42 | 42 | ##By default all bureaucrats can |
— | — | @@ -50,12 +50,12 @@ |
51 | 51 | */ |
52 | 52 | |
53 | 53 | $wgExtensionCredits['other'][] = array( |
54 | | -'name' => 'Permissions++', |
55 | | -'author' => 'Ryan Schmidt', |
56 | | -'url' => 'http://www.mediawiki.org/wiki/Extension:GroupPermissions_Manager', |
57 | | -'version' => '1.0', |
58 | | -'description' => 'Extended permissions system', |
59 | | -'descriptionmsg' => 'grouppermissions-desc2', |
| 54 | + 'name' => 'Permissions++', |
| 55 | + 'author' => 'Ryan Schmidt', |
| 56 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:GroupPermissions_Manager', |
| 57 | + 'version' => '1.0', |
| 58 | + 'description' => 'Extended permissions system', |
| 59 | + 'descriptionmsg' => 'grouppermissions-desc2', |
60 | 60 | ); |
61 | 61 | |
62 | 62 | $wgHooks['UserGetRights'][] = 'efGPManagerRevokeRights'; |
— | — | @@ -98,10 +98,13 @@ |
99 | 99 | 'emailconfirmed', 'noratelimit' ); |
100 | 100 | $wgGPManagerSort['misc'] = array(); //all rights added by extensions that don't have a sort clause get put here |
101 | 101 | |
102 | | -##Load the config file, if it exists. This must be the last thing to run in the startup part |
| 102 | +##Load the config files, if they exist. This must be the last thing to run in the startup part |
103 | 103 | if(file_exists(dirname(__FILE__) . "/config/GroupPermissions.php") ) { |
104 | 104 | require_once(dirname(__FILE__) . "/config/GroupPermissions.php"); |
105 | 105 | } |
| 106 | +if(file_exists(dirname(__FILE__) . "/config/SortPermissions.php")) { |
| 107 | + require_once(dirname(__FILE__) . "/config/SortPermissions.php"); |
| 108 | +} |
106 | 109 | |
107 | 110 | //Revoke the rights that are set to "never" |
108 | 111 | function efGPManagerRevokeRights(&$user, &$rights) { |
— | — | @@ -170,7 +173,7 @@ |
171 | 174 | } |
172 | 175 | } |
173 | 176 | //hack for the UserCanRead method |
174 | | - $res = efGPManagerExtendedPermissionsRevoke($title, $user, $action, &$result); |
| 177 | + $res = efGPManagerExtendedPermissionsRevoke($title, $user, $action, $result); |
175 | 178 | if(!$res) { |
176 | 179 | $result = false; |
177 | 180 | //yay epic hacking! If I can't choose to make it return badaccess-group0... I'll simply force it to |
Index: trunk/extensions/GroupPermissionsManager/SortPermissions.php |
— | — | @@ -0,0 +1,183 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | +* class definition for SortPermissions |
| 6 | +*/ |
| 7 | + |
| 8 | +class SortPermissions extends SpecialPage { |
| 9 | + var $permlist = array(); |
| 10 | + var $oldrev = ''; |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructor function |
| 14 | + * Registers the special page, restricts it to those with the 'grouppermissions' right |
| 15 | + */ |
| 16 | + function SortPermissions() { |
| 17 | + SpecialPage::SpecialPage( 'SortPermissions', 'grouppermissions' ); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * Main execution function |
| 22 | + * @param $par unused |
| 23 | + */ |
| 24 | + function execute( $par ) { |
| 25 | + global $wgRequest, $wgOut, $wgUser, $wgScriptPath; |
| 26 | + |
| 27 | + if( !$wgUser->isAllowed( 'grouppermissions' ) ) { |
| 28 | + $wgOut->permissionRequired( 'grouppermissions' ); |
| 29 | + return; |
| 30 | + } |
| 31 | + $wgOut->addHTML('<noscript><strong>' . wfMsg('grouppermissions-needjs') . '</strong></noscript>'); |
| 32 | + wfLoadExtensionMessages('GroupPermissions'); |
| 33 | + $this->setHeaders(); |
| 34 | + $wgOut->addWikiText( wfMsg( 'grouppermissions-sp-header' ) ); |
| 35 | + //if we posted, try to write the file |
| 36 | + if($wgRequest->wasPosted()) { |
| 37 | + $success = $this->writeFile(); |
| 38 | + if($success) { |
| 39 | + $wgOut->addWikiText(wfMsg('grouppermissions-sp-success')); |
| 40 | + } |
| 41 | + } |
| 42 | + $this->makeForm(); |
| 43 | + $dir = dirname(__FILE__); |
| 44 | + $pos = strpos($dir, $wgScriptPath); |
| 45 | + $inc = substr($dir, $pos); |
| 46 | + addScriptFile("$inc/scripts/permsort.js"); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Make the form |
| 51 | + */ |
| 52 | + function makeForm() { |
| 53 | + global $wgOut, $wgGPManagerSortTypes, $wgGroupPermissions; |
| 54 | + $a = '["' . implode('", "', $wgGPManagerSortTypes) . '"]'; |
| 55 | + if($a === '[""]') { |
| 56 | + $a = '[]'; |
| 57 | + } |
| 58 | + $nt = count($wgGPManagerSortTypes); |
| 59 | + $script = "<script type=\"text/javascript\">\n var numtypes = $nt;\n var types = [];\n"; |
| 60 | + $c = 0; |
| 61 | + foreach($wgGPManagerSortTypes as $type) { |
| 62 | + $script .= " types[$c] = '$type';\n"; |
| 63 | + $c++; |
| 64 | + } |
| 65 | + $script .= "</script>"; |
| 66 | + $wgOut->addHTML($script); |
| 67 | + $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() ); |
| 68 | + $mainform = "\n<fieldset>\n<legend>" . wfMsg('grouppermissions-sp-sort') . "</legend>\n"; |
| 69 | + $mainform .= "<form method=\"post\" action=\"".$thisTitle->getLocalUrl()."\">\n"; |
| 70 | + $mainform .= "<table id=\"sorttable\">"; |
| 71 | + foreach($wgGroupPermissions as $permissions) { |
| 72 | + foreach($permissions as $permission => $value) { |
| 73 | + $this->permlist[] = $permission; |
| 74 | + } |
| 75 | + } |
| 76 | + $this->permlist = array_unique($this->permlist); |
| 77 | + sort($this->permlist); |
| 78 | + foreach($this->permlist as $permission) { |
| 79 | + $mainform .= $this->makeRadios($permission, $wgGPManagerSortTypes ); |
| 80 | + } |
| 81 | + $mainform .= "\n</table>\n<input type=\"submit\" name=\"wpSave\" value=\"".wfMsg('grouppermissions-sp-save')."\" />"; |
| 82 | + $st = implode('|', $wgGPManagerSortTypes); |
| 83 | + $mainform .= "\n<input type=\"hidden\" name=\"sorttypes\" value=\"$st\" />\n</form>\n</fieldset>"; |
| 84 | + $wgOut->addHTML($mainform); |
| 85 | + $form = "\n<fieldset>\n<legend>".wfMsg('grouppermissions-sp-addtype')."</legend>\n"; |
| 86 | + $form .= "<form method=\"post\" action=\"\">\n<input type=\"text\" name=\"wpNewType\" id=\"wpNewType\" /> "; |
| 87 | + $form .= "<input type=\"button\" onclick=\"javascript:addColumn();\" value=\"".wfMsg('grouppermissions-sp-addtype')."\"/>\n</form>\n</fieldset>"; |
| 88 | + $form .= "\n<fieldset>\n<legend>".wfMsg('grouppermissions-sp-addperm')."</legend>\n"; |
| 89 | + $form .= "<form method=\"post\" action=\"\">\n<input type=\"text\" name=\"wpNewPerm\" id=\"wpNewPerm\" /> "; |
| 90 | + $form .= "<input type=\"button\" onclick=\"javascript:addRow();\" value=\"".wfMsg('grouppermissions-sp-addperm')."\"/>\n</form>\n</fieldset>"; |
| 91 | + $wgOut->addHTML($form); |
| 92 | + return true; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Make radio buttons for the form |
| 97 | + * @param $perm the permission to make a row for |
| 98 | + * @param $types array of sort types |
| 99 | + * @return $ret the HTML of the table row |
| 100 | + */ |
| 101 | + function makeRadios($perm, $types) { |
| 102 | + global $wgGPManagerSort; |
| 103 | + $ret = "\n<tr id=\"$perm\"><td>$perm</td>"; |
| 104 | + foreach($types as $type) { |
| 105 | + if(array_key_exists($type, $wgGPManagerSort) && in_array($perm, $wgGPManagerSort[$type])) { |
| 106 | + $ret .= "\n<td><input type=\"radio\" name=\"right-$perm\" id=\"$perm-$type\" value=\"$type\" checked=\"checked\" />"; |
| 107 | + } else { |
| 108 | + $ret .= "\n<td><input type=\"radio\" name=\"right-$perm\" id=\"$perm-$type\" value=\"$type\" />"; |
| 109 | + } |
| 110 | + $ret .= "<label for=\"$perm-$type\">$type</label>"; |
| 111 | + } |
| 112 | + $ret .= "\n</tr>"; |
| 113 | + return $ret; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Write the php file |
| 118 | + * @return bool the success of the file write |
| 119 | + * @private |
| 120 | + */ |
| 121 | + private function writeFile() { |
| 122 | + //can we write the file? |
| 123 | + if(!is_writable( dirname(__FILE__) . "/config" )) { |
| 124 | + echo( "<h2>Cannot write config file, aborting</h2> |
| 125 | + |
| 126 | + <p>In order to use this extension, you need to make the /config subdirectory of this extension |
| 127 | + writable by the webserver.</p> |
| 128 | + |
| 129 | + <p>Make the necessary changes, then refresh this page to try again</p>" ); |
| 130 | + die( 1 ); |
| 131 | + } |
| 132 | + $this->oldrev = gmdate('dmYHis'); |
| 133 | + if(file_exists(dirname(__FILE__) . '/config/SortPermissions.php')) { |
| 134 | + $r = rename(dirname(__FILE__) . '/config/SortPermissions.php', dirname(__FILE__) . '/config/SortPermissions.' . $this->oldrev . '.php'); |
| 135 | + if(!$r) { |
| 136 | + global $wgOut; |
| 137 | + $wgOut->addWikiText(wfMsg('grouppermissions-nooldrev')); |
| 138 | + } |
| 139 | + } |
| 140 | + $sortpermissions = '<?php |
| 141 | +##### This file was automatically generated by Special:SortPermissions. When changing |
| 142 | +##### permission sorting, please do so HERE instead of LocalSettings.php or anywhere |
| 143 | +##### else. If you sort permissions elsewhere, sorting them here may not produce the |
| 144 | +##### desired results.'; |
| 145 | + global $wgRequest; |
| 146 | + //define the sort types |
| 147 | + $sts = explode('|', $wgRequest->getVal('sorttypes')); |
| 148 | + $st = " '" . implode("', '", $sts) . "' "; |
| 149 | + if($st === " '' ") { |
| 150 | + $st = ''; |
| 151 | + } |
| 152 | + $sortpermissions .= "\n\$wgGPManagerSortTypes = array($st);"; |
| 153 | + //do the sorting by iterating through $_POST |
| 154 | + $sortpermissions .= "\n\$wgGPManagerSort = array();"; |
| 155 | + $sort = array(); |
| 156 | + foreach($_POST as $key => $value) { |
| 157 | + if(strpos($key, 'right-') === 0) { |
| 158 | + $rt = explode('-', $key, 2); |
| 159 | + $sort[$value][] = $rt[1]; |
| 160 | + $sort[$value] = array_unique($sort[$value]); |
| 161 | + } |
| 162 | + } |
| 163 | + //now implode it and put it in the file |
| 164 | + foreach($sort as $key => $rights) { |
| 165 | + $st = " '" . implode("', '", $rights) . "' "; |
| 166 | + if($st === " '' ") { |
| 167 | + $st = ''; |
| 168 | + } |
| 169 | + $sortpermissions .= "\n\$wgGPManagerSort['$key'] = array($st);"; |
| 170 | + } |
| 171 | + $sortpermissions = str_replace( "\r\n", "\n", $sortpermissions ); |
| 172 | + chdir( dirname(__FILE__) . "/config" ); |
| 173 | + $f = fopen( "SortPermissions.php", 'wt' ); |
| 174 | + if(fwrite( $f, $sortpermissions ) ) { |
| 175 | + fclose( $f ); |
| 176 | + print "\n"; |
| 177 | + return true; |
| 178 | + } else { |
| 179 | + fclose( $f ); |
| 180 | + echo("<p class='error'>An error occured while writing the config/SortPermissions.php file. Check user rights and disk space then try again.</p>"); |
| 181 | + return false; |
| 182 | + } |
| 183 | + } |
| 184 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/GroupPermissionsManager/SortPermissions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 185 | + native |