2005-01-17 11:45:47 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Provide an administration interface
|
2005-01-27 19:51:47 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2005-01-17 11:45:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** */
|
|
|
|
|
require_once('HTMLForm.php');
|
|
|
|
|
require_once('Group.php');
|
|
|
|
|
|
|
|
|
|
/** Entry point */
|
2005-05-06 07:03:09 +00:00
|
|
|
function wfSpecialGroups() {
|
2005-01-17 11:45:47 +00:00
|
|
|
global $wgRequest;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-05-01 12:59:39 +00:00
|
|
|
$form = new GroupsForm($wgRequest);
|
2005-01-17 11:45:47 +00:00
|
|
|
$form->execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A class to manage group levels rights.
|
2005-01-27 19:51:47 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2005-01-17 11:45:47 +00:00
|
|
|
*/
|
2005-05-01 12:59:39 +00:00
|
|
|
class GroupsForm extends HTMLForm {
|
2005-05-01 18:24:20 +00:00
|
|
|
var $mPosted, $mRequest, $mSaveprefs, $mChangeAllowed;
|
|
|
|
|
var $mNewName, $mDescription, $mOldName, $mRights, $mId;
|
|
|
|
|
var $mAdd, $mEdit;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-01-17 11:45:47 +00:00
|
|
|
/** Escaped local url name*/
|
2005-05-01 18:24:20 +00:00
|
|
|
var $action, $location;
|
2005-01-17 11:45:47 +00:00
|
|
|
|
|
|
|
|
/** Constructor*/
|
2005-05-01 12:59:39 +00:00
|
|
|
function GroupsForm ( &$request ) {
|
2005-05-01 18:24:20 +00:00
|
|
|
global $wgUser;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-01-17 11:45:47 +00:00
|
|
|
$this->mPosted = $request->wasPosted();
|
2005-05-14 05:41:22 +00:00
|
|
|
$this->mRequest =& $request;
|
2005-05-01 12:59:39 +00:00
|
|
|
$this->mName = 'groups';
|
2005-05-01 18:24:20 +00:00
|
|
|
|
|
|
|
|
$this->mNewName = trim( $request->getText('editgroup-name') );
|
|
|
|
|
$this->mOldName = trim( $request->getText('editgroup-oldname' ) );
|
|
|
|
|
$this->mDescription = trim( $request->getText( 'editgroup-description' ) );
|
|
|
|
|
$this->mRights = $request->getArray( 'editgroup-getrights' );
|
|
|
|
|
$this->mId = $this->mRequest->getInt('id');
|
|
|
|
|
$this->mEdit = $request->getCheck('edit');
|
|
|
|
|
$this->mAdd = $request->getCheck('add');
|
|
|
|
|
|
|
|
|
|
|
2005-05-01 12:59:39 +00:00
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, 'Groups' );
|
2005-01-17 11:45:47 +00:00
|
|
|
$this->action = $titleObj->escapeLocalURL();
|
2005-05-01 18:24:20 +00:00
|
|
|
if ( $this->mAdd ) {
|
|
|
|
|
$this->location = $titleObj->getLocalURL( "add=1&id={$this->mId}" );
|
|
|
|
|
} elseif ( $this->mEdit ) {
|
|
|
|
|
$this->location = $titleObj->getLocalURL( "edit=1&id={$this->mId}" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->location = $this->action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->mChangeAllowed = $wgUser->isAllowed( 'grouprights' ) && !Group::getStaticGroups();
|
2005-01-17 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2005-05-14 05:41:22 +00:00
|
|
|
* Manage forms to be shown according to posted data
|
|
|
|
|
* Depending on the submit button used, call a form or a saving function.
|
2005-01-17 11:45:47 +00:00
|
|
|
*/
|
|
|
|
|
function execute() {
|
2005-05-01 18:24:20 +00:00
|
|
|
global $wgOut;
|
2005-01-17 11:45:47 +00:00
|
|
|
|
2005-05-01 18:24:20 +00:00
|
|
|
if ( $this->mRequest->getBool( 'showrecord' ) ) {
|
|
|
|
|
$this->showRecord();
|
|
|
|
|
} elseif ( $this->mPosted && $this->mChangeAllowed && $this->mRequest->getCheck('savegroup') ) {
|
2005-01-17 11:45:47 +00:00
|
|
|
// save settings
|
2005-05-01 18:24:20 +00:00
|
|
|
$this->saveGroup();
|
|
|
|
|
} elseif ( $this->mEdit ) {
|
|
|
|
|
if ( $this->mPosted ) {
|
|
|
|
|
$wgOut->redirect( $this->location );
|
2006-01-07 13:31:29 +00:00
|
|
|
} else {
|
2005-05-01 18:24:20 +00:00
|
|
|
$this->switchForm();
|
2006-01-07 13:09:30 +00:00
|
|
|
$this->editGroupForm( $this->mId );
|
2005-05-01 18:24:20 +00:00
|
|
|
}
|
|
|
|
|
} elseif ( $this->mAdd ) {
|
|
|
|
|
if ( $this->mPosted ) {
|
|
|
|
|
$wgOut->redirect( $this->location );
|
|
|
|
|
} else {
|
|
|
|
|
$this->switchForm();
|
2006-01-07 13:09:30 +00:00
|
|
|
$this->editGroupForm( );
|
2005-05-01 18:24:20 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->showAllGroups();
|
|
|
|
|
if ( $this->mChangeAllowed ) {
|
|
|
|
|
$this->switchForm();
|
2005-01-17 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save a group
|
|
|
|
|
*/
|
2005-05-01 18:24:20 +00:00
|
|
|
function saveGroup() {
|
|
|
|
|
global $wgOut;
|
|
|
|
|
|
|
|
|
|
$this->mNewName = trim($this->mNewName);
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-05-01 18:24:20 +00:00
|
|
|
if ( $this->mNewName == '' ) {
|
|
|
|
|
$this->editGroupForm( $this->mGroupID, 'groups-noname' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($this->mOldName == '') {
|
|
|
|
|
// Check if the group already exists
|
|
|
|
|
$add = true;
|
|
|
|
|
$g = Group::newFromName( $this->mNewName );
|
|
|
|
|
if ( $g ) {
|
|
|
|
|
$this->editGroupForm( 0, 'groups-already-exists' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a new group
|
2005-05-14 05:41:22 +00:00
|
|
|
$g = new Group();
|
2005-01-17 11:45:47 +00:00
|
|
|
$g->addToDatabase();
|
|
|
|
|
} else {
|
2005-05-01 18:24:20 +00:00
|
|
|
$add = false;
|
|
|
|
|
$g = Group::newFromName($this->mOldName);
|
|
|
|
|
if ( !$g ) {
|
|
|
|
|
$this->editGroupForm( 0, 'groups-noname' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-01-17 11:45:47 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-01-17 11:45:47 +00:00
|
|
|
// save stuff
|
2005-05-01 18:24:20 +00:00
|
|
|
$g->setName($this->mNewName);
|
|
|
|
|
$g->setDescription($this->mDescription);
|
2006-01-07 13:09:30 +00:00
|
|
|
if( is_array( $this->mRights ) ) {
|
|
|
|
|
$g->setRights( implode(',',$this->mRights) );
|
2005-05-01 18:24:20 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-01-17 11:45:47 +00:00
|
|
|
$g->save();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-05-01 18:24:20 +00:00
|
|
|
// Make the log entry
|
2005-01-17 11:45:47 +00:00
|
|
|
$log = new LogPage( 'rights' );
|
2005-05-01 18:24:20 +00:00
|
|
|
$dummyTitle = Title::makeTitle( 0, '' );
|
|
|
|
|
if ( $add ) {
|
|
|
|
|
$log->addEntry( 'addgroup', $dummyTitle, '', array( $g->getNameForContent() ) );
|
|
|
|
|
} else {
|
|
|
|
|
if ( $this->mOldName != $this->mNewName ) {
|
|
|
|
|
// Abbreviated action name, must be less than 10 bytes
|
2006-01-07 13:09:30 +00:00
|
|
|
$log->addEntry( 'rngroup', $dummyTitle, '', array( Group::getMessageForContent( $this->mOldName ),
|
2005-05-01 18:24:20 +00:00
|
|
|
$g->getNameForContent() ) );
|
|
|
|
|
} else {
|
|
|
|
|
$log->addEntry( 'chgroup', $dummyTitle, '', array( $g->getNameForContent() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-17 11:45:47 +00:00
|
|
|
|
2005-05-01 18:24:20 +00:00
|
|
|
// Success, go back to all groups page
|
|
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, 'Groups' );
|
|
|
|
|
$url = $titleObj->getLocalURL();
|
|
|
|
|
|
|
|
|
|
$wgOut->redirect( $url );
|
2005-01-17 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The entry form
|
|
|
|
|
* It allows a user to edit or eventually add a group
|
|
|
|
|
*/
|
|
|
|
|
function switchForm() {
|
|
|
|
|
global $wgOut;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
|
|
|
|
// group selection
|
2005-01-17 11:45:47 +00:00
|
|
|
$wgOut->addHTML( "<form name=\"ulgroup\" action=\"$this->action\" method=\"post\">\n" );
|
|
|
|
|
$wgOut->addHTML( $this->fieldset( 'lookup-group',
|
2005-05-01 18:24:20 +00:00
|
|
|
HTMLSelectGroups('id', $this->mName.'-group-edit', array(0 => $this->mRequest->getVal('id')) ) .
|
|
|
|
|
' <input type="submit" name="edit" value="'.wfMsg('editgroup').'" />' .
|
|
|
|
|
'<br /><input type="submit" name="add" value="'.wfMsg('addgroup').'" />'
|
2005-01-17 11:45:47 +00:00
|
|
|
));
|
|
|
|
|
$wgOut->addHTML( "</form>\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Edit a group properties and rights.
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $groupname String: Name of a group to be edited.
|
|
|
|
|
* @param $error String: message name of the error to display
|
2005-01-17 11:45:47 +00:00
|
|
|
*/
|
2005-05-01 18:24:20 +00:00
|
|
|
function editGroupForm($groupID = 0, $error = '') {
|
2005-01-17 11:45:47 +00:00
|
|
|
global $wgOut;
|
|
|
|
|
|
2005-05-01 18:24:20 +00:00
|
|
|
if ( $error ) {
|
|
|
|
|
$errText = wfMsg( $error );
|
|
|
|
|
$wgOut->addHTML( "<p class='error'>$errText</p>" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($this->mRequest->getVal('edit')) {
|
2005-01-17 11:45:47 +00:00
|
|
|
// fetch data if we edit a group
|
|
|
|
|
$g = Group::newFromID($groupID);
|
|
|
|
|
$fieldname = 'editgroup';
|
|
|
|
|
} else {
|
2005-05-14 05:41:22 +00:00
|
|
|
// default data when we add a group
|
|
|
|
|
$g = new Group();
|
2005-01-17 11:45:47 +00:00
|
|
|
$fieldname = 'addgroup';
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-14 05:41:22 +00:00
|
|
|
$gName = htmlspecialchars( $g->getName() );
|
|
|
|
|
$gDescription = htmlspecialchars( $g->getDescription() );
|
2005-01-17 11:45:47 +00:00
|
|
|
|
|
|
|
|
|
2005-05-14 05:41:22 +00:00
|
|
|
$wgOut->addHTML( "<form name=\"editGroup\" action=\"{$this->action}\" method=\"post\">\n".
|
2005-05-01 18:24:20 +00:00
|
|
|
'<input type="hidden" name="editgroup-oldname" value="'.$gName."\" />\n" );
|
|
|
|
|
|
2005-01-17 11:45:47 +00:00
|
|
|
$wgOut->addHTML( $this->fieldset( $fieldname,
|
2005-05-01 18:24:20 +00:00
|
|
|
'<p>' . wfMsg( 'groups-editgroup-preamble' ) . "</p>\n" .
|
2005-01-17 11:45:47 +00:00
|
|
|
$this->textbox( 'editgroup-name', $gName ) .
|
|
|
|
|
$this->textareabox( 'editgroup-description', $gDescription ) .
|
|
|
|
|
'<br /><table border="0" align="center"><tr><td>'.
|
|
|
|
|
HTMLSelectRights($g->getRights()).
|
|
|
|
|
'</td></tr></table>'."\n".
|
|
|
|
|
'<input type="submit" name="savegroup" value="'.wfMsg('savegroup').'" />'
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$wgOut->addHTML( "</form>\n" );
|
|
|
|
|
}
|
2005-05-01 18:24:20 +00:00
|
|
|
|
|
|
|
|
function showAllGroups() {
|
|
|
|
|
global $wgOut;
|
|
|
|
|
$groups =& Group::getAllGroups();
|
|
|
|
|
|
|
|
|
|
$groupsExisting = wfMsg( 'groups-existing' );
|
|
|
|
|
$groupsHeader = wfMsg( 'groups-tableheader' );
|
|
|
|
|
|
|
|
|
|
$s = "{| border=1
|
|
|
|
|
|+'''$groupsExisting'''
|
|
|
|
|
|-
|
|
|
|
|
!$groupsHeader
|
|
|
|
|
";
|
|
|
|
|
foreach ( $groups as $group ) {
|
|
|
|
|
$s .= "|-\n| " . $group->getId() . ' || ' .
|
|
|
|
|
$group->getExpandedName() . ' || ' .
|
2006-01-07 13:09:30 +00:00
|
|
|
$group->getExpandedDescription() . ' || '.
|
2005-05-01 18:24:20 +00:00
|
|
|
// Insert spaces to make it wrap
|
|
|
|
|
str_replace( ',', ', ', $group->getRights() ) . "\n";
|
|
|
|
|
}
|
|
|
|
|
$s .= "|}\n";
|
|
|
|
|
$wgOut->addWikiText( $s );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-05-01 18:24:20 +00:00
|
|
|
function showRecord() {
|
|
|
|
|
global $wgOut;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-05-01 18:24:20 +00:00
|
|
|
$groups =& Group::getAllGroups();
|
|
|
|
|
$rec = serialize( $groups );
|
2005-05-14 09:24:51 +00:00
|
|
|
// Split it into lines
|
|
|
|
|
$rec = explode( "\r\n", chunk_split( $rec ) );
|
|
|
|
|
$s = '';
|
|
|
|
|
foreach ( $rec as $index => $line ) {
|
|
|
|
|
if ( trim( $line ) != '' ) {
|
|
|
|
|
if ( $s ) {
|
|
|
|
|
$s .= "' .\n\t'";
|
|
|
|
|
}
|
|
|
|
|
// Escape it for PHP
|
|
|
|
|
$line = str_replace( array( '\\', "'" ), array( '\\\\', "\\'" ), $line );
|
|
|
|
|
// Escape it for HTML
|
|
|
|
|
$line = htmlspecialchars( $line );
|
|
|
|
|
// Add it to the string
|
|
|
|
|
$s .= $line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$s .= "';";
|
2005-05-01 18:24:20 +00:00
|
|
|
$s = "<p>Copy the following into LocalSettings.php:</p>\n" .
|
|
|
|
|
"<textarea readonly rows=20>\n" .
|
2005-05-14 09:24:51 +00:00
|
|
|
"\$wgStaticGroups = \n\t'$s\n" .
|
2005-05-01 18:24:20 +00:00
|
|
|
"</textarea>";
|
|
|
|
|
$wgOut->addHTML( $s );
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-01 12:59:39 +00:00
|
|
|
} // end class GroupsForm
|
|
|
|
|
?>
|