*/ $wgExtensionFunctions[] = "userGroupExtension"; $wgExtensionCredits['specialpage'][] = array( 'name' => 'UserGroups', 'version' => '2007/04/05', 'author' => 'Austin Che', 'url' => 'http://openwetware.org/wiki/User:Austin_J._Che/Extensions/UserGroups', 'description' => 'Create user groups from pages on the wiki', ); function userGroupExtension() { global $wgMessageCache, $wgSpecialPages; $wgMessageCache->addMessages(array('group' => 'Group', )); $wgSpecialPages['Group'] = array('SpecialPage', 'Group'); } function wfSpecialGroup($par) { global $wgUser, $wgOut, $wgRequest, $wgUserGroups; $target = isset($par) ? $par : $wgRequest->getVal('target'); $page = Title::newFromURL($target); if (!is_object($page)) $wgUserGroups->enterGroupName(); else if (!$page->exists()) $wgOut->redirect($page->getLocalUrl()); // redirect to non-existing group page else { $action = $wgRequest->getVal('action'); if ($action == "raw") $wgUserGroups->printRawUsers($page); else $wgUserGroups->showGroup($page); } } class UserGroups { var $group_namespace; function enterGroupName() { global $wgOut; $title = Title::makeTitle(NS_SPECIAL, "Group"); $action = $title->escapeLocalUrl(); $group = wfMsg("group"); $wgOut->addHTML("
{$group}:
\n" ); } function printRawUsers($group) { global $wgOut; $wgOut->disable(); echo implode(" ", $this->getMembers($group)); } function showGroup($group) { global $wgOut, $wgUser; $skin = $wgUser->getSkin(); $wgOut->addHTML("" . $skin->makeLinkObj($group) . ""); $members = $this->getMembers($group); // ** print group hooks here $wgOut->addHTML("
    "); foreach ($members as $member) { $u = Title::makeTitle(NS_USER, $member); $wgOut->addHTML("
  1. " . $skin->makeLinkObj($u, $member) . "
  2. "); } $wgOut->addHTML("
"); } function getMembers($group) { $dbr =& wfGetDB(DB_SLAVE); list($pagelinks, $page, $redirect) = $dbr->tableNamesN('pagelinks','page','redirect'); $userns = NS_USER; $id = $group->getArticleID(); $sql = "SELECT DISTINCT pl_title, page_id, page_is_redirect FROM $pagelinks LEFT OUTER JOIN ($page) ON ($page.page_title=$pagelinks.pl_title AND $page.page_namespace=pl_namespace) WHERE pl_from=$id AND pl_namespace=$userns ORDER BY pl_title"; $res = $dbr->query($sql); $users = array(); while (($u = $dbr->fetchObject($res))) { $username = $u->pl_title; // check if it is redirect page if ($u->page_is_redirect) { $redirect_page = $dbr->selectField($redirect, "rd_title", "rd_namespace=$userns AND rd_from=" . $u->page_id); if ($redirect_page) $username = $redirect_page; } // only add if it is valid user // this also takes care of things like [[User:Foo/bar]] $user = User::newFromName($username); if (!is_null($user) && $user->canReceiveEmail()) { $username = $user->getName(); // use display form (spaces not underscores) $users[$username] = $username; // avoids adding the same user multiple times } } $dbr->freeResult($res); return $users; } } $wgUserGroups = new UserGroups(); ?>