Revert "Make WikiPage a ProperPageIdentity"
This reverts commit 8f46ef5ff4.
This has seemingly broken FlaggedRevs and thus a bunch of repos.
Bug: T272170
Change-Id: I67de3dbbbc9163aae937f710ecb0e40db0d483a0
This commit is contained in:
parent
a8fe6c9841
commit
a547ef3b9e
6 changed files with 29 additions and 140 deletions
|
|
@ -249,14 +249,13 @@ class ApiParse extends ApiBase {
|
|||
$wgTitle = $titleObj;
|
||||
if ( $titleObj->canExist() ) {
|
||||
$pageObj = WikiPage::factory( $titleObj );
|
||||
list( $popts, $reset ) = $this->makeParserOptions( $pageObj, $params );
|
||||
} else { // A special page, presumably
|
||||
// XXX: Why is this needed at all? Can't we just fail?
|
||||
$pageObj = null;
|
||||
$popts = ParserOptions::newCanonical( $this->getContext() );
|
||||
list( $popts, $reset ) = $this->tweakParserOptions( $popts, $titleObj, $params );
|
||||
} else {
|
||||
// Do like MediaWiki::initializeArticle()
|
||||
$article = Article::newFromTitle( $titleObj, $this->getContext() );
|
||||
$pageObj = $article->getPage();
|
||||
}
|
||||
|
||||
list( $popts, $reset ) = $this->makeParserOptions( $pageObj, $params );
|
||||
$textProvided = $text !== null;
|
||||
|
||||
if ( !$textProvided ) {
|
||||
|
|
@ -332,7 +331,7 @@ class ApiParse extends ApiBase {
|
|||
$result_array = [];
|
||||
|
||||
$result_array['title'] = $titleObj->getPrefixedText();
|
||||
$result_array['pageid'] = $pageid ?: $titleObj->getArticleID();
|
||||
$result_array['pageid'] = $pageid ?: $pageObj->getId();
|
||||
if ( $this->contentIsDeleted ) {
|
||||
$result_array['textdeleted'] = true;
|
||||
}
|
||||
|
|
@ -361,10 +360,7 @@ class ApiParse extends ApiBase {
|
|||
// - Hook: OutputPageBeforeHTML
|
||||
$context = new DerivativeContext( $this->getContext() );
|
||||
$context->setTitle( $titleObj );
|
||||
|
||||
if ( $pageObj ) {
|
||||
$context->setWikiPage( $pageObj );
|
||||
}
|
||||
$context->setWikiPage( $pageObj );
|
||||
// Some hooks only apply to pages when action=view, which this API
|
||||
// call is simulating.
|
||||
$context->setRequest( new FauxRequest( [ 'action' => 'view' ] ) );
|
||||
|
|
@ -608,21 +604,8 @@ class ApiParse extends ApiBase {
|
|||
*
|
||||
* @return array [ ParserOptions, ScopedCallback, bool $suppressCache ]
|
||||
*/
|
||||
private function makeParserOptions( WikiPage $pageObj, array $params ) {
|
||||
protected function makeParserOptions( WikiPage $pageObj, array $params ) {
|
||||
$popts = $pageObj->makeParserOptions( $this->getContext() );
|
||||
return $this->tweakParserOptions( $popts, $pageObj->getTitle(), $params );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaks a ParserOptions object
|
||||
*
|
||||
* @param ParserOptions $popts
|
||||
* @param Title $title
|
||||
* @param array $params
|
||||
*
|
||||
* @return array [ ParserOptions, ScopedCallback, bool $suppressCache ]
|
||||
*/
|
||||
private function tweakParserOptions( ParserOptions $popts, Title $title, array $params ) {
|
||||
$popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
|
||||
$popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
|
||||
$popts->setIsSectionPreview( $params['sectionpreview'] );
|
||||
|
|
@ -633,7 +616,7 @@ class ApiParse extends ApiBase {
|
|||
|
||||
$reset = null;
|
||||
$suppressCache = false;
|
||||
$this->getHookRunner()->onApiMakeParserOptions( $popts, $title,
|
||||
$this->getHookRunner()->onApiMakeParserOptions( $popts, $pageObj->getTitle(),
|
||||
$params, $this, $reset, $suppressCache );
|
||||
|
||||
return [ $popts, $reset, $suppressCache ];
|
||||
|
|
|
|||
|
|
@ -28,9 +28,7 @@ use MediaWiki\Edit\PreparedEdit;
|
|||
use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageIdentity;
|
||||
use MediaWiki\Page\ParserOutputAccess;
|
||||
use MediaWiki\Page\ProperPageIdentity;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionRenderer;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
|
|
@ -42,7 +40,6 @@ use MediaWiki\Storage\EditResultCache;
|
|||
use MediaWiki\Storage\PageUpdater;
|
||||
use MediaWiki\Storage\RevisionSlotsUpdate;
|
||||
use Wikimedia\Assert\Assert;
|
||||
use Wikimedia\Assert\PreconditionException;
|
||||
use Wikimedia\IPUtils;
|
||||
use Wikimedia\NonSerializable\NonSerializableTrait;
|
||||
use Wikimedia\Rdbms\FakeResultWrapper;
|
||||
|
|
@ -55,7 +52,7 @@ use Wikimedia\Rdbms\LoadBalancer;
|
|||
* Some fields are public only for backwards-compatibility. Use accessors.
|
||||
* In the past, this class was part of Article.php and everything was public.
|
||||
*/
|
||||
class WikiPage implements Page, IDBAccessObject, ProperPageIdentity {
|
||||
class WikiPage implements Page, IDBAccessObject {
|
||||
use NonSerializableTrait;
|
||||
use ProtectedHookAccessorTrait;
|
||||
|
||||
|
|
@ -137,17 +134,9 @@ class WikiPage implements Page, IDBAccessObject, ProperPageIdentity {
|
|||
private $derivedDataUpdater = null;
|
||||
|
||||
/**
|
||||
* @param PageIdentity $pageIdentity
|
||||
* @param Title $title
|
||||
*/
|
||||
public function __construct( PageIdentity $pageIdentity ) {
|
||||
$pageIdentity->assertWiki( PageIdentity::LOCAL );
|
||||
|
||||
if ( !$pageIdentity->canExist() ) {
|
||||
throw new MWException( "Title '$pageIdentity' cannot exist as a page" );
|
||||
}
|
||||
|
||||
// TODO: remove the need for casting to Title.
|
||||
$title = Title::castFromPageIdentity( $pageIdentity );
|
||||
public function __construct( Title $title ) {
|
||||
$this->mTitle = $title;
|
||||
}
|
||||
|
||||
|
|
@ -160,18 +149,16 @@ class WikiPage implements Page, IDBAccessObject, ProperPageIdentity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a WikiPage object of the appropriate class for the given PageIdentity.
|
||||
* The PageIdentity must represent a proper page that can exist on the wiki,
|
||||
* that is, not a special page or media link or section link or interwiki link.
|
||||
* Create a WikiPage object of the appropriate class for the given title.
|
||||
*
|
||||
* @param PageIdentity $pageIdentity
|
||||
* @param Title $title
|
||||
*
|
||||
* @throws MWException
|
||||
* @return WikiPage|WikiCategoryPage|WikiFilePage
|
||||
* @deprecated since 1.36, use WikiPageFactory::newFromTitle instead
|
||||
*/
|
||||
public static function factory( PageIdentity $pageIdentity ) {
|
||||
return MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $pageIdentity );
|
||||
public static function factory( Title $title ) {
|
||||
return MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -553,30 +540,9 @@ class WikiPage implements Page, IDBAccessObject, ProperPageIdentity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Throws if $wikiId is not PageIdentity::LOCAL.
|
||||
*
|
||||
* @since 1.36
|
||||
*
|
||||
* @param string|false $wikiId The wiki ID expected by the caller.
|
||||
* @throws PreconditionException
|
||||
*/
|
||||
public function assertWiki( $wikiId ) {
|
||||
if ( $wikiId !== PageIdentity::LOCAL ) {
|
||||
throw new PreconditionException(
|
||||
"Expected this PageIdentity to belong to $wikiId, "
|
||||
. 'but it belongs to the local wiki'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|false $wikiId
|
||||
*
|
||||
* @return int Page ID
|
||||
*/
|
||||
public function getId( $wikiId = PageIdentity::LOCAL ) {
|
||||
$this->assertWiki( $wikiId );
|
||||
|
||||
public function getId() {
|
||||
if ( !$this->mDataLoaded ) {
|
||||
$this->loadPageData();
|
||||
}
|
||||
|
|
@ -4070,44 +4036,4 @@ class WikiPage implements Page, IDBAccessObject, ProperPageIdentity {
|
|||
$this->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @since 1.36
|
||||
*/
|
||||
public function getNamespace() {
|
||||
return $this->getTitle()->getNamespace();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @since 1.36
|
||||
*/
|
||||
public function getDBkey() {
|
||||
return $this->getTitle()->getDBkey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false PageIdentity::LOCAL
|
||||
* @since 1.36
|
||||
*/
|
||||
public function getWikiId() {
|
||||
return $this->getTitle()->getWikiId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true
|
||||
* @since 1.36
|
||||
*/
|
||||
public function canExist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @since 1.36
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->mTitle->__toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use DBAccessObjectUtils;
|
|||
use InvalidArgumentException;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Page\Hook\WikiPageFactoryHook;
|
||||
use stdClass;
|
||||
use Title;
|
||||
use TitleFactory;
|
||||
use WikiCategoryPage;
|
||||
|
|
@ -46,27 +45,19 @@ class WikiPageFactory {
|
|||
/**
|
||||
* Create a WikiPage object from a title.
|
||||
*
|
||||
* @param PageIdentity $pageIdentity
|
||||
* @param Title $title
|
||||
*
|
||||
* @return WikiPage
|
||||
*/
|
||||
public function newFromTitle( PageIdentity $pageIdentity ) {
|
||||
if ( $pageIdentity instanceof WikiPage ) {
|
||||
return $pageIdentity;
|
||||
public function newFromTitle( Title $title ) {
|
||||
$ns = $title->getNamespace();
|
||||
|
||||
if ( $ns == NS_MEDIA ) {
|
||||
throw new InvalidArgumentException( "NS_MEDIA is a virtual namespace; use NS_FILE." );
|
||||
} elseif ( $ns < 0 ) {
|
||||
throw new InvalidArgumentException( "Invalid or virtual namespace $ns given." );
|
||||
}
|
||||
|
||||
if ( !$pageIdentity->canExist() ) {
|
||||
throw new InvalidArgumentException(
|
||||
"The given PageIdentity does not represent a proper page"
|
||||
);
|
||||
}
|
||||
|
||||
$ns = $pageIdentity->getNamespace();
|
||||
|
||||
// TODO: remove the need for casting to Title. We'll have to create a new hook to
|
||||
// replace the WikiPageFactory hook.
|
||||
$title = Title::castFromPageIdentity( $pageIdentity );
|
||||
|
||||
$page = null;
|
||||
if ( !$this->wikiPageFactoryHookRunner->onWikiPageFactory( $title, $page ) ) {
|
||||
return $page;
|
||||
|
|
@ -100,7 +91,7 @@ class WikiPageFactory {
|
|||
/**
|
||||
* Create a WikiPage object from a database row
|
||||
*
|
||||
* @param stdClass $row Database row containing at least fields returned by getQueryInfo().
|
||||
* @param \stdClass $row Database row containing at least fields returned by getQueryInfo().
|
||||
* @param string|int $from Source of $data:
|
||||
* - "fromdb" or WikiPage::READ_NORMAL: from a replica DB
|
||||
* - "fromdbmaster" or WikiPage::READ_LATEST: from the master DB
|
||||
|
|
|
|||
|
|
@ -34,11 +34,6 @@ class PrefixSearchTest extends MediaWikiLangTestCase {
|
|||
|
||||
$this->insertPage( 'User:Example' );
|
||||
|
||||
$this->setMwGlobals( [
|
||||
'wgExtraNamespaces' => [ self::NS_NONCAP => 'NonCap' ],
|
||||
'wgCapitalLinkOverrides' => [ self::NS_NONCAP => false ],
|
||||
] );
|
||||
|
||||
$this->insertPage( Title::makeTitle( self::NS_NONCAP, 'Bar' ) );
|
||||
$this->insertPage( Title::makeTitle( self::NS_NONCAP, 'Upper' ) );
|
||||
$this->insertPage( Title::makeTitle( self::NS_NONCAP, 'sandbox' ) );
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class ArticleTest extends \MediaWikiIntegrationTestCase {
|
|||
*/
|
||||
public function testMissingArticleMessage() {
|
||||
// Use a well-known system message
|
||||
$title = Title::makeTitle( NS_MEDIAWIKI, 'Uploadedimage' );
|
||||
$title = Title::makeTitle( NS_MEDIAWIKI, 'uploadedimage' );
|
||||
$article = new Article( $title, 0 );
|
||||
$article->getContext()->getOutput()->setTitle( $title );
|
||||
$article->showMissingArticle();
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
use MediaWiki\Edit\PreparedEdit;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageIdentity;
|
||||
use MediaWiki\Page\PageIdentityValue;
|
||||
use MediaWiki\Revision\MutableRevisionRecord;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
|
|
@ -915,7 +913,9 @@ class WikiPageDbTest extends MediaWikiLangTestCase {
|
|||
public function provideHasViewableContent() {
|
||||
return [
|
||||
[ 'WikiPageTest_testHasViewableContent', false, true ],
|
||||
[ 'Special:WikiPageTest_testHasViewableContent', false ],
|
||||
[ 'MediaWiki:WikiPageTest_testHasViewableContent', false ],
|
||||
[ 'Special:Userlogin', true ],
|
||||
[ 'MediaWiki:help', true ],
|
||||
];
|
||||
}
|
||||
|
|
@ -1661,11 +1661,6 @@ more stuff
|
|||
$title = Title::makeTitle( NS_MAIN, 'SomePage' );
|
||||
$page = WikiPage::factory( $title );
|
||||
$this->assertEquals( WikiPage::class, get_class( $page ) );
|
||||
$this->assertSame( $page, WikiPage::factory( $page ) );
|
||||
|
||||
$title = new PageIdentityValue( 0, NS_MAIN, 'SomePage', PageIdentity::LOCAL );
|
||||
$page = WikiPage::factory( $title );
|
||||
$this->assertEquals( WikiPage::class, get_class( $page ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2589,5 +2584,4 @@ more stuff
|
|||
$this->assertTrue( $isCalled );
|
||||
$this->assertSame( $expectedWikiPage, $wikiPage );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue