MediaWiki  master
PageReferenceValue.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Page;
22 
24 use Wikimedia\Assert\Assert;
25 use Wikimedia\NonSerializable\NonSerializableTrait;
26 
43 
44  /* Use JSON, but beware the note on serialization above. */
45  use NonSerializableTrait;
47 
49  private $namespace;
50 
52  private $dbKey;
53 
55  private $wikiId;
56 
63  public function __construct( int $namespace, string $dbKey, $wikiId ) {
64  $this->assertWikiIdParam( $wikiId );
65 
66  Assert::parameter( $dbKey !== '', '$dbKey', 'must not be empty' );
67 
68  // Replace spaces with underscores
69  $dbKey = str_replace( ' ', '_', $dbKey );
70 
71  $this->wikiId = $wikiId;
72  $this->namespace = $namespace;
73  $this->dbKey = $dbKey;
74  }
75 
83  public static function localReference( int $namespace, string $dbKey ): self {
84  return new self( $namespace, $dbKey, self::LOCAL );
85  }
86 
92  public function getWikiId() {
93  return $this->wikiId;
94  }
95 
101  public function getNamespace(): int {
102  return $this->namespace;
103  }
104 
110  public function getDBkey(): string {
111  return $this->dbKey;
112  }
113 
119  public function isSamePageAs( PageReference $other ): bool {
120  // NOTE: keep in sync with Title::isSamePageAs()!
121  // NOTE: keep in sync with WikiPage::isSamePageAs()!
122 
123  if ( $other->getWikiId() !== $this->getWikiId() ) {
124  return false;
125  }
126 
127  if ( $other->getNamespace() !== $this->getNamespace()
128  || $other->getDBkey() !== $this->getDBkey() ) {
129  return false;
130  }
131 
132  return true;
133  }
134 
141  public function __toString(): string {
142  $s = '[' . $this->namespace . ':' . $this->dbKey . ']';
143 
144  if ( $this->wikiId ) {
145  $s .= '@' . $this->wikiId;
146  }
147 
148  return $s;
149  }
150 
151 }
MediaWiki\DAO\WikiAwareEntityTrait
trait WikiAwareEntityTrait
Definition: WikiAwareEntityTrait.php:32
Page\PageReferenceValue\getNamespace
getNamespace()
Returns the page's namespace number.The value returned by this method should represent a valid namesp...
Definition: PageReferenceValue.php:101
Page\PageReferenceValue\$namespace
int $namespace
Definition: PageReferenceValue.php:49
Page\PageReferenceValue\__toString
__toString()
Returns a string representation of the title, for logging.
Definition: PageReferenceValue.php:141
if
if(ini_get( 'mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Definition: Setup.php:88
Page\PageReferenceValue\$wikiId
bool string $wikiId
Definition: PageReferenceValue.php:55
Page\PageReference
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
Definition: PageReference.php:49
Page\PageReferenceValue\__construct
__construct(int $namespace, string $dbKey, $wikiId)
Definition: PageReferenceValue.php:63
Page\PageReferenceValue\getWikiId
getWikiId()
Get the ID of the wiki provided to the constructor.
Definition: PageReferenceValue.php:92
Page\PageReferenceValue\$dbKey
string $dbKey
Definition: PageReferenceValue.php:52
Page\PageReference\getNamespace
getNamespace()
Returns the page's namespace number.
Page\PageReferenceValue\localReference
static localReference(int $namespace, string $dbKey)
Create PageReference for a local page.
Definition: PageReferenceValue.php:83
Page\PageReference\getWikiId
getWikiId()
Get the ID of the wiki this page belongs to.
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
Page\PageReference\getDBkey
getDBkey()
Get the page title in DB key form.
MediaWiki\DAO\assertWikiIdParam
assertWikiIdParam( $wikiId)
Asserts correct $wikiId parameter was passed.
Definition: WikiAwareEntityTrait.php:88
Page\PageReferenceValue\getDBkey
getDBkey()
Get the page title in DB key form.This may return a string starting with a hash, if the PageReference...
Definition: PageReferenceValue.php:110
Page\PageReferenceValue
Immutable value object representing a page reference.
Definition: PageReferenceValue.php:42
MediaWiki\Page
Definition: ContentModelChangeFactory.php:23
Page\PageReferenceValue\isSamePageAs
isSamePageAs(PageReference $other)
Definition: PageReferenceValue.php:119