summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialUserrights.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/specials/SpecialUserrights.php')
-rw-r--r--includes/specials/SpecialUserrights.php106
1 files changed, 70 insertions, 36 deletions
diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php
index 9f5a48a5..d4baae28 100644
--- a/includes/specials/SpecialUserrights.php
+++ b/includes/specials/SpecialUserrights.php
@@ -54,7 +54,7 @@ class UserrightsPage extends SpecialPage {
|| !empty( $available['remove'] )
|| ( ( $this->isself || !$checkIfSelf ) &&
( !empty( $available['add-self'] )
- || !empty( $available['remove-self'] ) ) );
+ || !empty( $available['remove-self'] ) ) );
}
/**
@@ -62,6 +62,7 @@ class UserrightsPage extends SpecialPage {
* Depending on the submit button used, call a form or a save function.
*
* @param $par Mixed: string if any subpage provided, else null
+ * @throws UserBlockedError|PermissionsError
*/
public function execute( $par ) {
// If the visitor doesn't have permissions to assign or remove
@@ -152,8 +153,8 @@ class UserrightsPage extends SpecialPage {
* Save user groups changes in the database.
* Data comes from the editUserGroupsForm() form function
*
- * @param $username String: username to apply changes to.
- * @param $reason String: reason for group change
+ * @param string $username username to apply changes to.
+ * @param string $reason reason for group change
* @return null
*/
function saveUserGroups( $username, $reason = '' ) {
@@ -188,9 +189,9 @@ class UserrightsPage extends SpecialPage {
* Save user groups changes in the database.
*
* @param $user User object
- * @param $add Array of groups to add
- * @param $remove Array of groups to remove
- * @param $reason String: reason for group change
+ * @param array $add of groups to add
+ * @param array $remove of groups to remove
+ * @param string $reason reason for group change
* @return Array: Tuple of added, then removed groups
*/
function doSaveUserGroups( $user, $add, $remove, $reason = '' ) {
@@ -239,26 +240,25 @@ class UserrightsPage extends SpecialPage {
return array( $add, $remove );
}
-
/**
* Add a rights log entry for an action.
*/
function addLogEntry( $user, $oldGroups, $newGroups, $reason ) {
- $log = new LogPage( 'rights' );
-
- $log->addEntry( 'rights',
- $user->getUserPage(),
- $reason,
- array(
- $this->makeGroupNameListForLog( $oldGroups ),
- $this->makeGroupNameListForLog( $newGroups )
- )
- );
+ $logEntry = new ManualLogEntry( 'rights', 'rights' );
+ $logEntry->setPerformer( $this->getUser() );
+ $logEntry->setTarget( $user->getUserPage() );
+ $logEntry->setComment( $reason );
+ $logEntry->setParameters( array(
+ '4::oldgroups' => $oldGroups,
+ '5::newgroups' => $newGroups,
+ ) );
+ $logid = $logEntry->insert();
+ $logEntry->publish( $logid );
}
/**
* Edit user groups membership
- * @param $username String: name of the user.
+ * @param string $username name of the user.
*/
function editUserGroupsForm( $username ) {
$status = $this->fetchUser( $username );
@@ -354,7 +354,16 @@ class UserrightsPage extends SpecialPage {
}
}
+ /**
+ * Make a list of group names to be stored as parameter for log entries
+ *
+ * @deprecated in 1.21; use LogFormatter instead.
+ * @param $ids array
+ * @return string
+ */
function makeGroupNameListForLog( $ids ) {
+ wfDeprecated( __METHOD__, '1.21' );
+
if( empty( $ids ) ) {
return '';
} else {
@@ -369,7 +378,7 @@ class UserrightsPage extends SpecialPage {
global $wgScript;
$this->getOutput()->addHTML(
Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'name' => 'uluser', 'id' => 'mw-userrights-form1' ) ) .
- Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
+ Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
Xml::fieldset( $this->msg( 'userrights-lookup-user' )->text() ) .
Xml::inputLabel( $this->msg( 'userrights-user-editname' )->text(), 'user', 'username', 30, str_replace( '_', ' ', $this->mTarget ) ) . ' ' .
Xml::submitButton( $this->msg( 'editusergroup' )->text() ) .
@@ -383,7 +392,7 @@ class UserrightsPage extends SpecialPage {
* form will be able to manipulate based on the current user's system
* permissions.
*
- * @param $groups Array: list of groups the given user is in
+ * @param array $groups list of groups the given user is in
* @return Array: Tuple of addable, then removable groups
*/
protected function splitGroups( $groups ) {
@@ -409,27 +418,41 @@ class UserrightsPage extends SpecialPage {
*/
protected function showEditUserGroupsForm( $user, $groups ) {
$list = array();
+ $membersList = array();
foreach( $groups as $group ) {
$list[] = self::buildGroupLink( $group );
+ $membersList[] = self::buildGroupMemberLink( $group );
}
- $autolist = array();
+ $autoList = array();
+ $autoMembersList = array();
if ( $user instanceof User ) {
foreach( Autopromote::getAutopromoteGroups( $user ) as $group ) {
- $autolist[] = self::buildGroupLink( $group );
+ $autoList[] = self::buildGroupLink( $group );
+ $autoMembersList[] = self::buildGroupMemberLink( $group );
}
}
+ $language = $this->getLanguage();
+ $displayedList = $this->msg( 'userrights-groupsmember-type',
+ $language->listToText( $list ),
+ $language->listToText( $membersList )
+ )->plain();
+ $displayedAutolist = $this->msg( 'userrights-groupsmember-type',
+ $language->listToText( $autoList ),
+ $language->listToText( $autoMembersList )
+ )->plain();
+
$grouplist = '';
$count = count( $list );
- if( $count > 0 ) {
+ if ( $count > 0 ) {
$grouplist = $this->msg( 'userrights-groupsmember', $count, $user->getName() )->parse();
- $grouplist = '<p>' . $grouplist . ' ' . $this->getLanguage()->listToText( $list ) . "</p>\n";
+ $grouplist = '<p>' . $grouplist . ' ' . $displayedList . "</p>\n";
}
- $count = count( $autolist );
- if( $count > 0 ) {
+ $count = count( $autoList );
+ if ( $count > 0 ) {
$autogrouplistintro = $this->msg( 'userrights-groupsmember-auto', $count, $user->getName() )->parse();
- $grouplist .= '<p>' . $autogrouplistintro . ' ' . $this->getLanguage()->listToText( $autolist ) . "</p>\n";
+ $grouplist .= '<p>' . $autogrouplistintro . ' ' . $displayedAutolist . "</p>\n";
}
$userToolLinks = Linker::userToolLinks(
@@ -479,10 +502,17 @@ class UserrightsPage extends SpecialPage {
* @return string
*/
private static function buildGroupLink( $group ) {
- static $cache = array();
- if( !isset( $cache[$group] ) )
- $cache[$group] = User::makeGroupLinkHtml( $group, htmlspecialchars( User::getGroupName( $group ) ) );
- return $cache[$group];
+ return User::makeGroupLinkHtml( $group, User::getGroupName( $group ) );
+ }
+
+ /**
+ * Format a link to a group member description page
+ *
+ * @param $group string
+ * @return string
+ */
+ private static function buildGroupMemberLink( $group ) {
+ return User::makeGroupLinkHtml( $group, User::getGroupMember( $group ) );
}
/**
@@ -497,7 +527,7 @@ class UserrightsPage extends SpecialPage {
* Adds a table with checkboxes where you can select what groups to add/remove
*
* @todo Just pass the username string?
- * @param $usergroups Array: groups the user belongs to
+ * @param array $usergroups groups the user belongs to
* @param $user User a user object
* @return string XHTML table element with checkboxes
*/
@@ -534,14 +564,14 @@ class UserrightsPage extends SpecialPage {
}
# Build the HTML table
- $ret .= Xml::openElement( 'table', array( 'class' => 'mw-userrights-groups' ) ) .
+ $ret .= Xml::openElement( 'table', array( 'class' => 'mw-userrights-groups' ) ) .
"<tr>\n";
foreach( $columns as $name => $column ) {
if( $column === array() )
continue;
$ret .= Xml::element( 'th', null, $this->msg( 'userrights-' . $name . '-col', count( $column ) )->text() );
}
- $ret.= "</tr>\n<tr>\n";
+ $ret .= "</tr>\n<tr>\n";
foreach( $columns as $column ) {
if( $column === array() )
continue;
@@ -581,7 +611,7 @@ class UserrightsPage extends SpecialPage {
}
/**
- * @param $group string: the name of the group to check
+ * @param string $group the name of the group to check
* @return bool Can we add the group?
*/
private function canAdd( $group ) {
@@ -592,7 +622,7 @@ class UserrightsPage extends SpecialPage {
/**
* Returns $this->getUser()->changeableGroups()
*
- * @return Array array( 'add' => array( addablegroups ), 'remove' => array( removablegroups ) , 'add-self' => array( addablegroups to self), 'remove-self' => array( removable groups from self) )
+ * @return Array array( 'add' => array( addablegroups ), 'remove' => array( removablegroups ), 'add-self' => array( addablegroups to self ), 'remove-self' => array( removable groups from self ) )
*/
function changeableGroups() {
return $this->getUser()->changeableGroups();
@@ -609,4 +639,8 @@ class UserrightsPage extends SpecialPage {
$output->addHTML( Xml::element( 'h2', null, $rightsLogPage->getName()->text() ) );
LogEventsList::showLogExtract( $output, 'rights', $user->getUserPage() );
}
+
+ protected function getGroupName() {
+ return 'users';
+ }
}