MediaWiki master
ForeignTitle.php
Go to the documentation of this file.
1<?php
25
26use RuntimeException;
27use Stringable;
28
33class ForeignTitle implements Stringable {
38 private $namespaceId;
40 private $namespaceName;
42 private $pageName;
43
52 public function __construct( $namespaceId, $namespaceName, $pageName ) {
53 if ( $namespaceId === null ) {
54 $this->namespaceId = null;
55 } else {
56 $this->namespaceId = intval( $namespaceId );
57 }
58 $this->namespaceName = str_replace( ' ', '_', $namespaceName );
59 $this->pageName = str_replace( ' ', '_', $pageName );
60 }
61
66 public function isNamespaceIdKnown() {
67 return $this->namespaceId !== null;
68 }
69
74 public function getNamespaceId() {
75 if ( $this->namespaceId === null ) {
76 throw new RuntimeException(
77 "Attempted to call getNamespaceId when the namespace ID is not known" );
78 }
79 return $this->namespaceId;
80 }
81
83 public function getNamespaceName() {
84 return $this->namespaceName;
85 }
86
88 public function getText() {
89 return $this->pageName;
90 }
91
93 public function getFullText() {
94 $result = '';
95 if ( $this->namespaceName ) {
96 $result .= $this->namespaceName . ':';
97 }
98 $result .= $this->pageName;
99 return $result;
100 }
101
110 public function __toString() {
111 $name = '';
112 if ( $this->isNamespaceIdKnown() ) {
113 $name .= '{ns' . $this->namespaceId . '}';
114 } else {
115 $name .= '{ns??}';
116 }
117 $name .= $this->namespaceName . ':' . $this->pageName;
118
119 return $name;
120 }
121}
122
124class_alias( ForeignTitle::class, 'ForeignTitle' );
A simple, immutable structure to hold the title of a page on a foreign MediaWiki installation.
isNamespaceIdKnown()
Do we know the namespace ID of the page on the foreign wiki?
__toString()
Returns a string representation of the title, for logging.
__construct( $namespaceId, $namespaceName, $pageName)
Creates a new ForeignTitle object.