protected function showForm() { global $wgScript; # Explanatory text $this->getOutput()->addWikiMsg('configuredpages-list', $this->getLang()->formatNum($this->pager->getNumRows())); $fields = array(); # Namespace selector if (count(FlaggedRevs::getReviewNamespaces()) > 1) { $fields[] = FlaggedRevsXML::getNamespaceMenu($this->namespace, ''); } # Default version selector $fields[] = FlaggedRevsXML::getDefaultFilterMenu($this->override); # Restriction level selector if (FlaggedRevs::getRestrictionLevels()) { $fields[] = FlaggedRevsXML::getRestrictionFilterMenu($this->autoreview); } $form = Html::openElement('form', array('name' => 'configuredpages', 'action' => $wgScript, 'method' => 'get')); $form .= Html::hidden('title', $this->getTitle()->getPrefixedDBKey()); $form .= "<fieldset><legend>" . wfMsg('configuredpages') . "</legend>\n"; $form .= implode(' ', $fields) . '<br/>'; $form .= Xml::submitButton(wfMsg('go')); $form .= "</fieldset>\n"; $form .= Html::closeElement('form') . "\n"; $this->getOutput()->addHTML($form); }
protected function showForm() { global $wgScript; $this->getOutput()->addWikiMsg('stablepages-list', $this->getLang()->formatNum($this->pager->getNumRows())); $fields = array(); // Namespace selector if (count(FlaggedRevs::getReviewNamespaces()) > 1) { $fields[] = FlaggedRevsXML::getNamespaceMenu($this->namespace, ''); } // Restriction level selector if (FlaggedRevs::getRestrictionLevels()) { $fields[] = FlaggedRevsXML::getRestrictionFilterMenu($this->autoreview); } $fields[] = Xml::checkLabel(wfMsg('stablepages-indef'), 'indef', 'stablepages-indef', $this->indef); $form = Html::openElement('form', array('name' => 'stablepages', 'action' => $wgScript, 'method' => 'get')); $form .= Html::hidden('title', $this->getTitle()->getPrefixedDBKey()); $form .= "<fieldset><legend>" . wfMsg('stablepages') . "</legend>\n"; $form .= implode(' ', $fields) . ' '; $form .= " " . Xml::submitButton(wfMsg('go')); $form .= "</fieldset>\n"; $form .= Html::closeElement('form') . "\n"; $this->getOutput()->addHTML($form); }
public function getAllowedParams() { // Replace '' with more readable 'none' in autoreview restiction levels $autoreviewLevels = FlaggedRevs::getRestrictionLevels(); $autoreviewLevels[] = 'none'; return array('protectlevel' => array(ApiBase::PARAM_TYPE => $autoreviewLevels, ApiBase::PARAM_DFLT => 'none'), 'expiry' => 'infinite', 'reason' => '', 'watch' => null, 'token' => null, 'title' => null); }
public function getAllowedParams() { $namespaces = FlaggedRevs::getReviewNamespaces(); // Replace '' with more readable 'none' in autoreview restiction levels $autoreviewLevels = FlaggedRevs::getRestrictionLevels(); $autoreviewLevels[] = 'none'; return array('start' => array(ApiBase::PARAM_TYPE => 'integer'), 'end' => array(ApiBase::PARAM_TYPE => 'integer'), 'dir' => array(ApiBase::PARAM_DFLT => 'newer', ApiBase::PARAM_TYPE => array('newer', 'older')), 'namespace' => array(ApiBase::PARAM_DFLT => null, ApiBase::PARAM_TYPE => 'namespace', ApiBase::PARAM_ISMULTI => true), 'default' => array(ApiBase::PARAM_DFLT => null, ApiBase::PARAM_TYPE => array('latest', 'stable')), 'autoreview' => array(ApiBase::PARAM_DFLT => null, ApiBase::PARAM_TYPE => $autoreviewLevels), '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)); }
/** * Check if an fpc_level value is valid * @param string $right */ protected static function isValidRestriction($right) { if ($right == '') { return true; // no restrictions (none) } return in_array($right, FlaggedRevs::getRestrictionLevels(), true); }
/** * Check if a user can set the autoreview restiction level to $right * @param User $user * @param string $right the level * @return bool */ public static function userCanSetAutoreviewLevel($user, $right) { if ($right == '') { return true; // no restrictions (none) } if (!in_array($right, FlaggedRevs::getRestrictionLevels())) { return false; // invalid restriction level } # Don't let them choose levels above their own rights if ($right == 'sysop') { // special case, rewrite sysop to editprotected if (!$user->isAllowed('editprotected')) { return false; } } elseif ($right == 'autoconfirmed') { // special case, rewrite autoconfirmed to editsemiprotected if (!$user->isAllowed('editsemiprotected')) { return false; } } elseif (!$user->isAllowed($right)) { return false; } return true; }
/** * Get a <select> of options of 'autoreview' restriction levels. Used for filters. * @param string $selected ('' for "any", 'none' for none) * @return string */ public static function getRestrictionFilterMenu($selected = '') { if (is_null($selected)) { $selected = ''; // "all" } $s = Xml::label(wfMsg('revreview-restrictfilter'), 'wpRestriction') . "\n"; $s .= Xml::openElement('select', array('name' => 'restriction', 'id' => 'wpRestriction')); $s .= Xml::option(wfMsg('revreview-restriction-any'), '', $selected == ''); if (!FlaggedRevs::useProtectionLevels()) { # All "protected" pages have a protection level, not "none" $s .= Xml::option(wfMsg('revreview-restriction-none'), 'none', $selected == 'none'); } foreach (FlaggedRevs::getRestrictionLevels() as $perm) { $key = "revreview-restriction-{$perm}"; $msg = wfMsg($key); if (wfEmptyMsg($key, $msg)) { $msg = $perm; // fallback to user right key } $s .= Xml::option($msg, $perm, $selected == $perm); } $s .= Xml::closeElement('select') . "\n"; return $s; }
/** * Get a <select> of options of 'autoreview' restriction levels. Used for filters. * @param string $selected ('' for "any", 'none' for none) * @return string */ public static function getRestrictionFilterMenu($selected = '') { if (is_null($selected)) { $selected = ''; // "all" } $s = Xml::label(wfMessage('revreview-restrictfilter')->text(), 'wpRestriction') . "\n"; $s .= Xml::openElement('select', array('name' => 'restriction', 'id' => 'wpRestriction')); $s .= Xml::option(wfMessage('revreview-restriction-any')->text(), '', $selected == ''); if (!FlaggedRevs::useProtectionLevels()) { # All "protected" pages have a protection level, not "none" $s .= Xml::option(wfMessage('revreview-restriction-none')->text(), 'none', $selected == 'none'); } foreach (FlaggedRevs::getRestrictionLevels() as $perm) { // Give grep a chance to find the usages: // revreview-restriction-any, revreview-restriction-none $key = "revreview-restriction-{$perm}"; if (wfMessage($key)->isDisabled()) { $msg = $perm; // fallback to user right key } else { $msg = wfMessage($key)->text(); } $s .= Xml::option($msg, $perm, $selected == $perm); } $s .= Xml::closeElement('select') . "\n"; return $s; }
protected function reallyDoCheckParameters() { $this->override = $this->override ? 1 : 0; // default version settings is 0 or 1 // Check autoreview restriction setting if ($this->autoreview != '' && !in_array($this->autoreview, FlaggedRevs::getRestrictionLevels())) { return 'stabilize_invalid_autoreview'; // invalid value } if (!FlaggedRevs::userCanSetAutoreviewLevel($this->user, $this->autoreview)) { return 'stabilize_denied'; // invalid value } return true; }
protected function buildSelector($selected) { $allowedLevels = array(); $levels = FlaggedRevs::getRestrictionLevels(); array_unshift($levels, ''); // Add a "none" level foreach ($levels as $key) { # Don't let them choose levels they can't set, # but *show* them all when the form is disabled. if ($this->form->isAllowed() && !FlaggedRevs::userCanSetAutoreviewLevel($this->getUser(), $key)) { continue; } $allowedLevels[] = $key; } $id = 'mwProtect-level-autoreview'; $attribs = array('id' => $id, 'name' => $id, 'size' => count($allowedLevels)) + $this->disabledAttr(); $out = Xml::openElement('select', $attribs); foreach ($allowedLevels as $key) { $out .= Xml::option($this->getOptionLabel($key), $key, $key == $selected); } $out .= Xml::closeElement('select'); return $out; }
public static function onProtectionForm(Page $article, &$output) { global $wgUser, $wgOut, $wgRequest, $wgLang; if (!$article->exists()) { return true; // nothing to do } elseif (!FlaggedRevs::inReviewNamespace($article->getTitle())) { return true; // not a reviewable page } $form = new PageStabilityProtectForm($wgUser); $form->setPage($article->getTitle()); # Can the user actually do anything? $isAllowed = $form->isAllowed(); $disabledAttrib = $isAllowed ? array() : array('disabled' => 'disabled'); # Get the current config/expiry $config = FRPageConfig::getStabilitySettings($article->getTitle(), FR_MASTER); $oldExpirySelect = $config['expiry'] == 'infinity' ? 'infinite' : 'existing'; # Load requested restriction level, default to current level... $restriction = $wgRequest->getVal('mwStabilityLevel', FRPageConfig::getProtectionLevel($config)); # Load the requested expiry time (dropdown) $expirySelect = $wgRequest->getVal('mwStabilizeExpirySelection', $oldExpirySelect); # Load the requested expiry time (field) $expiryOther = $wgRequest->getVal('mwStabilizeExpiryOther', ''); if ($expiryOther != '') { $expirySelect = 'othertime'; } // mutual exclusion # Add an extra row to the protection fieldset tables. # Includes restriction dropdown and expiry dropdown & field. $output .= "<tr><td>"; $output .= Xml::openElement('fieldset'); $legendMsg = wfMsgExt('flaggedrevs-protect-legend', 'parseinline'); $output .= "<legend>{$legendMsg}</legend>"; # Add a "no restrictions" level $effectiveLevels = FlaggedRevs::getRestrictionLevels(); array_unshift($effectiveLevels, "none"); # Show all restriction levels in a <select>... $attribs = array('id' => 'mwStabilityLevel', 'name' => 'mwStabilityLevel', 'size' => count($effectiveLevels)) + $disabledAttrib; $output .= Xml::openElement('select', $attribs); foreach ($effectiveLevels as $limit) { if ($limit == 'none') { $label = wfMsg('flaggedrevs-protect-none'); } else { $label = wfMsg('flaggedrevs-protect-' . $limit); } // Default to the key itself if no UI message if (wfEmptyMsg('flaggedrevs-protect-' . $limit, $label)) { $label = 'flaggedrevs-protect-' . $limit; } $output .= Xml::option($label, $limit, $limit == $restriction); } $output .= Xml::closeElement('select'); # Get expiry dropdown <select>... $scExpiryOptions = wfMsgForContent('protect-expiry-options'); $showProtectOptions = $scExpiryOptions !== '-' && $isAllowed; # Add the current expiry as an option $expiryFormOptions = ''; if ($config['expiry'] != 'infinity') { $timestamp = $wgLang->timeanddate($config['expiry']); $d = $wgLang->date($config['expiry']); $t = $wgLang->time($config['expiry']); $expiryFormOptions .= Xml::option(wfMsg('protect-existing-expiry', $timestamp, $d, $t), 'existing', $expirySelect == 'existing') . "\n"; } $expiryFormOptions .= Xml::option(wfMsg('protect-othertime-op'), 'othertime') . "\n"; # Add custom dropdown levels (from MediaWiki message) foreach (explode(',', $scExpiryOptions) as $option) { if (strpos($option, ":") === false) { $show = $value = $option; } else { list($show, $value) = explode(":", $option); } $show = htmlspecialchars($show); $value = htmlspecialchars($value); $expiryFormOptions .= Xml::option($show, $value, $expirySelect == $value) . "\n"; } # Actually add expiry dropdown to form $output .= "<table>"; // expiry table start if ($showProtectOptions && $isAllowed) { $output .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('stabilization-expiry'), 'mwStabilizeExpirySelection') . "</td>\n\t\t\t\t\t<td class='mw-input'>" . Xml::tags('select', array('id' => 'mwStabilizeExpirySelection', 'name' => 'mwStabilizeExpirySelection', 'onchange' => 'onFRChangeExpiryDropdown()') + $disabledAttrib, $expiryFormOptions) . "</td>\n\t\t\t\t</tr>"; } # Add custom expiry field to form $attribs = array('id' => 'mwStabilizeExpiryOther', 'onkeyup' => 'onFRChangeExpiryField()') + $disabledAttrib; $output .= "\n\t\t\t<tr>\n\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('stabilization-othertime'), 'mwStabilizeExpiryOther') . '</td> <td class="mw-input">' . Xml::input('mwStabilizeExpiryOther', 50, $expiryOther, $attribs) . '</td> </tr>'; $output .= "</table>"; // expiry table end # Close field set and table row $output .= Xml::closeElement('fieldset'); $output .= "</td></tr>"; # Add some javascript for expiry dropdowns $wgOut->addScript("<script type=\"text/javascript\">\n\t\t\t\tfunction onFRChangeExpiryDropdown() {\n\t\t\t\t\tdocument.getElementById('mwStabilizeExpiryOther').value = '';\n\t\t\t\t}\n\t\t\t\tfunction onFRChangeExpiryField() {\n\t\t\t\t\tdocument.getElementById('mwStabilizeExpirySelection').value = 'othertime';\n\t\t\t\t}\n\t\t\t</script>"); return true; }