MediaWiki master
MediaWiki\Page\PageIdentity Interface Reference

Interface for objects (potentially) representing an editable wiki page. More...

Inherits MediaWiki\Page\PageReference.

Inherited by MediaWiki\Page\ProperPageIdentity, and MediaWiki\Title\Title.

Collaboration diagram for MediaWiki\Page\PageIdentity:

Public Member Functions

 canExist ()
 Checks whether this PageIdentity represents a "proper" page, meaning that it could exist as an editable page on the wiki.
 
 exists ()
 Checks if the page currently exists.
 
 getId ( $wikiId=self::LOCAL)
 Returns the page ID.
 
- Public Member Functions inherited from MediaWiki\Page\PageReference
 __toString ()
 Returns an informative human readable unique representation of the page identity, for use as a cache key and for logging and debugging.
 
 getDBkey ()
 Get the page title in DB key form.
 
 getNamespace ()
 Returns the page's namespace number.
 
 getWikiId ()
 Get the ID of the wiki this page belongs to.
 
 isSamePageAs (PageReference $other)
 Checks whether the given PageReference refers to the same page as this PageReference.
 
- Public Member Functions inherited from MediaWiki\DAO\WikiAwareEntity
 assertWiki ( $wikiId)
 Throws if $wikiId is different from the return value of getWikiId().
 

Detailed Description

Interface for objects (potentially) representing an editable wiki page.

The identity of any PageIdentity object is defined by the namespace, the dbkey, and the wiki ID. The page ID together with the wiki ID also identifies the page, unless the page ID is 0. If the wiki ID is self::LOCAL, the identity is relative to the local wiki.

Note
For compatibility with the Title class, PageIdentity instances may for now not only represent non-existing pages, but also things that are not actually pages, such as interwiki links, section links, or Special pages (which exist, but are not proper editable pages). This is intended to change in the future, so that a PageIdentity always represents a "proper" page. Until then, code that requires a proper page should call canExist() to check, or require a ProperPageIdentity. Eventually, ProperPageIdentity is intended to become an alias for PageIdentity.
For compatibility with the Title class, PageIdentity instances may be mutable, and return different values from methods such as getId() or exist() at different times. In the future, the contract of this interface is intended to be changed to disallow this.
Instances of Title shall be the only instances of PageIdentity that are not proper pages. Other classes implementing PageIdentity must represent proper pages, and also implement ProperPageIdentity. The idea is that once Title has been removed, all PageIdentities are then proper pages, and the distinction between PageIdentity and ProperPageIdentity becomes redundant.
Code that deserializes instances of PageIdentity must ensure that the original meaning of the "local" Wiki ID is preserved if the PageIdentity originated on another wiki.
See also
https://www.mediawiki.org/wiki/Manual:Modeling_pages
Stability: stable
to type
Since
1.36

Definition at line 67 of file PageIdentity.php.

Member Function Documentation

◆ canExist()

MediaWiki\Page\PageIdentity::canExist ( )

Checks whether this PageIdentity represents a "proper" page, meaning that it could exist as an editable page on the wiki.

Note
This method only exists to allow Title to implement this interface. Title instances may represent things that are not pages, such as relative section links or interwiki links. The idea is that code that expects a PageIdentity is expecting an actual page. The canExist() method can be used to ensure that it is.
Eventually, this method should be guaranteed to return true, then be deprecated, and then removed.
Returns
bool
See also
Title::getArticleID()
Title::toPageIdentity()
getId()

Implemented in MediaWiki\Page\PageIdentityValue, MediaWiki\Page\ProperPageIdentity, WikiPage, and MediaWiki\Title\Title.

Referenced by RefreshLinksJob\__construct(), and RecentChange\newLogEntry().

◆ exists()

MediaWiki\Page\PageIdentity::exists ( )

Checks if the page currently exists.

Implementations must ensure that this method returns false when getId() would throw or return 0. This also implies that this method must return false if canExist() would return false.

See also
Title::exists()
Returns
bool

Implemented in MediaWiki\Page\ExistingPageRecord, MediaWiki\Page\PageIdentityValue, and WikiPage.

Referenced by MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate\__construct(), MediaWiki\Storage\PageUpdatedEvent\__construct(), MediaWiki\Rest\Handler\SearchHandler\execute(), MediaWiki\Language\LanguageConverter\findVariantLink(), MediaWiki\Parser\ParserCache\get(), and MediaWiki\Api\getWatchlistValue().

◆ getId()

MediaWiki\Page\PageIdentity::getId ( $wikiId = self::LOCAL)

Returns the page ID.

If this ID is 0, this means the page does not exist.

Implementations must call assertWiki().

Note
As a concession to allowing Title to implement this interface, PageIdentity instances may represent things that are not pages, such as relative section links or interwiki links. If getId() is called on a PageIdentity that does not actually represent a page, it must throw a RuntimeException. The idea is that code that expects a PageIdentity is expecting an actual page. The canExist() method can be used to ensure that it is.
Parameters
string | false$wikiIdMust be provided when accessing the ID of a non-local PageIdentity, to prevent data corruption when using a PageIdentity belonging to one wiki in the context of another. Should be omitted if expecting the local wiki.
Returns
int
Exceptions
RuntimeExceptionif this PageIdentity is not a "proper" page identity, but e.g. a relative section link, an interwiki link, etc.
PreconditionExceptionif this PageIdentity does not belong to the wiki identified by $wikiId.
See also
Title::getArticleID()
Title::toPageIdentity()
canExist()

Implemented in MediaWiki\Page\PageIdentityValue, MediaWiki\Page\ProperPageIdentity, WikiPage, and MediaWiki\Title\Title.

Referenced by MediaWiki\Pager\MergeHistoryPager\__construct(), MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate\__construct(), RecentChange\newForCategorization(), CategoryMembershipChangeJob\newSpec(), and MediaWiki\Page\RedirectStore\updateRedirectTarget().


The documentation for this interface was generated from the following file: