本文整理汇总了PHP中RequestContext::setUser方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::setUser方法的具体用法?PHP RequestContext::setUser怎么用?PHP RequestContext::setUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestContext
的用法示例。
在下文中一共展示了RequestContext::setUser方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: setUp
protected function setUp()
{
parent::setUp();
global $wgLang;
$this->setMwGlobals(['wgLogTypes' => ['phpunit'], 'wgLogActionsHandlers' => ['phpunit/test' => 'LogFormatter', 'phpunit/param' => 'LogFormatter'], 'wgUser' => User::newFromName('Testuser'), 'wgExtensionMessagesFiles' => ['LogTests' => __DIR__ . '/LogTests.i18n.php']]);
Language::getLocalisationCache()->recache($wgLang->getCode());
$this->user = User::newFromName('Testuser');
$this->title = Title::newFromText('SomeTitle');
$this->target = Title::newFromText('TestTarget');
$this->context = new RequestContext();
$this->context->setUser($this->user);
$this->context->setTitle($this->title);
$this->context->setLanguage($wgLang);
$this->user_comment = '<User comment about action>';
}
示例3: getTestContext
public function getTestContext(User $user)
{
$context = new RequestContext();
$context->setLanguage(Language::factory('en'));
$context->setUser($user);
return $context;
}
示例4: 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;
}
示例5: testGetMembersActionWithMultiUsers
/**
* @dataProvider getSlugs
*/
public function testGetMembersActionWithMultiUsers($slug)
{
$this->addSlugToCache($slug, array(array('slug' => $this->user->Slug, 'name' => $this->user->Title, 'pingedAt' => null, 'updateMeta' => false)));
// set new user
$user = new \stdClass();
$user->Slug = 'bobdoll';
$user->Title = 'Bob Doll';
// update logged-in user
$this->requestContext->setUser($user);
$this->request->addRouteParameters(array('slug' => $slug));
ob_start();
$this->controller->getMembersAction();
$output = ob_get_contents();
ob_end_clean();
$this->assertJsonStringEqualsJsonString($output, json_encode(array(array('slug' => $this->user->Slug, 'name' => $this->user->Title, 'pingedAt' => null, 'updateMeta' => false), array('slug' => $user->Slug, 'name' => $user->Title, 'pingedAt' => null, 'updateMeta' => false))));
}
示例6: testBug41337
/**
* Make sure a nickname which is longer than $wgMaxSigChars
* is not throwing a fatal error.
*
* Test specifications by Alexandre "ialex" Emsenhuber.
* @todo give this test a real name explaining what is being tested here
*/
public function testBug41337()
{
// Set a low limit
$this->setMwGlobals('wgMaxSigChars', 2);
$user = $this->getMock('User');
$user->expects($this->any())->method('isAnon')->will($this->returnValue(false));
# Yeah foreach requires an array, not NULL =(
$user->expects($this->any())->method('getEffectiveGroups')->will($this->returnValue([]));
# The mocked user has a long nickname
$user->expects($this->any())->method('getOption')->will($this->returnValueMap([['nickname', null, false, 'superlongnickname']]));
# Forge a request to call the special page
$context = new RequestContext();
$context->setRequest(new FauxRequest());
$context->setUser($user);
$context->setTitle(Title::newFromText('Test'));
# Do the call, should not spurt a fatal error.
$special = new SpecialPreferences();
$special->setContext($context);
$this->assertNull($special->execute([]));
}
示例7: testProfileAndNamespaceLoading
/**
* @covers SpecialSearch::load
* @dataProvider provideSearchOptionsTests
* @param $requested Array Request parameters. For example array( 'ns5' => true, 'ns6' => true). NULL to use default options.
* @param $userOptions Array User options to test with. For example array('searchNs5' => 1 );. NULL to use default options.
* @param $expectedProfile An expected search profile name
* @param $expectedNs Array Expected namespaces
*/
function testProfileAndNamespaceLoading($requested, $userOptions, $expectedProfile, $expectedNS, $message = 'Profile name and namespaces mismatches!')
{
$context = new RequestContext();
$context->setUser($this->newUserWithSearchNS($userOptions));
/*
$context->setRequest( new FauxRequest( array(
'ns5'=>true,
'ns6'=>true,
) ));
*/
$context->setRequest(new FauxRequest($requested));
$search = new SpecialSearch();
$search->setContext($context);
$search->load();
/**
* Verify profile name and namespace in the same assertion to make
* sure we will be able to fully compare the above code. PHPUnit stop
* after an assertion fail.
*/
$this->assertEquals(array('ProfileName' => $expectedProfile, 'Namespaces' => $expectedNS), array('ProfileName' => $search->getProfile(), 'Namespaces' => $search->getNamespaces()), $message);
}
示例8: testRedLinks
/**
* @dataProvider providerShowRedLinks
*/
public function testRedLinks($showRedLinks, $showRedLinksAnon, $username, $expected)
{
// set config variables, which we test here
$values = array('wgMFShowRedLinks' => $showRedLinks, 'wgMFShowRedLinksAnon' => $showRedLinksAnon, 'wgMFEnableBeta' => true);
$this->setMwGlobals($values);
// create our specific user object
$user = User::newFromName($username);
$user->load();
// create a new RequestContext for this test case and set User and title
$context = new RequestContext();
$context->setUser($user);
$context->setTitle(Title::newFromText('Main_page'));
// create SkinMinerva to test
$skin = $this->getSkin();
$skin->setContext($context);
// set the fake mobile mode
MobileContext::singleton()->setMobileMode($this->getMode());
// test now
$vars = $skin->getSkinConfigVariables();
$this->assertEquals($expected, $vars['wgMFShowRedLinks']);
}
示例9: testGetContextSpecificModules
/**
* Check, if context modules aren't arrays. They will be added as an array with modules to
* to load, which doesn't allow arrays as values.
*/
public function testGetContextSpecificModules()
{
// try to cover all possible modules (maybe extent, if other modules added)
$values = array('wgMFEnableBeta' => true);
$this->setMwGlobals($values);
// UTSysop will be a logged in user
$user = User::newFromName('UTSysop');
$user->load();
// create a new RequestContext for this test case and set User and title
$context = new RequestContext();
$context->setUser($user);
// UTPage is an existing page in the main namespace
$context->setTitle(Title::newFromText('UTPage'));
MobileContext::singleton()->setMobileMode('alpha');
$skin = $this->getSkin();
$skin->setContext($context);
$modules = $skin->getContextSpecificModules();
foreach ($modules as $module) {
$this->assertFalse(is_array($module), 'Context specific modules can\'t be arrays.');
}
}
示例10: braceSubstitution
//.........这里部分代码省略.........
if ($frame->depth >= $limit) {
$found = true;
$text = '<span class="error">' . wfMessage('parser-template-recursion-depth-warning')->numParams($limit)->inContentLanguage()->text() . '</span>';
}
}
}
# Load from database
if (!$found && $title) {
if (!Profiler::instance()->isPersistent()) {
# Too many unique items can kill profiling DBs/collectors
$titleProfileIn = __METHOD__ . "-title-" . $title->getPrefixedDBkey();
wfProfileIn($titleProfileIn);
// template in
}
wfProfileIn(__METHOD__ . '-loadtpl');
if (!$title->isExternal()) {
if ($title->isSpecialPage() && $this->mOptions->getAllowSpecialInclusion() && $this->ot['html']) {
// Pass the template arguments as URL parameters.
// "uselang" will have no effect since the Language object
// is forced to the one defined in ParserOptions.
$pageArgs = array();
for ($i = 0; $i < $args->getLength(); $i++) {
$bits = $args->item($i)->splitArg();
if (strval($bits['index']) === '') {
$name = trim($frame->expand($bits['name'], PPFrame::STRIP_COMMENTS));
$value = trim($frame->expand($bits['value']));
$pageArgs[$name] = $value;
}
}
// Create a new context to execute the special page
$context = new RequestContext();
$context->setTitle($title);
$context->setRequest(new FauxRequest($pageArgs));
$context->setUser($this->getUser());
$context->setLanguage($this->mOptions->getUserLangObj());
$ret = SpecialPageFactory::capturePath($title, $context);
if ($ret) {
$text = $context->getOutput()->getHTML();
$this->mOutput->addOutputPageMetadata($context->getOutput());
$found = true;
$isHTML = true;
$this->disableCache();
}
} elseif (MWNamespace::isNonincludable($title->getNamespace())) {
$found = false;
# access denied
wfDebug(__METHOD__ . ": template inclusion denied for " . $title->getPrefixedDBkey() . "\n");
} else {
list($text, $title) = $this->getTemplateDom($title);
if ($text !== false) {
$found = true;
$isChildObj = true;
}
}
# If the title is valid but undisplayable, make a link to it
if (!$found && ($this->ot['html'] || $this->ot['pre'])) {
$text = "[[:{$titleText}]]";
$found = true;
}
} elseif ($title->isTrans()) {
# Interwiki transclusion
if ($this->ot['html'] && !$forceRawInterwiki) {
$text = $this->interwikiTransclude($title, 'render');
$isHTML = true;
} else {
$text = $this->interwikiTransclude($title, 'raw');
示例11: execute
//.........这里部分代码省略.........
$requestArray['wpSection'] = '';
}
$watch = $this->getWatchlistValue($params['watchlist'], $titleObj);
// Deprecated parameters
if ($params['watch']) {
$this->logFeatureUsage('action=edit&watch');
$watch = true;
} elseif ($params['unwatch']) {
$this->logFeatureUsage('action=edit&unwatch');
$watch = false;
}
if ($watch) {
$requestArray['wpWatchthis'] = '';
}
// Apply change tags
if (count($params['tags'])) {
if ($user->isAllowed('applychangetags')) {
$requestArray['wpChangeTags'] = implode(',', $params['tags']);
} else {
$this->dieUsage('You don\'t have permission to set change tags.', 'taggingnotallowed');
}
}
// Pass through anything else we might have been given, to support extensions
// This is kind of a hack but it's the best we can do to make extensions work
$requestArray += $this->getRequest()->getValues();
global $wgTitle, $wgRequest;
$req = new DerivativeRequest($this->getRequest(), $requestArray, true);
// Some functions depend on $wgTitle == $ep->mTitle
// TODO: Make them not or check if they still do
$wgTitle = $titleObj;
$articleContext = new RequestContext();
$articleContext->setRequest($req);
$articleContext->setWikiPage($pageObj);
$articleContext->setUser($this->getUser());
/** @var $articleObject Article */
$articleObject = Article::newFromWikiPage($pageObj, $articleContext);
$ep = new EditPage($articleObject);
$ep->setApiEditOverride(true);
$ep->setContextTitle($titleObj);
$ep->importFormData($req);
$content = $ep->textbox1;
// The following is needed to give the hook the full content of the
// new revision rather than just the current section. (Bug 52077)
if (!is_null($params['section']) && $contentHandler->supportsSections() && $titleObj->exists()) {
// If sectiontitle is set, use it, otherwise use the summary as the section title (for
// backwards compatibility with old forms/bots).
if ($ep->sectiontitle !== '') {
$sectionTitle = $ep->sectiontitle;
} else {
$sectionTitle = $ep->summary;
}
$contentObj = $contentHandler->unserializeContent($content, $contentFormat);
$fullContentObj = $articleObject->replaceSectionContent($params['section'], $contentObj, $sectionTitle);
if ($fullContentObj) {
$content = $fullContentObj->serialize($contentFormat);
} else {
// This most likely means we have an edit conflict which means that the edit
// wont succeed anyway.
$this->dieUsageMsg('editconflict');
}
}
// Run hooks
// Handle APIEditBeforeSave parameters
$r = array();
if (!Hooks::run('APIEditBeforeSave', array($ep, $content, &$r))) {
if (count($r)) {
示例12: execute
//.........这里部分代码省略.........
if ($params['minor'] || !$params['notminor'] && $user->getOption('minordefault')) {
$requestArray['wpMinoredit'] = '';
}
if ($params['recreate']) {
$requestArray['wpRecreate'] = '';
}
if (!is_null($params['section'])) {
$section = intval($params['section']);
if ($section == 0 && $params['section'] != '0' && $params['section'] != 'new') {
$this->dieUsage("The section parameter must be set to an integer or 'new'", "invalidsection");
}
$requestArray['wpSection'] = $params['section'];
} else {
$requestArray['wpSection'] = '';
}
$watch = $this->getWatchlistValue($params['watchlist'], $titleObj);
// Deprecated parameters
if ($params['watch']) {
$watch = true;
} elseif ($params['unwatch']) {
$watch = false;
}
if ($watch) {
$requestArray['wpWatchthis'] = '';
}
global $wgTitle, $wgRequest;
$req = new DerivativeRequest($this->getRequest(), $requestArray, true);
// Some functions depend on $wgTitle == $ep->mTitle
// TODO: Make them not or check if they still do
$wgTitle = $titleObj;
$articleContext = new RequestContext();
$articleContext->setRequest($req);
$articleContext->setWikiPage($pageObj);
$articleContext->setUser($this->getUser());
/** @var $articleObject Article */
$articleObject = Article::newFromWikiPage($pageObj, $articleContext);
$ep = new EditPage($articleObject);
// allow editing of non-textual content.
$ep->allowNonTextContent = true;
$ep->setContextTitle($titleObj);
$ep->importFormData($req);
// Run hooks
// Handle APIEditBeforeSave parameters
$r = array();
if (!wfRunHooks('APIEditBeforeSave', array($ep, $ep->textbox1, &$r))) {
if (count($r)) {
$r['result'] = 'Failure';
$apiResult->addValue(null, $this->getModuleName(), $r);
return;
} else {
$this->dieUsageMsg('hookaborted');
}
}
// Do the actual save
$oldRevId = $articleObject->getRevIdFetched();
$result = null;
// Fake $wgRequest for some hooks inside EditPage
// @todo FIXME: This interface SUCKS
$oldRequest = $wgRequest;
$wgRequest = $req;
$status = $ep->internalAttemptSave($result, $user->isAllowed('bot') && $params['bot']);
$wgRequest = $oldRequest;
global $wgMaxArticleSize;
switch ($status->value) {
case EditPage::AS_HOOK_ERROR:
case EditPage::AS_HOOK_ERROR_EXPECTED:
示例13: createContext
/**
* Create a new RequestContext object to use e.g. for calls to other parts
* the software.
* The object will have the WebRequest and the User object set to the ones
* used in this instance.
*
* @return RequestContext
*/
public function createContext()
{
global $wgUser;
$context = new RequestContext();
$context->setRequest($this->getMain()->getRequest());
$context->setUser($wgUser);
/// @todo FIXME: we should store the User object
return $context;
}