本文整理汇总了PHP中RequestContext类的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext类的具体用法?PHP RequestContext怎么用?PHP RequestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: encodeData
/**
* Get the formatter output for the given input data
* @param array $params Query parameters
* @param array $data Data to encode
* @param string $class Printer class to use instead of the normal one
* @return string
* @throws Exception
*/
protected function encodeData(array $params, array $data, $class = null)
{
$context = new RequestContext();
$context->setRequest(new FauxRequest($params, true));
$main = new ApiMain($context);
if ($class !== null) {
$main->getModuleManager()->addModule($this->printerName, 'format', $class);
}
$result = $main->getResult();
$result->addArrayType(null, 'default');
foreach ($data as $k => $v) {
$result->addValue(null, $k, $v);
}
$printer = $main->createPrinterByName($this->printerName);
$printer->initPrinter();
$printer->execute();
ob_start();
try {
$printer->closePrinter();
return ob_get_clean();
} catch (Exception $ex) {
ob_end_clean();
throw $ex;
}
}
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:33,代码来源:ApiFormatTestBase.php
示例2: getDefinitions
/**
* @see BaseDependencyContainer::registerDefinitions
*
* @since 1.9
*
* @return array
*/
protected function getDefinitions()
{
return array('ParserData' => $this->getParserData(), 'NamespaceExaminer' => $this->getNamespaceExaminer(), 'JobFactory' => function (DependencyBuilder $builder) {
return new \SMW\MediaWiki\Jobs\JobFactory();
}, 'ContentParser' => function (DependencyBuilder $builder) {
return new ContentParser($builder->getArgument('Title'));
}, 'RequestContext' => function (DependencyBuilder $builder) {
$instance = new \RequestContext();
if ($builder->hasArgument('Title')) {
$instance->setTitle($builder->getArgument('Title'));
}
if ($builder->hasArgument('Language')) {
$instance->setLanguage($builder->getArgument('Language'));
}
return $instance;
}, 'WikiPage' => function (DependencyBuilder $builder) {
return \WikiPage::factory($builder->getArgument('Title'));
}, 'TitleCreator' => function (DependencyBuilder $builder) {
return new TitleCreator(new PageCreator());
}, 'PageCreator' => function (DependencyBuilder $builder) {
return new PageCreator();
}, 'MessageFormatter' => function (DependencyBuilder $builder) {
return new MessageFormatter($builder->getArgument('Language'));
});
}
开发者ID:whysasse,项目名称:kmwiki,代码行数:32,代码来源:SharedDependencyContainer.php
示例3: testPreferences
function testPreferences()
{
global $wgUser, $wgOut, $wgTitle;
// This test makes call to the parser which requires valids Outputpage
// and Title objects. Set them up there, they will be released at the
// end of the test.
$old_wgOut = $wgOut;
$old_wgTitle = $wgTitle;
$wgTitle = Title::newFromText('Parser test for Gadgets extension');
// Proceed with test setup:
$prefs = array();
$context = new RequestContext();
$wgOut = $context->getOutput();
$wgOut->setTitle(Title::newFromText('test'));
Gadget::loadStructuredList('* foo | foo.js
==keep-section1==
* bar| bar.js
==remove-section==
* baz [rights=embezzle] |baz.js
==keep-section2==
* quux [rights=read] | quux.js');
$this->assertTrue(GadgetHooks::getPreferences($wgUser, $prefs), 'GetPrefences hook should return true');
$options = $prefs['gadgets']['options'];
$this->assertFalse(isset($options['<gadget-section-remove-section>']), 'Must not show empty sections');
$this->assertTrue(isset($options['<gadget-section-keep-section1>']));
$this->assertTrue(isset($options['<gadget-section-keep-section2>']));
// Restore globals
$wgOut = $old_wgOut;
$wgTitle = $old_wgTitle;
}
开发者ID:Tarendai,项目名称:spring-website,代码行数:30,代码来源:GadgetTest.php
示例4: getTestContext
public function getTestContext(User $user)
{
$context = new RequestContext();
$context->setLanguage(Language::factory('en'));
$context->setUser($user);
return $context;
}
开发者ID:Habatchii,项目名称:wikibase-for-mediawiki,代码行数:7,代码来源:TestRecentChangesHelper.php
示例5: testProcess
/**
* @dataProvider titleDataProvider
*/
public function testProcess($setup, $expected)
{
$skin = $this->getMockBuilder('\\Skin')->disableOriginalConstructor()->getMock();
$context = new \RequestContext();
$context->setTitle($setup['title']);
$context->setLanguage(Language::factory('en'));
$outputPage = new OutputPage($context);
$instance = new BeforePageDisplay($outputPage, $skin);
$result = $instance->process();
$this->assertInternalType('boolean', $result);
$this->assertTrue($result);
$contains = false;
if (method_exists($outputPage, 'getHeadLinksArray')) {
foreach ($outputPage->getHeadLinksArray() as $key => $value) {
if (strpos($value, 'ExportRDF')) {
$contains = true;
break;
}
}
} else {
// MW 1.19
if (strpos($outputPage->getHeadLinks(), 'ExportRDF')) {
$contains = true;
}
}
$expected['result'] ? $this->assertTrue($contains) : $this->assertFalse($contains);
}
开发者ID:WolfgangFahl,项目名称:SemanticMediaWiki,代码行数:30,代码来源:BeforePageDisplayTest.php
示例6: testCrossDomainMangling
public function testCrossDomainMangling()
{
$config = new HashConfig(array('MangleFlashPolicy' => false));
$context = new RequestContext();
$context->setConfig(new MultiConfig(array($config, $context->getConfig())));
$main = new ApiMain($context);
$main->getResult()->addValue(null, null, '< Cross-Domain-Policy >');
if (!function_exists('wfOutputHandler')) {
function wfOutputHandler($s)
{
return $s;
}
}
$printer = $main->createPrinterByName('php');
ob_start('wfOutputHandler');
$printer->initPrinter();
$printer->execute();
$printer->closePrinter();
$ret = ob_get_clean();
$this->assertSame('a:1:{i:0;s:23:"< Cross-Domain-Policy >";}', $ret);
$config->set('MangleFlashPolicy', true);
$printer = $main->createPrinterByName('php');
ob_start('wfOutputHandler');
try {
$printer->initPrinter();
$printer->execute();
$printer->closePrinter();
ob_end_clean();
$this->fail('Expected exception not thrown');
} catch (UsageException $ex) {
ob_end_clean();
$this->assertSame('This response cannot be represented using format=php. See https://phabricator.wikimedia.org/T68776', $ex->getMessage(), 'Expected exception');
}
}
开发者ID:ngertrudiz,项目名称:mediawiki,代码行数:34,代码来源:ApiFormatPhpTest.php
示例7: setUp
function setUp()
{
global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $parserMemc, $wgThumbnailScriptPath, $wgScriptPath, $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
$wgScript = '/index.php';
$wgScriptPath = '/';
$wgArticlePath = '/wiki/$1';
$wgStyleSheetPath = '/skins';
$wgStylePath = '/skins';
$wgThumbnailScriptPath = false;
$wgLocalFileRepo = array('class' => 'LocalRepo', 'name' => 'local', 'directory' => wfTempDir() . '/test-repo', 'url' => 'http://example.com/images', 'deletedDir' => wfTempDir() . '/test-repo/delete', 'hashLevels' => 2, 'transformVia404' => false);
$wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
$wgNamespaceAliases['Image'] = NS_FILE;
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
$wgEnableParserCache = false;
$wgDeferredUpdateList = array();
$wgMemc = wfGetMainCache();
$messageMemc = wfGetMessageCacheStorage();
$parserMemc = wfGetParserCacheStorage();
// $wgContLang = new StubContLang;
$wgUser = new User();
$context = new RequestContext();
$wgLang = $context->getLang();
$wgOut = $context->getOutput();
$wgParser = new StubObject('wgParser', $wgParserConf['class'], array($wgParserConf));
$wgRequest = new WebRequest();
if ($wgStyleDirectory === false) {
$wgStyleDirectory = "{$IP}/skins";
}
}
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:29,代码来源:UploadFromUrlTestSuite.php
示例8: testGetDesktopUrl
/**
* @dataProvider provideGetDesktopUrl
* @param string $class
* @param string $subPage
* @param array $params
* @param string|null $expected
*/
public function testGetDesktopUrl($class, $subPage, array $params, $expected)
{
$context = new RequestContext();
$context->setRequest(new FauxRequest($params));
$page = new $class();
$page->setContext($context);
$this->assertEquals($expected, $page->getDesktopUrl($subPage));
}
开发者ID:micha6554,项目名称:mediawiki-extensions-MobileFrontend,代码行数:15,代码来源:MobileSpecialPageTest.php
示例9: fromRequestContext
/**
* Updates the RequestContext information based on a HttpFoundation Request.
*
* @param RequestContext $requestContext
*
* @return $this The current instance, implementing a fluent interface
*
*/
public static function fromRequestContext(RequestContext $requestContext)
{
$Url = new static();
$Url->setScheme($requestContext->getScheme());
$Url->setHost($requestContext->getHost());
$Url->setPath($requestContext->getPath());
$Url->setParameters($requestContext->getParameters());
return $Url;
}
开发者ID:shakhraj,项目名称:reroute,代码行数:17,代码来源:Url.php
示例10: setUp
function setUp()
{
$this->page = new MIMESearchPage();
$context = new RequestContext();
$context->setTitle(Title::makeTitle(NS_SPECIAL, 'MIMESearch'));
$context->setRequest(new FauxRequest());
$this->page->setContext($context);
parent::setUp();
}
开发者ID:rploaiza,项目名称:dbpedia-latinoamerica,代码行数:9,代码来源:SpecialMIMESearchTest.php
示例11: getTestContext
public function getTestContext(User $user)
{
$context = new RequestContext();
$context->setLanguage('en');
$context->setUser($user);
$title = Title::newFromText('RecentChanges', NS_SPECIAL);
$context->setTitle($title);
return $context;
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:9,代码来源:TestRecentChangesHelper.php
示例12: testHandleNormalization
public function testHandleNormalization()
{
$context = new RequestContext();
$context->setRequest(new FauxRequest(['titles' => "a|B|å"]));
$main = new ApiMain($context);
$pageSet = new ApiPageSet($main);
$pageSet->execute();
$this->assertSame([0 => ['A' => -1, 'B' => -2, 'Å' => -3]], $pageSet->getAllTitlesByNamespace());
$this->assertSame([['fromencoded' => true, 'from' => 'a%CC%8A', 'to' => 'å'], ['fromencoded' => false, 'from' => 'a', 'to' => 'A'], ['fromencoded' => false, 'from' => 'å', 'to' => 'Å']], $pageSet->getNormalizedTitlesAsResult());
}
开发者ID:paladox,项目名称:mediawiki,代码行数:10,代码来源:ApiPageSetTest.php
示例13: __construct
public function __construct()
{
parent::__construct();
$this->prefUsers['noemail'] = new User();
$this->prefUsers['notauth'] = new User();
$this->prefUsers['notauth']->setEmail('[email protected]');
$this->prefUsers['auth'] = new User();
$this->prefUsers['auth']->setEmail('[email protected]');
$this->prefUsers['auth']->setEmailAuthenticationTimestamp(1330946623);
$this->context = new RequestContext();
$this->context->setTitle(Title::newFromText('PreferencesTest'));
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:12,代码来源:PreferencesTest.php
示例14: setUp
protected function setUp()
{
parent::setUp();
global $wgLang;
$this->setMwGlobals(array('wgLogTypes' => array('phpunit'), 'wgLogActionsHandlers' => array('phpunit/test' => 'LogFormatter', 'phpunit/param' => 'LogFormatter'), 'wgUser' => User::newFromName('Testuser'), 'wgExtensionMessagesFiles' => array('LogTests' => __DIR__ . '/LogTests.i18n.php')));
Language::getLocalisationCache()->recache($wgLang->getCode());
$this->user = User::newFromName('Testuser');
$this->title = Title::newMainPage();
$this->context = new RequestContext();
$this->context->setUser($this->user);
$this->context->setTitle($this->title);
$this->context->setLanguage($wgLang);
}
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:13,代码来源:LogFormatterTest.php
示例15: assertConditions
/** helper to test SpecialRecentchanges::buildMainQueryConds() */
private function assertConditions($expected, $requestOptions = null, $message = '')
{
$context = new RequestContext();
$context->setRequest(new FauxRequest($requestOptions));
# setup the rc object
$this->rc = new SpecialRecentChanges();
$this->rc->setContext($context);
$formOptions = $this->rc->setup(null);
# Filter out rc_timestamp conditions which depends on the test runtime
# This condition is not needed as of march 2, 2011 -- hashar
# @todo FIXME: Find a way to generate the correct rc_timestamp
$queryConditions = array_filter($this->rc->buildMainQueryConds($formOptions), 'SpecialRecentchangesTest::filterOutRcTimestampCondition');
$this->assertEquals($expected, $queryConditions, $message);
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:15,代码来源:SpecialRecentchangesTest.php
示例16: execute
public function execute()
{
global $wgUser;
$wgUser = User::newFromName('Maintenance script');
RequestContext::getMain()->setUser($wgUser);
$dbr = CentralAuthUser::getCentralSlaveDB();
if ($this->getOption('fix', false) !== false) {
$this->fix = true;
}
if ($this->getOption('safe-migrate', false) !== false) {
$this->safe = true;
$this->migrate = true;
}
if ($this->getOption('migrate', false) !== false) {
$this->migrate = true;
}
if ($this->getOption('suppressrc', false) !== false) {
$this->suppressRC = true;
}
$end = $dbr->selectField('globaluser', 'MAX(gu_id)');
for ($cur = 0; $cur <= $end; $cur += $this->mBatchSize) {
$this->output("PROGRESS: {$cur} / {$end}\n");
$result = $dbr->select(array('globaluser', 'localuser'), array('gu_name'), array('lu_name' => null, "gu_id >= {$cur}", 'gu_id < ' . ($cur + $this->mBatchSize)), __METHOD__, array('ORDER BY' => 'gu_id'), array('localuser' => array('LEFT JOIN', 'gu_name=lu_name')));
foreach ($result as $row) {
$this->process($row->gu_name);
}
if ($this->fix) {
CentralAuthUser::waitForSlaves();
}
}
$this->output("done.\n");
}
开发者ID:NDKilla,项目名称:mediawiki-extensions-CentralAuth,代码行数:32,代码来源:deleteEmptyAccounts.php
示例17: execute
function execute($par)
{
/**
* Some satellite ISPs use broken precaching schemes that log people out straight after
* they're logged in (bug 17790). Luckily, there's a way to detect such requests.
*/
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '&') !== false) {
wfDebug("Special:Userlogout request {$_SERVER['REQUEST_URI']} looks suspicious, denying.\n");
throw new HttpError(400, $this->msg('suspicious-userlogout'), $this->msg('loginerror'));
}
$this->setHeaders();
$this->outputHeader();
// Make sure it's possible to log out
$session = MediaWiki\Session\SessionManager::getGlobalSession();
if (!$session->canSetUser()) {
throw new ErrorPageError('cannotlogoutnow-title', 'cannotlogoutnow-text', [$session->getProvider()->describe(RequestContext::getMain()->getLanguage())]);
}
$user = $this->getUser();
$oldName = $user->getName();
$user->logout();
$loginURL = SpecialPage::getTitleFor('Userlogin')->getFullURL($this->getRequest()->getValues('returnto', 'returntoquery'));
$out = $this->getOutput();
$out->addWikiMsg('logouttext', $loginURL);
// Hook.
$injected_html = '';
Hooks::run('UserLogoutComplete', [&$user, &$injected_html, $oldName]);
$out->addHTML($injected_html);
$out->returnToMain();
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:29,代码来源:SpecialUserlogout.php
示例18: setRawSession
/**
* @param string $id Session ID
* @param array|mixed $blob Session metadata and data
* @param int $expiry Expiry
*/
public function setRawSession($id, $blob, $expiry = 0)
{
if ($expiry <= 0) {
$expiry = \RequestContext::getMain()->getConfig()->get('ObjectCacheSessionExpiry');
}
$this->set(wfMemcKey('MWSession', $id), $blob, $expiry);
}
开发者ID:Gomyul,项目名称:mediawiki,代码行数:12,代码来源:TestBagOStuff.php
示例19: 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
示例20: doApiRequest
/**
* Does the API request and returns the result.
*
* The returned value is an array containing
* - the result data (array)
* - the request (WebRequest)
* - the session data of the request (array)
* - if $appendModule is true, the Api module $module
*
* @param array $params
* @param array|null $session
* @param bool $appendModule
* @param User|null $user
*
* @return array
*/
protected function doApiRequest(array $params, array $session = null, $appendModule = false, User $user = null)
{
global $wgRequest, $wgUser;
if (is_null($session)) {
// re-use existing global session by default
$session = $wgRequest->getSessionArray();
}
// set up global environment
if ($user) {
$wgUser = $user;
}
$wgRequest = new FauxRequest($params, true, $session);
RequestContext::getMain()->setRequest($wgRequest);
RequestContext::getMain()->setUser($wgUser);
// set up local environment
$context = $this->apiContext->newTestContext($wgRequest, $wgUser);
$module = new ApiMain($context, true);
// run it!
$module->execute();
// construct result
$results = array($module->getResult()->getResultData(null, array('Strip' => 'all')), $context->getRequest(), $context->getRequest()->getSessionArray());
if ($appendModule) {
$results[] = $module;
}
return $results;
}
开发者ID:lourinaldi,项目名称:mediawiki,代码行数:42,代码来源:ApiTestCase.php
注:本文中的RequestContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论