當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DerivativeContext::setRequest方法代碼示例

本文整理匯總了PHP中DerivativeContext::setRequest方法的典型用法代碼示例。如果您正苦於以下問題:PHP DerivativeContext::setRequest方法的具體用法?PHP DerivativeContext::setRequest怎麽用?PHP DerivativeContext::setRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DerivativeContext的用法示例。


在下文中一共展示了DerivativeContext::setRequest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * Format the rows (generated by SpecialRecentchanges or SpecialRecentchangeslinked)
  * as an RSS/Atom feed.
  */
 public function execute()
 {
     $config = $this->getConfig();
     $this->params = $this->extractRequestParams();
     if (!$config->get('Feed')) {
         $this->dieUsage('Syndication feeds are not available', 'feed-unavailable');
     }
     $feedClasses = $config->get('FeedClasses');
     if (!isset($feedClasses[$this->params['feedformat']])) {
         $this->dieUsage('Invalid subscription feed type', 'feed-invalid');
     }
     $this->getMain()->setCacheMode('public');
     if (!$this->getMain()->getParameter('smaxage')) {
         // bug 63249: This page gets hit a lot, cache at least 15 seconds.
         $this->getMain()->setCacheMaxAge(15);
     }
     $feedFormat = $this->params['feedformat'];
     $specialClass = $this->params['target'] !== null ? 'SpecialRecentchangeslinked' : 'SpecialRecentchanges';
     $formatter = $this->getFeedObject($feedFormat, $specialClass);
     // Parameters are passed via the request in the context… :(
     $context = new DerivativeContext($this);
     $context->setRequest(new DerivativeRequest($this->getRequest(), $this->params, $this->getRequest()->wasPosted()));
     // The row-getting functionality should be factored out of ChangesListSpecialPage too…
     $rc = new $specialClass();
     $rc->setContext($context);
     $rows = $rc->getRows();
     $feedItems = $rows ? ChangesFeed::buildItems($rows) : array();
     ApiFormatFeedWrapper::setResult($this->getResult(), $formatter, $feedItems);
 }
開發者ID:mb720,項目名稱:mediawiki,代碼行數:33,代碼來源:ApiFeedRecentChanges.php

示例2: getManager

 private static function getManager($continue, $allModules, $generatedModules)
 {
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest(new FauxRequest(array('continue' => $continue)));
     $main = new ApiMain($context);
     return new ApiContinuationManager($main, $allModules, $generatedModules);
 }
開發者ID:Acidburn0zzz,項目名稱:mediawiki,代碼行數:7,代碼來源:ApiContinuationManagerTest.php

示例3: testForm

 /**
  * @dataProvider provideValidate
  */
 public function testForm($text, $value)
 {
     $form = HTMLForm::factory('ooui', ['restrictions' => ['class' => HTMLRestrictionsField::class]]);
     $request = new FauxRequest(['wprestrictions' => $text], true);
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest($request);
     $form->setContext($context);
     $form->setTitle(Title::newFromText('Main Page'))->setSubmitCallback(function () {
         return true;
     })->prepareForm();
     $status = $form->trySubmit();
     if ($status instanceof StatusValue) {
         $this->assertEquals($value !== false, $status->isGood());
     } elseif ($value === false) {
         $this->assertNotSame(true, $status);
     } else {
         $this->assertSame(true, $status);
     }
     if ($value !== false) {
         $restrictions = $form->mFieldData['restrictions'];
         $this->assertInstanceOf(MWRestrictions::class, $restrictions);
         $this->assertEquals($value, $restrictions->toArray()['IPAddresses']);
     }
     // sanity
     $form->getHTML($status);
 }
開發者ID:paladox,項目名稱:mediawiki,代碼行數:29,代碼來源:HTMLRestrictionsFieldTest.php

示例4: getContext

 private function getContext($requestedAction = null)
 {
     $request = new FauxRequest(array('action' => $requestedAction));
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest($request);
     $context->setWikiPage($this->getPage());
     return $context;
 }
