/** * Get a FlaggedRevision of the stable version of a title. * Skips tracking tables to figure out new stable version. * @param Title $title, page title * @param int $flags (FR_MASTER, FR_FOR_UPDATE) * @param array $config, optional page config (use to skip queries) * @param string $precedence (latest,quality,pristine) * @return FlaggedRevision|null (null on failure) */ public static function determineStable(Title $title, $flags = 0, $config = array(), $precedence = 'latest') { if (!FlaggedRevs::inReviewNamespace($title)) { return null; // short-circuit } $options = array(); # User master/slave as appropriate... if ($flags & FR_FOR_UPDATE || $flags & FR_MASTER) { $db = wfGetDB(DB_MASTER); if ($flags & FR_FOR_UPDATE) { $options[] = 'FOR UPDATE'; } $pageId = $title->getArticleID(Title::GAID_FOR_UPDATE); } else { $db = wfGetDB(DB_SLAVE); $pageId = $title->getArticleID(); } if (!$pageId) { return null; // short-circuit query } # Get visiblity settings to see if page is reviewable... if (FlaggedRevs::useOnlyIfProtected()) { if (empty($config)) { $config = FRPageConfig::getStabilitySettings($title, $flags); } if (!$config['override']) { return null; // page is not reviewable; no stable version } } $baseConds = array('fr_page_id' => $pageId, 'rev_id = fr_rev_id', 'rev_page = fr_page_id', $db->bitAnd('rev_deleted', Revision::DELETED_TEXT) . ' = 0'); $options['ORDER BY'] = 'fr_rev_timestamp DESC'; $row = null; if ($precedence !== 'latest') { # Look for the latest pristine revision... if (FlaggedRevs::pristineVersions()) { $prow = $db->selectRow(array('flaggedrevs', 'revision'), self::selectFields(), array_merge($baseConds, array('fr_quality' => FR_PRISTINE)), __METHOD__, $options); # Looks like a plausible revision $row = $prow ? $prow : $row; } if ($row && $precedence === 'pristine') { // we have what we want already # Look for the latest quality revision... } elseif (FlaggedRevs::qualityVersions()) { // If we found a pristine rev above, this one must be newer... $newerClause = $row ? array('fr_rev_timestamp > ' . $db->addQuotes($row->fr_rev_timestamp)) : array(); $qrow = $db->selectRow(array('flaggedrevs', 'revision'), self::selectFields(), array_merge($baseConds, array('fr_quality' => FR_QUALITY), $newerClause), __METHOD__, $options); $row = $qrow ? $qrow : $row; } } # Do we have one? If not, try the latest reviewed revision... if (!$row) { $row = $db->selectRow(array('flaggedrevs', 'revision'), self::selectFields(), $baseConds, __METHOD__, $options); if (!$row) { return null; } } $frev = new self($row); $frev->mTitle = $title; return $frev; }
public static function parserPendingChangeLevel(&$parser, $page = '') { $title = Title::newFromText($page); if (!$title instanceof Title) { $title = $parser->getTitle(); } if (!FlaggedRevs::inReviewNamespace($title) || !$parser->incrementExpensiveFunctionCount()) { return ''; } else { $config = FRPageConfig::getStabilitySettings($title); return $config['autoreview']; } }
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; }
public function getOldConfig() { if ($this->getState() == self::FORM_UNREADY) { throw new MWException(__CLASS__ . " input fields not set yet.\n"); } if ($this->oldConfig === array() && $this->page) { $this->oldConfig = FRPageConfig::getStabilitySettings($this->page); } return $this->oldConfig; }
public static function onParserGetVariableValueSwitch(&$parser, &$cache, &$word, &$ret) { if ($word == 'pendingchangelevel') { $title = $parser->getTitle(); if (!FlaggedRevs::inReviewNamespace($title)) { $ret = ''; } else { $config = FRPageConfig::getStabilitySettings($title); $ret = $config['autoreview']; } } return true; }