MediaWiki  master
PageIdentityValue.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Page;
22 
23 use InvalidArgumentException;
24 use Wikimedia\Assert\Assert;
25 
42 
44  private $pageId;
45 
61  public static function tryNew( int $pageId, int $namespace, string $dbKey, $wikiId ) {
62  try {
63  return new static( $pageId, $namespace, $dbKey, $wikiId );
64  } catch ( InvalidArgumentException $ex ) {
65  return null;
66  }
67  }
68 
76  public function __construct( int $pageId, int $namespace, string $dbKey, $wikiId ) {
77  Assert::parameter( $pageId >= 0, '$pageId', 'must not be negative' );
78  Assert::parameter( $namespace >= 0, '$namespace', 'must not be negative' );
79 
80  // Not full validation, intended to help detect lack of validation in the caller.
81  Assert::parameter(
82  !preg_match( '/[#|]/', $dbKey ),
83  '$dbKey',
84  'must not contain pipes or hashes: ' . $dbKey
85  );
86 
87  parent::__construct( $namespace, $dbKey, $wikiId );
88 
89  $this->pageId = $pageId;
90  }
91 
100  public static function localIdentity( int $pageId, int $namespace, string $dbKey ): self {
101  return new self( $pageId, $namespace, $dbKey, self::LOCAL );
102  }
103 
112  public function getId( $wikiId = self::LOCAL ): int {
113  $this->assertWiki( $wikiId );
114  return $this->pageId;
115  }
116 
122  public function exists(): bool {
123  return $this->getId( $this->getWikiId() ) > 0;
124  }
125 
129  public function canExist(): bool {
130  return true;
131  }
132 
133 }
Page\PageReferenceValue\$namespace
int $namespace
Definition: PageReferenceValue.php:49
Page\PageReferenceValue\$wikiId
bool string $wikiId
Definition: PageReferenceValue.php:55
Page\PageIdentityValue\__construct
__construct(int $pageId, int $namespace, string $dbKey, $wikiId)
Definition: PageIdentityValue.php:76
Page\PageReferenceValue\getWikiId
getWikiId()
Get the ID of the wiki provided to the constructor.
Definition: PageReferenceValue.php:92
Page\PageIdentityValue\$pageId
int $pageId
Definition: PageIdentityValue.php:44
Page\PageReferenceValue\$dbKey
string $dbKey
Definition: PageReferenceValue.php:52
Page\PageIdentityValue\localIdentity
static localIdentity(int $pageId, int $namespace, string $dbKey)
Create PageIdentity for a local page.
Definition: PageIdentityValue.php:100
Page\PageIdentityValue\canExist
canExist()
Definition: PageIdentityValue.php:129
Page\ProperPageIdentity
Interface for objects representing a page that is (or could be, or used to be) an editable page on a ...
Definition: ProperPageIdentity.php:43
MediaWiki\DAO\WikiAwareEntity\assertWiki
assertWiki( $wikiId)
Throws if $wikiId is different from the return value of getWikiId().
Page\PageIdentityValue\tryNew
static tryNew(int $pageId, int $namespace, string $dbKey, $wikiId)
Constructs a PageIdentityValue, or returns null if the parameters are not valid.
Definition: PageIdentityValue.php:61
Page\PageReferenceValue
Immutable value object representing a page reference.
Definition: PageReferenceValue.php:42
Page\PageIdentityValue\exists
exists()
Returns whether the page currently exists.
Definition: PageIdentityValue.php:122
Page\PageIdentityValue
Immutable value object representing a page identity.
Definition: PageIdentityValue.php:41
MediaWiki\Page
Definition: ContentModelChangeFactory.php:23
Page\PageIdentityValue\getId
getId( $wikiId=self::LOCAL)
The numerical page ID provided to the constructor.
Definition: PageIdentityValue.php:112