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


PHP DerivativeContext類代碼示例

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


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

示例1: 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

示例2: execute

 /**
  * Main execution point
  *
  * @param string $par title fragment
  */
 public function execute($par)
 {
     $this->setHeaders();
     $this->outputHeader();
     $out = $this->getOutput();
     $lang = $this->getLanguage();
     $out->setPageTitle($this->msg('ipblocklist'));
     $out->addModuleStyles('mediawiki.special');
     $request = $this->getRequest();
     $par = $request->getVal('ip', $par);
     $this->target = trim($request->getVal('wpTarget', $par));
     $this->options = $request->getArray('wpOptions', array());
     $action = $request->getText('action');
     if ($action == 'unblock' || $action == 'submit' && $request->wasPosted()) {
         # B/C @since 1.18: Unblock interface is now at Special:Unblock
         $title = SpecialPage::getTitleFor('Unblock', $this->target);
         $out->redirect($title->getFullURL());
         return;
     }
     # Just show the block list
     $fields = array('Target' => array('type' => 'text', 'label-message' => 'ipadressorusername', 'tabindex' => '1', 'size' => '45', 'default' => $this->target), 'Options' => array('type' => 'multiselect', 'options' => array($this->msg('blocklist-userblocks')->text() => 'userblocks', $this->msg('blocklist-tempblocks')->text() => 'tempblocks', $this->msg('blocklist-addressblocks')->text() => 'addressblocks', $this->msg('blocklist-rangeblocks')->text() => 'rangeblocks'), 'flatlist' => true), 'Limit' => array('class' => 'HTMLBlockedUsersItemSelect', 'label-message' => 'table_pager_limit_label', 'options' => array($lang->formatNum(20) => 20, $lang->formatNum(50) => 50, $lang->formatNum(100) => 100, $lang->formatNum(250) => 250, $lang->formatNum(500) => 500), 'name' => 'limit', 'default' => 50));
     $context = new DerivativeContext($this->getContext());
     $context->setTitle($this->getPageTitle());
     // Remove subpage
     $form = new HTMLForm($fields, $context);
     $form->setMethod('get');
     $form->setWrapperLegendMsg('ipblocklist-legend');
     $form->setSubmitTextMsg('ipblocklist-submit');
     $form->prepareForm();
     $form->displayForm('');
     $this->showList();
 }
開發者ID:Tarendai,項目名稱:spring-website,代碼行數:37,代碼來源:SpecialBlockList.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: 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

示例5: 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

示例6: setEditTokenFromUser

 /**
  * If we are trying to edit and no token is set, supply one.
  *
  * @param DerivativeContext $context
  */
 private function setEditTokenFromUser(DerivativeContext $context)
 {
     $request = $context->getRequest();
     // Edits via GET are a security issue and should not succeed. On the other hand, not all
     // POST requests are edits, but should ignore unused parameters.
     if (!$request->getCheck('wpEditToken') && $request->wasPosted()) {
         $request->setVal('wpEditToken', $context->getUser()->getEditToken());
     }
 }
開發者ID:claudinec,項目名稱:galan-wiki,代碼行數:14,代碼來源:SpecialPageExecutor.php

示例7: 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

示例8: 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

示例9: showResetForm

 private function showResetForm()
 {
     if (!$this->getUser()->isAllowed('editmyoptions')) {
         throw new PermissionsError('editmyoptions');
     }
     $this->getOutput()->addWikiMsg('prefs-reset-intro');
     $context = new DerivativeContext($this->getContext());
     $context->setTitle($this->getPageTitle('reset'));
     // Reset subpage
     $htmlForm = new HTMLForm(array(), $context, 'prefs-restore');
     $htmlForm->setSubmitTextMsg('restoreprefs');
     $htmlForm->setSubmitCallback(array($this, 'submitReset'));
     $htmlForm->suppressReset();
     $htmlForm->show();
 }
開發者ID:Tarendai,項目名稱:spring-website,代碼行數:15,代碼來源:SpecialPreferences.php

