protected function showPageList() { if ($this->pager->getNumRows()) { $this->getOutput()->addHTML($this->pager->getNavigationBar()); $this->getOutput()->addHTML($this->pager->getBody()); $this->getOutput()->addHTML($this->pager->getNavigationBar()); } else { $this->getOutput()->addWikiMsg('configuredpages-none'); } # Purge expired entries on one in every 10 queries if (!mt_rand(0, 10)) { FRPageConfig::purgeExpiredConfigurations(); } }
/** * Set the page field data loaded from some source * @param $data Database row object or "fromdb" * @return void */ public function loadPageData($data = 'fromdb') { $this->mDataLoaded = true; // sanity # Fetch data from DB as needed... if ($data === 'fromdb' || $data === 'fromdbmaster') { $db = $data == 'fromdbmaster' ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE); $data = $this->pageDataFromTitle($db, $this->mTitle); } # Load in primary page data... parent::loadPageData($data); # Load in FlaggedRevs page data... $this->stable = 0; // 0 => "found nothing" $this->stableRev = null; // defer this one... $this->revsArePending = false; // false => "found nothing" or "none pending" $this->pendingRevCount = null; // defer this one... $this->pageConfig = FRPageConfig::getDefaultVisibilitySettings(); // default $this->syncedInTracking = true; // false => "unreviewed" or "synced" # Load in flaggedrevs Row data if the page exists...(sanity check NS) if ($data && FlaggedRevs::inReviewNamespace($this->mTitle)) { if ($data->fpc_override !== null) { // page config row found $this->pageConfig = FRPageConfig::getVisibilitySettingsFromRow($data); } if ($data->fp_stable !== null) { // stable rev found $this->stable = (int) $data->fp_stable; $this->revsArePending = $data->fp_pending_since !== null; // revs await review $this->syncedInTracking = (bool) $data->fp_reviewed; } } }
/** * Record a log entry on the stability config change action * @param Title $title * @param array $config * @param array $oldConfig * @param string $reason */ public static function updateStabilityLog(Title $title, array $config, array $oldConfig, $reason) { $log = new LogPage('stable'); if (FRPageConfig::configIsReset($config)) { # We are going back to default settings $log->addEntry('reset', $title, $reason); } else { # We are changing to non-default settings $action = $oldConfig === FRPageConfig::getDefaultVisibilitySettings() ? 'config' : 'modify'; // modified an existing custom configuration $log->addEntry($action, $title, $reason, FlaggedRevsLog::collapseParams(self::stabilityLogParams($config))); } }
/** * 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']; } }
protected function reallyDoCheckParameters() { # WMF temp hack...protection limit quota global $wgFlaggedRevsProtectQuota; $oldConfig = $this->getOldConfig(); if (isset($wgFlaggedRevsProtectQuota) && $this->autoreview != '' && FRPageConfig::getProtectionLevel($oldConfig) == 'none') { $dbw = wfGetDB(DB_MASTER); $count = $dbw->selectField('flaggedpage_config', 'COUNT(*)', '', __METHOD__); if ($count >= $wgFlaggedRevsProtectQuota) { return 'stabilize_protect_quota'; } } # Autoreview only when protecting currently unprotected pages $this->reviewThis = FRPageConfig::getProtectionLevel($oldConfig) == 'none'; # Autoreview restriction => use stable # No autoreview restriction => site default $this->override = $this->autoreview != '' ? 1 : (int) FlaggedRevs::isStableShownByDefault(); // site default # Check that settings are a valid protection level... $newConfig = array('override' => $this->override, 'autoreview' => $this->autoreview); if (FRPageConfig::getProtectionLevel($newConfig) == 'invalid') { return 'stabilize_invalid_level'; // double-check configuration } # Check autoreview restriction setting if (!FlaggedRevs::userCanSetAutoreviewLevel($this->user, $this->autoreview)) { return 'stabilize_denied'; // invalid value } return true; }
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 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; }