r39650 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39649‎ | r39650 | r39651 >
Date:17:40, 19 August 2008
Author:brion
Status:old
Tags:
Comment:
Revert r39582 "(bug 12518) Interwiki userrights now reflects remote groups, not local groups."
This won't actually work -- it checks the InitialiseSettings.php conf array for $wgGroupPermissions, but we don't set $wgGroupPermissions individually for every wiki. We use a system of several override variables which get applied in CommonSettings.php onto the default template.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserrights.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -166,7 +166,6 @@
167167 'upload',
168168 'upload_by_url',
169169 'userrights',
170 - 'userrights-interwiki',
171170 );
172171 /**
173172 * \type{\string} Cached results of getAllRights()
Index: trunk/phase3/includes/specials/SpecialUserrights.php
@@ -57,8 +57,7 @@
5858 * edit their own groups, automatically set them as the
5959 * target.
6060 */
61 - global $wgUser;
62 - $available = $this->changeableGroups($wgUser);
 61+ $available = $this->changeableGroups();
6362 if (empty($available['add']) && empty($available['remove']))
6463 $this->mTarget = $wgUser->getName();
6564 }
@@ -124,7 +123,7 @@
125124 return;
126125 }
127126
128 - $allgroups = $this->getAllGroups($user);
 127+ $allgroups = $this->getAllGroups();
129128 $addgroup = array();
130129 $removegroup = array();
131130
@@ -141,7 +140,7 @@
142141 }
143142
144143 // Validate input set...
145 - $changeable = $this->changeableGroups($user);
 144+ $changeable = $this->changeableGroups();
