本文整理汇总了PHP中IContextSource::canUseWikiPage方法的典型用法代码示例。如果您正苦于以下问题:PHP IContextSource::canUseWikiPage方法的具体用法?PHP IContextSource::canUseWikiPage怎么用?PHP IContextSource::canUseWikiPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContextSource
的用法示例。
在下文中一共展示了IContextSource::canUseWikiPage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initializeArticle
/**
* Initialize the main Article object for "standard" actions (view, etc)
* Create an Article object for the page, following redirects if needed.
*
* @return mixed An Article, or a string to redirect to another URL
*/
private function initializeArticle()
{
$title = $this->context->getTitle();
if ($this->context->canUseWikiPage()) {
// Try to use request context wiki page, as there
// is already data from db saved in per process
// cache there from this->getAction() call.
$page = $this->context->getWikiPage();
$article = Article::newFromWikiPage($page, $this->context);
} else {
// This case should not happen, but just in case.
$article = Article::newFromTitle($title, $this->context);
$this->context->setWikiPage($article->getPage());
}
// NS_MEDIAWIKI has no redirects.
// It is also used for CSS/JS, so performance matters here...
if ($title->getNamespace() == NS_MEDIAWIKI) {
return $article;
}
$request = $this->context->getRequest();
// Namespace might change when using redirects
// Check for redirects ...
$action = $request->getVal('action', 'view');
$file = $title->getNamespace() == NS_FILE ? $article->getFile() : null;
if (($action == 'view' || $action == 'render') && !$request->getVal('oldid') && !$request->getVal('diff') && $request->getVal('redirect') != 'no' && !(is_object($file) && $file->exists() && !$file->getRedirected())) {
// Give extensions a change to ignore/handle redirects as needed
$ignoreRedirect = $target = false;
Hooks::run('InitializeArticleMaybeRedirect', array(&$title, &$request, &$ignoreRedirect, &$target, &$article));
// Follow redirects only for... redirects.
// If $target is set, then a hook wanted to redirect.
if (!$ignoreRedirect && ($target || $article->isRedirect())) {
// Is the target already set by an extension?
$target = $target ? $target : $article->followRedirect();
if (is_string($target)) {
if (!$this->config->get('DisableHardRedirects')) {
// we'll need to redirect
return $target;
}
}
if (is_object($target)) {
// Rewrite environment to redirected article
$rarticle = Article::newFromTitle($target, $this->context);
$rarticle->loadPageData();
if ($rarticle->exists() || is_object($file) && !$file->isLocal()) {
$rarticle->setRedirectedFrom($title);
$article = $rarticle;
$this->context->setTitle($target);
$this->context->setWikiPage($article->getPage());
}
}
} else {
$this->context->setTitle($article->getTitle());
$this->context->setWikiPage($article->getPage());
}
}
return $article;
}
示例2: getActionName
/**
* Get the action that will be executed, not necessarily the one passed
* passed through the "action" request parameter. Actions disabled in
* $wgActions will be replaced by "nosuchaction".
*
* @since 1.19
* @param $context IContextSource
* @return string: action name
*/
final public static function getActionName( IContextSource $context ) {
global $wgActions;
$request = $context->getRequest();
$actionName = $request->getVal( 'action', 'view' );
// Check for disabled actions
if ( isset( $wgActions[$actionName] ) && $wgActions[$actionName] === false ) {
$actionName = 'nosuchaction';
}
// Workaround for bug #20966: inability of IE to provide an action dependent
// on which submit button is clicked.
if ( $actionName === 'historysubmit' ) {
if ( $request->getBool( 'revisiondelete' ) ) {
$actionName = 'revisiondelete';
} else {
$actionName = 'view';
}
} elseif ( $actionName == 'editredlink' ) {
$actionName = 'edit';
}
// Trying to get a WikiPage for NS_SPECIAL etc. will result
// in WikiPage::factory throwing "Invalid or virtual namespace -1 given."
// For SpecialPages et al, default to action=view.
if ( !$context->canUseWikiPage() ) {
return 'view';
}
$action = Action::factory( $actionName, $context->getWikiPage(), $context );
if ( $action instanceof Action ) {
return $action->getName();
}
return 'nosuchaction';
}
示例3: initializeArticle
/**
* Initialize the main Article object for "standard" actions (view, etc)
* Create an Article object for the page, following redirects if needed.
*
* @return Article|string An Article, or a string to redirect to another URL
*/
private function initializeArticle()
{
$title = $this->context->getTitle();
if ($this->context->canUseWikiPage()) {
// Try to use request context wiki page, as there
// is already data from db saved in per process
// cache there from this->getAction() call.
$page = $this->context->getWikiPage();
} else {
// This case should not happen, but just in case.
// @TODO: remove this or use an exception
$page = WikiPage::factory($title);
$this->context->setWikiPage($page);
wfWarn("RequestContext::canUseWikiPage() returned false");
}
// Make GUI wrapper for the WikiPage
$article = Article::newFromWikiPage($page, $this->context);
// Skip some unnecessary code if the content model doesn't support redirects
if (!ContentHandler::getForTitle($title)->supportsRedirects()) {
return $article;
}
$request = $this->context->getRequest();
// Namespace might change when using redirects
// Check for redirects ...
$action = $request->getVal('action', 'view');
$file = $page instanceof WikiFilePage ? $page->getFile() : null;
if (($action == 'view' || $action == 'render') && !$request->getVal('oldid') && !$request->getVal('diff') && $request->getVal('redirect') != 'no' && !(is_object($file) && $file->exists() && !$file->getRedirected())) {
// Give extensions a change to ignore/handle redirects as needed
$ignoreRedirect = $target = false;
Hooks::run('InitializeArticleMaybeRedirect', [&$title, &$request, &$ignoreRedirect, &$target, &$article]);
$page = $article->getPage();
// reflect any hook changes
// Follow redirects only for... redirects.
// If $target is set, then a hook wanted to redirect.
if (!$ignoreRedirect && ($target || $page->isRedirect())) {
// Is the target already set by an extension?
$target = $target ? $target : $page->followRedirect();
if (is_string($target)) {
if (!$this->config->get('DisableHardRedirects')) {
// we'll need to redirect
return $target;
}
}
if (is_object($target)) {
// Rewrite environment to redirected article
$rpage = WikiPage::factory($target);
$rpage->loadPageData();
if ($rpage->exists() || is_object($file) && !$file->isLocal()) {
$rarticle = Article::newFromWikiPage($rpage, $this->context);
$rarticle->setRedirectedFrom($title);
$article = $rarticle;
$this->context->setTitle($target);
$this->context->setWikiPage($article->getPage());
}
}
} else {
// Article may have been changed by hook
$this->context->setTitle($article->getTitle());
$this->context->setWikiPage($article->getPage());
}
}
return $article;
}