Remove direct access to Action::page and Article::page properties

Bug: T239975
Change-Id: Id0d4d1e099edbdd67cabbed423dfff68cc48d323
This commit is contained in:
ArtBaltai 2020-03-26 03:43:50 +03:00 committed by Ppchelko
parent 5d9e300534
commit 726a2650d3
20 changed files with 90 additions and 65 deletions

View file

@ -2007,8 +2007,8 @@ class Linker {
* Returns HTML for the "hidden categories on this page" list.
*
* @since 1.16.3
* @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
* or similar
* @param array $hiddencats Array of hidden categories
* from {@link WikiPage::getHiddenCategories} or similar
* @return string HTML output
*/
public static function formatHiddenCategories( $hiddencats ) {

View file

@ -210,7 +210,7 @@ class ProtectionForm {
if ( $this->mContext->getRequest()->wasPosted() ) {
if ( $this->save() ) {
$q = $this->mArticle->isRedirect() ? 'redirect=no' : '';
$q = $this->mArticle->getPage()->isRedirect() ? 'redirect=no' : '';
$this->mContext->getOutput()->redirect( $this->mTitle->getFullURL( $q ) );
}
} else {
@ -333,7 +333,7 @@ class ProtectionForm {
$this->mCascade = $request->getBool( 'mwProtect-cascade' );
$status = $this->mArticle->doUpdateRestrictions(
$status = $this->mArticle->getPage()->doUpdateRestrictions(
$this->mRestrictions,
$expiry,
$this->mCascade,

View file

@ -168,7 +168,7 @@ abstract class CachedAction extends FormlessAction implements ICacheHelper {
*/
protected function getCacheKey() {
return [
get_class( $this->page ),
get_class( $this->getArticle() ),
$this->getName(),
$this->getLanguage()->getCode()
];

View file

@ -44,7 +44,7 @@ class CreditsAction extends FormlessAction {
* @return string HTML
*/
public function onView() {
if ( $this->page->getID() == 0 ) {
if ( $this->getWikiPage()->getID() == 0 ) {
$s = $this->msg( 'nocredits' )->parse();
} else {
$s = $this->getCredits( -1 );
@ -64,7 +64,7 @@ class CreditsAction extends FormlessAction {
$s = '';
if ( $cnt != 0 ) {
$s = $this->getAuthor( $this->page );
$s = $this->getAuthor();
if ( $cnt > 1 || $cnt < 0 ) {
$s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
}
@ -75,12 +75,12 @@ class CreditsAction extends FormlessAction {
/**
* Get the last author with the last modification time
* @param Page $page
*
* @return string HTML
*/
protected function getAuthor( Page $page ) {
$wikipage = $page instanceof Article ? $page->getPage() : $page;
$user = User::newFromName( $wikipage->getUserText(), false );
private function getAuthor() {
$page = $this->getWikiPage();
$user = User::newFromName( $page->getUserText(), false );
$timestamp = $page->getTimestamp();
if ( $timestamp ) {
@ -114,7 +114,7 @@ class CreditsAction extends FormlessAction {
* @return string Html
*/
protected function getContributors( $cnt, $showIfMax ) {
$contributors = $this->page->getContributors();
$contributors = $this->getWikiPage()->getContributors();
$others_link = false;

View file

@ -38,7 +38,7 @@ class DeleteAction extends FormlessAction {
public function show() {
$this->useTransactionalTimeLimit();
$this->addHelpLink( 'Help:Sysop deleting and undeleting' );
$this->page->delete();
$this->getArticle()->delete();
}
public function doesWrites() {

View file

@ -74,7 +74,14 @@ abstract class FormAction extends Action {
$this->fields = $this->getFormFields();
// Give hooks a chance to alter the form, adding extra fields or text etc
Hooks::run( 'ActionModifyFormFields', [ $this->getName(), &$this->fields, $this->page ] );
Hooks::run(
'ActionModifyFormFields',
[
$this->getName(),
&$this->fields,
$this->getArticle()
]
);
if ( $this->usesOOUI() ) {
$form = HTMLForm::factory( 'ooui', $this->fields, $this->getContext(), $this->getName() );
@ -99,7 +106,11 @@ abstract class FormAction extends Action {
$this->alterForm( $form );
// Give hooks a chance to alter the form, adding extra fields or text etc
Hooks::run( 'ActionBeforeFormDisplay', [ $this->getName(), &$form, $this->page ] );
Hooks::run( 'ActionBeforeFormDisplay', [
$this->getName(),
&$form,
$this->getArticle()
] );
return $form;
}

View file

@ -81,13 +81,6 @@ class HistoryAction extends FormlessAction {
return Html::rawElement( 'div', [ 'class' => 'mw-history-subtitle' ], $subtitle );
}
/**
* @return WikiPage|Article|ImagePage|CategoryPage|Page The Article object we are working on.
*/
public function getArticle() {
return $this->page;
}
/**
* As we use the same small set of messages in various methods and that
* they are called often, we call them once and save them in $this->message
@ -158,7 +151,7 @@ class HistoryAction extends FormlessAction {
// markers to appear, is for the page to be edited, which updates page_touched/Last-Modified.
if (
!$this->hasUnseenRevisionMarkers() &&
$out->checkLastModified( $this->page->getTouched() )
$out->checkLastModified( $this->getWikiPage()->getTouched() )
) {
return null; // Client cache fresh and headers sent, nothing more to do.
}
@ -203,7 +196,7 @@ class HistoryAction extends FormlessAction {
);
// Fail nicely if article doesn't exist.
if ( !$this->page->exists() ) {
if ( !$this->getWikiPage()->exists() ) {
global $wgSend404Code;
if ( $wgSend404Code ) {
$out->setStatusCode( 404 );
@ -290,7 +283,13 @@ class HistoryAction extends FormlessAction {
$out->addHTML( $htmlForm->getHTML( false ) );
Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
Hooks::run(
'PageHistoryBeforeList',
[
$this->getArticle(),
$this->getContext()
]
);
// Create and output the list.
$dateComponents = explode( '-', $ts );
@ -354,7 +353,7 @@ class HistoryAction extends FormlessAction {
$offsets = [];
}
$page_id = $this->page->getId();
$page_id = $this->getWikiPage()->getId();
$revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo();
return $dbr->select(

View file

@ -91,9 +91,9 @@ class InfoAction extends FormlessAction {
$content = '';
// Validate revision
$oldid = $this->page->getOldID();
$oldid = $this->getArticle()->getOldID();
if ( $oldid ) {
$revision = $this->page->getRevisionFetched();
$revision = $this->getArticle()->getRevisionFetched();
// Revision is missing
if ( $revision === null ) {
@ -227,7 +227,7 @@ class InfoAction extends FormlessAction {
$config = $this->context->getConfig();
$linkRenderer = $services->getLinkRenderer();
$pageCounts = $this->pageCounts( $this->page );
$pageCounts = $this->pageCounts();
$props = PageProps::getInstance()->getAllProperties( $title );
$pageProperties = $props[$id] ?? [];
@ -244,7 +244,7 @@ class InfoAction extends FormlessAction {
];
// Is it a redirect? If so, where to?
$redirectTarget = $this->page->getRedirectTarget();
$redirectTarget = $this->getWikiPage()->getRedirectTarget();
if ( $redirectTarget !== null ) {
$pageInfo['header-basic'][] = [
$this->msg( 'pageinfo-redirectsto' ),
@ -335,7 +335,7 @@ class InfoAction extends FormlessAction {
}
// Use robot policy logic
$policy = $this->page->getRobotPolicy( 'view', $pOutput );
$policy = $this->getArticle()->getRobotPolicy( 'view', $pOutput );
$pageInfo['header-basic'][] = [
// Messages: pageinfo-robot-index, pageinfo-robot-noindex
$this->msg( 'pageinfo-robot-policy' ),
@ -395,7 +395,7 @@ class InfoAction extends FormlessAction {
];
// Is it counted as a content page?
if ( $this->page->isCountable() ) {
if ( $this->getWikiPage()->isCountable() ) {
$pageInfo['header-basic'][] = [
$this->msg( 'pageinfo-contentpage' ),
$this->msg( 'pageinfo-contentpage-yes' )
@ -530,7 +530,7 @@ class InfoAction extends FormlessAction {
),
];
if ( !$this->page->exists() ) {
if ( !$this->getWikiPage()->exists() ) {
return $pageInfo;
}
@ -539,8 +539,8 @@ class InfoAction extends FormlessAction {
$firstRev = MediaWikiServices::getInstance()
->getRevisionLookup()
->getFirstRevision( $this->page->getTitle() );
$lastRev = $this->page->getRevision();
->getFirstRevision( $this->getTitle() );
$lastRev = $this->getWikiPage()->getRevision();
$batch = new LinkBatch;
if ( $firstRev ) {
@ -592,9 +592,9 @@ class InfoAction extends FormlessAction {
$this->msg( 'pageinfo-lasttime' ),
$linkRenderer->makeKnownLink(
$title,
$lang->userTimeAndDate( $this->page->getTimestamp(), $user ),
$lang->userTimeAndDate( $this->getWikiPage()->getTimestamp(), $user ),
[],
[ 'oldid' => $this->page->getLatest() ]
[ 'oldid' => $this->getWikiPage()->getLatest() ]
)
];
}
@ -641,7 +641,7 @@ class InfoAction extends FormlessAction {
}
$localizedList = Html::rawElement( 'ul', [], implode( '', $listItems ) );
$hiddenCategories = $this->page->getHiddenCategories();
$hiddenCategories = $this->getWikiPage()->getHiddenCategories();
if (
count( $listItems ) > 0 ||
@ -728,10 +728,10 @@ class InfoAction extends FormlessAction {
/**
* Returns page counts that would be too "expensive" to retrieve by normal means.
*
* @param WikiPage|Article|Page $page
* @return array
*/
protected function pageCounts( Page $page ) {
private function pageCounts() {
$page = $this->getWikiPage();
$fname = __METHOD__;
$config = $this->context->getConfig();
$services = MediaWikiServices::getInstance();
@ -888,7 +888,7 @@ class InfoAction extends FormlessAction {
* @return string Html
*/
protected function getContributors() {
$contributors = $this->page->getContributors();
$contributors = $this->getWikiPage()->getContributors();
$real_names = [];
$user_names = [];
$anon_ips = [];

View file

@ -26,7 +26,7 @@ class McrRestoreAction extends McrUndoAction {
}
protected function initFromParameters() {
$curRev = $this->page->getRevision();
$curRev = $this->getWikiPage()->getRevision();
if ( !$curRev ) {
throw new ErrorPageError( 'mcrundofailed', 'nopagetext' );
}

View file

@ -98,7 +98,7 @@ class McrUndoAction extends FormAction {
throw new ErrorPageError( 'mcrundofailed', 'mcrundo-missingparam' );
}
$curRev = $this->page->getRevision();
$curRev = $this->getWikiPage()->getRevision();
if ( !$curRev ) {
throw new ErrorPageError( 'mcrundofailed', 'nopagetext' );
}
@ -260,7 +260,7 @@ class McrUndoAction extends FormAction {
$note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
$parserOptions = $this->page->makeParserOptions( $this->context );
$parserOptions = $this->getWikiPage()->makeParserOptions( $this->context );
$parserOptions->setIsPreview( true );
$parserOptions->setIsSectionPreview( false );
$parserOptions->enableLimitReport();
@ -310,7 +310,7 @@ class McrUndoAction extends FormAction {
return false;
}
$updater = $this->page->getPage()->newPageUpdater( $this->context->getUser() );
$updater = $this->getWikiPage()->newPageUpdater( $this->context->getUser() );
$curRev = $updater->grabParentRevision();
if ( !$curRev ) {
throw new ErrorPageError( 'mcrundofailed', 'nopagetext' );

View file

@ -44,7 +44,7 @@ class ProtectAction extends FormlessAction {
] );
}
$this->page->protect();
$this->getArticle()->protect();
}
public function doesWrites() {

View file

@ -42,7 +42,7 @@ class PurgeAction extends FormAction {
}
public function onSubmit( $data ) {
return $this->page->doPurge();
return $this->getWikiPage()->doPurge();
}
public function show() {

View file

@ -59,7 +59,9 @@ class RawAction extends FormlessAction {
$response = $request->response();
$config = $this->context->getConfig();
if ( $this->getOutput()->checkLastModified( $this->page->getTouched() ) ) {
if ( $this->getOutput()->checkLastModified(
$this->getWikiPage()->getTouched()
) ) {
return null; // Client cache fresh and headers sent, nothing more to do.
}
@ -255,7 +257,7 @@ class RawAction extends FormlessAction {
$prevRev = null;
if ( !$oldid ) {
# get the current revision so we can get the penultimate one
$oldid = $this->page->getLatest();
$oldid = $this->getWikiPage()->getLatest();
}
$oldRev = $rl->getRevisionById( $oldid );
if ( $oldRev ) {

View file

@ -36,6 +36,6 @@ class RenderAction extends FormlessAction {
}
public function show() {
$this->page->render();
$this->getArticle()->render();
}
}

View file

@ -94,7 +94,7 @@ class RollbackAction extends FormAction {
$request = $this->getRequest();
$user = $this->getUser();
$from = $request->getVal( 'from' );
$rev = $this->page->getRevision();
$rev = $this->getWikiPage()->getRevision();
if ( $from === null ) {
throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
}
@ -110,7 +110,7 @@ class RollbackAction extends FormAction {
}
$data = null;
$errors = $this->page->doRollback(
$errors = $this->getWikiPage()->doRollback(
$from,
$request->getText( 'summary' ),
$request->getVal( 'token' ),
@ -175,7 +175,7 @@ class RollbackAction extends FormAction {
);
if ( $user->getBoolOption( 'watchrollback' ) ) {
$user->addWatch( $this->page->getTitle(), User::IGNORE_USER_RIGHTS );
$user->addWatch( $this->getTitle(), User::IGNORE_USER_RIGHTS );
}
$this->getOutput()->returnToMain( false, $this->getTitle() );

View file

@ -32,7 +32,7 @@ class UnprotectAction extends ProtectAction {
}
public function show() {
$this->page->unprotect();
$this->getArticle()->unprotect();
}
public function doesWrites() {

View file

@ -40,14 +40,17 @@ class ViewAction extends FormlessAction {
if (
$config->get( 'DebugToolbar' ) == false && // don't let this get stuck on pages
$this->page->checkTouched() // page exists and is not a redirect
$this->getWikiPage()->checkTouched() // page exists and is not a redirect
) {
// Include any redirect in the last-modified calculation
$redirFromTitle = $this->page->getRedirectedFrom();
$redirFromTitle = $this->getArticle()->getRedirectedFrom();
if ( !$redirFromTitle ) {
$touched = $this->page->getTouched();
$touched = $this->getWikiPage()->getTouched();
} elseif ( $config->get( 'MaxRedirects' ) <= 1 ) {
$touched = max( $this->page->getTouched(), $redirFromTitle->getTouched() );
$touched = max(
$this->getWikiPage()->getTouched(),
$redirFromTitle->getTouched()
);
} else {
// Don't bother following the chain and getting the max mtime
$touched = null;
@ -60,6 +63,6 @@ class ViewAction extends FormlessAction {
}
}
$this->page->view();
$this->getArticle()->view();
}
}

View file

@ -25,7 +25,7 @@
* Special handling for category description pages, showing pages,
* subcategories and file that belong to the category
*
* @property WikiCategoryPage $mPage Set by overwritten newPage() in this class
* @method WikiCategoryPage getPage() Set by overwritten newPage() in this class
*/
class CategoryPage extends Article {
# Subclasses can change this to override the viewer class.
@ -71,7 +71,10 @@ class CategoryPage extends Article {
# Use adaptive TTLs for CDN so delayed/failed purges are noticed less often
$outputPage = $this->getContext()->getOutput();
$outputPage->adaptCdnTTL( $this->mPage->getTouched(), IExpiringStore::TTL_MINUTE );
$outputPage->adaptCdnTTL(
$this->getPage()->getTouched(),
IExpiringStore::TTL_MINUTE
);
}
function openShowCategory() {

View file

@ -379,7 +379,13 @@ class SkinTemplate extends Skin {
if ( $wgMaxCredits != 0 ) {
/** @var CreditsAction $action */
$action = Action::factory(
'credits', $this->getWikiPage(), $this->getContext() );
'credits',
Article::newFromWikiPage(
$this->getWikiPage(),
$this->getContext()
),
$this->getContext()
);
'@phan-var CreditsAction $action';
$tpl->set( 'credits',
$action->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );

View file

@ -129,7 +129,8 @@ class ArticleViewTest extends MediaWikiTestCase {
}
/**
* @covers Article::getRedirectTarget()
* @covers Article::getPage()
* @covers WikiPage::getRedirectTarget()
*/
public function testViewRedirect() {
$target = Title::makeTitle( $this->getDefaultWikitextNS(), 'Test_Target' );
@ -142,11 +143,11 @@ class ArticleViewTest extends MediaWikiTestCase {
$article->view();
$this->assertNotNull(
$article->getRedirectTarget()->getPrefixedDBkey()
$article->getPage()->getRedirectTarget()->getPrefixedDBkey()
);
$this->assertSame(
$target->getPrefixedDBkey(),
$article->getRedirectTarget()->getPrefixedDBkey()
$article->getPage()->getRedirectTarget()->getPrefixedDBkey()
);
$output = $article->getContext()->getOutput();