3 namespace MediaWiki\Page
;
5 use MediaWiki\Title\Title
;
8 * Convenience trait for conversion to PageIdentity.
10 * For the cross-wiki aware code, this should be used instead of PageIdentity::getId
11 * until Title is dropped. Before transition to PageIdentity, Title could exist for
12 * foreign wikis with no indication about it (Title does not have $wikiId).
13 * It was very brittle, but it worked. Until Title is deprecated in the codebase,
14 * most of the PageIdentity instances passed around are Titles. So for cross-wiki access,
15 * stricter domain validation of PageIdentity::getId will break wikis.
17 * Additionally, loose checks on Title regarding whether the page can exist or not
18 * have been depended upon in a number of places in the codebase.
20 * This trait is only supposed to be used in cross-wiki aware code, and only exists until
21 * code up the stack is guaranteed not to pass Title.
25 trait LegacyArticleIdAccess
{
27 * Before transition to PageIdentity, Title could exist for foreign wikis.
28 * It was very brittle, but it worked. Until Title is deprecated in the codebase,
29 * most of the PageIdentity instances passed around are Titles.
30 * So for cross-wiki access, stricter domain validation of PageIdentity::getId
31 * will break wikis. This method supposed to exist only for the transition period
32 * and will be removed after.
34 * Additionally, loose checks on Title regarding whether the page can exist or not
35 * have been depended upon in a number of places in the codebase.
37 * @param PageIdentity $title
40 protected function getArticleId( PageIdentity
$title ): int {
41 if ( $title instanceof Title
) {
42 return $title->getArticleID();
44 return $title->getId( $this->getWikiId() );
48 * Get the ID of the wiki this revision belongs to.
50 * @return string|false The wiki's logical name, of false to indicate the local wiki.
52 abstract protected function getWikiId();