summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLegoktm <legoktm@debian.org>2021-12-14 20:34:46 +0000
committerLegoktm <legoktm@debian.org>2021-12-14 21:29:37 +0000
commitab0018128e82d81c3c659ee0b01ac3902768c7ae (patch)
tree9af2688220591ca2238bb42b97097235048da62b
parent6a9160bb09adbd2e3eed924e5ba59c9b82cef6b7 (diff)
Revert "Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage"
This reverts commit ef458e894888d5d984f6b8dcf75cfae008d544d0. Reason for revert: Causes page tabs to disappear on Special:WhatLinksHere. Bug: T297744 Change-Id: I0ee282a9f7a5a9b2cfdc3261d800d9e27eaf977e (cherry picked from commit 93f79a9122e21bac30d7aaa4961ddf76706710db)
-rw-r--r--includes/MediaWiki.php25
-rw-r--r--includes/OutputPage.php7
-rw-r--r--includes/actions/ActionFactory.php6
-rw-r--r--includes/actions/pagers/HistoryPager.php35
-rw-r--r--includes/diff/DifferenceEngine.php10
-rw-r--r--includes/skins/Skin.php2
-rw-r--r--includes/skins/SkinTemplate.php6
-rw-r--r--includes/specialpage/SpecialPageFactory.php11
-rw-r--r--tests/phpunit/includes/ExtraParserTest.php3
-rw-r--r--tests/phpunit/includes/actions/ActionTest.php1
-rw-r--r--tests/phpunit/includes/context/RequestContextTest.php7
-rw-r--r--tests/phpunit/unit/includes/actions/ActionFactoryTest.php4
12 files changed, 56 insertions, 61 deletions
diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index 217e232e7cb9..0c809532e2c4 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -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();
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 94e9dc1bed1a..03ad08125e02 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -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();
diff --git a/includes/actions/ActionFactory.php b/includes/actions/ActionFactory.php
index a0a68988834a..c966854607da 100644
--- a/includes/actions/ActionFactory.php
+++ b/includes/actions/ActionFactory.php
@@ -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 );
}
}
diff --git a/includes/actions/pagers/HistoryPager.php b/includes/actions/pagers/HistoryPager.php
index 33b5f64af667..f3cbb096493d 100644
--- a/includes/actions/pagers/HistoryPager.php
+++ b/includes/actions/pagers/HistoryPager.php
@@ -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 ),
[],
[
diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php
index 88e26d2ff3cf..40cd7e0270f3 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -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 );
diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php
index 5236dd1db81f..6046de0c7b24 100644
--- a/includes/skins/Skin.php
+++ b/includes/skins/Skin.php
@@ -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 );
}
diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php
index ec4f39a436d4..6ad28196d1d5 100644
--- a/includes/skins/SkinTemplate.php
+++ b/includes/skins/SkinTemplate.php
@@ -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
diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php
index 95a53751a1fc..23335efae33d 100644
--- a/includes/specialpage/SpecialPageFactory.php
+++ b/includes/specialpage/SpecialPageFactory.php
@@ -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
diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php
index 672b2395411a..6fdff0480c96 100644
--- a/tests/phpunit/includes/ExtraParserTest.php
+++ b/tests/phpunit/includes/ExtraParserTest.php
@@ -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 );
}
/**
diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php
index b7cd67b91a2a..aacea68be9fc 100644
--- a/tests/phpunit/includes/actions/ActionTest.php
+++ b/tests/phpunit/includes/actions/ActionTest.php
@@ -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;
}
diff --git a/tests/phpunit/includes/context/RequestContextTest.php b/tests/phpunit/includes/context/RequestContextTest.php
index de249825a206..cb2b9cee582d 100644
--- a/tests/phpunit/includes/context/RequestContextTest.php
+++ b/tests/phpunit/includes/context/RequestContextTest.php
@@ -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."
);
diff --git a/tests/phpunit/unit/includes/actions/ActionFactoryTest.php b/tests/phpunit/unit/includes/actions/ActionFactoryTest.php
index 8eaeef760459..63cfa566d3e7 100644
--- a/tests/phpunit/unit/includes/actions/ActionFactoryTest.php
+++ b/tests/phpunit/unit/includes/actions/ActionFactoryTest.php
@@ -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,