Revert "Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage"
This reverts commit ef458e8948.
Reason for revert: Causes page tabs to disappear on Special:WhatLinksHere.
Bug: T297744
Change-Id: I0ee282a9f7a5a9b2cfdc3261d800d9e27eaf977e
This commit is contained in:
parent
7622840cd5
commit
93f79a9122
12 changed files with 56 additions and 61 deletions
|
|
@ -409,22 +409,26 @@ class MediaWiki {
|
|||
* Initialize the main Article object for "standard" actions (view, etc)
|
||||
* Create an Article object for the page, following redirects if needed.
|
||||
*
|
||||
* @throws MWException
|
||||
* @return Article|string An Article, or a string to redirect to another URL
|
||||
*/
|
||||
private function initializeArticle() {
|
||||
$title = $this->context->getTitle();
|
||||
$services = MediaWikiServices::getInstance();
|
||||
if ( $title !== null && $title->canExist() ) {
|
||||
$wikiPage = $services->getWikiPageFactory()->newFromTitle( $title );
|
||||
$this->context->setWikiPage( $wikiPage );
|
||||
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.
|
||||
throw new MWException( "This is not an article: '$title'." );
|
||||
// This case should not happen, but just in case.
|
||||
// @TODO: remove this or use an exception
|
||||
$page = $services->getWikiPageFactory()->newFromTitle( $title );
|
||||
$this->context->setWikiPage( $page );
|
||||
wfWarn( "RequestContext::canUseWikiPage() returned false" );
|
||||
}
|
||||
|
||||
// Make GUI wrapper for the WikiPage
|
||||
$article = Article::newFromWikiPage( $wikiPage, $this->context );
|
||||
$article = Article::newFromWikiPage( $page, $this->context );
|
||||
|
||||
// Skip some unnecessary code if the content model doesn't support redirects
|
||||
if ( !$services->getContentHandlerFactory()
|
||||
|
|
@ -438,8 +442,8 @@ class MediaWiki {
|
|||
|
||||
// Namespace might change when using redirects
|
||||
// Check for redirects ...
|
||||
$action = $request->getVal( 'action', 'view' );
|
||||
$file = ( $wikiPage instanceof WikiFilePage ) ? $wikiPage->getFile() : null;
|
||||
$action = $request->getRawVal( 'action', 'view' );
|
||||
$file = ( $page instanceof WikiFilePage ) ? $page->getFile() : null;
|
||||
if ( ( $action == 'view' || $action == 'render' ) // ... for actions that show content
|
||||
&& !$request->getCheck( 'oldid' ) // ... and are not old revisions
|
||||
&& !$request->getCheck( 'diff' ) // ... and not when showing diff
|
||||
|
|
@ -881,8 +885,7 @@ class MediaWiki {
|
|||
}
|
||||
// Do any stats increment/watchlist stuff, assuming user is viewing the
|
||||
// latest revision (which should always be the case for file cache)
|
||||
$wikiPage = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
|
||||
$wikiPage->doViewUpdates( $this->context->getUser() );
|
||||
$this->context->getWikiPage()->doViewUpdates( $this->context->getUser() );
|
||||
// Tell OutputPage that output is taken care of
|
||||
$output->disable();
|
||||
|
||||
|
|
|
|||
|
|
@ -3368,9 +3368,10 @@ class OutputPage extends ContextSource {
|
|||
list( $canonicalSpecialPageName, /*...*/ ) =
|
||||
$services->getSpecialPageFactory()->
|
||||
resolveAlias( $title->getDBkey() );
|
||||
} elseif ( $title->canExist() ) {
|
||||
$curRevisionId = $title->getLatestRevID();
|
||||
$articleId = $title->getArticleID();
|
||||
} elseif ( $this->canUseWikiPage() ) {
|
||||
$wikiPage = $this->getWikiPage();
|
||||
$curRevisionId = $wikiPage->getLatest();
|
||||
$articleId = $wikiPage->getId();
|
||||
}
|
||||
|
||||
$lang = $title->getPageViewLanguage();
|
||||
|
|
|
|||
|
|
@ -312,8 +312,7 @@ class ActionFactory {
|
|||
// Trying to get a WikiPage for NS_SPECIAL etc. will result
|
||||
// in WikiPageFactory::newFromTitle throwing "Invalid or virtual namespace -1 given."
|
||||
// For SpecialPages et al, default to action=view.
|
||||
$title = $context->getTitle();
|
||||
if ( $title === null || !( $title->canExist() ) ) {
|
||||
if ( !$context->canUseWikiPage() ) {
|
||||
return 'view';
|
||||
}
|
||||
|
||||
|
|
@ -385,8 +384,7 @@ class ActionFactory {
|
|||
* @return Article
|
||||
*/
|
||||
protected function getArticle( IContextSource $context ): Article {
|
||||
$title = $context->getTitle();
|
||||
return Article::newFromTitle( $title, $context );
|
||||
return Article::newFromWikiPage( $context->getWikiPage(), $context );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\CommentFormatter\CommentFormatter;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageRecord;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use MediaWiki\Watchlist\WatchlistManager;
|
||||
|
|
@ -68,9 +67,6 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
/** @var CommentFormatter */
|
||||
private $commentFormatter;
|
||||
|
||||
/** @var PageRecord */
|
||||
private $pageRecord;
|
||||
|
||||
/**
|
||||
* @var RevisionRecord[] Revisions, with the key being their result offset
|
||||
*/
|
||||
|
|
@ -105,7 +101,6 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
) {
|
||||
parent::__construct( $historyPage->getContext() );
|
||||
$this->historyPage = $historyPage;
|
||||
$this->pageRecord = $historyPage->getWikiPage();
|
||||
$this->tagFilter = $tagFilter;
|
||||
$this->getDateCond( $year, $month, $day );
|
||||
$this->conds = $conds;
|
||||
|
|
@ -142,7 +137,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
'tables' => $revQuery['tables'],
|
||||
'fields' => $revQuery['fields'],
|
||||
'conds' => array_merge(
|
||||
[ 'rev_page' => $this->pageRecord->getId() ],
|
||||
[ 'rev_page' => $this->getWikiPage()->getId() ],
|
||||
$this->conds ),
|
||||
'options' => [ 'USE INDEX' => [ 'revision' => $revIndex ] ],
|
||||
'join_conds' => $revQuery['joins'],
|
||||
|
|
@ -176,7 +171,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
|
||||
$notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
|
||||
? $this->watchlistManager
|
||||
->getTitleNotificationTimestamp( $this->getUser(), $this->pageRecord )
|
||||
->getTitleNotificationTimestamp( $this->getUser(), $this->getTitle() )
|
||||
: false;
|
||||
|
||||
$s = $this->historyLine( $this->lastRow, $row, $notifTimestamp,
|
||||
|
|
@ -198,6 +193,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
# Do a link batch query
|
||||
$batch = $this->linkBatchFactory->newLinkBatch();
|
||||
$revIds = [];
|
||||
$title = $this->getTitle();
|
||||
foreach ( $this->mResult as $row ) {
|
||||
if ( $row->rev_parent_id ) {
|
||||
$revIds[] = (int)$row->rev_parent_id;
|
||||
|
|
@ -212,7 +208,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
$this->revisions[] = $this->revisionStore->newRevisionFromRow(
|
||||
$row,
|
||||
RevisionStore::READ_NORMAL,
|
||||
$this->pageRecord
|
||||
$title
|
||||
);
|
||||
}
|
||||
$this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
|
||||
|
|
@ -333,7 +329,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
|
||||
$notifTimestamp = $this->getConfig()->get( 'ShowUpdatedMarker' )
|
||||
? $this->watchlistManager
|
||||
->getTitleNotificationTimestamp( $this->getUser(), $this->pageRecord )
|
||||
->getTitleNotificationTimestamp( $this->getUser(), $this->getTitle() )
|
||||
: false;
|
||||
|
||||
$s = $this->historyLine( $this->lastRow, $next, $notifTimestamp,
|
||||
|
|
@ -389,12 +385,13 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
$previousRevRecord = $this->revisionStore->newRevisionFromRow(
|
||||
$next,
|
||||
RevisionStore::READ_NORMAL,
|
||||
$this->pageRecord
|
||||
$this->getTitle()
|
||||
);
|
||||
} else {
|
||||
$previousRevRecord = null;
|
||||
}
|
||||
$latest = $revRecord->getId() === $this->pageRecord->getLatest();
|
||||
|
||||
$latest = $revRecord->getId() === $this->getWikiPage()->getLatest();
|
||||
$curlink = $this->curLink( $revRecord );
|
||||
$lastlink = $this->lastLink( $revRecord, $next );
|
||||
$curLastlinks = Html::rawElement( 'span', [], $curlink ) .
|
||||
|
|
@ -487,8 +484,8 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
|
||||
# Rollback and undo links
|
||||
|
||||
if ( $previousRevRecord && $this->getAuthority()->probablyCan( 'edit', $this->pageRecord ) ) {
|
||||
if ( $latest && $this->getAuthority()->probablyCan( 'rollback', $this->pageRecord )
|
||||
if ( $previousRevRecord && $this->getAuthority()->probablyCan( 'edit', $this->getTitle() ) ) {
|
||||
if ( $latest && $this->getAuthority()->probablyCan( 'rollback', $this->getTitle() )
|
||||
) {
|
||||
// Get a rollback link without the brackets
|
||||
$rollbackLink = Linker::generateRollback(
|
||||
|
|
@ -510,7 +507,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
? [ 'title' => $this->msg( 'tooltip-undo' )->text() ]
|
||||
: [];
|
||||
$undolink = $this->getLinkRenderer()->makeKnownLink(
|
||||
$this->pageRecord,
|
||||
$this->getTitle(),
|
||||
$this->msg( 'editundo' )->text(),
|
||||
$undoTooltip,
|
||||
[
|
||||
|
|
@ -588,14 +585,14 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
*/
|
||||
private function curLink( RevisionRecord $rev ) {
|
||||
$cur = $this->historyPage->message['cur'];
|
||||
$latest = $this->pageRecord->getLatest();
|
||||
$latest = $this->getWikiPage()->getLatest();
|
||||
if ( $latest === $rev->getId()
|
||||
|| !$rev->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() )
|
||||
) {
|
||||
return $cur;
|
||||
} else {
|
||||
return $this->getLinkRenderer()->makeKnownLink(
|
||||
$this->pageRecord,
|
||||
$this->getTitle(),
|
||||
new HtmlArmor( $cur ),
|
||||
[],
|
||||
[
|
||||
|
|
@ -627,7 +624,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
if ( $next === 'unknown' ) {
|
||||
# Next row probably exists but is unknown, use an oldid=prev link
|
||||
return $linkRenderer->makeKnownLink(
|
||||
$this->pageRecord,
|
||||
$this->getTitle(),
|
||||
new HtmlArmor( $last ),
|
||||
[],
|
||||
[
|
||||
|
|
@ -640,7 +637,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
$nextRev = $this->revisionStore->newRevisionFromRow(
|
||||
$next,
|
||||
RevisionStore::READ_NORMAL,
|
||||
$this->pageRecord
|
||||
$this->getTitle()
|
||||
);
|
||||
|
||||
if ( !$prevRev->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ||
|
||||
|
|
@ -650,7 +647,7 @@ class HistoryPager extends ReverseChronologicalPager {
|
|||
}
|
||||
|
||||
return $linkRenderer->makeKnownLink(
|
||||
$this->pageRecord,
|
||||
$this->getTitle(),
|
||||
new HtmlArmor( $last ),
|
||||
[],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -1012,7 +1012,15 @@ class DifferenceEngine extends ContextSource {
|
|||
// NOTE: sync with hooks called in Article::view()
|
||||
} else {
|
||||
// Normal page
|
||||
$wikiPage = $this->wikiPageFactory->newFromTitle( $this->mNewPage );
|
||||
if ( $this->getTitle()->equals( $this->mNewPage ) ) {
|
||||
// If the Title stored in the context is the same as the one
|
||||
// of the new revision, we can use its associated WikiPage
|
||||
// object.
|
||||
$wikiPage = $this->getWikiPage();
|
||||
} else {
|
||||
// Otherwise we need to create our own WikiPage object
|
||||
$wikiPage = $this->wikiPageFactory->newFromTitle( $this->mNewPage );
|
||||
}
|
||||
|
||||
$parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRevisionRecord );
|
||||
|
||||
|
|
|
|||
|
|
@ -2529,7 +2529,7 @@ abstract class Skin extends ContextSource {
|
|||
|
||||
/** @var CreditsAction $action */
|
||||
if ( $useCredits ) {
|
||||
$article = Article::newFromTitle( $title, $this );
|
||||
$article = Article::newFromWikiPage( $this->getWikiPage(), $this );
|
||||
$action = Action::factory( 'credits', $article, $this );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1257,12 +1257,8 @@ class SkinTemplate extends Skin {
|
|||
// signal to hide this from simple content_actions
|
||||
$content_navigation['views']['view']['redundant'] = true;
|
||||
}
|
||||
$page = false;
|
||||
$title = $this->getTitle();
|
||||
if ( $title->canExist() ) {
|
||||
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
|
||||
}
|
||||
|
||||
$page = $this->canUseWikiPage() ? $this->getWikiPage() : false;
|
||||
$isRemoteContent = $page && !$page->isLocal();
|
||||
|
||||
// If it is a non-local file, show a link to the file in its own repository
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ use MediaWiki\Config\ServiceOptions;
|
|||
use MediaWiki\HookContainer\HookContainer;
|
||||
use MediaWiki\HookContainer\HookRunner;
|
||||
use MediaWiki\Linker\LinkRenderer;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageReference;
|
||||
use Profiler;
|
||||
use RequestContext;
|
||||
|
|
@ -1401,7 +1400,7 @@ class SpecialPageFactory {
|
|||
// phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgUser
|
||||
global $wgTitle, $wgOut, $wgRequest, $wgUser, $wgLang;
|
||||
$main = RequestContext::getMain();
|
||||
$title = $main->getTitle();
|
||||
|
||||
// Save current globals and main context
|
||||
$glob = [
|
||||
'title' => $wgTitle,
|
||||
|
|
@ -1411,16 +1410,14 @@ class SpecialPageFactory {
|
|||
'language' => $wgLang,
|
||||
];
|
||||
$ctx = [
|
||||
'title' => $title,
|
||||
'title' => $main->getTitle(),
|
||||
'output' => $main->getOutput(),
|
||||
'request' => $main->getRequest(),
|
||||
'user' => $main->getUser(),
|
||||
'language' => $main->getLanguage(),
|
||||
];
|
||||
|
||||
if ( $title && $title->canExist() ) {
|
||||
$wikiPage = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
|
||||
$ctx['wikipage'] = $wikiPage;
|
||||
if ( $main->canUseWikiPage() ) {
|
||||
$ctx['wikipage'] = $main->getWikiPage();
|
||||
}
|
||||
|
||||
// just needed for $wgTitle and RequestContext::setTitle
|
||||
|
|
|
|||
|
|
@ -62,12 +62,13 @@ class ExtraParserTest extends MediaWikiIntegrationTestCase {
|
|||
$options = ParserOptions::newFromUser( new User() );
|
||||
|
||||
RequestContext::getMain()->setTitle( $title );
|
||||
RequestContext::getMain()->getWikiPage()->CustomTestProp = true;
|
||||
|
||||
$parsed = $this->parser->parse( $text, $title, $options )->getText();
|
||||
$this->assertStringContainsString( 'apihelp-header', $parsed );
|
||||
|
||||
// Verify that this property wasn't wiped out by the parse
|
||||
$this->assertEquals( $title, RequestContext::getMain()->getTitle() );
|
||||
$this->assertTrue( RequestContext::getMain()->getWikiPage()->CustomTestProp );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -105,7 +105,6 @@ class ActionTest extends MediaWikiIntegrationTestCase {
|
|||
$context = new DerivativeContext( RequestContext::getMain() );
|
||||
$context->setRequest( $request );
|
||||
$context->setWikiPage( $this->getPage() );
|
||||
$context->setTitle( $this->getPage()->getTitle() );
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Permissions\UltimateAuthority;
|
||||
use MediaWiki\User\UserIdentityValue;
|
||||
|
||||
|
|
@ -20,8 +19,7 @@ class RequestContextTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
$curTitle = Title::newFromText( "A" );
|
||||
$context->setTitle( $curTitle );
|
||||
$wikiPage = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $context->getTitle() );
|
||||
$this->assertTrue( $curTitle->equals( $wikiPage->getTitle() ),
|
||||
$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" );
|
||||
|
|
@ -31,9 +29,8 @@ class RequestContextTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
$curTitle = Title::newFromText( "C" );
|
||||
$context->setTitle( $curTitle );
|
||||
$wikiPage = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $context->getTitle() );
|
||||
$this->assertTrue(
|
||||
$curTitle->equals( $wikiPage->getTitle() ),
|
||||
$curTitle->equals( $context->getWikiPage()->getTitle() ),
|
||||
"When a title is updated the WikiPage should be purged "
|
||||
. "and recreated on-demand with the new title."
|
||||
);
|
||||
|
|
|
|||
|
|
@ -275,9 +275,7 @@ class ActionFactoryTest extends MediaWikiUnitTestCase {
|
|||
array $hooks = []
|
||||
) {
|
||||
$context = $this->createMock( IContextSource::class );
|
||||
$title = $this->createMock( Title::class );
|
||||
$title->method( 'canExist' )->willReturn( true );
|
||||
$context->method( 'getTitle' )->willReturn( $title );
|
||||
$context->method( 'canUseWikiPage' )->willReturn( true );
|
||||
|
||||
$request = new FauxRequest( [
|
||||
'action' => $requestAction,
|
||||
|
|
|
|||
Loading…
Reference in a new issue