function getMustShowThreads($threads = array()) { if ($this->request->getCheck('lqt_operand')) { $operands = explode(',', $this->request->getVal('lqt_operand')); $threads = array_merge($threads, $operands); } if ($this->request->getCheck('lqt_mustshow')) { // Check for must-show in the request $specifiedMustShow = $this->request->getVal('lqt_mustshow'); $specifiedMustShow = explode(',', $specifiedMustShow); $threads = array_merge($threads, $specifiedMustShow); } foreach ($threads as $walk_thread) { do { if (!is_object($walk_thread)) { $walk_thread = Threads::withId($walk_thread); } if (!is_object($walk_thread)) { continue; } $threads[$walk_thread->id()] = $walk_thread; $walk_thread = $walk_thread->superthread(); } while ($walk_thread); } return $threads; }
/** * @param WebRequest $request * * @return array("<overall message>","<select value>","<text field value>") */ function loadDataFromRequest($request) { if ($request->getCheck($this->mName)) { $list = $request->getText($this->mName); $text = $request->getText($this->mName . '-other'); // Should be built the same as in mediawiki.htmlform.js if ($list == 'other') { $final = $text; } elseif (!in_array($list, $this->mFlatOptions, true)) { # User has spoofed the select form to give an option which wasn't # in the original offer. Sulk... $final = $text; } elseif ($text == '') { $final = $list; } else { $final = $list . $this->msg('colon-separator')->inContentLanguage()->text() . $text; } } else { $final = $this->getDefault(); $list = 'other'; $text = $final; foreach ($this->mFlatOptions as $option) { $match = $option . $this->msg('colon-separator')->inContentLanguage()->text(); if (strpos($text, $match) === 0) { $list = $option; $text = substr($text, strlen($match)); break; } } } return array($final, $list, $text); }
/** * Constructor * @param WebRequest $request A WebRequest object passed by reference */ function LoginForm(&$request, $par = '') { global $wgLang, $wgAllowRealName, $wgEnableEmail; global $wgAuth; $this->mType = $par == 'signup' ? $par : $request->getText('type'); # Check for [[Special:Userlogin/signup]] $this->mName = $request->getText('wpName'); $this->mPassword = $request->getText('wpPassword'); $this->mRetype = $request->getText('wpRetype'); $this->mRetypeEmail = $request->getText('wpRetypeEmail'); $this->mDomain = $request->getText('wpDomain'); $this->mReturnTo = $request->getVal('returnto'); $this->mAutoRedirect = $request->getVal('autoredirect'); $this->mFromSite = $request->getVal('sitelogin'); $this->mCookieCheck = $request->getVal('wpCookieCheck'); $this->mPosted = $request->wasPosted(); $this->mCreateaccount = $request->getCheck('wpCreateaccount'); $this->mCreateaccountMail = $request->getCheck('wpCreateaccountMail') && $wgEnableEmail; $this->mMailmypassword = $request->getCheck('wpMailmypassword') && $wgEnableEmail; $this->mLoginattempt = $request->getCheck('wpLoginattempt'); $this->mAction = $request->getVal('action'); $this->mRemember = $request->getCheck('wpRemember'); $this->mLanguage = $request->getText('uselang'); if ($wgEnableEmail) { $this->mEmail = $request->getText('wpEmail'); } else { $this->mEmail = ''; } if ($wgAllowRealName && $request->getText('wpUseRealNameAsDisplay') == "on") { $this->mRealName = @strip_tags($request->getText('wpRealName')); } else { $this->mRealName = ''; } if (!$wgAuth->validDomain($this->mDomain)) { $this->mDomain = 'invaliddomain'; } $wgAuth->setDomain($this->mDomain); # When switching accounts, it sucks to get automatically logged out if ($this->mReturnTo == $wgLang->specialPage('Userlogout')) { $this->mReturnTo = ''; } if ($this->mAutoRedirect == $wgLang->specialPage('Userlogout')) { $this->mAutoRedirect = ''; } }
/** * @param WebRequest $request * * @return string */ function loadDataFromRequest($request) { if ($request->getCheck($this->mName)) { $val = $request->getText($this->mName); if ($val === 'other') { $val = $request->getText($this->mName . '-other'); } return $val; } else { return $this->getDefault(); } }
/** * @param WebRequest $request * * @return string */ function loadDataFromRequest($request) { $invert = isset($this->mParams['invert']) && $this->mParams['invert']; // GetCheck won't work like we want for checks. // Fetch the value in either one of the two following case: // - we have a valid token (form got posted or GET forged by the user) // - checkbox name has a value (false or true), ie is not null if ($request->getCheck('wpEditToken') || $request->getVal($this->mName) !== null) { return $invert ? !$request->getBool($this->mName) : $request->getBool($this->mName); } else { return $this->getDefault(); } }
/** * @param WebRequest $request * @return string|MWRestrictions Restrictions object or original string if invalid */ function loadDataFromRequest($request) { if (!$request->getCheck($this->mName)) { return $this->getDefault(); } $value = rtrim($request->getText($this->mName), "\r\n"); $ips = $value === '' ? [] : explode(PHP_EOL, $value); try { return MWRestrictions::newFromArray(['IPAddresses' => $ips]); } catch (InvalidArgumentException $e) { return $value; } }
/** * Constructor * @param WebRequest $request A WebRequest object passed by reference */ function LoginForm(&$request) { global $wgLang, $wgAllowRealName, $wgEnableEmail; global $wgAuth; $this->mType = $request->getText('type'); $this->mName = $request->getText('wpName'); $this->mPassword = $request->getText('wpPassword'); $this->mRetype = $request->getText('wpRetype'); $this->mDomain = $request->getText('wpDomain'); $this->mReturnTo = $request->getVal('returnto'); $this->mCookieCheck = $request->getVal('wpCookieCheck'); $this->mPosted = $request->wasPosted(); $this->mCreateaccount = $request->getCheck('wpCreateaccount'); $this->mCreateaccountMail = $request->getCheck('wpCreateaccountMail') && $wgEnableEmail; $this->mMailmypassword = $request->getCheck('wpMailmypassword') && $wgEnableEmail; $this->mLoginattempt = $request->getCheck('wpLoginattempt'); $this->mAction = $request->getVal('action'); $this->mRemember = $request->getCheck('wpRemember'); $this->mLanguage = $request->getText('uselang'); if ($wgEnableEmail) { $this->mEmail = $request->getText('wpEmail'); } else { $this->mEmail = ''; } if ($wgAllowRealName) { $this->mRealName = $request->getText('wpRealName'); } else { $this->mRealName = ''; } if (!$wgAuth->validDomain($this->mDomain)) { $this->mDomain = 'invaliddomain'; } $wgAuth->setDomain($this->mDomain); # When switching accounts, it sucks to get automatically logged out if ($this->mReturnTo == $wgLang->specialPage('Userlogout')) { $this->mReturnTo = ''; } }
/** * @param WebRequest $request * * @return string */ function loadDataFromRequest($request) { $invert = false; if (isset($this->mParams['invert']) && $this->mParams['invert']) { $invert = true; } // GetCheck won't work like we want for checks. // Fetch the value in either one of the two following case: // - we have a valid token (form got posted or GET forged by the user) // - checkbox name has a value (false or true), ie is not null if ($request->getCheck('wpEditToken') || $request->getVal($this->mName) !== null) { // XOR has the following truth table, which is what we want // INVERT VALUE | OUTPUT // true true | false // false true | true // false false | false // true false | true return $request->getBool($this->mName) xor $invert; } else { return $this->getDefault(); } }
/** * Put together a rev_deleted bitfield from the submitted checkboxes * @param WebRequest $request * @return int */ private function extractBitfield($request) { $bitfield = 0; foreach ($this->checks as $item) { list(, $name, $field) = $item; if ($request->getCheck($name)) { $bitfield |= $field; } } return $bitfield; }
/** * Extract "power search" namespace settings from the request object, * returning a list of index numbers to search. * * @param WebRequest $request * @return array */ protected function powerSearch(&$request) { $arr = array(); foreach (SearchEngine::searchableNamespaces() as $ns => $name) { if ($request->getCheck('ns' . $ns)) { $arr[] = $ns; } } return $arr; }
/** * Get the value that this input has been set to from a posted form, * or the input's default value if it has not been set. * * @param WebRequest $request * @return string The value */ function loadDataFromRequest($request) { if ($request->getCheck($this->mName)) { return $request->getText($this->mName); } else { return $this->getDefault(); } }
private function printForm(&$parameters, WebRequest &$request) { global $wgOut, $sfgFormPrinter; // Prepare parameters for SFFormPrinter::formHTML // there is no ONE target page $targetTitle = null; // formDefinition $formName = $request->getText('form'); // if query string did not contain these variables, try the URL if ($formName === '') { $queryparts = explode('/', $parameters); $formName = isset($queryparts[0]) ? $queryparts[0] : null; // if the form name wasn't in the URL either, throw an error if (is_null($formName) || $formName === '') { throw new SPSException(SPSUtils::buildMessage('spserror-noformname')); } } $formTitle = Title::makeTitleSafe(SF_NS_FORM, $formName); if (!$formTitle->exists()) { throw new SPSException(SPSUtils::buildMessage('spserror-formunknown', $formName)); } $formArticle = new Article($formTitle); $formDefinition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $formArticle->getContent()); // formSubmitted $formSubmitted = false; // pageContents $pageContents = null; // get 'preload' query value, if it exists if ($request->getCheck('preload')) { $pageContents = SFFormUtils::getPreloadedText($request->getVal('preload')); } else { // let other extensions preload the page, if they want wfRunHooks('sfEditFormPreloadText', array(&$pageContents, $targetTitle, $formTitle)); } // pageIsSource $pageIsSource = $pageContents != null; // pageNameFormula // parse the form to see if it has a 'page name' value set $matches; if (preg_match('/{{{info.*page name\\s*=\\s*(.*)}}}/m', $formDefinition, $matches)) { $pageNameElements = SFUtils::getFormTagComponents($matches[1]); $pageNameFormula = $pageNameElements[0]; } else { return 'sf_formedit_badurl'; } // get the iterator parameters $iteratorData = $this->buildIteratorParameters($request); // Call SFFormPrinter::formHTML list($formText, $javascriptText, $dataText, $formPageTitle, $generatedPageName) = $sfgFormPrinter->formHTML($formDefinition, $formSubmitted, $pageIsSource, $formArticle->getID(), $pageContents, '', $pageNameFormula); // Set Special page main header; // override the default title for this page if a title was specified in the form if ($formPageTitle != null) { $wgOut->setPageTitle($formPageTitle); } else { $wgOut->setPageTitle(SPSUtils::buildMessage('sf_formedit_createtitlenotarget', $formTitle->getText())); } $preFormHtml = ''; wfRunHooks('sfHTMLBeforeForm', array(&$targetTitle, &$preFormHtml)); $text = '<form name="createbox" id="sfForm" action="" method="post" class="createbox">' . $preFormHtml . "\n" . SFFormUtils::hiddenFieldHTML('iteratordata', $iteratorData) . $formText; SFUtils::addJavascriptAndCSS(); if (!empty($javascriptText)) { $wgOut->addScript(' <script type="text/javascript">' . "\n{$javascriptText}\n" . '</script>' . "\n"); } $wgOut->addHTML($text); return null; }
/** * Extract "power search" namespace settings from the request object, * returning a list of index numbers to search. * * @param WebRequest $request * @return array */ protected function powerSearch(&$request) { $arr = []; foreach ($this->searchConfig->searchableNamespaces() as $ns => $name) { if ($request->getCheck('ns' . $ns)) { $arr[] = $ns; } } return $arr; }
private static function parseCreateEditQuizRequest(WebRequest $request, $quiz, &$error) { $wgUser = F::app()->getGlobal('wgUser'); $wgLang = F::app()->getGlobal('wgContLang'); // parse quiz fields $quizContent = ''; // title if (!empty($quiz)) { $title = $quiz->getTitle(); } else { $title = trim($request->getVal('title')); } // title screen text $titleScreenText = trim($request->getVal('titlescreentext')); if ($titleScreenText) { $quizContent .= WikiaQuiz::TITLESCREENTEXT_MARKER . $titleScreenText . "\n"; } // facebook recommendation description $fbRecommendationText = trim($request->getVal('fbrecommendationtext')); if ($fbRecommendationText) { $quizContent .= WikiaQuiz::FBRECOMMENDATIONTEXT_MARKER . $fbRecommendationText . "\n"; } // title screen images $titleScreenImages = $request->getArray('titlescreenimage'); foreach ($titleScreenImages as $image) { if ($image) { if (!self::isValidImage($image)) { $error = wfMsg('wikiaquiz-error-invalid-image', $image); return; } $quizContent .= WikiaQuiz::IMAGE_MARKER . $image . "\n"; } } // More Info heading $moreInfoHeading = trim($request->getVal('moreinfoheading')); if ($moreInfoHeading) { $quizContent .= WikiaQuiz::MOREINFOHEADING_MARKER . $moreInfoHeading . "\n"; } // Are emails required? if ($request->getCheck('requireemail')) { $quizContent .= WikiaQuiz::REQUIRE_EMAIL_MARKER . "true\n"; } // More Info links $moreInfoArticles = $request->getArray('moreinfoarticle'); $moreInfoLinkTexts = $request->getArray('moreinfolinktext'); foreach ($moreInfoArticles as $index => $articleName) { if ($articleName) { $moreInfoLinkText = isset($moreInfoLinkTexts[$index]) ? $moreInfoLinkTexts[$index] : ''; if (Http::isValidURI($articleName)) { $quizContent .= WikiaQuiz::MOREINFOLINK_MARKER . $articleName . WikiaQuiz::MOREINFOLINK_TEXT_MARKER . $moreInfoLinkText . "\n"; } else { $title_object = F::build('Title', array($articleName), 'newFromText'); if (is_object($title_object) && $title_object->exists()) { $quizContent .= WikiaQuiz::MOREINFOLINK_MARKER . $articleName . WikiaQuiz::MOREINFOLINK_TEXT_MARKER . $moreInfoLinkText . "\n"; } else { $error = wfMsg('wikiaquiz-error-invalid-article-with-details', $articleName); return; } } } } $patternCategory = "/\\[\\[" . $wgLang->getNsText(NS_CATEGORY) . "\\:" . WikiaQuiz::QUIZ_CATEGORY_PREFIX . $title . "(\\|(.+))*\\]\\]/"; //process questions (quizelements) $questions = $request->getArray('question'); foreach ($questions as $index => $question) { $question = trim($question); if (!$question) { continue; } $title_object = F::build('Title', array($question, NS_WIKIA_QUIZARTICLE), 'newFromText'); if (is_object($title_object) && $title_object->exists()) { // update category tag $article = F::build('Article', array($title_object)); $content = $article->getContent(); $newContent = null; $matches = null; preg_match($patternCategory, $content, $matches); if (isset($matches[2])) { if ($matches[2] != $index) { $replace = "[[" . $wgLang->getNsText(NS_CATEGORY) . ":" . WikiaQuiz::QUIZ_CATEGORY_PREFIX . $title . "|" . $index . "]]"; $newContent = preg_replace($patternCategory, $replace, $content); } } else { // this category is new for this article. append to contents. $newContent .= self::getCategoryText($title, $index); } if ($newContent) { $status = $article->doEdit($newContent, 'Quiz Question and Answers Updated', EDIT_UPDATE, false, $wgUser); } } else { if ($title_object == null) { $error = wfMsg('wikiaquiz-error-invalid-question'); return; } else { // create question $content = self::getCategoryText($title, $index); $article = F::build('Article', array($title_object)); $status = $article->doEdit($content, 'Quiz Article Created', EDIT_NEW, false, $wgUser); //@todo check status } } } if (!empty($quiz)) { // remove old questions from quiz $questionKeys = array_flip($questions); $elements = $quiz->getElements(); if (is_array($elements)) { foreach ($elements as $element) { $question = trim($element['title']); if ($question) { if (!array_key_exists($question, $questionKeys)) { $title_object = F::build('Title', array($question, NS_WIKIA_QUIZARTICLE), 'newFromText'); $article = F::build('Article', array($title_object)); $content = $article->getContent(); $content = preg_replace($patternCategory, '', $content); $status = $article->doEdit($content, 'Quiz Question and Answers Updated', EDIT_UPDATE, false, $wgUser); } } } } } return $quizContent; }
/** * Generates form elements for a (web)requested format. * * Required by getFormatSelectBox() to recieve form elements from the * Web. UIs may need to overload processFormatOptions(), * processFormatSelectBox() and getFormatSelectBox() to change behavior. * * @param WebRequest $wgRequest * @return boolean true if format options were requested and returned, else false */ protected function processFormatOptions($wgRequest) { global $wgOut; if ($wgRequest->getCheck('showformatoptions')) { // handle Ajax action $format = $wgRequest->getVal('showformatoptions'); $params = $wgRequest->getArray('params'); $wgOut->disable(); echo $this->showFormatOptions($format, $params); return true; } else { return false; } }
/** * @param WebRequest $request * @param TranslatablePage $page */ protected function handlePriorityLanguages(WebRequest $request, TranslatablePage $page) { // new priority languages $npLangs = rtrim(trim($request->getVal('prioritylangs')), ','); $npForce = $request->getCheck('forcelimit') ? 'on' : 'off'; $npReason = trim($request->getText('priorityreason')); // Normalize $npLangs = array_map('trim', explode(',', $npLangs)); $npLangs = array_unique($npLangs); // Remove invalid language codes. $languages = Language::fetchLanguageNames(); foreach ($npLangs as $index => $language) { if (!array_key_exists($language, $languages)) { unset($npLangs[$index]); } } $npLangs = implode(',', $npLangs); if ($npLangs === '') { $npLangs = false; $npForce = false; $npReason = false; } $groupId = $page->getMessageGroupId(); // old priority languages $opLangs = TranslateMetadata::get($groupId, 'prioritylangs'); $opForce = TranslateMetadata::get($groupId, 'priorityforce'); $opReason = TranslateMetadata::get($groupId, 'priorityreason'); TranslateMetadata::set($groupId, 'prioritylangs', $npLangs); TranslateMetadata::set($groupId, 'priorityforce', $npForce); TranslateMetadata::set($groupId, 'priorityreason', $npReason); if ($opLangs !== $npLangs || $opForce !== $npForce || $opReason !== $npReason) { $params = array('languages' => $npLangs, 'force' => $npForce, 'reason' => $npReason); $entry = new ManualLogEntry('pagetranslation', 'prioritylanguages'); $entry->setPerformer($this->getUser()); $entry->setTarget($page->getTitle()); $entry->setParameters($params); $entry->setComment($npReason); $logid = $entry->insert(); $entry->publish($logid); } }