r36961 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36960‎ | r36961 | r36962 >
Date:23:35, 2 July 2008
Author:skizzerz
Status:old
Tags:
Comment:
* update for GroupPermissionsManager extension, now with 2 more special pages and a bugfix :)
Modified paths:
  • /trunk/extensions/GroupPermissionsManager/GroupPermissionsManager.i18n.php (modified) (history)
  • /trunk/extensions/GroupPermissionsManager/GroupPermissionsManager.php (modified) (history)
  • /trunk/extensions/GroupPermissionsManager/GroupPermissionsManager_body.php (modified) (history)
  • /trunk/extensions/GroupPermissionsManager/RemoveUnusedGroups.php (added) (history)
  • /trunk/extensions/GroupPermissionsManager/SortPermissions.php (added) (history)
  • /trunk/extensions/GroupPermissionsManager/scripts (added) (history)
  • /trunk/extensions/GroupPermissionsManager/scripts/permsort.js (added) (history)

Diff [purge]

Index: trunk/extensions/GroupPermissionsManager/GroupPermissionsManager_body.php
@@ -20,10 +20,11 @@
2121
2222 /**
2323 * Main execution function
 24+ * @param $par the target group to act upon
2425 */
2526 function execute( $par ) {
2627 global $wgRequest, $wgOut, $wgUser;
27 -
 28+
2829 if( !$wgUser->isAllowed( 'grouppermissions' ) ) {
2930 $wgOut->permissionRequired( 'grouppermissions' );
3031 return;
@@ -35,7 +36,7 @@
3637 //display the search form and define an array of the usergroups and an array of all current permissions
3738 global $wgGroupPermissions;
3839 $this->target = $par ? $par : $wgRequest->getText( 'groupsearch', '');
39 -
 40+
4041 foreach($wgGroupPermissions as $group => $permissions) {
4142 $this->groupslist[] = $group;
4243 foreach($permissions as $right => $value) {
@@ -48,7 +49,7 @@
4950 sort($this->permissionslist);
5051
5152 $wgOut->addHtml( $this->makeSearchForm() );
52 -
 53+
5354 //test if we have a valid target to act upon
5455 if( $this->target != '') {
5556 //ok, we do. Now, what action was just being performed?
@@ -100,6 +101,7 @@
101102
102103 /**
103104 * Produce a form to search for a group
 105+ * @return $form the HTML of the form
104106 */
105107 function makeSearchForm() {
106108 $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
@@ -114,6 +116,7 @@
115117
116118 /**
117119 * Produce a form for changing group permissions
 120+ * @return $form the HTML of the form
118121 */
119122 function makeChangeForm() {
120123 //Returns the checkbox toggles for the given group.
@@ -121,7 +124,7 @@
122125 $form = "<br /><div>\n";
123126 $form .= "<form method=\"post\" action=\"".$thisTitle->getLocalUrl()."\" id=\"preferences\">\n";
124127 //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 );
126129 $form .= "<br />\n";
127130 $form .= "<label for=\"comment\">".wfMsg('grouppermissions-comment')."</label> ";
128131 $form .= "<input type=\"text\" name=\"comment\" id=\"comment\" size=\"45\" />\n";
@@ -131,9 +134,10 @@
132135 $form .= "</form>\n</div>\n";
133136 return $form;
134137 }
135 -
 138+
136139 /**
137140 * Produce a form to delete a group
 141+ * @return $form the HTML of the form
138142 */
139143 function makeDeleteForm() {
140144 //sanity check, make sure that we aren't showing this for the automatic groups
@@ -152,17 +156,18 @@
153157 $form .= "</form>\n</fieldset>\n";
154158 return $form;
155159 }
156 -
 160+
157161 /**
158162 * Produce a form to add a group
 163+ * @return $form the HTML of the form
159164 */
160165 function makeAddForm() {
161166 //make a new group and return all toggles
162167 $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
163168 $form = "<br /><div>\n";
164169 $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 );
167172 $form .= "<br />\n";
168173 $form .= "<label for=\"addcomment\">".wfMsg('grouppermissions-comment')."</label> ";
169174 $form .= "<input type=\"text\" name=\"addcomment\" id=\"addcomment\" size=\"45\" />\n";
@@ -174,7 +179,10 @@
175180 }
176181
177182 /**
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
179187 */
180188 function addLogItem( $type, $comment = '' ) {
181189 $target = $this->target;
@@ -189,8 +197,9 @@
190198
191199 /**
192200 * 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
195204 */
196205 function createCheckboxes( &$form, $getcurrentvalues ) {
197206 global $wgGroupPermissions, $wgGPManagerSortTypes, $wgGPManagerSort, $wgGPManagerNeverGrant;
@@ -207,7 +216,7 @@
208217 foreach($wgGPManagerSortTypes as $type) {
209218 $sort[$type] = array();
210219 }
211 -
 220+
212221 foreach($this->permissionslist as $right) {
213222 $s = false;
214223 foreach($wgGPManagerSortTypes as $type) {
@@ -254,22 +263,25 @@
255264 }
256265 $form .= "</td></tr>\n";
257266 }
258 - $form .= "\n</table></fieldset>\n";
 267+ $form .= "</table></fieldset>\n";
259268 }
 269+ return true;
260270 }
261 -
 271+
262272 /**
263273 * 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
264277 */
265 - function writeFile( $type ) {
 278+ private function writeFile( $type ) {
266279 //can we write the file?
267280 if(!is_writable( dirname(__FILE__) . "/config" )) {
268281 echo( "<h2>Cannot write config file, aborting</h2>
269 -
 282+
270283 <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+
274286 <p>Make the necessary changes, then refresh this page to try again</p>" );
275287 die( 1 );
276288 }
@@ -282,7 +294,7 @@
283295 }
284296 }
285297 $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
287299 ##### permissions, please do so HERE instead of LocalSettings.php or anywhere else. If you
288300 ##### set permissions elsewhere, changing them here may not produce the desired results.
289301 $wgGroupPermissions = array();
@@ -307,7 +319,7 @@
308320 }
309321 }
310322 }
311 -
 323+
312324 if($type == 'add') {
313325 //add the new group and its permissions
314326 foreach($_POST as $key => $value) {
@@ -318,7 +330,7 @@
319331 }
320332 }
321333 }
322 -
 334+
323335 //let's iterate through the never grants now
324336 if($wgGPManagerNeverGrant === array()) {
325337 foreach($wgGroupPermissions as $group => $permissions) {
@@ -376,7 +388,7 @@
377389 $grouppermissions .= "\n\$wgGPManagerNeverGrant['".$group."'] = ".$str.";";
378390 }
379391 }
380 -
 392+
381393 $grouppermissions = str_replace( "\r\n", "\n", $grouppermissions );
382394 chdir( dirname(__FILE__) . "/config" );
383395 $f = fopen( "GroupPermissions.php", 'wt' );
@@ -390,7 +402,14 @@
391403 return false;
392404 }
393405 }
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+ */
395414 function makeRadio( $right = '', $value = '', $checked = false ) {
396415 if($checked) {
397416 $input = "<input type=\"radio\" name=\"right-{$right}\" id=\"{$right}-{$value}\" class=\"{$value}\" value=\"{$value}\" checked=\"checked\" />";
@@ -400,4 +419,4 @@
401420 $input .= " <label for=\"{$right}-{$value}\">".wfMsgHtml('grouppermissions-'.$value)."</label> ";
402421 return $input;
403422 }
404 -}
 423+}
