public function doExecute() { global $wgUser; $params = $this->extractRequestParams(); $form = new PageStabilityProtectForm($wgUser); $form->setPage($this->title); # Our target page $form->setWatchThis($params['watch']); # Watch this page $form->setReason($params['reason']); # Reason $form->setReasonSelection('other'); # Reason dropdown $form->setExpiry($params['expiry']); # Expiry $form->setExpirySelection('other'); # Expiry dropdown $restriction = $params['protectlevel']; if ($restriction == 'none') { $restriction = ''; // 'none' => '' } $form->setAutoreview($restriction); # Autoreview restriction $form->ready(); $status = $form->submit(); // true/error message key if ($status !== true) { $this->dieUsageMsg(wfMsg($status)); } # Output success line with the title and config parameters $res = array(); $res['title'] = $this->title->getPrefixedText(); $res['protectlevel'] = $params['protectlevel']; $res['expiry'] = $form->getExpiry(); $this->getResult()->addValue(null, $this->getModuleName(), $res); }
public static function onProtectionSave(Page $article, &$errorMsg) { global $wgUser, $wgRequest; if (!$article->exists()) { return true; // simple custom levels set for action=protect } elseif (!FlaggedRevs::inReviewNamespace($article->getTitle())) { return true; // not a reviewable page } elseif (wfReadOnly() || !$wgUser->isAllowed('stablesettings')) { return true; // user cannot change anything } $form = new PageStabilityProtectForm($wgUser); $form->setPage($article->getTitle()); // target page $permission = $wgRequest->getVal('mwStabilityLevel'); if ($permission == "none") { $permission = ''; // 'none' => '' } $form->setAutoreview($permission); // protection level (autoreview restriction) $form->setWatchThis(null); // protection form already has a watch check $form->setReasonExtra($wgRequest->getText('mwProtect-reason')); // manual $form->setReasonSelection($wgRequest->getVal('wpProtectReasonSelection')); // dropdown $form->setExpiryCustom($wgRequest->getVal('mwStabilizeExpiryOther')); // manual $form->setExpirySelection($wgRequest->getVal('mwStabilizeExpirySelection')); // dropdown $form->ready(); // params all set if ($wgRequest->wasPosted() && $form->isAllowed()) { $status = $form->submit(); if ($status !== true) { $errorMsg = wfMsg($status); // some error message } } return true; }