開發者ID:Habatchii,項目名稱:wikibase-for-mediawiki,代碼行數:8,代碼來源:ActionTest.php

示例5: newTestContext

 /**
  * Returns a DerivativeContext with the request variables in place
  *
  * @param $request WebRequest request object including parameters and session
  * @param $user User or null
  * @return DerivativeContext
  */
 public function newTestContext(WebRequest $request, User $user = null)
 {
     $context = new DerivativeContext($this);
     $context->setRequest($request);
     if ($user !== null) {
         $context->setUser($user);
     }
     return $context;
 }
開發者ID:biribogos,項目名稱:wikihow-src,代碼行數:16,代碼來源:ApiTestContext.php

示例6: makeContext

 /**
  * @param string $url
  * @param array $cookies
  * @return MobileContext
  */
 private function makeContext($url = '/', $cookies = array())
 {
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest(new MFFauxRequest($url, $cookies));
     $context->setOutput(new OutputPage($context));
     $instance = unserialize('O:13:"MobileContext":0:{}');
     $instance->setContext($context);
     return $instance;
 }
開發者ID:negati-ve,項目名稱:openshift-mediawiki,代碼行數:14,代碼來源:MobileContextTest.php

示例7: newContext

 /**
  * @param WebRequest|null $request
  * @param Language|string|null $language
  * @param User|null $user
  *
  * @return DerivativeContext
  */
 private function newContext(WebRequest $request = null, $language = null, User $user = null)
 {
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest($request ?: new FauxRequest());
     if ($language !== null) {
         $context->setLanguage($language);
     }
     if ($user !== null) {
         $context->setUser($user);
     }
     $this->setEditTokenFromUser($context);
     return $context;
 }
開發者ID:claudinec,項目名稱:galan-wiki,代碼行數:20,代碼來源:SpecialPageExecutor.php

示例8: makeContext

 /**
  * @param string $url
  * @param array $cookies
  * @return MobileContext
  */
 private function makeContext($url = '/', $cookies = array())
 {
     $query = array();
     if ($url) {
         $params = wfParseUrl(wfExpandUrl($url));
         if (isset($params['query'])) {
             $query = wfCgiToArray($params['query']);
         }
     }
     $request = new FauxRequest($query);
     $request->setRequestURL($url);
     $request->setCookies($cookies, '');
     $context = new DerivativeContext(RequestContext::getMain());
     $context->setRequest($request);
     $context->setOutput(new OutputPage($context));
     $instance = unserialize('O:13:"MobileContext":0:{}');
     $instance->setContext($context);
     return $instance;
 }
開發者ID:paladox,項目名稱:mediawiki-extensions-MobileFrontend,代碼行數:24,代碼來源:MobileContextTest.php

示例9: testGetParameterFromSettings

 /**
  * @dataProvider provideGetParameterFromSettings
  * @param string|null $input
  * @param array $paramSettings
  * @param mixed $expected
  * @param string[] $warnings
  */
 public function testGetParameterFromSettings($input, $paramSettings, $expected, $warnings)
 {
     $mock = new MockApi();
     $wrapper = TestingAccessWrapper::newFromObject($mock);
     $context = new DerivativeContext($mock);
     $context->setRequest(new FauxRequest($input !== null ? ['foo' => $input] : []));
     $wrapper->mMainModule = new ApiMain($context);
     if ($expected instanceof UsageException) {
         try {
             $wrapper->getParameterFromSettings('foo', $paramSettings, true);
         } catch (UsageException $ex) {
             $this->assertEquals($expected, $ex);
         }
     } else {
         $result = $wrapper->getParameterFromSettings('foo', $paramSettings, true);
         $this->assertSame($expected, $result);
         $this->assertSame($warnings, $mock->warnings);
     }
 }
開發者ID:paladox,項目名稱:mediawiki,代碼行數:26,代碼來源:ApiBaseTest.php