\ No newline at end of file
Index: trunk/extensions/GroupPermissionsManager/GroupPermissionsManager.i18n.php
@@ -6,12 +6,14 @@
77 */
88
99 $messages = array();
10 -
 10+
1111 /** English
1212 * @author Ryan Schmidt
1313 */
1414 $messages['en'] = array(
1515 'grouppermissions' => 'Manage Group Permissions',
 16+ 'sortpermissions' => 'Sort Permissions',
 17+ 'removeunusedgroups' => 'Remove Unused Groups',
1618 'grouppermissions-desc' => 'Manage group permissions via a special page',
1719 'grouppermissions-desc2' => 'Extended permissions system',
1820 'grouppermissions-header' => 'You may use this page to change the underlying permissions of the various usergroups',
@@ -46,7 +48,14 @@
4749 'grouppermissions-log-header' => 'This page tracks changes to the underlying permissions of user groups',
4850 'grouppermissions-needjs' => 'Warning: JavaScript is disabled on your browser. Some features may not work!',
4951 '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',
5160 'right-viewsource' => 'View wiki source of protected pages',
5261 'right-raw' => 'View raw pages',
5362 'right-render' => 'View rendered pages without navigation',
@@ -415,5 +424,4 @@
416425 'grouppermissions-dosearch' => 'వెళ్ళు',
417426 'grouppermissions-comment' => 'వ్యాఖ్య:',
418427 '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
185 + 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
163 + native
Index: trunk/extensions/GroupPermissionsManager/GroupPermissionsManager.php
@@ -14,16 +14,16 @@
1515 'name' => 'GroupPermissions Manager',
1616 'author' => 'Ryan Schmidt',
1717 'url' => 'http://www.mediawiki.org/wiki/Extension:GroupPermissions_Manager',
18 - 'version' => '3.0',
 18+ 'version' => '3.1',
1919 'description' => 'Manage group permissions via a special page',
2020 'descriptionmsg' => 'grouppermissions-desc',
2121 );
2222 $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';
2525 $wgSpecialPages['GroupPermissions'] = 'GroupPermissions';
26 -#$wgSpecialPages['RemoveUnusedGroups'] = 'RemoveUnusedGroups';
27 -#$wgSpecialPages['SortPermissions'] = 'SortPermissions';
 26+$wgSpecialPages['RemoveUnusedGroups'] = 'RemoveUnusedGroups';
 27+$wgSpecialPages['SortPermissions'] = 'SortPermissions';
