/** * 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; }
/** * Show the special page * @param string|null $par */ public function execute($par) { $this->setHeaders(); $this->outputHeader(); $out = $this->getOutput(); $out->addModuleStyles('mediawiki.special'); $out->addHTML(\Html::openElement('table', array('class' => 'wikitable mw-listgrouprights-table')) . '<tr>' . \Html::element('th', null, $this->msg('listgrants-grant')->text()) . \Html::element('th', null, $this->msg('listgrants-rights')->text()) . '</tr>'); foreach ($this->getConfig()->get('GrantPermissions') as $grant => $rights) { $descs = array(); $rights = array_filter($rights); // remove ones with 'false' foreach ($rights as $permission => $granted) { $descs[] = $this->msg('listgrouprights-right-display', \User::getRightDescription($permission), '<span class="mw-listgrants-right-name">' . $permission . '</span>')->parse(); } if (!count($descs)) { $grantCellHtml = ''; } else { sort($descs); $grantCellHtml = '<ul><li>' . implode("</li>\n<li>", $descs) . '</li></ul>'; } $id = \Sanitizer::escapeId($grant); $out->addHTML(\Html::rawElement('tr', array('id' => $id), "<td>" . $this->msg("grant-{$grant}")->escaped() . "</td>" . "<td>" . $grantCellHtml . '</td>')); } $out->addHTML(\Html::closeElement('table')); }
/** * Create a user-readable list of permissions from the given array. * * @param $permissions Array of permission => bool (from $wgGroupPermissions items) * @return string List of all granted permissions, separated by comma separator */ private static function formatPermissions($permissions, $add, $remove) { global $wgLang; $r = array(); foreach ($permissions as $permission => $granted) { if ($granted) { $description = wfMsgExt('listgrouprights-right-display', array('parseinline'), User::getRightDescription($permission), $permission); $r[] = $description; } } sort($r); if ($add === true) { $r[] = wfMsgExt('listgrouprights-addgroup-all', array('escape')); } else { if (is_array($add) && count($add)) { $r[] = wfMsgExt('listgrouprights-addgroup', array('parseinline'), $wgLang->listToText(array_map(array('User', 'makeGroupLinkWiki'), $add)), count($add)); } } if ($remove === true) { $r[] = wfMsgExt('listgrouprights-removegroup-all', array('escape')); } else { if (is_array($remove) && count($remove)) { $r[] = wfMsgExt('listgrouprights-removegroup', array('parseinline'), $wgLang->listToText(array_map(array('User', 'makeGroupLinkWiki'), $remove)), count($remove)); } } if (empty($r)) { return ''; } else { return '<ul><li>' . implode("</li>\n<li>", $r) . '</li></ul>'; } }
/** * @param $group * @return string */ function buildCheckboxes($group) { $editable = $this->userCanEdit($this->getUser()); $assignedRights = $this->getAssignedRights($group); $checkboxes = array(); $attribs = array(); if (!$editable) { $attribs['disabled'] = 'disabled'; if (!$assignedRights) { $this->getOutput()->wrapWikiMsg('<div class="error">$1</div>', array('centralauth-editgroup-nonexistent', $group)); } } $rights = User::getAllRights(); sort($rights); foreach ($rights as $right) { // Build a checkbox $checked = in_array($right, $assignedRights); $desc = $this->getOutput()->parseInline(User::getRightDescription($right)) . ' ' . Xml::element('code', null, $this->msg('parentheses', $right)->text()); $checkbox = Xml::check("wpRightAssigned-{$right}", $checked, array_merge($attribs, array('id' => "wpRightAssigned-{$right}"))); $label = Xml::tags('label', array('for' => "wpRightAssigned-{$right}"), $desc); $liClass = $checked ? 'mw-centralauth-editgroup-checked' : 'mw-centralauth-editgroup-unchecked'; $checkboxes[] = Html::rawElement('li', array('class' => $liClass), "{$checkbox} {$label}"); } $count = count($checkboxes); $html = Html::openElement('div', array('class' => 'mw-centralauth-rights')) . '<ul>'; foreach ($checkboxes as $cb) { $html .= $cb; } $html .= '</ul>' . Html::closeElement('div'); return $html; }
/** * Create a user-readable list of permissions from the given array. * * @param $permissions Array of permission => bool (from $wgGroupPermissions items) * @param $revoke Array of permission => bool (from $wgRevokePermissions items) * @param $add Array of groups this group is allowed to add or true * @param $remove Array of groups this group is allowed to remove or true * @param $addSelf Array of groups this group is allowed to add to self or true * @param $removeSelf Array of group this group is allowed to remove from self or true * @return string List of all granted permissions, separated by comma separator */ private function formatPermissions($permissions, $revoke, $add, $remove, $addSelf, $removeSelf) { $r = array(); foreach ($permissions as $permission => $granted) { //show as granted only if it isn't revoked to prevent duplicate display of permissions if ($granted && (!isset($revoke[$permission]) || !$revoke[$permission])) { $description = wfMsgExt('listgrouprights-right-display', array('parseinline'), User::getRightDescription($permission), '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'); $r[] = $description; } } foreach ($revoke as $permission => $revoked) { if ($revoked) { $description = wfMsgExt('listgrouprights-right-revoked', array('parseinline'), User::getRightDescription($permission), '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'); $r[] = $description; } } sort($r); $lang = $this->getLanguage(); if ($add === true) { $r[] = wfMsgExt('listgrouprights-addgroup-all', array('escape')); } elseif (is_array($add) && count($add)) { $add = array_values(array_unique($add)); $r[] = wfMsgExt('listgrouprights-addgroup', array('parseinline'), $lang->listToText(array_map(array('User', 'makeGroupLinkWiki'), $add)), count($add)); } if ($remove === true) { $r[] = wfMsgExt('listgrouprights-removegroup-all', array('escape')); } elseif (is_array($remove) && count($remove)) { $remove = array_values(array_unique($remove)); $r[] = wfMsgExt('listgrouprights-removegroup', array('parseinline'), $lang->listToText(array_map(array('User', 'makeGroupLinkWiki'), $remove)), count($remove)); } if ($addSelf === true) { $r[] = wfMsgExt('listgrouprights-addgroup-self-all', array('escape')); } elseif (is_array($addSelf) && count($addSelf)) { $addSelf = array_values(array_unique($addSelf)); $r[] = wfMsgExt('listgrouprights-addgroup-self', array('parseinline'), $lang->listToText(array_map(array('User', 'makeGroupLinkWiki'), $addSelf)), count($addSelf)); } if ($removeSelf === true) { $r[] = wfMsgExt('listgrouprights-removegroup-self-all', array('escape')); } elseif (is_array($removeSelf) && count($removeSelf)) { $removeSelf = array_values(array_unique($removeSelf)); $r[] = wfMsgExt('listgrouprights-removegroup-self', array('parseinline'), $lang->listToText(array_map(array('User', 'makeGroupLinkWiki'), $removeSelf)), count($removeSelf)); } if (empty($r)) { return ''; } else { return '<ul><li>' . implode("</li>\n<li>", $r) . '</li></ul>'; } }
/** * Create a user-readable list of permissions from the given array. * * @param array $permissions Array of permission => bool (from $wgGroupPermissions items) * @param array $revoke Array of permission => bool (from $wgRevokePermissions items) * @param array $add Array of groups this group is allowed to add or true * @param array $remove Array of groups this group is allowed to remove or true * @param array $addSelf Array of groups this group is allowed to add to self or true * @param array $removeSelf Array of group this group is allowed to remove from self or true * @return string List of all granted permissions, separated by comma separator */ private function formatPermissions($permissions, $revoke, $add, $remove, $addSelf, $removeSelf) { $r = []; foreach ($permissions as $permission => $granted) { // show as granted only if it isn't revoked to prevent duplicate display of permissions if ($granted && (!isset($revoke[$permission]) || !$revoke[$permission])) { $r[] = $this->msg('listgrouprights-right-display', User::getRightDescription($permission), '<span class="mw-listgrouprights-right-name">' . $permission . '</span>')->parse(); } } foreach ($revoke as $permission => $revoked) { if ($revoked) { $r[] = $this->msg('listgrouprights-right-revoked', User::getRightDescription($permission), '<span class="mw-listgrouprights-right-name">' . $permission . '</span>')->parse(); } } sort($r); $lang = $this->getLanguage(); $allGroups = User::getAllGroups(); $changeGroups = ['addgroup' => $add, 'removegroup' => $remove, 'addgroup-self' => $addSelf, 'removegroup-self' => $removeSelf]; foreach ($changeGroups as $messageKey => $changeGroup) { if ($changeGroup === true) { // For grep: listgrouprights-addgroup-all, listgrouprights-removegroup-all, // listgrouprights-addgroup-self-all, listgrouprights-removegroup-self-all $r[] = $this->msg('listgrouprights-' . $messageKey . '-all')->escaped(); } elseif (is_array($changeGroup)) { $changeGroup = array_intersect(array_values(array_unique($changeGroup)), $allGroups); if (count($changeGroup)) { // For grep: listgrouprights-addgroup, listgrouprights-removegroup, // listgrouprights-addgroup-self, listgrouprights-removegroup-self $r[] = $this->msg('listgrouprights-' . $messageKey, $lang->listToText(array_map(['User', 'makeGroupLinkWiki'], $changeGroup)), count($changeGroup))->parse(); } } } if (empty($r)) { return ''; } else { return '<ul><li>' . implode("</li>\n<li>", $r) . '</li></ul>'; } }
/** * @param $group * @return string */ function buildCheckboxes($group) { $editable = $this->userCanEdit($this->getUser()); $rights = User::getAllRights(); $assignedRights = $this->getAssignedRights($group); sort($rights); $checkboxes = array(); $attribs = array(); if (!$editable) { $attribs['disabled'] = 'disabled'; } foreach ($rights as $right) { # Build a checkbox. $checked = in_array($right, $assignedRights); $desc = $this->getOutput()->parseInline(User::getRightDescription($right)) . ' ' . Xml::element('tt', null, wfMsg('parentheses', $right)); $checkbox = Xml::check("wpRightAssigned-{$right}", $checked, array_merge($attribs, array('id' => "wpRightAssigned-{$right}"))); $label = Xml::tags('label', array('for' => "wpRightAssigned-{$right}"), $desc); $checkboxes[] = "<li>{$checkbox} {$label}</li>"; } $count = count($checkboxes); $firstCol = round($count / 2); $checkboxes1 = array_slice($checkboxes, 0, $firstCol); $checkboxes2 = array_slice($checkboxes, $firstCol); $html = '<table><tbody><tr><td><ul>'; foreach ($checkboxes1 as $cb) { $html .= $cb; } $html .= '</ul></td><td><ul>'; foreach ($checkboxes2 as $cb) { $html .= $cb; } $html .= '</ul></td></tr></tbody></table>'; return $html; }
/** * 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; } }
function formatConfigInput($var, $type, $wiki = '') { global $wgConfigure, $wgRequest; $val = $wgConfigure->getSetting($wiki, $var); $descr = wfMsg('configurewmf-var-' . strtolower($var)); $descrlabel = Xml::label($descr, $var); $r = "<tr><td class='mw-label'>{$descrlabel}:</td>\n\n<td class='mw-input'>"; switch ($type) { case 'string': $r .= Xml::input($var, false, $val); break; case 'bool': $r .= Xml::check($var, $val); break; case 'stringarray': $val = $val ? implode("\n", $val) : ''; $r .= Xml::textarea($var, $val); break; case 'logo': global $wgConfigureStdlogo; $isstd = $val == $wgConfigureStdlogo; $r .= '<div>' . Xml::radioLabel(wfMsgHtml('configurewmf-stdlogo'), $var, 'stdlogo', 'wgLogoStdlogo', $isstd) . '</div>'; $r .= '<div>' . Xml::radioLabel(wfMsgHtml('configurewmf-otherlogo'), $var, 'other', 'wgLogoOther', !$isstd) . ' ' . Xml::input("{$var}Other", false, $isstd ? '' : $val) . '</div>'; break; case 'groupperms': $groups = $wgConfigure->getGroupPermissions($wiki); $group = $wgRequest->getVal('group'); $perms = isset($groups[$group]) ? $groups[$group] : array(); $rights = User::getAllRights(); sort($rights); $checkboxes = array(); foreach ($rights as $right) { $label = wfMsgExt('configurewmf-permission', array('parseinline'), User::getRightDescription($right), $right); $checkboxes[] = Xml::checkLabel($label, "{$var}-{$right}", "{$var}-{$right}", @$perms[$right]); } $firstCol = round(count($checkboxes) / 2); $checkboxes1 = array_slice($checkboxes, 0, $firstCol); $checkboxes2 = array_slice($checkboxes, $firstCol); $r .= '<table><tbody><tr><td><ul><li>' . implode('</li><li>', $checkboxes1) . '</li></ul></td><td><ul><li>' . implode('</li><li>', $checkboxes2) . '</li></ul></td></tr></tbody></table>'; $r .= Html::Hidden('group', $group); break; case 'grouplist': $targetgroup = $wgRequest->getVal('group'); $r .= '<ul>'; foreach (array_keys($wgConfigure->getGroupPermissions($wiki)) as $group) { if (in_array($group, $wgConfigure->getSetting($wiki, 'wgImplicitGroups'))) { continue; } $checked = isset($val[$targetgroup]) ? in_array($group, $val[$targetgroup]) : false; $checkbox = Xml::checkLabel(User::getGroupName($group), "{$var}-{$group}", "{$var}-{$group}", $checked); $r .= "<li>{$checkbox}</li>\n"; } $r .= '</ul>'; break; } return $r . '</td></tr>'; }
/** * Build a row for group-bool or group-array array type, taken out of * buildArrayInput() to called with ajax * @param $conf String: setting name * @param $type String: array type * @param $all Array: all avialable rights * @param $allowed Boolean * @param $group String: group name * @param $levs Array: rights given to $group * @return String: XHTML */ public static function buildGroupSettingRow($conf, $type, $all, $allowed, $group, $levs) { $attr = !$allowed ? array('disabled' => 'disabled') : array(); $row = Html::openElement('div', array('class' => 'configure-biglist ' . $type . '-element')) . Html::openElement('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); if ($type == 'group-bool') { $desc = User::getRightDescription($right) . " (" . Html::element('tt', array('class' => 'configure-right-id'), $right) . ")"; } else { $desc = User::getGroupName($right); } $checkedArr = $checked ? array('checked' => 'checked') : array(); $row .= Html::rawElement('li', array(), Html::input($id, '1', 'checkbox', $attr + array('id' => $id) + $checkedArr) . ' ' . Html::rawElement('label', array('for' => $id), $desc)) . "\n"; } $row .= Html::closeElement('ul') . Html::closeElement('div'); return $row; }