/** * Finds search suggestions phrases for chosen query * * @requestParam string $query search term for suggestions * * @responseParam array $items The list of phrases matching the query * * @example &query=los */ public function getList() { wfProfileIn(__METHOD__); if (!empty($this->wg->EnableLinkSuggestExt)) { $query = trim($this->request->getVal(self::PARAMETER_QUERY, null)); if (empty($query)) { throw new MissingParameterApiException(self::PARAMETER_QUERY); } $request = new WebRequest(); $request->setVal('format', 'array'); $linkSuggestions = LinkSuggest::getLinkSuggest($request); if (!empty($linkSuggestions)) { foreach ($linkSuggestions as $suggestion) { $searchSuggestions[]['title'] = $suggestion; } $this->response->setVal('items', $searchSuggestions); } else { throw new NotFoundApiException(); } $this->response->setCacheValidity(WikiaResponse::CACHE_STANDARD); } else { throw new NotFoundApiException('Link Suggest extension not available'); } wfProfileOut(__METHOD__); }
/** * Initialize instance variables from request and create an Upload handler * * What was changed here: $this->mIgnoreWarning is now unconditionally true * and we use our own handler for $this->mUpload instead of UploadBase * * @param WebRequest $request The request to extract variables from */ protected function loadRequest($request) { global $wgUser; $this->mRequest = $request; $this->mSourceType = $request->getVal('wpSourceType', 'file'); $this->mUpload = FanBoxUpload::createFromRequest($request); $this->mUploadClicked = $request->wasPosted() && ($request->getCheck('wpUpload') || $request->getCheck('wpUploadIgnoreWarning')); // Guess the desired name from the filename if not provided $this->mDesiredDestName = $request->getText('wpDestFile'); if (!$this->mDesiredDestName && $request->getFileName('wpUploadFile') !== null) { $this->mDesiredDestName = $request->getFileName('wpUploadFile'); } $this->mComment = $request->getText('wpUploadDescription'); $this->mLicense = $request->getText('wpLicense'); $this->mDestWarningAck = $request->getText('wpDestFileWarningAck'); $this->mIgnoreWarning = true; //$request->getCheck( 'wpIgnoreWarning' ) || $request->getCheck( 'wpUploadIgnoreWarning' ); $this->mWatchthis = $request->getBool('wpWatchthis') && $wgUser->isLoggedIn(); $this->mCopyrightStatus = $request->getText('wpUploadCopyStatus'); $this->mCopyrightSource = $request->getText('wpUploadSource'); $this->mForReUpload = $request->getBool('wpForReUpload'); // updating a file $this->mCancelUpload = $request->getCheck('wpCancelUpload') || $request->getCheck('wpReUpload'); // b/w compat // If it was posted check for the token (no remote POST'ing with user credentials) $token = $request->getVal('wpEditToken'); if ($this->mSourceType == 'file' && $token == null) { // Skip token check for file uploads as that can't be faked via JS... // Some client-side tools don't expect to need to send wpEditToken // with their submissions, as that's new in 1.16. $this->mTokenOk = true; } else { $this->mTokenOk = $wgUser->matchEditToken($token); } }
public function send($message, $list) { $webRequest = new WebRequest(); $params = array("profileId" => $this->profileId, "user" => $this->user, "pwd" => $this->pwd, "senderId" => $this->senderId, "mobileno" => implode(",", $list), "msgtext" => "this is a test message"); $result = $webRequest->get("http://bulksmsindia.mobi/sendurlcomma.aspx?", $params); return $result; }
/** * Concatenate categories on EditPage POST * * @param EditPage $editPage * @param WebRequest $request * * @return Boolean because it's a hook */ public static function onEditPageImportFormData($editPage, $request) { $app = F::app(); if ($request->wasPosted()) { $categories = $editPage->safeUnicodeInput($request, 'categories'); $categories = CategoryHelper::changeFormat($categories, 'json', 'array'); // Concatenate categories to article wikitext (if there are any). if (!empty($categories)) { if (!empty($app->wg->EnableAnswers)) { // don't add categories if the page is a redirect $magicWords = $app->wg->ContLang->getMagicWords(); $redirects = $magicWords['redirect']; // first element doesn't interest us array_shift($redirects); // check for localized versions of #REDIRECT foreach ($redirects as $alias) { if (stripos($editPage->textbox1, $alias) === 0) { return true; } } } // Extract categories from the article, merge them with those passed in, weed out // duplicates and finally append them back to the article (BugId:99348). $data = CategoryHelper::extractCategoriesFromWikitext($editPage->textbox1, true); $categories = CategoryHelper::getUniqueCategories($data['categories'], $categories); $categories = CategoryHelper::changeFormat($categories, 'array', 'wikitext'); // Remove trailing whitespace (BugId:11238) $editPage->textbox1 = $data['wikitext'] . rtrim($categories); } } return true; }
/** * @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); }
public static function onAfterInitialize($title, $article, $output, $user, WebRequest $request, $wiki) { global $wgPaidAssetDropConfig; if ($request->getBool(static::PAD_FORCE_PARAMETER, false)) { $wgPaidAssetDropConfig = true; } return true; }
/** * @dataProvider pageIsTrackableProvider * @param $ns int namespace * @param $action string action=... value * @param $exists bool does the page exist? * @param $expectedResult bool expected result */ public function testPageIsTrackable($ns, $action, $exists, $expectedResult) { $title = $this->mockClassWithMethods('Title', ['getNamespace' => $ns, 'exists' => $exists]); $request = new WebRequest(); $request->setVal('action', $action); $this->mockGlobalVariable('wgRequest', $request); $this->assertEquals($expectedResult, LyricFindHooks::pageIsTrackable($title)); }
/** * @param WebRequest $request */ function initializeFromRequest(&$request) { $upload = $request->getUpload('wpUploadFile'); $desiredDestName = $request->getText('wpDestFile'); if (!$desiredDestName) { $desiredDestName = $upload->getName(); } $this->initialize($desiredDestName, $upload); }
/** * Constructs a page from WebRequest. * This interface is a big klunky. * @param $request WebRequest * @return TranslationEditPage */ public static function newFromRequest(WebRequest $request) { $title = Title::newFromText($request->getText('page')); if (!$title) { return null; } $obj = new self($title); $obj->suggestions = $request->getText('suggestions'); return $obj; }
/** * Try and get an email for the user from Facebook. If Facebook has an email for the user * we don't have to confirm it, Facebook has done that for us. If Facebook doesn't have one, * try and pull one from the form and make note that we'll have to confirm the user. * @param WebRequest $request * @return String */ private function getUserEmail(WebRequest $request) { $userInfo = FacebookClient::getInstance()->getUserInfo(); $userEmail = $userInfo->getProperty('email'); if (empty($userEmail)) { // Email didn't come from facebook, we have to confirm it ourselves $this->hasConfirmedEmail = false; $userEmail = $request->getVal('email', ''); } return $userEmail; }
/** * Handle URL parameters and set proper global variables early enough * * @author Sergey Naumov */ public static function onAfterInitialize($title, $article, $output, $user, WebRequest $request, $wiki) { global $wgAdDriverUseSevenOneMedia, $wgNoExternals, $wgUsePostScribe; // TODO: we shouldn't have it in AdEngine - ticket for Platform: PLATFORM-1296 $wgNoExternals = $request->getBool('noexternals', $wgNoExternals); // use PostScribe with 71Media - check scriptwriter.js:35 if ($wgAdDriverUseSevenOneMedia) { $wgUsePostScribe = true; } return true; }
public function upload() { $cfile = new CURLFile('useruploaddata.xls', 'application/vnd.ms-excel', 'useruploaddata.xls'); $webRequest = new WebRequest(); $params = array("action" => 'login', "username" => "admin", "password" => "admin"); $result = $webRequest->post("http://localhost/rozgarmela/admin/", $params); //echo "tried to login, result is " . $result . "\n"; $params = array("user_group_id" => 'JobSeeker', "import_file" => $cfile, "file_type" => 'xls', "csv_delimiter" => 'semicolon', "encodingFromCharset" => 'UTF-8', "action" => 'Import'); $result = $webRequest->post("http://localhost/rozgarmela/admin/import-users/", $params); echo "sent data, result is " . $result . "\n"; return $result; }
/** * @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(); } }
public function __construct(WebRequest $request) { $this->mType = $request->getText('type'); $this->mOid = preg_replace('/\\?.*$/', '', $request->getText('oid')); parse_str(urldecode($request->getText('params')), $this->mParams); $this->mCb = $request->getInt('cb'); if (!empty($this->mParams['noexternals'])) { $this->mNoExternals = true; } if (!empty($this->mParams['forceprofile'])) { $this->mForceProfile = true; } }
/** * @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; } }
/** * @param $resourceLoader ResourceLoader * @param $request WebRequest */ public function __construct($resourceLoader, WebRequest $request) { global $wgDefaultSkin, $wgResourceLoaderDebug; $this->resourceLoader = $resourceLoader; $this->request = $request; // Interpret request // List of modules $modules = $request->getVal('modules'); $this->modules = $modules ? self::expandModuleNames($modules) : array(); // Various parameters $this->skin = $request->getVal('skin'); $this->user = $request->getVal('user'); $this->debug = $request->getFuzzyBool('debug', $wgResourceLoaderDebug); $this->only = $request->getVal('only'); $this->version = $request->getVal('version'); // Wikia - change begin - @author: wladek $this->sassParams = array(); foreach ($request->getValues() as $key => $value) { if (startsWith($key, 'sass_')) { $this->sassParams[substr($key, strlen('sass_'))] = $value; } } ksort($this->sassParams); // Wikia - change end $skinnames = Skin::getSkinNames(); // If no skin is specified, or we don't recognize the skin, use the default skin if (!$this->skin || !isset($skinnames[$this->skin])) { $this->skin = $wgDefaultSkin; } }
public function __construct(WebRequest $request) { parent::__construct($request); $files = explode(',', $this->mOid); foreach ($files as $file) { // fake single SASS file request $sassRequest = new WebRequest(); $sassRequest->setVal('type', 'sass'); $sassRequest->setVal('oid', $file); $builder = new AssetsManagerSassBuilder($sassRequest); $this->mContent .= "\n\n/* {$file} */\n" . $builder->getContent(); } $this->mContentType = AssetsManager::TYPE_CSS; }
/** * @param WebRequest $request * * @return string */ function loadDataFromRequest($request) { $size = $request->getInt($this->mName); if (!$size) { return $this->getDefault(); } $size = abs($size); // negative numbers represent "max", positive numbers represent "min" if ($request->getVal($this->mName . '-mode') === 'max') { return -$size; } else { return $size; } }
public function __construct(WebRequest $request) { parent::__construct($request); $groups = explode(',', $this->mOid); foreach ($groups as $groupName) { // fake request to a group $groupRequest = new WebRequest(); $groupRequest->setVal('type', 'group'); $groupRequest->setVal('oid', $groupName); $builder = new AssetsManagerGroupBuilder($groupRequest); $this->mContent .= "\n\n" . $builder->getContent(); $this->mContentType = $builder->getContentType(); } }
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; }
private function handleLogin() { global $gLogger; $gLogger->log("Handling login"); // variable to set the status of the login // defaults to false. $success = false; $error = ""; $username = WebRequest::post("lgUsername"); $password = WebRequest::post("lgPassword"); $userAccount = InternalUser::getByName($username); if ($userAccount) { if ($userAccount->authenticate($password)) { // log in $gLogger->log("Login: OK"); $success = true; Session::setLoggedInUser($userAccount->getId()); } else { $error = "bad-password"; $gLogger->log("Login:Bad password"); } } else { $error = "bad-username"; $gLogger->log("Login:Bad username"); } if ($success) { global $cWebPath; $this->mHeaders[] = "HTTP/1.1 303 See Other"; $this->mHeaders[] = "Location: " . $cWebPath . "/management.php"; } else { $this->error($error); $this->showLoginForm(); } }
public function provideTestToString() { $mockToStringObj = $this->getMock('stdClass', ['__toString']); $mockToStringObj->expects($this->any())->method('__toString')->will($this->returnValue('{STRING_OBJ_VAL}')); $requestId = 'requestId=' . WebRequest::getRequestId(); return [[$this->getMockJob(false), 'someCommand ' . $requestId], [$this->getMockJob(['key' => 'val']), 'someCommand key=val ' . $requestId], [$this->getMockJob(['key' => ['inkey' => 'inval']]), 'someCommand key={"inkey":"inval"} ' . $requestId], [$this->getMockJob(['val1']), 'someCommand 0=val1 ' . $requestId], [$this->getMockJob(['val1', 'val2']), 'someCommand 0=val1 1=val2 ' . $requestId], [$this->getMockJob([new stdClass()]), 'someCommand 0=object(stdClass) ' . $requestId], [$this->getMockJob([$mockToStringObj]), 'someCommand 0={STRING_OBJ_VAL} ' . $requestId], [$this->getMockJob(["pages" => ["932737" => [0, "Robert_James_Waller"]], "rootJobSignature" => "45868e99bba89064e4483743ebb9b682ef95c1a7", "rootJobTimestamp" => "20160309110158", "masterPos" => ["file" => "db1023-bin.001288", "pos" => "308257743", "asOfTime" => 1457521464.3814], "triggeredRecursive" => true]), 'someCommand pages={"932737":[0,"Robert_James_Waller"]} ' . 'rootJobSignature=45868e99bba89064e4483743ebb9b682ef95c1a7 ' . 'rootJobTimestamp=20160309110158 masterPos=' . '{"file":"db1023-bin.001288","pos":"308257743","asOfTime":1457521464.3814} ' . 'triggeredRecursive=1 ' . $requestId]]; }
public static function getErrorDisplay($arguments) { $smarty = $arguments[1]; $error = WebRequest::get("lgerror") or ""; $smarty->assign("lgerror", $error); return true; }
protected function runPage() { if (WebRequest::get("showall") === "yes") { $phpinfo_parts = INFO_ALL; $linktarget = "?showall=no"; } else { $phpinfo_parts = INFO_VARIABLES; $linktarget = "?showall=yes"; } ob_clean(); phpinfo($phpinfo_parts); $pinfo = ob_get_contents(); ob_clean(); if (WebRequest::get("showall") === "yes") { $pinfo1 = explode("<table", $pinfo, 2); $pinfo = "<table" . $pinfo1[1]; $pinfo1 = explode("<h2>PHP License</h2>", $pinfo); $pinfo = $pinfo1[0]; } else { $pinfo1 = explode("<h2>", $pinfo); $pinfo = "<h2>" . $pinfo1[1]; $pinfo1 = explode("<br />", $pinfo); $pinfo = $pinfo1[0]; } $pinfo = str_replace('class="e"', 'style="background-color: #ccccff; font-weight: bold; color: #000000;border: 1px solid #000000; font-size: 75%; vertical-align: baseline;"', $pinfo); $pinfo = str_replace('class="v"', 'style="background-color: #cccccc; color: #000000;border: 1px solid #000000; font-size: 75%; vertical-align: baseline;"', $pinfo); $pinfo = str_replace('<table ', '<table style="border-collapse: collapse;font-family: sans-serif;" ', $pinfo); $this->mSmarty->assign("content", "<a href=\"{$linktarget}\">Toggle all/variables</a>" . $pinfo); }
/** * Handle a thumbnail request via thumbnail file URL * * @return void */ function wfThumbHandle404() { global $wgArticlePath; # Set action base paths so that WebRequest::getPathInfo() # recognizes the "X" as the 'title' in ../thumb_handler.php/X urls. # Note: If Custom per-extension repo paths are set, this may break. $repo = RepoGroup::singleton()->getLocalRepo(); $oldArticlePath = $wgArticlePath; $wgArticlePath = $repo->getZoneUrl( 'thumb' ) . '/$1'; $matches = WebRequest::getPathInfo(); $wgArticlePath = $oldArticlePath; if ( !isset( $matches['title'] ) ) { wfThumbError( 404, 'Could not determine the name of the requested thumbnail.' ); return; } $params = wfExtractThumbRequestInfo( $matches['title'] ); // basic wiki URL param extracting if ( $params == null ) { wfThumbError( 400, 'The specified thumbnail parameters are not recognized.' ); return; } wfStreamThumb( $params ); // stream the thumbnail }
/** * @dataProvider provideDetectServer */ function testDetectServer($expected, $input, $description) { $oldServer = $_SERVER; $_SERVER = $input; $result = WebRequest::detectServer(); $_SERVER = $oldServer; $this->assertEquals($expected, $result, $description); }
/** * エラーメッセージをセットする * @access public * @param String $message メッセージ * @param string $name HTML_QuickFormの要素名 */ public function setErrMessages($message, $name = null) { if (empty($name)) { $name = $this->errRegKey; $this->errRegKey += 1; } $this->request->setError($name, $message); }
/** * @group Slow * @slowExecutionTime 0.01651 ms * @dataProvider resourceLoaderModifyMaxAgeDataProvider * * @param $timestamp int timestamp in URL * @param $ttl int expected caching period */ public function testResourceLoaderModifyMaxAge($version, $ttl) { global $wgHooks; $resourceLoader = new ResourceLoader(); $resourceLoader->register('WikiaTestModule', array('class' => 'TestResourceLoaderModule')); $request = new WebRequest(); $request->setVal('modules', 'WikiaTestModule'); $request->setVal('version', join('-', $version)); // set up hooks $wgHooks['ResourceLoaderCacheControlHeaders'][] = 'ResourceLoaderTest::onResourceLoaderCacheControlHeaders'; ob_start(); $resourceLoader->respond(new ResourceLoaderContext($resourceLoader, $request)); ob_end_clean(); // hook ResourceLoaderHooks::onResourceLoaderModifyMaxAge was called // check modified caching period with expected one $this->assertEquals($ttl, self::$ttl, 'TTL should match expected value'); }
private function process(WebRequest &$request, OutputPage &$output) { global $wgLinkTitlesTimeLimit; // Start the stopwatch $startTime = microtime(true); // Connect to the database $dbr = wfGetDB(DB_SLAVE); // Fetch the start index and max number of records from the POST // request. $postValues = $request->getValues(); // Convert the start index to an integer; this helps preventing // SQL injection attacks via forged POST requests. $start = intval($postValues['s']); // If an end index was given, we don't need to query the database if (array_key_exists('e', $postValues)) { $end = intval($postValues['e']); } else { // No end index was given. Therefore, count pages now. $end = $this->countPages($dbr); } array_key_exists('r', $postValues) ? $reloads = $postValues['r'] : ($reloads = 0); // Retrieve page names from the database. $res = $dbr->select('page', 'page_title', array('page_namespace = 0'), __METHOD__, array('LIMIT' => 999999999, 'OFFSET' => $start)); // Iterate through the pages; break if a time limit is exceeded. foreach ($res as $row) { $curTitle = $row->page_title; LinkTitles::processPage($curTitle, $this->getContext()); $start += 1; // Check if the time limit is exceeded if (microtime(true) - $startTime > $wgLinkTitlesTimeLimit) { break; } } $this->addProgressInfo($output, $curTitle, $start, $end); // If we have not reached the last page yet, produce code to reload // the extension's special page. if ($start < $end) { $reloads += 1; // Build a form with hidden values and output JavaScript code that // immediately submits the form in order to continue the process. $output->addHTML($this->getReloaderForm($request->getRequestURL(), $start, $end, $reloads)); } else { $this->addCompletedInfo($output, $start, $end, $reloads); } }