2828 $wgExtensionMessagesFiles['GroupPermissions'] = dirname(__FILE__) . '/GroupPermissionsManager.i18n.php';
2929
3030 $wgLogTypes[] = 'gpmanager';
@@ -34,8 +34,8 @@
3535 $wgLogHeaders['gpmanager'] = 'grouppermissions-log-header';
3636 $wgLogNames['gpmanager'] = 'grouppermissions-log-name';
3737 $wgSpecialPageGroups['GroupPermissions'] = 'wiki';
38 -#$wgSpecialPageGroups['RemoveUnusedGroups'] = 'user';
39 -#$wgSpecialPageGroups['SortPermissions'] = 'wiki';
 38+$wgSpecialPageGroups['RemoveUnusedGroups'] = 'users';
 39+$wgSpecialPageGroups['SortPermissions'] = 'wiki';
4040
4141 ##Permission required to use the 'GroupPermissions' and 'SortPermissions' special page
4242 ##By default all bureaucrats can
@@ -50,12 +50,12 @@
5151 */
5252
5353 $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',
6060 );
6161
6262 $wgHooks['UserGetRights'][] = 'efGPManagerRevokeRights';
@@ -98,10 +98,13 @@
9999 'emailconfirmed', 'noratelimit' );
100100 $wgGPManagerSort['misc'] = array(); //all rights added by extensions that don't have a sort clause get put here
101101
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
103103 if(file_exists(dirname(__FILE__) . "/config/GroupPermissions.php") ) {
104104 require_once(dirname(__FILE__) . "/config/GroupPermissions.php");
105105 }
 106+if(file_exists(dirname(__FILE__) . "/config/SortPermissions.php")) {
 107+ require_once(dirname(__FILE__) . "/config/SortPermissions.php");
 108+}
106109
107110 //Revoke the rights that are set to "never"
108111 function efGPManagerRevokeRights(&$user, &$rights) {
@@ -170,7 +173,7 @@
171174 }
172175 }
173176 //hack for the UserCanRead method
174 - $res = efGPManagerExtendedPermissionsRevoke($title, $user, $action, &$result);
 177+ $res = efGPManagerExtendedPermissionsRevoke($title, $user, $action, $result);
175178 if(!$res) {
176179 $result = false;
177180 //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
1185 + native

Status & tagging log