示例10: getContextSetup

 /**
  * Creates a new set of object for the actual test context, including a new
  * outputpage and skintemplate.
  *
  * @param string $mode The mode for the test cases (desktop, mobile)
  * @return array Array of objects, including MobileContext (context),
  * SkinTemplate (sk) and OutputPage (out)
  */
 protected function getContextSetup($mode, $mfXAnalyticsItems)
 {
     // Create a new MobileContext object for this test
     MobileContext::setInstance(null);
     // create a new instance of MobileContext
     $context = MobileContext::singleton();
     // create a DerivativeContext to use in MobileContext later
     $mainContext = new DerivativeContext(RequestContext::getMain());
     // create a new, empty OutputPage
     $out = new OutputPage($context);
     // create a new, empty SkinTemplate
     $sk = new SkinTemplate();
     // create a new Title (main page)
     $title = Title::newMainPage();
     // create a FauxRequest to use instead of a WebRequest object (FauxRequest forces
     // the creation of a FauxResponse, which allows to investigate sent header values)
     $request = new FauxRequest();
     // set the new request object to the context
     $mainContext->setRequest($request);
     // set the main page title to the context
     $mainContext->setTitle($title);
     // set the context to the SkinTemplate
     $sk->setContext($mainContext);
     // set the OutputPage to the context
     $mainContext->setOutput($out);
     // set the DerivativeContext as a base to MobileContext
     $context->setContext($mainContext);
     // set the mode to MobileContext
     $context->setUseFormat($mode);
     // if there are any XAnalytics items, add them
     foreach ($mfXAnalyticsItems as $key => $val) {
         $context->addAnalyticsLogItem($key, $val);
     }
     // set the newly created MobileContext object as the current instance to use
     MobileContext::setInstance($context);
     // return the stuff
     return array('out' => $out, 'sk' => $sk, 'context' => $context);
 }
開發者ID:micha6554,項目名稱:mediawiki-extensions-MobileFrontend,代碼行數:46,代碼來源:MobileFrontend.hooksTest.php

示例11: getAuthForm

 /**
  * @param AuthenticationRequest[] $requests
  * @param string $action AuthManager action name (one of the AuthManager::ACTION_* constants)
  * @return HTMLForm
  */
 protected function getAuthForm(array $requests, $action)
 {
     $formDescriptor = $this->getAuthFormDescriptor($requests, $action);
     $context = $this->getContext();
     if ($context->getRequest() !== $this->getRequest()) {
         // We have overridden the request, need to make sure the form uses that too.
         $context = new DerivativeContext($this->getContext());
         $context->setRequest($this->getRequest());
     }
     $form = HTMLForm::factory('ooui', $formDescriptor, $context);
     $form->setAction($this->getFullTitle()->getFullURL($this->getPreservedParams()));
     $form->addHiddenField($this->getTokenName(), $this->getToken()->toString());
     $form->addHiddenField('authAction', $this->authAction);
     $form->suppressDefaultSubmit(!$this->needsSubmitButton($formDescriptor));
     return $form;
 }
開發者ID:claudinec,項目名稱:galan-wiki,代碼行數:21,代碼來源:AuthManagerSpecialPage.php