示例10: getWarningMessageText

 /**
  * Returns warning messages in situations where a revision cannot be viewed by a user
  * explaining to them why.
  * Returns empty string when the revision can be viewed.
  *
  * @return string
  */
 public function getWarningMessageText()
 {
     $msg = '';
     if ($this->isHiddenFromUser()) {
         $allowed = $this->isUserAllowedToSee();
         $suppressed = $this->isSuppressedDiff();
         // This IContextSource object will be used to get a message object for the
         // messages used in this function. We need to to this to allow the message to
         // get the correct value for the FULLPAGENAME inclusion (which is used in
         // rev-suppressed-no-diff, e.g.). Otherwise it would use Special:MobileDiff as
         // the target for Special:Log/delete?page=Special:MobileDiff/..., which isn't
         // correct and very helpful. To fix this bug, we create a new context from the
         // current one and set the title object (which we can get from the new revision).
         // Bug: T122984
         $context = new DerivativeContext($this->getContext());
         $revision = $this->mNewRev;
         $context->setTitle($revision->getTitle());
         if (!$allowed) {
             $msg = $context->msg($suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff')->parse();
         } else {
             # Give explanation and add a link to view the diff...
             $query = $this->getRequest()->appendQueryValue('unhide', '1', true);
             $link = $this->getTitle()->getFullURL($query);
             $msg = $context->msg($suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff', $link)->parse();
         }
     }
     return $msg;
 }
開發者ID:micha6554,項目名稱:mediawiki-extensions-MobileFrontend,代碼行數:35,代碼來源:InlineDifferenceEngine.php

示例11: 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

示例12: 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

示例13: execute

 public function execute()
 {
     $params = $this->extractRequestParams();
     $modules = array();
     foreach ($params['modules'] as $path) {
         $modules[] = $this->getModuleFromPath($path);
     }
     // Get the help
     $context = new DerivativeContext($this->getMain()->getContext());
     $context->setSkin(SkinFactory::getDefaultInstance()->makeSkin('apioutput'));
     $context->setLanguage($this->getMain()->getLanguage());
     $context->setTitle(SpecialPage::getTitleFor('ApiHelp'));
     $out = new OutputPage($context);
     $out->setCopyrightUrl('https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright');
     $context->setOutput($out);
     self::getHelp($context, $modules, $params);
     // Grab the output from the skin
     ob_start();
     $context->getOutput()->output();
     $html = ob_get_clean();
     $result = $this->getResult();
     if ($params['wrap']) {
         $data = array('mime' => 'text/html', 'help' => $html);
         ApiResult::setSubelementsList($data, 'help');
         $result->addValue(null, $this->getModuleName(), $data);
     } else {
         $result->reset();
         $result->addValue(null, 'text', $html, ApiResult::NO_SIZE_CHECK);
         $result->addValue(null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK);
     }
 }
開發者ID:paladox,項目名稱:2,代碼行數:31,代碼來源:ApiHelp.php

示例14: 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

示例15: closePrinter

 /**
  * Finish printing and output buffered data.
  */
 public function closePrinter()
 {
     if ($this->mDisabled) {
         return;
     }
     $mime = $this->getMimeType();
     if ($this->getIsHtml() && $mime !== null) {
         $format = $this->getFormat();
         $lcformat = strtolower($format);
         $result = $this->getBuffer();
         $context = new DerivativeContext($this->getMain());
         $context->setSkin(SkinFactory::getDefaultInstance()->makeSkin('apioutput'));
         $context->setTitle(SpecialPage::getTitleFor('ApiHelp'));
         $out = new OutputPage($context);
         $context->setOutput($out);
         $out->addModuleStyles('mediawiki.apipretty');
         $out->setPageTitle($context->msg('api-format-title'));
         if (!$this->getIsWrappedHtml()) {
             // When the format without suffix 'fm' is defined, there is a non-html version
             if ($this->getMain()->getModuleManager()->isDefined($lcformat, 'format')) {
                 $msg = $context->msg('api-format-prettyprint-header')->params($format, $lcformat);
             } else {
                 $msg = $context->msg('api-format-prettyprint-header-only-html')->params($format);
             }
             $header = $msg->parseAsBlock();
             $out->addHTML(Html::rawElement('div', ['class' => 'api-pretty-header'], ApiHelp::fixHelpLinks($header)));
         }
         if (Hooks::run('ApiFormatHighlight', [$context, $result, $mime, $format])) {
             $out->addHTML(Html::element('pre', ['class' => 'api-pretty-content'], $result));
         }
         if ($this->getIsWrappedHtml()) {
             // This is a special output mode mainly intended for ApiSandbox use
             $time = microtime(true) - $this->getConfig()->get('RequestTime');
             $json = FormatJson::encode(['html' => $out->getHTML(), 'modules' => array_values(array_unique(array_merge($out->getModules(), $out->getModuleScripts(), $out->getModuleStyles()))), 'time' => round($time * 1000)], false, FormatJson::ALL_OK);
             // Bug 66776: wfMangleFlashPolicy() is needed to avoid a nasty bug in
             // Flash, but what it does isn't friendly for the API, so we need to
             // work around it.
             if (preg_match('/\\<\\s*cross-domain-policy\\s*\\>/i', $json)) {
                 $json = preg_replace('/\\<(\\s*cross-domain-policy\\s*)\\>/i', '\\u003C$1\\u003E', $json);
             }
             echo $json;
         } else {
             // API handles its own clickjacking protection.
             // Note, that $wgBreakFrames will still override $wgApiFrameOptions for format mode.
             $out->allowClickjacking();
             $out->output();
         }
     } else {
         // For non-HTML output, clear all errors that might have been
         // displayed if display_errors=On
         ob_clean();
         echo $this->getBuffer();
     }
 }
開發者ID:claudinec,項目名稱:galan-wiki,代碼行數:57,代碼來源:ApiFormatBase.php


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