MediaWiki  1.34.4
ForeignTitle.php
Go to the documentation of this file.
1 <?php
28 class ForeignTitle {
33  private $namespaceId;
35  private $namespaceName;
37  private $pageName;
38 
48  if ( is_null( $namespaceId ) ) {
49  $this->namespaceId = null;
50  } else {
51  $this->namespaceId = intval( $namespaceId );
52  }
53  $this->namespaceName = str_replace( ' ', '_', $namespaceName );
54  $this->pageName = str_replace( ' ', '_', $pageName );
55  }
56 
61  public function isNamespaceIdKnown() {
62  return !is_null( $this->namespaceId );
63  }
64 
70  public function getNamespaceId() {
71  if ( is_null( $this->namespaceId ) ) {
72  throw new MWException(
73  "Attempted to call getNamespaceId when the namespace ID is not known" );
74  }
75  return $this->namespaceId;
76  }
77 
79  public function getNamespaceName() {
80  return $this->namespaceName;
81  }
82 
84  public function getText() {
85  return $this->pageName;
86  }
87 
89  public function getFullText() {
90  $result = '';
91  if ( $this->namespaceName ) {
92  $result .= $this->namespaceName . ':';
93  }
94  $result .= $this->pageName;
95  return $result;
96  }
97 
106  public function __toString() {
107  $name = '';
108  if ( $this->isNamespaceIdKnown() ) {
109  $name .= '{ns' . $this->namespaceId . '}';
110  } else {
111  $name .= '{ns??}';
112  }
113  $name .= $this->namespaceName . ':' . $this->pageName;
114 
115  return $name;
116  }
117 }
ForeignTitle\$namespaceName
string $namespaceName
Definition: ForeignTitle.php:35
ForeignTitle\getText
getText()
Definition: ForeignTitle.php:84
ForeignTitle\getFullText
getFullText()
Definition: ForeignTitle.php:89
ForeignTitle\$pageName
string $pageName
Definition: ForeignTitle.php:37
MWException
MediaWiki exception.
Definition: MWException.php:26
ForeignTitle\getNamespaceName
getNamespaceName()
Definition: ForeignTitle.php:79
ForeignTitle\getNamespaceId
getNamespaceId()
Definition: ForeignTitle.php:70
ForeignTitle\__toString
__toString()
Returns a string representation of the title, for logging.
Definition: ForeignTitle.php:106
ForeignTitle\$namespaceId
int null $namespaceId
Null if we don't know the namespace ID (e.g.
Definition: ForeignTitle.php:33
ForeignTitle\__construct
__construct( $namespaceId, $namespaceName, $pageName)
Creates a new ForeignTitle object.
Definition: ForeignTitle.php:47
ForeignTitle
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
Definition: ForeignTitle.php:28
ForeignTitle\isNamespaceIdKnown
isNamespaceIdKnown()
Do we know the namespace ID of the page on the foreign wiki?
Definition: ForeignTitle.php:61