146145 $addable = array_merge( $changeable['add'], $this->isself ? $changeable['add-self'] : array() );
147146 $removable = array_merge( $changeable['remove'], $this->isself ? $changeable['remove-self'] : array() );
148147
@@ -322,12 +321,10 @@
323322 * permissions.
324323 *
325324 * @param $groups Array: list of groups the given user is in
326 - * @param $user User object to edit.
327325 * @return Array: Tuple of addable, then removable groups
328326 */
329 - protected function splitGroups( $groups, $user = null ) {
330 - global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
331 - list($addable, $removable, $addself, $removeself) = array_values( $this->changeableGroups( $user ) );
 327+ protected function splitGroups( $groups ) {
 328+ list($addable, $removable, $addself, $removeself) = array_values( $this->changeableGroups() );
332329
333330 $removable = array_intersect(
334331 array_merge( $this->isself ? $removeself : array(), $removable ),
@@ -348,7 +345,7 @@
349346 protected function showEditUserGroupsForm( $user, $groups ) {
350347 global $wgOut, $wgUser, $wgLang;
351348
352 - list( $addable, $removable ) = $this->splitGroups( $groups, $user );
 349+ list( $addable, $removable ) = $this->splitGroups( $groups );
353350
354351 $list = array();
355352 foreach( $user->getGroups() as $group )
@@ -368,7 +365,7 @@
369366 wfMsgExt( 'editinguser', array( 'parse' ), wfEscapeWikiText( $user->getName() ) ) .
370367 wfMsgExt( 'userrights-groups-help', array( 'parse' ) ) .
371368 $grouplist .
372 - Xml::tags( 'p', null, $this->groupCheckboxes( $groups, $user ) ) .
 369+ Xml::tags( 'p', null, $this->groupCheckboxes( $groups ) ) .
373370 Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-userrights-table-outer' ) ) .
374371 "<tr>
375372 <td class='mw-label'>" .
@@ -405,62 +402,20 @@
406403
407404 /**
408405 * Returns an array of all groups that may be edited
409 - * @param $user User object of the user whose groups are being edited. Optional.
410406 * @return array Array of groups that may be edited.
411407 */
412 - protected static function getAllGroups($user=null) {
413 - if ($user instanceof UserRightsProxy) {
414 - // Remote user object.
415 - return self::getRemoteGroups( $user->database );
416 - }
417 -
418 - // Regular user object
 408+ protected static function getAllGroups() {
419409 return User::getAllGroups();
420410 }
421 -
422 - /**
423 - * Returns all groups which can be set on a remote wiki.
424 - * @param $db String - database name of the foreign wiki.
425 - * @return array Array of groups that may be edited.
426 - */
427 - static function getRemoteGroups( $wiki ) {
428 - // Stolen from CentralAuth - a dirty hack indeed.
429 - global $wgConf, $IP;
430 - static $initialiseSettingsDone = false;
431411
432 - // This is a damn dirty hack
433 - if ( !$initialiseSettingsDone ) {
434 - $initialiseSettingsDone = true;
435 - if( file_exists( "$IP/InitialiseSettings.php" ) ) {
436 - require_once "$IP/InitialiseSettings.php";
437 - }
438 - }
439 -
440 - list( $major, $minor ) = $wgConf->siteFromDB( $wiki );
441 - if( isset( $major ) ) {
442 - $groupperms = $wgConf->get( 'wgGroupPermissions', $wiki, $major,
443 - array( 'lang' => $minor, 'site' => $major ) );
444 -
445 - $groups = array_keys($groupperms);
446 -
447 - if (count($groups)==0) {
448 - // Fallback
449 - return User::getAllGroups();
450 - }
451 -
452 - return $groups;
453 - }
454 - }
455 -
456412 /**
457413 * Adds a table with checkboxes where you can select what groups to add/remove
458414 *
459415 * @param $usergroups Array: groups the user belongs to
460 - * @param $user User object: the user to build checkboxes for.
461416 * @return string XHTML table element with checkboxes
462417 */
463 - private function groupCheckboxes( $usergroups, $user ) {
464 - $allgroups = $this->getAllGroups( $user );
 418+ private function groupCheckboxes( $usergroups ) {
 419+ $allgroups = $this->getAllGroups();
465420 $ret = '';
466421
467422 $column = 1;
@@ -471,12 +426,12 @@
472427 $set = in_array( $group, $usergroups );
473428 # Should the checkbox be disabled?
474429 $disabled = !(
475 - ( $set && $this->canRemove( $group, $user ) ) ||
476 - ( !$set && $this->canAdd( $group, $user ) ) );
 430+ ( $set && $this->canRemove( $group ) ) ||
 431+ ( !$set && $this->canAdd( $group ) ) );
477432 # Do we need to point out that this action is irreversible?
478433 $irreversible = !$disabled && (
479 - ($set && !$this->canAdd( $group, $user )) ||
480 - (!$set && !$this->canRemove( $group, $user ) ) );
 434+ ($set && !$this->canAdd( $group )) ||
 435+ (!$set && !$this->canRemove( $group ) ) );
481436
482437 $attr = $disabled ? array( 'disabled' => 'disabled' ) : array();
483438 $text = $irreversible
@@ -528,54 +483,44 @@
529484
530485 /**
531486 * @param $group String: the name of the group to check
532 - * @param $user User object: The user in question.
533487 * @return bool Can we remove the group?
534488 */
535 - private function canRemove( $group, $user=null ) {
 489+ private function canRemove( $group ) {
536490 // $this->changeableGroups()['remove'] doesn't work, of course. Thanks,
537491 // PHP.
538 - $groups = $this->changeableGroups($user);
 492+ $groups = $this->changeableGroups();
539493 return in_array( $group, $groups['remove'] ) || ($this->isself && in_array( $group, $groups['remove-self'] ));
540494 }
541495
542496 /**
543497 * @param $group string: the name of the group to check
544 - * @param $user User object: The user in question.
545498 * @return bool Can we add the group?
546499 */
547 - private function canAdd( $group, $user=null ) {
548 - $groups = $this->changeableGroups($user);
 500+ private function canAdd( $group ) {
 501+ $groups = $this->changeableGroups();
549502 return in_array( $group, $groups['add'] ) || ($this->isself && in_array( $group, $groups['add-self'] ));
550503 }
551504
552505 /**
553506 * Returns an array of the groups that the user can add/remove.
554507 *
555 - * @param $user User object to check groups for.
556508 * @return Array array( 'add' => array( addablegroups ), 'remove' => array( removablegroups ) , 'add-self' => array( addablegroups to self), 'remove-self' => array( removable groups from self) )
557509 */
558 - function changeableGroups( $user=null ) {
 510+ function changeableGroups() {
559511 global $wgUser;
560 -
561 - if ($user == null)
562 - $user = $wgUser; // Doesn't make a difference which user, so long as it's a local one.
563512
564 - if( $wgUser->isAllowed( 'userrights' ) ||
565 - $wgUser->isAllowed( 'userrights-interwiki' ) && $user instanceof UserRightsProxy ) {
 513+ if( $wgUser->isAllowed( 'userrights' ) ) {
566514 // This group gives the right to modify everything (reverse-
567515 // compatibility with old "userrights lets you change
568516 // everything")
569517 // Using array_merge to make the groups reindexed
570 - $all = array_merge( $this->getAllGroups( $user ) );
 518+ $all = array_merge( User::getAllGroups() );
571519 return array(
572520 'add' => $all,
573521 'remove' => $all,
574522 'add-self' => array(),
575523 'remove-self' => array()
576524 );
577 - } elseif ( $user instanceof UserRightsProxy ) {
578 - // Userrightsproxy without userrights-interwiki rights. Should have already been rejected.
579 - return array( 'add' => array(), 'remove' => array(), 'add-self' => array(), 'remove-self' => array() );
580525 }
581526
582527 // Okay, it's not so simple, we will have to go through the arrays
Index: trunk/phase3/RELEASE-NOTES
@@ -134,9 +134,7 @@
135135 * Avoid recursive crazy expansions in section edit comments for pages which
136136 contain '/*' in the title
137137 * Fix excessive memory usage when parsing pages with lots of links
138 -* (bug 12518) Interwiki userrights now reflects remote groups, not local groups
139138
140 -
141139 === API changes in 1.14 ===
142140
143141 * Registration time of users registered before the DB field was created is now

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r39582(bug 12518) Interwiki userrights now reflects remote groups, not local groups.werdna12:41, 18 August 2008

Status & tagging log