MediaWiki master
ForeignTitle.php
Go to the documentation of this file.
1<?php
11
12use RuntimeException;
13use Stringable;
14
19class ForeignTitle implements Stringable {
24 private $namespaceId;
26 private $namespaceName;
28 private $pageName;
29
38 public function __construct( $namespaceId, $namespaceName, $pageName ) {
39 if ( $namespaceId === null ) {
40 $this->namespaceId = null;
41 } else {
42 $this->namespaceId = intval( $namespaceId );
43 }
44 $this->namespaceName = str_replace( ' ', '_', $namespaceName );
45 $this->pageName = str_replace( ' ', '_', $pageName );
46 }
47
52 public function isNamespaceIdKnown() {
53 return $this->namespaceId !== null;
54 }
55
60 public function getNamespaceId() {
61 if ( $this->namespaceId === null ) {
62 throw new RuntimeException(
63 "Attempted to call getNamespaceId when the namespace ID is not known" );
64 }
65 return $this->namespaceId;
66 }
67
69 public function getNamespaceName() {
70 return $this->namespaceName;
71 }
72
74 public function getText() {
75 return $this->pageName;
76 }
77
79 public function getFullText() {
80 $result = '';
81 if ( $this->namespaceName ) {
82 $result .= $this->namespaceName . ':';
83 }
84 $result .= $this->pageName;
85 return $result;
86 }
87
96 public function __toString() {
97 $name = '';
98 if ( $this->isNamespaceIdKnown() ) {
99 $name .= '{ns' . $this->namespaceId . '}';
100 } else {
101 $name .= '{ns??}';
102 }
103 $name .= $this->namespaceName . ':' . $this->pageName;
104
105 return $name;
106 }
107}
108
110class_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.