示例12: getAuthForm

 /**
  * Generates a form from the given request.
  * @param AuthenticationRequest[] $requests
  * @param string $action AuthManager action name
  * @param string|Message $msg
  * @param string $msgType
  * @return HTMLForm
  */
 protected function getAuthForm(array $requests, $action, $msg = '', $msgType = 'error')
 {
     global $wgSecureLogin, $wgLoginLanguageSelector;
     // FIXME merge this with parent
     if (isset($this->authForm)) {
         return $this->authForm;
     }
     $usingHTTPS = $this->getRequest()->getProtocol() === 'https';
     // get basic form description from the auth logic
     $fieldInfo = AuthenticationRequest::mergeFieldInfo($requests);
     $fakeTemplate = $this->getFakeTemplate($msg, $msgType);
     $this->fakeTemplate = $fakeTemplate;
     // FIXME there should be a saner way to pass this to the hook
     // this will call onAuthChangeFormFields()
     $formDescriptor = static::fieldInfoToFormDescriptor($requests, $fieldInfo, $this->authAction);
     $this->postProcessFormDescriptor($formDescriptor, $requests);
     $context = $this->getContext();
     if ($context->getRequest() !== $this->getRequest()) {
         // We have overridden the request, need to make sure the form uses that too.
         $context = new DerivativeContext($this->getContext());
         $context->setRequest($this->getRequest());
     }
     $form = HTMLForm::factory('vform', $formDescriptor, $context);
     $form->addHiddenField('authAction', $this->authAction);
     if ($wgLoginLanguageSelector) {
         $form->addHiddenField('uselang', $this->mLanguage);
     }
     $form->addHiddenField('force', $this->securityLevel);
     $form->addHiddenField($this->getTokenName(), $this->getToken()->toString());
     if ($wgSecureLogin) {
         // If using HTTPS coming from HTTP, then the 'fromhttp' parameter must be preserved
         if (!$this->isSignup()) {
             $form->addHiddenField('wpForceHttps', (int) $this->mStickHTTPS);
             $form->addHiddenField('wpFromhttp', $usingHTTPS);
         }
     }
     // set properties of the form itself
     $form->setAction($this->getPageTitle()->getLocalURL($this->getReturnToQueryStringFragment()));
     $form->setName('userlogin' . ($this->isSignup() ? '2' : ''));
     if ($this->isSignup()) {
         $form->setId('userlogin2');
     }
     $form->suppressDefaultSubmit();
     $this->authForm = $form;
     return $form;
 }
開發者ID:paladox,項目名稱:mediawiki,代碼行數:54,代碼來源:LoginSignupSpecialPage.php

示例13: postMemberList

 /**
  * @param $title Title
  * @param $summary string
  * @param $context IContextSource
  * @todo rework this to use a generic CollaborationList editor function once it exists
  */
 public static function postMemberList(Title $title, $summary, IContextSource $context)
 {
     $username = $context->getUser()->getName();
     $collabList = self::makeMemberList($username, $context->msg('collaborationkit-hub-members-description'));
     // Ensure that a valid context is provided to the API in unit tests
     $der = new DerivativeContext($context);
     $request = new DerivativeRequest($context->getRequest(), ['action' => 'edit', 'title' => $title->getFullText(), 'contentmodel' => 'CollaborationListContent', 'contentformat' => 'application/json', 'text' => $collabList->serialize(), 'summary' => $summary, 'token' => $context->getUser()->getEditToken()], true);
     $der->setRequest($request);
     try {
         $api = new ApiMain($der, true);
         $api->execute();
     } catch (UsageException $e) {
         return Status::newFatal($context->msg('collaborationkit-hub-edit-apierror', $e->getCodeString()));
     }
     return Status::newGood();
 }
開發者ID:wikimedia,項目名稱:mediawiki-extensions-CollaborationKit,代碼行數:22,代碼來源:CollaborationListContentHandler.php

