本文整理汇总了PHP中RequestContext类的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext类的具体用法?PHP RequestContext怎么用?PHP RequestContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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'));
});
}
示例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;
}
示例4: getTestContext
public function getTestContext(User $user)
{
$context = new RequestContext();
$context->setLanguage(Language::factory('en'));
$context->setUser($user);
return $context;
}
示例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);
}
示例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');
}
}
示例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";
}
}
示例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));
}
示例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;
}
示例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();
}
示例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;
}
示例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());
}
示例13: __construct
public function __construct()
{
parent::__construct();
$this->prefUsers['noemail'] = new User();
$this->prefUsers['notauth'] = new User();
$this->prefUsers['notauth']->setEmail('noauth@example.org');
$this->prefUsers['auth'] = new User();
$this->prefUsers['auth']->setEmail('noauth@example.org');
$this->prefUsers['auth']->setEmailAuthenticationTimestamp(1330946623);
$this->context = new RequestContext();
$this->context->setTitle(Title::newFromText('PreferencesTest'));
}
示例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);
}
示例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);
}