From 28ea816fbafe96825d3c35187a12cadafca6905f Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 24 Oct 2004 19:14:48 +0000 Subject: [PATCH] Implementing user levels management. This is only a very basic interface and several things need to be done! A tracking bug is at http://bugzilla.wikipedia.org/show_bug.cgi?id=767 --- includes/Article.php | 10 +-- includes/DefaultSettings.php | 8 ++ includes/DifferenceEngine.php | 4 +- includes/ImagePage.php | 2 +- includes/LogPage.php | 8 +- includes/SearchEngine.php | 8 +- includes/Skin.php | 27 +++---- includes/SkinPHPTal.php | 10 ++- includes/SpecialAsksql.php | 2 +- includes/SpecialBlockip.php | 2 +- includes/SpecialContributions.php | 4 +- includes/SpecialDebug.php | 2 +- includes/SpecialIpblocklist.php | 4 +- includes/SpecialLockdb.php | 2 +- includes/SpecialMakesysop.php | 8 +- includes/SpecialNewpages.php | 4 +- includes/SpecialPage.php | 19 ++--- includes/SpecialSpecialpages.php | 21 +++++- includes/SpecialUnlockdb.php | 2 +- includes/SpecialUserlevels.php | 75 ++++++++++++++----- includes/Title.php | 37 +++++---- includes/User.php | 64 +++++++++++++--- index.php | 3 + languages/Language.php | 9 +++ .../patch-userlevels-defaultgroups.sql | 10 +++ maintenance/parserTests.txt | 1 - maintenance/postgresql/pg_tables.sql | 4 +- skins/CologneBlue.php | 4 +- skins/Standard.php | 2 +- 29 files changed, 262 insertions(+), 94 deletions(-) create mode 100644 maintenance/archives/patch-userlevels-defaultgroups.sql diff --git a/includes/Article.php b/includes/Article.php index 80474304e5..fdb9d464cd 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -885,7 +885,7 @@ class Article { # If we have been passed an &rcid= parameter, we want to give the user a # chance to mark this new article as patrolled. if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->getID() != 0 && - ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) ) + ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) { $wgOut->addHTML( wfMsg ( 'markaspatrolledlink', $sk->makeKnownLinkObj ( $this->mTitle, wfMsg ( 'markaspatrolledtext' ), @@ -1284,7 +1284,7 @@ class Article { $wgOut->loginToUse(); return; } - if ( $wgOnlySysopsCanPatrol && !$wgUser->isSysop() ) + if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') ) { $wgOut->sysopRequired(); return; @@ -1355,7 +1355,7 @@ class Article { function protect( $limit = 'sysop' ) { global $wgUser, $wgOut, $wgRequest; - if ( ! $wgUser->isSysop() ) { + if ( ! $wgUser->isAllowed('protect') ) { $wgOut->sysopRequired(); return; } @@ -1482,7 +1482,7 @@ class Article { # This code desperately needs to be totally rewritten # Check permissions - if ( ( ! $wgUser->isSysop() ) ) { + if ( ( ! $wgUser->isAllowed('delete') ) ) { $wgOut->sysopRequired(); return; } @@ -1790,7 +1790,7 @@ class Article { global $wgUser, $wgOut, $wgRequest; $fname = 'Article::rollback'; - if ( ! $wgUser->isSysop() ) { + if ( ! $wgUser->isAllowed('rollback') ) { $wgOut->sysopRequired(); return; } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 093a37532a..06b7b3a57d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -807,6 +807,14 @@ $wgBrowserBlackList = array( # $wgLocaltimezone = 'Europe/Sweden'; # $wgLocaltimezone = 'CET'; +# User level management +# The number is the database id of a group you want users to be attached by +# default. A better interface should be coded [av] +$wgAnonGroupId = 1; +$wgLoggedInGroupId = 2; + +$wgWhitelistRead = array ( ':Accueil', ':Main_Page'); + } else { die(); } diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index e1cfa32941..09c9a80fbd 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -109,14 +109,14 @@ class DifferenceEngine { 'target=' . urlencode($this->mOldUser) ); $newContribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), $contribs, 'target=' . urlencode($this->mNewUser) ); - if ( !$this->mNewid && $wgUser->isSysop() ) { + if ( !$this->mNewid && $wgUser->isAllowed('rollback') ) { $rollback = '   [' . $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'rollbacklink' ), 'action=rollback&from=' . urlencode($this->mNewUser) ) . ']'; } else { $rollback = ''; } if ( $wgUseRCPatrol && $this->mRcidMarkPatrolled != 0 && $wgUser->getID() != 0 && - ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) ) + ( $wgUser->isAllowed('rollback') || !$wgOnlySysopsCanPatrol ) ) { $patrol = ' [' . $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'markaspatrolleddiff' ), "action=markpatrolled&rcid={$this->mRcidMarkPatrolled}" ) . ']'; diff --git a/includes/ImagePage.php b/includes/ImagePage.php index e251b9313d..1a3b9382d1 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -159,7 +159,7 @@ class ImagePage extends Article { # Only sysops can delete images. Previously ordinary users could delete # old revisions, but this is no longer the case. - if ( !$wgUser->isSysop() ) { + if ( !$wgUser->isAllowed('delete') ) { $wgOut->sysopRequired(); return; } diff --git a/includes/LogPage.php b/includes/LogPage.php index 1923048e68..68b73b2dcb 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -162,7 +162,13 @@ class LogPage { return "$action $titleLink"; } } - + + /** + * Add a log entry + * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload' + * @param &$target + * @param string $comment Description associated + */ function addEntry( $action, &$target, $comment ) { global $wgLang, $wgUser; diff --git a/includes/SearchEngine.php b/includes/SearchEngine.php index 295b0be567..58b8cf29ab 100644 --- a/includes/SearchEngine.php +++ b/includes/SearchEngine.php @@ -1,5 +1,10 @@ \ No newline at end of file +?> diff --git a/includes/Skin.php b/includes/Skin.php index 06bc505409..16615f6e9e 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -294,7 +294,7 @@ class Skin { } else $a = array( 'bgcolor' => '#FFFFFF' ); if($wgOut->isArticle() && $wgUser->getOption('editondblclick') && - (!$wgTitle->isProtected() || $wgUser->isSysop()) ) { + (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) { $t = wfMsg( 'editthispage' ); $oid = $red = ''; if ( !empty($redirect) && $redirect == 'no' ) { @@ -597,7 +597,7 @@ class Skin { function getUndeleteLink() { global $wgUser, $wgTitle, $wgContLang, $action; - if( $wgUser->isSysop() && + if( $wgUser->isAllowed('rollback') && (($wgTitle->getArticleId() == 0) || ($action == "history")) && ($n = $wgTitle->isDeleted() ) ) { return wfMsg( 'thisisdeleted', @@ -800,10 +800,11 @@ class Skin { } } } - if ( $wgUser->isSysop() && $wgTitle->getArticleId() ) { - $s .= "\n
" . $this->deleteThisPage() . - $sep . $this->protectThisPage() . - $sep . $this->moveThisPage(); + if ( $wgTitle->getArticleId() ) { + $s .= "\n
"; + if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); } + if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); } + if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); } } $s .= "
\n" . $this->otherLanguages(); } @@ -1020,7 +1021,7 @@ class Skin { global $wgUser, $wgOut, $wgTitle, $wgRequest; $diff = $wgRequest->getVal( 'diff' ); - if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isSysop() ) { + if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) { $n = $wgTitle->getPrefixedText(); $t = wfMsg( 'deletethispage' ); @@ -1035,7 +1036,7 @@ class Skin { global $wgUser, $wgOut, $wgTitle, $wgRequest; $diff = $wgRequest->getVal( 'diff' ); - if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isSysop() ) { + if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) { $n = $wgTitle->getPrefixedText(); if ( $wgTitle->isProtected() ) { @@ -2220,7 +2221,7 @@ class Skin { $diffLink = wfMsg( 'diff' ); } else { if ( $wgUseRCPatrol && $rc_patrolled == 0 && $wgUser->getID() != 0 && - ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) ) + ( $wgUser->isAllowed('protect') || !$wgOnlySysopsCanPatrol ) ) $rcidparam = "&rcid={$rc_id}"; else $rcidparam = ""; @@ -2242,7 +2243,7 @@ class Skin { # If it's a new article, there is no diff link, but if it hasn't been # patrolled yet, we need to give users a way to do so if ( $wgUseRCPatrol && $rc_type == RC_NEW && $rc_patrolled == 0 && - $wgUser->getID() != 0 && ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) ) + $wgUser->getID() != 0 && ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" ); else $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '' ); @@ -2277,7 +2278,7 @@ class Skin { } # Block link $blockLink=''; - if ( ( 0 == $rc_user ) && $wgUser->isSysop() ) { + if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) { $blockLink = $this->makeKnownLink( $wgContLang->specialPage( 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text ); @@ -2379,7 +2380,7 @@ class Skin { $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname ); global $wgDisableAnonTalk; - if ( ( 0 == $rc_user ) && $wgUser->isSysop() ) { + if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) { $blockLink = $this->makeKnownLink( $wgContLang->specialPage( 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text ); if( $wgDisableAnonTalk ) @@ -2498,7 +2499,7 @@ class Skin { if ( $iscur ) { $url = Image::wfImageUrl( $img ); $rlink = $cur; - if ( $wgUser->isSysop() ) { + if ( $wgUser->isAllowed('delete') ) { $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() . '&action=delete' ); $style = $this->getInternalLinkAttributes( $link, $delall ); diff --git a/includes/SkinPHPTal.php b/includes/SkinPHPTal.php index f986ae4b6e..9a68314ca7 100644 --- a/includes/SkinPHPTal.php +++ b/includes/SkinPHPTal.php @@ -208,7 +208,6 @@ class SkinPHPTal extends Skin { $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" ); $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" ); $tpl->set( "helppage", wfMsg('helppage')); - $tpl->set( "sysop", $wgUser->isSysop() ); */ $tpl->set( 'searchaction', $this->escapeSearchLink() ); $tpl->setRef( 'stylepath', $wgStylePath ); @@ -474,9 +473,10 @@ class SkinPHPTal extends Skin { 'href' => $this->makeUrl($this->thispage, 'action=rollback'), 'ttip' => wfMsg('tooltip-rollback'), 'akey' => wfMsg('accesskey-rollback')); - }*/ + } + */ - if($wgUser->isSysop()){ + if($wgUser->isAllowed('protect')){ if(!$wgTitle->isProtected()){ $content_actions['protect'] = array( 'class' => ($action == 'protect') ? 'selected' : false, @@ -491,6 +491,8 @@ class SkinPHPTal extends Skin { 'href' => $this->makeUrl($this->thispage, 'action=unprotect') ); } + } + if($wgUser->isAllowed('delete')){ $content_actions['delete'] = array( 'class' => ($action == 'delete') ? 'selected' : false, 'text' => wfMsg('delete'), @@ -507,7 +509,7 @@ class SkinPHPTal extends Skin { } } else { //article doesn't exist or is deleted - if($wgUser->isSysop()){ + if($wgUser->isAllowed('delete')){ if( $n = $wgTitle->isDeleted() ) { $content_actions['undelete'] = array( 'class' => false, diff --git a/includes/SpecialAsksql.php b/includes/SpecialAsksql.php index 666030bf81..f48eedc96a 100644 --- a/includes/SpecialAsksql.php +++ b/includes/SpecialAsksql.php @@ -20,7 +20,7 @@ function wfSpecialAsksql() { $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" ); return; } - if( !$wgUser->isSysop() ) { + if( !$wgUser->isAllowed('asksql') ) { $wgOut->sysopRequired(); return; } diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index 34fde400a1..f3e15342bc 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -12,7 +12,7 @@ function wfSpecialBlockip() { global $wgUser, $wgOut, $wgRequest; - if ( ! $wgUser->isSysop() ) { + if ( ! $wgUser->isAllowed('block') ) { $wgOut->sysopRequired(); return; } diff --git a/includes/SpecialContributions.php b/includes/SpecialContributions.php index 9a97865780..4b41a752a6 100644 --- a/includes/SpecialContributions.php +++ b/includes/SpecialContributions.php @@ -198,8 +198,8 @@ function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $t } else { $difftext .= wfMsg('newarticle'); } - $sysop = $wgUser->isSysop(); - if($sysop ) { + + if( $wgUser->isAllowed('rollback') ) { $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : ''; # $target = $wgRequest->getText( 'target' ); $topmarktext .= ' ['. $sk->makeKnownLink( $page, diff --git a/includes/SpecialDebug.php b/includes/SpecialDebug.php index b628128972..cc82c0a411 100644 --- a/includes/SpecialDebug.php +++ b/includes/SpecialDebug.php @@ -11,7 +11,7 @@ function wfSpecialDebug() { global $wgUser, $wgOut; - if ( ! $wgUser->isDeveloper() ) { + if ( ! $wgUser->isAllowed('siteadmin') ) { $wgOut->developerRequired(); return; } diff --git a/includes/SpecialIpblocklist.php b/includes/SpecialIpblocklist.php index 87d9e39038..71f8ec14f5 100644 --- a/includes/SpecialIpblocklist.php +++ b/includes/SpecialIpblocklist.php @@ -21,7 +21,7 @@ function wfSpecialIpblocklist() { $msg = wfMsg( "ipusuccess", htmlspecialchars( $ip ) ); $ipu->showList( $msg ); } else if ( "submit" == $action && $wgRequest->wasPosted() ) { - if ( ! $wgUser->isSysop() ) { + if ( ! $wgUser->isAllowed('block') ) { $wgOut->sysopRequired(); return; } @@ -161,7 +161,7 @@ function wfAddRow( $block, $tag ) { $wgOut->addHTML( " ({$clink})" ); } - if ( $wgUser->isSysop() ) { + if ( $wgUser->isAllowed('block') ) { $titleObj = Title::makeTitle( NS_SPECIAL, "Ipblocklist" ); $ublink = "escapeLocalURL( "action=unblock&ip=" . urlencode( $addr ) ) . "\">" . diff --git a/includes/SpecialLockdb.php b/includes/SpecialLockdb.php index bbc8e7e0be..1635aa4d57 100644 --- a/includes/SpecialLockdb.php +++ b/includes/SpecialLockdb.php @@ -12,7 +12,7 @@ function wfSpecialLockdb() { global $wgUser, $wgOut, $wgRequest; - if ( ! $wgUser->isDeveloper() ) { + if ( ! $wgUser->isAllowed('siteadmin') ) { $wgOut->developerRequired(); return; } diff --git a/includes/SpecialMakesysop.php b/includes/SpecialMakesysop.php index ef3d0f22a0..57eb11ba30 100644 --- a/includes/SpecialMakesysop.php +++ b/includes/SpecialMakesysop.php @@ -1,10 +1,14 @@ errorpage( "movenologin", "movenologintext" ); return; } - if (! $wgUser->isBureaucrat() && ! $wgUser->isDeveloper() ){ + if (! $wgUser->isAllowed('userrights') ) { $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" ); return; } diff --git a/includes/SpecialNewpages.php b/includes/SpecialNewpages.php index 33a4a0093d..123ab1db1b 100644 --- a/includes/SpecialNewpages.php +++ b/includes/SpecialNewpages.php @@ -30,7 +30,7 @@ class NewPagesPage extends QueryPage { function getSQL() { global $wgUser, $wgOnlySysopsCanPatrol, $wgUseRCPatrol; $usepatrol = ( $wgUseRCPatrol && $wgUser->getID() != 0 && - ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) ) ? 1 : 0; + ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) ? 1 : 0; $dbr =& wfGetDB( DB_SLAVE ); extract( $dbr->tableNames( 'recentchanges', 'cur' ) ); @@ -74,7 +74,7 @@ class NewPagesPage extends QueryPage { # mark the article as patrolled if it isn't already if ( $wgUseRCPatrol && !is_null ( $result->usepatrol ) && $result->usepatrol && $result->patrolled == 0 && $wgUser->getID() != 0 && - ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) ) + ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) $link = $skin->makeKnownLink( $result->title, '', "rcid={$result->rcid}" ); else $link = $skin->makeKnownLink( $result->title, '' ); diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 767b2c737d..8a299e5a4c 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -27,7 +27,7 @@ $wgSpecialPages = array( 'BrokenRedirects' => new UnlistedSpecialPage ( 'BrokenRedirects' ), 'Disambiguations' => new UnlistedSpecialPage ( 'Disambiguations' ), - 'Userlogin' => new SpecialPage( 'Userlogin' ), + 'Userlogin' => new SpecialPage( 'Userlogin', 'createaccount' ), 'Userlogout' => new UnlistedSpecialPage( 'Userlogout' ), 'Preferences' => new SpecialPage( 'Preferences' ), 'Watchlist' => new SpecialPage( 'Watchlist' ), @@ -80,17 +80,18 @@ $wgSpecialPages = array_merge($wgSpecialPages, array ( 'Allmessages' => new SpecialPage( 'Allmessages' ), 'Search' => new UnlistedSpecialPage( 'Search' ), 'Log' => new SpecialPage( 'Log' ), - 'Blockip' => new SpecialPage( 'Blockip', 'sysop' ), - 'Asksql' => new SpecialPage( 'Asksql', 'sysop' ), - 'Undelete' => new SpecialPage( 'Undelete', 'sysop' ), - 'Makesysop' => new SpecialPage( 'Makesysop', 'sysop' ), + 'Blockip' => new SpecialPage( 'Blockip', 'block' ), + 'Asksql' => new SpecialPage( 'Asksql', 'asksql' ), + 'Undelete' => new SpecialPage( 'Undelete', 'delete' ), + // Makesysop is obsolete, replaced by Special:Userlevels [av] + # 'Makesysop' => new SpecialPage( 'Makesysop', 'userrights' ), # Special:Import is half-written # "Import" => new SpecialPage( "Import", "sysop" ), - 'Lockdb' => new SpecialPage( 'Lockdb', 'developer' ), - 'Unlockdb' => new SpecialPage( 'Unlockdb', 'developer' ), - 'Sitesettings' => new SpecialPage( 'Sitesettings', 'sysop' ), - 'Userlevels' => new SpecialPage( 'Userlevels', 'sysop' ), + 'Lockdb' => new SpecialPage( 'Lockdb', 'siteadmin' ), + 'Unlockdb' => new SpecialPage( 'Unlockdb', 'siteadmin' ), + 'Sitesettings' => new SpecialPage( 'Sitesettings', 'siteadmin' ), + 'Userlevels' => new SpecialPage( 'Userlevels', 'userrights' ), )); /** diff --git a/includes/SpecialSpecialpages.php b/includes/SpecialSpecialpages.php index 041a22fa51..bc59328500 100644 --- a/includes/SpecialSpecialpages.php +++ b/includes/SpecialSpecialpages.php @@ -9,7 +9,7 @@ * */ function wfSpecialSpecialpages() { - global $wgLang, $wgOut, $wgUser; + global $wgLang, $wgOut, $wgUser, $wgAvailableRights; $wgOut->setRobotpolicy( 'index,nofollow' ); $sk = $wgUser->getSkin(); @@ -17,6 +17,24 @@ function wfSpecialSpecialpages() { # Get listable pages $pages = SpecialPage::getPages(); + /** pages available to all */ + wfSpecialSpecialpages_gen($pages[''],'spheading',$sk); + + /** show pages splitted by user rights */ + foreach($wgAvailableRights as $right) { + /** only show pages a user can access */ + if( $wgUser->isAllowed($right) ) { + /** some rights might not have any special page associated */ + if(isset($pages[$right])) { + wfSpecialSpecialpages_gen($pages[$right], $right.'pheading', $sk); + } + } + + } + +/** FIXME : spheading, sysopspheading, developerspheading need to be removed +from language files [av] */ +/** # all users special pages wfSpecialSpecialpages_gen($pages[''],'spheading',$sk); @@ -30,6 +48,7 @@ function wfSpecialSpecialpages() { wfSpecialSpecialpages_gen($pages['developer'],'developerspheading',$sk); } +*/ } /** diff --git a/includes/SpecialUnlockdb.php b/includes/SpecialUnlockdb.php index f2d056e081..fa674d7e67 100644 --- a/includes/SpecialUnlockdb.php +++ b/includes/SpecialUnlockdb.php @@ -11,7 +11,7 @@ function wfSpecialUnlockdb() { global $wgUser, $wgOut, $wgRequest; - if ( ! $wgUser->isDeveloper() ) { + if ( ! $wgUser->isAllowed('siteadmin') ) { $wgOut->developerRequired(); return; } diff --git a/includes/SpecialUserlevels.php b/includes/SpecialUserlevels.php index f7f68b3f0b..ef710336e0 100644 --- a/includes/SpecialUserlevels.php +++ b/includes/SpecialUserlevels.php @@ -11,7 +11,8 @@ require_once('Group.php'); /** Entry point */ function wfSpecialUserlevels($par=null) { global $wgRequest; -// print_r($_POST); + # Debug statement + // print_r($_POST); $form = new UserlevelsForm($wgRequest); $form->execute(); } @@ -54,7 +55,8 @@ class UserlevelsForm extends HTMLForm { if($this->mRequest->getCheck('savegroup')) { $this->saveGroup($this->mRequest->getVal('editgroup-name'), $this->mRequest->getVal('editgroup-oldname'), - $this->mRequest->getVal('editgroup-description')); + $this->mRequest->getVal('editgroup-description'), + $this->mRequest->getVal('editgroup-getrights')); } elseif($this->mRequest->getCheck('saveusergroups')) { $this->saveUserGroups($this->mRequest->getVal('user-editname'), @@ -70,9 +72,10 @@ class UserlevelsForm extends HTMLForm { * @param string $newname Group name. * @param string $oldname Old (current) group name. * @param string $description Group description. - * @todo FIXME : doesnt validate anything. + * + * @todo FIXME : doesnt validate anything. Log is incorrect. */ - function saveGroup($newname, $oldname, $description) { + function saveGroup($newname, $oldname, $description, $rights) { $newame = trim($newname); if($oldname == '') { @@ -86,7 +89,13 @@ class UserlevelsForm extends HTMLForm { // save stuff $g->setName($newname); $g->setDescription($description); + if(isset($rights)) { $g->setRights( implode(',',$rights) ); } + $g->save(); + + $log = new LogPage( 'rights' ); + $log->addEntry( 'rights', Title::makeTitle( NS_SPECIAL, $g->getName()) , ' '.$g->getRights() ); + } /** @@ -96,6 +105,8 @@ class UserlevelsForm extends HTMLForm { * @param string $username Username to apply changes to. * @param array $removegroup id of groups to be removed. * @param array $addgroup id of groups to be added. + * + * @todo Log groupname instead of group id. */ function saveUserGroups($username,$removegroup,$addgroup) { $u = User::NewFromName($username); @@ -112,12 +123,22 @@ class UserlevelsForm extends HTMLForm { $u->setID( $id ); $groups = $u->getGroups(); + $logcomment = ' '; // remove then add groups - if(isset($removegroup)) { $groups = array_diff($groups, $removegroup); } - if(isset($addgroup)) { $groups = array_merge($groups, $addgroup); } + if(isset($removegroup)) { + $groups = array_diff($groups, $removegroup); + $logcomment .= implode( ' -', $removegroup); + } + if(isset($addgroup)) { + $groups = array_merge($groups, $addgroup); + $logcomment .= implode( ' +', $addgroup ); + } // save groups in user object and database $u->setGroups($groups); $u->saveSettings(); + + $log = new LogPage( 'rights' ); + $log->addEntry( 'rights', Title::makeTitle( NS_USER, $u->getName() ), $logcomment ); } /** @@ -143,7 +164,7 @@ class UserlevelsForm extends HTMLForm { $this->textbox( 'user-editname' ) . '' )); - $wgOut->addHTML( "" ); + $wgOut->addHTML( '' ); } /** @@ -152,28 +173,33 @@ class UserlevelsForm extends HTMLForm { */ function editGroupForm($groupID = 0) { global $wgOut; - + if($this->mRequest->getVal('seditgroup')) { // fetch data if we edit a group $g = Group::newFromID($groupID); - $gName = $g->getName(); - $gDescription = $g->getDescription(); $fieldname = 'editgroup'; } else { // default datas when we add a group - $gName = ''; - $gDescription = ''; + $g = new group(); $fieldname = 'addgroup'; } + $gName = $g->getName(); + $gDescription = $g->getDescription(); + + $wgOut->addHTML( "
action\" method=\"post\">". ''); $wgOut->addHTML( $this->fieldset( $fieldname, $this->textbox( 'editgroup-name', $gName ) . $this->textareabox( 'editgroup-description', $gDescription ) . + '
'. + $this->HTMLSelectRights($g->getRights()). + '
'. '' )); - $wgOut->addHTML( "
" ); + + $wgOut->addHTML( "\n" ); } /** @@ -201,7 +227,7 @@ class UserlevelsForm extends HTMLForm { ''); $wgOut->addHTML( $this->fieldset( 'editusergroup', wfMsg('editing', $this->mRequest->getVal('user-editname')).'.
' . - '
'. + '
'. $this->HTMLSelectGroups('groupsmember', $groups,true,6). ''. $this->HTMLSelectGroups('groupsavailable', $groups,true,6,true). @@ -209,7 +235,7 @@ class UserlevelsForm extends HTMLForm { '

'.wfMsg('userlevels-groupshelp').'

'. '' )); - $wgOut->addHTML( "" ); + $wgOut->addHTML( "\n" ); } @@ -243,10 +269,25 @@ class UserlevelsForm extends HTMLForm { $out .= 'value="'.$g->group_id.'">'.$g->group_name.''; } } - $out .= ''; return $out; } - + + function HTMLSelectRights($selected='') { + global $wgAvailableRights; + $out = '