示例14: execute

 /**
  * Executes the log-in attempt using the parameters passed. If
  * the log-in succeeds, it attaches a cookie to the session
  * and outputs the user id, username, and session token. If a
  * log-in fails, as the result of a bad password, a nonexistent
  * user, or any other reason, the host is cached with an expiry
  * and no log-in attempts will be accepted until that expiry
  * is reached. The expiry is $this->mLoginThrottle.
  */
 public function execute()
 {
     // If we're in a mode that breaks the same-origin policy, no tokens can
     // be obtained
     if ($this->lacksSameOriginSecurity()) {
         $this->getResult()->addValue(null, 'login', array('result' => 'Aborted', 'reason' => 'Cannot log in when the same-origin policy is not applied'));
         return;
     }
     $params = $this->extractRequestParams();
     $result = array();
     // Init session if necessary
     if (session_id() == '') {
         wfSetupSession();
     }
     $context = new DerivativeContext($this->getContext());
     $context->setRequest(new DerivativeRequest($this->getContext()->getRequest(), array('wpName' => $params['name'], 'wpPassword' => $params['password'], 'wpDomain' => $params['domain'], 'wpLoginToken' => $params['token'], 'wpRemember' => '')));
     $loginForm = new LoginForm();
     $loginForm->setContext($context);
     $authRes = $loginForm->authenticateUserData();
     switch ($authRes) {
         case LoginForm::SUCCESS:
             $user = $context->getUser();
             $this->getContext()->setUser($user);
             $user->setCookies($this->getRequest(), null, true);
             ApiQueryInfo::resetTokenCache();
             // Run hooks.
             // @todo FIXME: Split back and frontend from this hook.
             // @todo FIXME: This hook should be placed in the backend
             $injected_html = '';
             Hooks::run('UserLoginComplete', array(&$user, &$injected_html));
             $result['result'] = 'Success';
             $result['lguserid'] = intval($user->getId());
             $result['lgusername'] = $user->getName();
             $result['lgtoken'] = $user->getToken();
             $result['cookieprefix'] = $this->getConfig()->get('CookiePrefix');
             $result['sessionid'] = session_id();
             break;
         case LoginForm::NEED_TOKEN:
             $result['result'] = 'NeedToken';
             $result['token'] = $loginForm->getLoginToken();
             $result['cookieprefix'] = $this->getConfig()->get('CookiePrefix');
             $result['sessionid'] = session_id();
             break;
         case LoginForm::WRONG_TOKEN:
             $result['result'] = 'WrongToken';
             break;
         case LoginForm::NO_NAME:
             $result['result'] = 'NoName';
             break;
         case LoginForm::ILLEGAL:
             $result['result'] = 'Illegal';
             break;
         case LoginForm::WRONG_PLUGIN_PASS:
             $result['result'] = 'WrongPluginPass';
             break;
         case LoginForm::NOT_EXISTS:
             $result['result'] = 'NotExists';
             break;
             // bug 20223 - Treat a temporary password as wrong. Per SpecialUserLogin:
             // The e-mailed temporary password should not be used for actual logins.
         // bug 20223 - Treat a temporary password as wrong. Per SpecialUserLogin:
         // The e-mailed temporary password should not be used for actual logins.
         case LoginForm::RESET_PASS:
         case LoginForm::WRONG_PASS:
             $result['result'] = 'WrongPass';
             break;
         case LoginForm::EMPTY_PASS:
             $result['result'] = 'EmptyPass';
             break;
         case LoginForm::CREATE_BLOCKED:
             $result['result'] = 'CreateBlocked';
             $result['details'] = 'Your IP address is blocked from account creation';
             $block = $context->getUser()->getBlock();
             if ($block) {
                 $result = array_merge($result, ApiQueryUserInfo::getBlockInfo($block));
             }
             break;
         case LoginForm::THROTTLED:
             $result['result'] = 'Throttled';
             $throttle = $this->getConfig()->get('PasswordAttemptThrottle');
             $result['wait'] = intval($throttle['seconds']);
             break;
         case LoginForm::USER_BLOCKED:
             $result['result'] = 'Blocked';
             $block = User::newFromName($params['name'])->getBlock();
             if ($block) {
                 $result = array_merge($result, ApiQueryUserInfo::getBlockInfo($block));
             }
             break;
         case LoginForm::ABORTED:
             $result['result'] = 'Aborted';
//.........這裏部分代碼省略.........
開發者ID:MediaWiki-stable,項目名稱:1.26.1,代碼行數:101,代碼來源:ApiLogin.php

示例15: wfDeprecated

 function __construct(Page $page, $request = false)
 {
     wfDeprecated(__CLASS__, '1.19');
     parent::__construct($page);
     if ($request !== false) {
         $context = new DerivativeContext($this->getContext());
         $context->setRequest($request);
         $this->context = $context;
     }
 }
開發者ID:nischayn22,項目名稱:mediawiki-core,代碼行數:10,代碼來源:RawAction.php


注:本文中的DerivativeContext::setRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。