/** * Ajax function to create checkboxes for a new group in $wgGroupPermissions * * @param String $group new group name * @return either <err#> if group already exist or html fragment */ function efConfigureAjax($group) { global $wgUser, $wgGroupPermissions; if (!$wgUser->isAllowed('configure-all')) { return '<err#>'; } if (isset($wgGroupPermissions[$group])) { $html = '<err#>'; } else { if (is_callable(array('User', 'getAllRights'))) { // 1.13 + $all = User::getAllRights(); } else { $all = array(); foreach ($wgGroupPermissions as $rights) { $all = array_merge($all, array_keys($rights)); } $all = array_unique($all); } $row = '<div style="-moz-column-count:2"><ul>'; foreach ($all as $right) { $id = Sanitizer::escapeId('wpwgGroupPermissions-' . $group . '-' . $right); $desc = is_callable(array('User', 'getRightDescription')) ? User::getRightDescription($right) : $right; $row .= '<li>' . Xml::checkLabel($desc, $id, $id) . "</li>\n"; } $row .= '</ul></div>'; $groupName = User::getGroupName($group); // Firefox seems to not like that :( $html = str_replace(' ', ' ', $row); } return $html; }
private static function parseOptions($opts) { $options = array(); $segments = explode('|', $opts); foreach ($segments as $opt) { // Extract key=value pair $exploded = explode('=', $opt, 2); $key = $exploded[0]; $value = isset($exploded[1]) ? $exploded[1] : ''; switch ($key) { case 'replace': // Replace the text instead of marking as spam $options['replace'] = $value; break; default: if (in_array($key, \User::getAllRights())) { // If the name is a user right if (isset($options['right'])) { $options['right'][] = $key; } else { $options['right'] = array($key); } } else { if (in_array($key, \User::getAllGroups())) { // If the name is a user group if (isset($options['group'])) { $options['group'][] = $key; } else { $options['group'] = array($key); } } } } } return $options; }
/** * @param $group string */ function doSubmit($group) { // Paranoia -- the edit token shouldn't match anyway if (!$this->userCanEdit($this->getUser())) { return; } $reason = $this->getRequest()->getVal('wpReason', ''); // Current name of the group $group = Title::newFromText($group); if (!$group) { $this->getOutput()->addWikiMsg('centralauth-editgroup-invalid-name'); return; } $group = $group->getUserCaseDBKey(); // (Potentially) New name of the group $newname = $this->getRequest()->getVal('wpGlobalGroupName', $group); $newname = Title::newFromText($newname); if (!$newname) { $this->getOutput()->addWikiMsg('centralauth-editgroup-invalid-name'); return; } $newname = $newname->getUserCaseDBKey(); if ($group != $newname) { if (in_array($newname, CentralAuthUser::availableGlobalGroups())) { $this->getOutput()->addWikiMsg('centralauth-editgroup-rename-taken', $newname); return; } $dbw = CentralAuthUser::getCentralDB(); $updates = array('global_group_permissions' => 'ggp_group', 'global_group_restrictions' => 'ggr_group', 'global_user_groups' => 'gug_group'); foreach ($updates as $table => $field) { $dbw->update($table, array($field => $newname), array($field => $group), __METHOD__); } $this->addRenameLog($group, $newname, $reason); // The rest of the changes here will be performed on the "new" group $group = $newname; } // Permissions $addRights = array(); $removeRights = array(); $oldRights = $this->getAssignedRights($group); $allRights = User::getAllRights(); foreach ($allRights as $right) { $alreadyAssigned = in_array($right, $oldRights); if (!$alreadyAssigned && $this->getRequest()->getCheck("wpRightAssigned-{$right}")) { $addRights[] = $right; } elseif ($alreadyAssigned && !$this->getRequest()->getCheck("wpRightAssigned-{$right}")) { $removeRights[] = $right; } # Otherwise, do nothing. } // Assign the rights. if (count($addRights) > 0) { $this->grantRightsToGroup($group, $addRights); } if (count($removeRights) > 0) { $this->revokeRightsFromGroup($group, $removeRights); } // Log it if (!(count($addRights) == 0 && count($removeRights) == 0)) { $this->addPermissionLog($group, $addRights, $removeRights, $reason); } // Change set $current = WikiSet::getWikiSetForGroup($group); $new = $this->getRequest()->getVal('set'); if ($current != $new) { $this->setRestrictions($group, $new); $this->addWikiSetLog($group, $current, $new, $reason); } $this->invalidateRightsCache($group); // Display success $this->getOutput()->setSubTitle($this->msg('centralauth-editgroup-success')); $this->getOutput()->addWikiMsg('centralauth-editgroup-success-text', $group); }
public function testAvailableRights() { $missingRights = array_diff($this->getAllVisibleRights(), User::getAllRights()); $this->assertEquals(array(), array_values($missingRights), 'Additional user rights need to be added to $wgAvailableRights or ' . 'via the "UserGetAllRights" hook. See the instructions at: ' . 'https://www.mediawiki.org/wiki/Manual:User_rights#Adding_new_rights'); }
public function getAllowedParams() { $userGroups = User::getAllGroups(); $userRights = User::getAllRights(); return ['group' => [ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true], 'excludegroup' => [ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true], 'rights' => [ApiBase::PARAM_TYPE => $userRights, ApiBase::PARAM_ISMULTI => true], 'excluderights' => [ApiBase::PARAM_TYPE => $userRights, ApiBase::PARAM_ISMULTI => true], 'limit' => [ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2], 'continue' => [ApiBase::PARAM_HELP_MSG => 'api-help-param-continue']]; }
public function getAllowedParams() { $userGroups = User::getAllGroups(); return array('from' => null, 'to' => null, 'prefix' => null, 'dir' => array(ApiBase::PARAM_DFLT => 'ascending', ApiBase::PARAM_TYPE => array('ascending', 'descending')), 'group' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'excludegroup' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'rights' => array(ApiBase::PARAM_TYPE => User::getAllRights(), ApiBase::PARAM_ISMULTI => true), 'prop' => array(ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_TYPE => array('blockinfo', 'groups', 'implicitgroups', 'rights', 'editcount', 'registration')), 'limit' => array(ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2), 'witheditsonly' => false, 'activeusers' => false); }
/** * Test, if for all rights a right- message exist, * which is used on Special:ListGroupRights as help text * Extensions and core */ public function testAllRightsWithMessage() { // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights $allRights = User::getAllRights(); $allMessageKeys = Language::getMessageKeysFor('en'); $rightsWithMessage = array(); foreach ($allMessageKeys as $message) { // === 0: must be at beginning of string (position 0) if (strpos($message, 'right-') === 0) { $rightsWithMessage[] = substr($message, strlen('right-')); } } sort($allRights); sort($rightsWithMessage); $this->assertEquals($allRights, $rightsWithMessage, 'Each user rights (core/extensions) has a corresponding right- message.'); }
public function getAllowedParams() { $userGroups = User::getAllGroups(); return array('from' => null, 'to' => null, 'prefix' => null, 'dir' => array(ApiBase::PARAM_DFLT => 'ascending', ApiBase::PARAM_TYPE => array('ascending', 'descending')), 'group' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'excludegroup' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'rights' => array(ApiBase::PARAM_TYPE => User::getAllRights(), ApiBase::PARAM_ISMULTI => true), 'prop' => array(ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_TYPE => array('blockinfo', 'groups', 'implicitgroups', 'rights', 'editcount', 'registration', 'centralids'), ApiBase::PARAM_HELP_MSG_PER_VALUE => array()), 'limit' => array(ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2), 'witheditsonly' => false, 'activeusers' => array(ApiBase::PARAM_DFLT => false, ApiBase::PARAM_HELP_MSG => array('apihelp-query+allusers-param-activeusers', $this->getConfig()->get('ActiveUserDays'))), 'attachedwiki' => null); }
public function getAllowedParams() { $userGroups = User::getAllGroups(); $userRights = User::getAllRights(); return array('group' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'excludegroup' => array(ApiBase::PARAM_TYPE => $userGroups, ApiBase::PARAM_ISMULTI => true), 'rights' => array(ApiBase::PARAM_TYPE => $userRights, ApiBase::PARAM_ISMULTI => true), 'excluderights' => array(ApiBase::PARAM_TYPE => $userRights, ApiBase::PARAM_ISMULTI => true), 'limit' => array(ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2), 'continue' => null); }
protected function ajaxGetNewGroup($setting, $group) { $settings = ConfigurationSettings::singleton(CONF_SETTINGS_BOTH); if ($settings->getSettingType($setting) != 'array') { return array('error', 'notarray'); } $type = $settings->getArrayType($setting); switch ($type) { case 'group-bool': if (isset($GLOBALS[$setting]) && isset($GLOBALS[$setting][$group])) { return array('error', 'exists'); } $row = ConfigurationPage::buildGroupSettingRow($setting, $type, User::getAllRights(), true, $group, array()); // Firefox seems to not like that :( return array('ajax', str_replace(' ', ' ', $row)); case 'promotion-conds': if (isset($GLOBALS[$setting]) && isset($GLOBALS[$setting][$group])) { return array('error', 'exists'); } return array('ajax', ConfigurationPage::buildPromotionCondsSettingRow($setting, true, $group, array())); default: return array('error', 'notvalidarray'); } }
function doSubmit($group) { // Paranoia -- the edit token shouldn't match anyway if (!$this->userCanEdit($this->getUser())) { return; } $newRights = array(); $addRights = array(); $removeRights = array(); $oldRights = $this->getAssignedRights($group); $allRights = User::getAllRights(); $reason = $this->getRequest()->getVal('wpReason', ''); foreach ($allRights as $right) { $alreadyAssigned = in_array($right, $oldRights); if ($this->getRequest()->getCheck("wpRightAssigned-{$right}")) { $newRights[] = $right; } if (!$alreadyAssigned && $this->getRequest()->getCheck("wpRightAssigned-{$right}")) { $addRights[] = $right; } elseif ($alreadyAssigned && !$this->getRequest()->getCheck("wpRightAssigned-{$right}")) { $removeRights[] = $right; } # Otherwise, do nothing. } // Assign the rights. if (count($addRights) > 0) { $this->grantRightsToGroup($group, $addRights); } if (count($removeRights) > 0) { $this->revokeRightsFromGroup($group, $removeRights); } // Log it if (!(count($addRights) == 0 && count($removeRights) == 0)) { $this->addLogEntry($group, $addRights, $removeRights, $reason); } // Change set $current = WikiSet::getWikiSetForGroup($group); $new = $this->getRequest()->getVal('set'); if ($current != $new) { $this->setRestrictions($group, $new); $this->addLogEntry2($group, $current, $new, $reason); } $this->invalidateRightsCache($group); // Display success $this->getOutput()->setSubTitle(wfMsg('centralauth-editgroup-success')); $this->getOutput()->addWikiMsg('centralauth-editgroup-success-text', $group); }
/** * Build an input for an array setting * * @param str $conf setting name * @param mixed $default current value (but should be array :) * @param bool $allowed */ protected function buildArrayInput($conf, $default, $allowed) { if (!isset(self::$arrayDefs[$conf]) || self::$arrayDefs[$conf] == 'array') { return $allowed ? '<span class="array">(array)</span>' : '<span class="array-disabled">(array)</span>'; } $type = self::$arrayDefs[$conf]; if ($type == 'simple') { if (!$allowed) { return "<pre>\n" . htmlspecialchars(is_array($default) ? implode("\n", $default) : $default) . "\n</pre>"; } $text = "<textarea id='wp{$conf}' name='wp{$conf}' cols='30' rows='8'>"; if (is_array($default)) { $text .= implode("\n", $default); } $text .= "</textarea>\n"; return $text; } if ($type == 'assoc') { $keydesc = wfMsgHtml('configure-desc-key'); $valdesc = wfMsgHtml('configure-desc-val'); $class = !$allowed ? array('class' => 'disabled') : array(); $encConf = htmlspecialchars($conf); $text = "<table class='assoc' id='{$encConf}'>\n<tr><th>{$keydesc}</th><th>{$valdesc}</th></tr>\n"; if (is_array($default) && count($default) > 0) { $i = 0; foreach ($default as $key => $val) { $text .= '<tr>' . Xml::openElement('td', $class); if ($allowed) { $text .= Xml::element('input', array('name' => 'wp' . $conf . "-key-{$i}", 'type' => 'text', 'value' => $key)) . "<br/>\n"; } else { $text .= htmlspecialchars($key); } $text .= '</td>' . Xml::openElement('td', $class); if ($allowed) { $text .= Xml::element('input', array('name' => 'wp' . $conf . "-val-{$i}", 'type' => 'text', 'value' => $val)) . "<br/>\n"; } else { $text .= htmlspecialchars($val); } $text .= '</td></tr>'; $i++; } } else { if ($allowed) { $text .= '<tr><td>'; $text .= Xml::element('input', array('name' => 'wp' . $conf . "-key-0", 'type' => 'text', 'value' => '')) . "<br/>\n"; $text .= '</td><td>'; $text .= Xml::element('input', array('name' => 'wp' . $conf . "-val-0", 'type' => 'text', 'value' => '')) . "<br/>\n"; $text .= '</td></tr>'; } else { $text .= "<tr><td class='disabled' style='width:10em; height:1.5em;'><hr /></td><td class='disabled' style='width:10em; height:1.5em;'><hr /></td></tr>\n"; } } $text .= '</table>'; return $text; } if ($type == 'simple-dual') { $var = array(); foreach ($default as $arr) { $var[] = implode(',', $arr); } if (!$allowed) { return "<pre>\n" . htmlspecialchars(implode("\n", $var)) . "\n</pre>"; } $text = "<textarea id='wp{$conf}' name='wp{$conf}' cols='30' rows='8'>"; if (is_array($var)) { $text .= implode("\n", $var); } $text .= "</textarea>\n"; return $text; } if ($type == 'ns-bool') { global $wgContLang; $text = ''; $attr = !$allowed ? array('disabled' => 'disabled') : array(); foreach ($wgContLang->getNamespaces() as $ns => $name) { $name = str_replace('_', ' ', $name); if ('' == $name) { $name = wfMsgExt('blanknamespace', array('parseinline')); } $text .= Xml::checkLabel($name, "wp{$conf}-ns{$ns}", "wp{$conf}-ns{$ns}", isset($default[$ns]) && $default[$ns], $attr) . "\n"; } return $text; } if ($type == 'ns-text') { global $wgContLang; $nsdesc = wfMsgHtml('configure-desc-ns'); $valdesc = wfMsgHtml('configure-desc-val'); $text = "<table class='ns-text'>\n<tr><th>{$nsdesc}</th><th>{$valdesc}</th></tr>\n"; foreach ($wgContLang->getNamespaces() as $ns => $name) { $name = str_replace('_', ' ', $name); if ('' == $name) { $name = wfMsgExt('blanknamespace', array('parseinline')); } $text .= '<tr><td>' . $name . '</td><td>'; if ($allowed) { $text .= Xml::element('input', array('name' => "wp{$conf}-ns{$ns}", 'type' => 'text', 'value' => isset($default[$ns]) ? $default[$ns] : '')) . "\n"; } else { $text .= htmlspecialchars(isset($default[$ns]) ? $default[$ns] : ''); } $text .= '</td></tr>'; } $text .= '</table>'; return $text; } if ($type == 'ns-array') { global $wgContLang; $nsdesc = wfMsgHtml('configure-desc-ns'); $valdesc = wfMsgHtml('configure-desc-val'); $text = "<table class='ns-array'>\n<tr><th>{$nsdesc}</th><th>{$valdesc}</th></tr>\n"; foreach ($wgContLang->getNamespaces() as $ns => $name) { if ($ns < 0) { continue; } $name = str_replace('_', ' ', $name); if ('' == $name) { $name = wfMsgExt('blanknamespace', array('parseinline')); } $text .= '<tr><td>' . $name . '</td><td>'; if ($allowed) { $text .= Xml::openElement('textarea', array('name' => "wp{$conf}-ns{$ns}", 'id' => "wp{$conf}-ns{$ns}", 'cols' => 30, 'rows' => 5)) . (isset($default[$ns]) ? implode("\n", $default[$ns]) : '') . Xml::closeElement('textarea') . "<br/>\n"; } else { $text .= "<pre>\n" . (isset($default[$ns]) ? htmlspecialchars(implode("\n", $default[$ns])) : '') . "\n</pre>"; } $text .= '</td></tr>'; } $text .= '</table>'; return $text; } if ($type == 'group-bool' || $type == 'group-array') { $all = array(); $attr = !$allowed ? array('disabled' => 'disabled') : array(); if ($type == 'group-bool') { if (is_callable(array('User', 'getAllRights'))) { // 1.13 + $all = User::getAllRights(); } else { foreach ($default as $rights) { $all = array_merge($all, array_keys($rights)); } $all = array_unique($all); } $iter = $default; } else { $all = array_keys($this->getSettingValue('wgGroupPermissions')); $iter = array(); foreach ($all as $group) { $iter[$group] = isset($default[$group]) && is_array($default[$group]) ? $default[$group] : array(); } if ($this->isSettingAvailable('wgImplicitGroups')) { // 1.12 + $all = array_diff($all, $this->getSettingValue('wgImplicitGroups')); } else { $all = array_diff($all, User::getImplicitGroups()); } } $groupdesc = wfMsgHtml('configure-desc-group'); $valdesc = wfMsgHtml('configure-desc-val'); $encConf = htmlspecialchars($conf); $text = "<table id= '{$encConf}' class='{$type}'>\n<tr><th>{$groupdesc}</th><th>{$valdesc}</th></tr>\n"; foreach ($iter as $group => $levs) { $row = '<div style="-moz-column-count:2"><ul>'; foreach ($all as $right) { if ($type == 'group-bool') { $checked = isset($levs[$right]) && $levs[$right]; } else { $checked = in_array($right, $levs); } $id = Sanitizer::escapeId('wp' . $conf . '-' . $group . '-' . $right); $desc = $type == 'group-bool' && is_callable(array('User', 'getRightDescription')) ? User::getRightDescription($right) : $right; $row .= '<li>' . Xml::checkLabel($desc, $id, $id, $checked, $attr) . "</li>\n"; } $row .= '</ul></div>'; $groupName = User::getGroupName($group); $encId = Sanitizer::escapeId('wp' . $conf . '-' . $group); $text .= "<tr id=\"{$encId}\">\n<td>{$groupName}</td>\n<td>{$row}</td>\n</tr>"; } $text .= '</table>'; return $text; } }
/** * Prevents that the wiki gets accidentally inaccessible for all users. * Some of the rights which are pre-set in the $bsgPermissionConfig have * a the flag "preventLockout" set to true. This makes it impossible to * save the permission settings if not at least one group has these rights enabled. * * @param array $aGroupPermissions * @return bool|String */ protected static function preventPermissionLockout(&$aGroupPermissions) { global $bsgPermissionConfig; $aRights = User::getAllRights(); if (!is_array($aRights)) { return false; } foreach ($aRights as $sRight) { if (isset($bsgPermissionConfig[$sRight]['preventLockout'])) { $bIsSet = false; if (is_array($aGroupPermissions)) { foreach ($aGroupPermissions as $aDataset) { if (isset($aDataset[$sRight]) && $aDataset[$sRight]) { $bIsSet = true; continue 2; } } if (!$bIsSet) { return Message::newFromKey('bs-permissionmanager-error-lockout')->params($sRight)->plain(); } } } } return true; }
function formatValues($wiki, $config) { global $wgRequest, $wgConfigure; $values = array(); $logs = array(); $error = false; foreach (ConfigureWMF::$settings[$config] as $name => $value) { switch ($value) { case 'string': $values[$name] = $wgRequest->getVal($name); $logs[] = $wgRequest->getVal($name); break; case 'bool': $values[$name] = $wgRequest->getCheck($name); $logs[] = wfMsgForContent('configurewmf-log-' . ($values[$name] ? 'true' : 'false')); break; case 'stringarray': $values[$name] = array_unique(preg_split('/\\n/', $wgRequest->getVal($name), -1, PREG_SPLIT_NO_EMPTY)); $logs[] = $values[$name] ? implode(', ', $values[$name]) : wfMsgForContent('rightsnone'); break; case 'logo': global $wgConfigureStdlogo; $input = $wgRequest->getVal($name); $values[$name] = $input == 'stdlogo' ? $wgConfigureStdlogo : $wgRequest->getVal("{$name}Other"); $logs[] = $input == 'stdlogo' ? wfMsgForContent('configurewmf-log-stdlogo') : $wgRequest->getVal("{$name}Other"); break; case 'groupperms': $groupperms = $wgConfigure->getGroupPermissions($wiki); $group = $wgRequest->getVal('group'); $perms = isset($groupperms[$group]) ? $groupperms[$group] : array(); $rights = User::getAllRights(); $changes = array(); foreach ($rights as $right) { if ((bool) @$perms[$right] != $wgRequest->getCheck("{$name}-{$right}")) { $changes[$right] = $wgRequest->getCheck("{$name}-{$right}"); } } if ($changes) { $override = $wgConfigure->getOverride($config, $wiki); $override = $override && isset($override->cfg_value['wgGroupPermissions']) ? $override->cfg_value['wgGroupPermissions'] : array(); if (!isset($override[$group])) { $override[$group] = array(); } $override[$group] = $changes + $override[$group]; $values[$name] = $override; } $added = $removed = array(); foreach ($changes as $perm => $value) { if ($value) { $added[] = $perm; } else { $removed[] = $perm; } } $logs[] = $group; $logs[] = $added ? implode(', ', $added) : wfMsgForContent('rightsnone'); $logs[] = $removed ? implode(', ', $removed) : wfMsgForContent('rightsnone'); break; case 'grouplist': $targetgroup = $wgRequest->getVal('group'); $oldval = $wgConfigure->getSetting($wiki, $name); $old = isset($oldval[$targetgroup]) ? $oldval[$targetgroup] : array(); $override = $wgConfigure->getOverride($config, $wiki); $override = $override && isset($override->cfg_value[$name]) ? $override->cfg_value[$name] : array(); $new = array(); foreach (array_keys($wgConfigure->getGroupPermissions($wiki)) as $group) { if ($wgRequest->getCheck("{$name}-{$group}")) { $new[] = $group; } } var_dump($old, $new, $override); if (array_diff($old, $new)) { $override[$targetgroup] = $new; $values[$name] = $new; } $logs[] = $new ? implode(', ', $new) : wfMsgForContent('rightsnone'); break; } } return array($values, $logs, $error); }
/** * Build an input for an array setting * TODO Consolidate some of the duplicated code here. * * @param $conf String: setting name * @param $default Mixed: current value (but should be array :) * @param $allowed Boolean */ protected function buildArrayInput($conf, $default, $allowed) { $type = $this->getArrayType($conf); if ($type === null || $type == 'array') { return Html::rawElement('span', array('class' => $allowed ? 'array' : 'array-disabled'), '(array)'); } if ($type == 'simple') { if (!$allowed) { return "<pre>" . htmlspecialchars(is_array($default) ? implode("\n", $default) : $default) . "\n</pre>"; } $text = $this->msg('configure-arrayinput-oneperline')->parse(); $text .= Html::textarea("wp{$conf}", is_array($default) ? implode("\n", $default) : '', array('id' => "wp{$conf}", 'rows' => 8, 'style' => 'width:95%;')); return $text; } if ($type == 'assoc') { ## See if the key/value has a special description $keydescmsg = $this->msg("configure-setting-{$conf}-key"); if ($keydescmsg->exists()) { $keydesc = $keydescmsg->parse(); } else { $keydesc = $this->msg('configure-desc-key')->escaped(); } $valdescmsg = $this->msg("configure-setting-{$conf}-value"); if ($valdescmsg->exists()) { $valdesc = $valdescmsg->parse(); } else { $valdesc = $this->msg('configure-desc-val')->escaped(); } $classes = array('configure-array-table', 'assoc'); if (!$allowed) { $classes[] = 'disabled'; } if (count($default) > 5) { $classes[] = 'configure-biglist'; } $text = Html::openElement('table', array('class' => implode(' ', $classes), 'id' => $conf)) . "\n"; $text .= Html::rawElement('tr', array(), Html::rawElement('th', array(), $keydesc) . Html::rawElement('th', array(), $valdesc)); if (is_array($default) && count($default) > 0) { $i = 0; foreach ($default as $key => $val) { $text .= Html::openElement('tr') . Html::openElement('td'); if ($allowed) { $text .= Html::element('input', array('name' => 'wp' . $conf . "-key-{$i}", 'type' => 'text', 'value' => $key, 'size' => 20)) . Html::element('br') . "\n"; } else { $text .= '<code>' . htmlspecialchars($key) . '</code>'; } $text .= Html::closeElement('td') . Html::openElement('td'); if ($allowed) { $text .= Html::element('input', array('name' => 'wp' . $conf . "-val-{$i}", 'type' => 'text', 'value' => $val, 'size' => 20)) . Html::element('br') . "\n"; } else { $text .= '<code>' . htmlspecialchars($val) . '</code>'; } $text .= Html::closeElement('td') . Html::closeElement('tr'); $i++; } } else { if ($allowed) { $text .= Html::openElement('tr') . Html::openElement('td'); $text .= Html::element('input', array('name' => 'wp' . $conf . "-key-0", 'type' => 'text', 'value' => '', 'size' => 20)) . Html::element('br') . "\n"; $text .= Html::closeElement('td') . Html::openElement('td'); $text .= Html::element('input', array('name' => 'wp' . $conf . "-val-0", 'type' => 'text', 'value' => '', 'size' => 20)) . Html::element('br') . "\n"; $text .= Html::closeElement('td') . Html::closeElement('tr'); } else { $text .= Html::rawElement('tr', array(), Html::rawElement('td', array('style' => 'width:10em;height:1.5em;'), Html::element('hr')) . Html::rawElement('td', array('style' => 'width:10em;height:1.5em;'), Html::element('hr'))) . "\n"; } } $text .= Html::closeElement('table'); return $text; } if ($type == 'rate-limits') { ## Some of this is stolen from assoc, since it's an assoc with an assoc. $keydescmsg = $this->msg("configure-setting-{$conf}-key"); if ($keydescmsg->exists()) { $keydesc = $keydescmsg->parse(); } else { $keydesc = $this->msg('configure-desc-key')->escaped(); } $valdescmsg = $this->msg("configure-setting-{$conf}-value"); if ($valdescmsg->exists()) { $valdesc = $valdescmsg->parse(); } else { $valdesc = $this->msg('configure-desc-val')->escaped(); } $classes = array('configure-array-table', 'configure-rate-limits'); if (!$allowed) { $classes[] = 'disabled'; } $rows = Html::rawElement('tr', array(), Html::rawElement('th', array(), $keydesc) . " " . Html::rawElement('th', array(), $valdesc)) . "\n"; # TODO put this stuff in one place. $validActions = array('edit', 'move', 'mailpassword', 'emailuser', 'rollback'); $validGroups = array('anon', 'user', 'newbie', 'ip', 'subnet'); foreach ($validActions as $action) { $val = array(); if (isset($default[$action])) { $val = $default[$action]; } $key = Html::rawElement('td', array(), $this->msg("configure-throttle-action-{$action}")->parse()); ## Build YET ANOTHER ASSOC TABLE ARGH! $innerRows = Html::rawElement('tr', array(), Html::rawElement('th', array(), $this->msg('configure-throttle-group')->parse()) . ' ' . Html::rawElement('th', array(), $this->msg('configure-throttle-limit')->parse())) . "\n"; foreach ($validGroups as $type) { $limits = null; if (isset($default[$action][$type])) { $limits = $default[$action][$type]; } if (is_array($limits) && count($limits) == 2) { list($count, $period) = $limits; } else { $count = $period = 0; } $id = 'wp' . $conf . '-key-' . $action . '-' . $type; $left_col = Html::rawElement('td', array(), $this->msg("configure-throttle-group-{$type}")->parse()); if ($allowed) { $right_col = Html::element('label', array('for' => "{$id}-count"), $this->msg('configure-throttle-count')->text()) . ' ' . Html::input("{$id}-count", $count, 'text', array('name' => "{$id}-count", 'size' => 15)) . Html::element('br') . Html::element('label', array('for' => "{$id}-period"), $this->msg('configure-throttle-period')->text()) . ' ' . Html::input("{$id}-period", $period, 'text', array('name' => "{$id}-period", 'size' => 15)); } else { $right_col = $count && $period ? $this->msg('configure-throttle-summary', $count, $period)->text() : $this->msg('configure-throttle-none')->text(); ## Laziness: Make summaries work by putting the data in hidden fields, rather than a special case in JS. $right_col .= "\n" . Html::hidden("{$id}-count", $count, array('id' => "{$id}-count")) . Html::hidden("{$id}-period", $period, array('id' => "{$id}-period")); } $right_col = Html::rawElement('td', array(), $right_col); $innerRows .= Html::rawElement('tr', array('id' => $id), $left_col . $right_col) . "\n"; } $value = Html::rawElement('td', array(), Html::rawElement('table', array('class' => 'configure-biglist configure-rate-limits-action'), Html::rawElement('tbody', array(), $innerRows))); $rows .= Html::rawElement('tr', array(), $key . $value) . "\n"; } return Html::rawElement('table', array('class' => implode(' ', $classes)), Html::rawElement('tbody', null, $rows)); } if ($type == 'simple-dual') { $var = array(); if (is_array($default)) { foreach ($default as $arr) { $var[] = implode(',', $arr); } } if (!$allowed) { return "<pre>\n" . htmlspecialchars(implode("\n", $var)) . "\n</pre>"; } $text = "<textarea id='wp{$conf}' name='wp{$conf}' cols='30' rows='8'>"; if (is_array($var)) { $text .= implode("\n", $var); } $text .= "</textarea>\n"; return $text; } if ($type == 'ns-bool' || $type == 'ns-simple') { global $wgContLang; $text = ''; $attr = !$allowed ? array('disabled' => 'disabled') : array(); foreach ($wgContLang->getNamespaces() as $ns => $name) { $name = str_replace('_', ' ', $name); if ('' == $name) { $name = $this->msg('blanknamespace')->parse(); } if ($type == 'ns-bool') { $checked = isset($default[$ns]) && $default[$ns]; } else { $checked = in_array($ns, (array) $default); } $inputAttribs = array('name' => "wp{$conf}-ns{$ns}", 'id' => "wp{$conf}-ns{$ns}", 'type' => 'checkbox', 'value' => 1); if ($checked) { $inputAttribs['checked'] = 'checked'; } $inputAttribs += $attr; $text .= Html::rawElement('span', array('style' => 'white-space:nowrap;'), Html::element('input', $inputAttribs) . ' ' . Html::element('label', array('for' => "wp{$conf}-ns{$ns}"), $name)) . "\n"; } $text = Html::rawElement('div', array('class' => 'configure-biglist ' . $type), $text); return $text; } if ($type == 'ns-text') { global $wgContLang; $nsdesc = $this->msg('configure-desc-ns')->escaped(); $valdescmsg = $this->msg("configure-setting-{$conf}-value"); if ($valdescmsg->exists()) { $valdesc = $valdescmsg->parse(); } else { $valdesc = $this->msg('configure-desc-val')->escaped(); } $text = Html::openElement('table', array('class' => 'configure-array-table ns-text configure-biglist')) . "\n" . Html::rawElement('tr', array(), Html::rawElement('th', array(), $nsdesc) . Html::rawElement('th', array(), $valdesc)) . "\n"; foreach ($wgContLang->getNamespaces() as $ns => $name) { $name = str_replace('_', ' ', $name); if ('' == $name) { $name = $this->msg('blanknamespace')->parse(); } $text .= Html::openElement('tr', array()) . Html::rawElement('td', array(), $name) . Html::openElement('td', array()); if ($allowed) { $text .= Html::element('input', array('size' => 20, 'name' => "wp{$conf}-ns{$ns}", 'type' => 'text', 'value' => isset($default[$ns]) ? $default[$ns] : '')) . "\n"; } else { $text .= htmlspecialchars(isset($default[$ns]) ? $default[$ns] : ''); } $text .= Html::closeElement('td') . Html::closeElement('tr'); } $text .= Html::closeElement('table'); return $text; } if ($type == 'ns-array') { global $wgContLang; $nsdesc = $this->msg('configure-desc-ns')->escaped(); $valdescmsg = $this->msg("configure-setting-{$conf}-value"); if ($valdescmsg->exists()) { $valdesc = $valdescmsg->parse(); } else { $valdesc = $this->msg('configure-desc-val')->escaped(); } $text = Html::openElement('table', array('class' => 'ns-array configure-biglist configure-array-table')) . "\n" . Html::rawElement('tr', array(), Html::rawElement('th', array(), $nsdesc) . Html::rawElement('th', array(), $valdesc)) . "\n"; foreach ($wgContLang->getNamespaces() as $ns => $name) { if ($ns < 0) { continue; } $name = str_replace('_', ' ', $name); if ('' == $name) { $name = $this->msg('blanknamespace')->parse(); } $text .= Html::openElement('tr') . Html::rawElement('td', array(), Html::rawElement('label', array('for' => "wp{$conf}-ns{$ns}"), $name)) . Html::openElement('td'); if ($allowed) { $text .= Html::textarea("wp{$conf}-ns{$ns}", isset($default[$ns]) ? implode("\n", (array) $default[$ns]) : '', array('id' => "wp{$conf}-ns{$ns}", 'rows' => 5)) . Html::element('br') . "\n"; } else { $text .= "<pre>" . (isset($default[$ns]) ? htmlspecialchars(implode("\n", (array) $default[$ns])) : '') . "\n</pre>"; } $text .= Html::closeElement('td') . Html::closeElement('tr'); } $text .= Html::closeElement('table'); return $text; } if ($type == 'group-bool' || $type == 'group-array') { $all = array(); if ($type == 'group-bool') { $all = User::getAllRights(); $iter = $default; $allGroups = array_keys($all); $autopromote = array_keys($this->getSettingValue('wgAutopromote')); $newGroups = array_diff($autopromote, $allGroups); foreach ($newGroups as $newGroup) { $iter[$newGroup] = array(); } } else { $all = array_keys($this->getSettingValue('wgGroupPermissions')); $iter = array(); foreach ($all as $group) { $iter[$group] = isset($default[$group]) && is_array($default[$group]) ? $default[$group] : array(); } $all = array_diff($all, $this->getSettingValue('wgImplicitGroups')); } sort($all); $groupdesc = $this->msg('configure-desc-group')->escaped(); $valdescmsg = $this->msg("configure-setting-{$conf}-value"); if ($valdescmsg->exists()) { $valdesc = $valdescmsg->parse(); } else { $valdesc = $this->msg('configure-desc-val')->escaped(); } $classes = "{$type} configure-array-table" . ($type == 'group-bool' ? ' ajax-group' : ''); $text = Html::openElement('table', array('id' => $conf, 'class' => $classes)) . "\n"; $text .= Html::rawElement('tr', array('class' => 'configure-maintable-row'), Html::rawElement('th', array(), $groupdesc) . Html::rawElement('th', array(), $valdesc)) . "\n"; foreach ($iter as $group => $levs) { $row = self::buildGroupSettingRow($conf, $type, $all, $allowed, $group, $levs); $groupName = User::getGroupName($group); $text .= Html::rawElement('tr', array('class' => 'configure-maintable-row', 'id' => 'wp' . $conf . '-' . $group), Html::rawElement('td', array('class' => 'configure-grouparray-group'), $groupName) . "\n" . Html::rawElement('td', array('class' => 'configure-grouparray-value'), $row)); } $text .= Html::closeElement('table'); return $text; } if ($type == 'promotion-conds') { $groupdesc = $this->msg('configure-desc-group')->escaped(); $valdescmsg = $this->msg("configure-setting-{$conf}-value"); if ($valdescmsg->exists()) { $valdesc = $valdescmsg->parse(); } else { $valdesc = $this->msg('configure-desc-val')->escaped(); } $text = Html::openElement('table', array('id' => $conf, 'class' => "{$type} configure-array-table ajax-group")) . "\n"; $text .= Html::rawElement('tr', array('class' => 'configure-maintable-row'), Html::rawElement('th', array(), $groupdesc) . Html::rawElement('th', array(), $valdesc)) . "\n"; foreach ($default as $group => $groupConds) { $row = self::buildPromotionCondsSettingRow($conf, $allowed, $group, $groupConds); $groupName = User::getGroupName($group); $text .= Html::rawElement('tr', array('class' => 'configure-maintable-row', 'id' => 'wp' . $conf . '-' . $group), Html::rawElement('td', array('class' => 'configure-promotion-group'), $groupName) . "\n" . Html::rawElement('td', array('class' => 'configure-promotion-value'), $row)); } $text .= Html::closeElement('table'); return $text; } }