本文整理汇总了PHP中RequestContext::setTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::setTitle方法的具体用法?PHP RequestContext::setTitle怎么用?PHP RequestContext::setTitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestContext
的用法示例。
在下文中一共展示了RequestContext::setTitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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'));
}
示例2: 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);
}
示例3: testWikiPageTitle
/**
* Test the relationship between title and wikipage in RequestContext
* @covers RequestContext::getWikiPage
* @covers RequestContext::getTitle
*/
public function testWikiPageTitle()
{
$context = new RequestContext();
$curTitle = Title::newFromText("A");
$context->setTitle($curTitle);
$this->assertTrue($curTitle->equals($context->getWikiPage()->getTitle()), "When a title is first set WikiPage should be created on-demand for that title.");
$curTitle = Title::newFromText("B");
$context->setWikiPage(WikiPage::factory($curTitle));
$this->assertTrue($curTitle->equals($context->getTitle()), "Title must be updated when a new WikiPage is provided.");
$curTitle = Title::newFromText("C");
$context->setTitle($curTitle);
$this->assertTrue($curTitle->equals($context->getWikiPage()->getTitle()), "When a title is updated the WikiPage should be purged " . "and recreated on-demand with the new title.");
}
示例4: 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>';
}
示例5: 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'));
});
}
示例6: 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);
}
示例7: 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;
}
示例8: 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();
}
示例9: testTryPrependHtmlForNonViewAction
public function testTryPrependHtmlForNonViewAction()
{
$context = new \RequestContext();
$context->setRequest(new \FauxRequest(array('action' => 'edit'), true));
$context->setTitle(Title::newFromText(__METHOD__));
$htmlBreadcrumbLinksBuilder = $this->getMockBuilder('\\SBL\\HtmlBreadcrumbLinksBuilder')->disableOriginalConstructor()->getMock();
$title = $this->getMockBuilder('\\Title')->disableOriginalConstructor()->getMock();
$title->expects($this->once())->method('isKnown')->will($this->returnValue(true));
$title->expects($this->once())->method('isSpecialPage')->will($this->returnValue(false));
$output = $this->getMockBuilder('\\OutputPage')->disableOriginalConstructor()->getMock();
$output->expects($this->never())->method('prependHTML');
$output->expects($this->once())->method('getContext')->will($this->returnValue($context));
$output->expects($this->atLeastOnce())->method('getTitle')->will($this->returnValue($title));
$instance = new SkinTemplateOutputModifier($htmlBreadcrumbLinksBuilder);
$this->assertTrue($instance->modifyOutput($output));
}
示例10: 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([]));
}
示例11: 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.');
}
}
示例12: 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']);
}
示例13: capturePath
/**
* Just like executePath() except it returns the HTML instead of outputting it
* Returns false if there was no such special page, or a title object if it was
* a redirect.
*
* Also saves the current $wgTitle, $wgOut, and $wgRequest variables so that
* the special page will get the context it'd expect on a normal request,
* and then restores them to their previous values after.
*
* @param $title Title
*
* @return String: HTML fragment
*/
static function capturePath(&$title)
{
global $wgOut, $wgTitle, $wgRequest;
$oldTitle = $wgTitle;
$oldOut = $wgOut;
$oldRequest = $wgRequest;
// Don't want special pages interpreting ?feed=atom parameters.
$wgRequest = new FauxRequest(array());
$context = new RequestContext();
$context->setTitle($title);
$context->setRequest($wgRequest);
$wgOut = $context->getOutput();
$ret = self::executePath($title, $context, true);
if ($ret === true) {
$ret = $wgOut->getHTML();
}
$wgTitle = $oldTitle;
$wgOut = $oldOut;
$wgRequest = $oldRequest;
return $ret;
}
示例14: braceSubstitution
//.........这里部分代码省略.........
# Do recursion depth check
$limit = $this->mOptions->getMaxTemplateDepth();
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;
示例15: execute
public function execute()
{
global $wgRequestTime;
if (!$this->enabled) {
$this->error("Nothing to do -- \$wgUseFileCache is disabled.", true);
}
$start = $this->getOption('start', "0");
if (!ctype_digit($start)) {
$this->error("Invalid value for start parameter.", true);
}
$start = intval($start);
$end = $this->getOption('end', "0");
if (!ctype_digit($end)) {
$this->error("Invalid value for end parameter.", true);
}
$end = intval($end);
$this->output("Building content page file cache from page {$start}!\n");
$dbr = $this->getDB(DB_REPLICA);
$overwrite = $this->getOption('overwrite', false);
$start = $start > 0 ? $start : $dbr->selectField('page', 'MIN(page_id)', false, __METHOD__);
$end = $end > 0 ? $end : $dbr->selectField('page', 'MAX(page_id)', false, __METHOD__);
if (!$start) {
$this->error("Nothing to do.", true);
}
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip';
// hack, no real client
# Do remaining chunk
$end += $this->mBatchSize - 1;
$blockStart = $start;
$blockEnd = $start + $this->mBatchSize - 1;
$dbw = $this->getDB(DB_MASTER);
// Go through each page and save the output
while ($blockEnd <= $end) {
// Get the pages
$res = $dbr->select('page', ['page_namespace', 'page_title', 'page_id'], ['page_namespace' => MWNamespace::getContentNamespaces(), "page_id BETWEEN {$blockStart} AND {$blockEnd}"], __METHOD__, ['ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY']);
$this->beginTransaction($dbw, __METHOD__);
// for any changes
foreach ($res as $row) {
$rebuilt = false;
$title = Title::makeTitleSafe($row->page_namespace, $row->page_title);
if (null == $title) {
$this->output("Page {$row->page_id} has bad title\n");
continue;
// broken title?
}
$context = new RequestContext();
$context->setTitle($title);
$article = Article::newFromTitle($title, $context);
$context->setWikiPage($article->getPage());
// If the article is cacheable, then load it
if ($article->isFileCacheable(HTMLFileCache::MODE_REBUILD)) {
$viewCache = new HTMLFileCache($title, 'view');
$historyCache = new HTMLFileCache($title, 'history');
if ($viewCache->isCacheGood() && $historyCache->isCacheGood()) {
if ($overwrite) {
$rebuilt = true;
} else {
$this->output("Page '{$title}' (id {$row->page_id}) already cached\n");
continue;
// done already!
}
}
MediaWiki\suppressWarnings();
// header notices
// Cache ?action=view
$wgRequestTime = microtime(true);
# bug 22852
ob_start();
$article->view();
$context->getOutput()->output();
$context->getOutput()->clearHTML();
$viewHtml = ob_get_clean();
$viewCache->saveToFileCache($viewHtml);
// Cache ?action=history
$wgRequestTime = microtime(true);
# bug 22852
ob_start();
Action::factory('history', $article, $context)->show();
$context->getOutput()->output();
$context->getOutput()->clearHTML();
$historyHtml = ob_get_clean();
$historyCache->saveToFileCache($historyHtml);
MediaWiki\restoreWarnings();
if ($rebuilt) {
$this->output("Re-cached page '{$title}' (id {$row->page_id})...");
} else {
$this->output("Cached page '{$title}' (id {$row->page_id})...");
}
$this->output("[view: " . strlen($viewHtml) . " bytes; " . "history: " . strlen($historyHtml) . " bytes]\n");
} else {
$this->output("Page '{$title}' (id {$row->page_id}) not cacheable\n");
}
}
$this->commitTransaction($dbw, __METHOD__);
// commit any changes (just for sanity)
$blockStart += $this->mBatchSize;
$blockEnd += $this->mBatchSize;
}
$this->output("Done!\n");
}