MediaWiki master
ForeignTitle.php
Go to the documentation of this file.
1<?php
25
26use RuntimeException;
27
37 private $namespaceId;
39 private $namespaceName;
41 private $pageName;
42
51 public function __construct( $namespaceId, $namespaceName, $pageName ) {
52 if ( $namespaceId === null ) {
53 $this->namespaceId = null;
54 } else {
55 $this->namespaceId = intval( $namespaceId );
56 }
57 $this->namespaceName = str_replace( ' ', '_', $namespaceName );
58 $this->pageName = str_replace( ' ', '_', $pageName );
59 }
60
65 public function isNamespaceIdKnown() {
66 return $this->namespaceId !== null;
67 }
68
73 public function getNamespaceId() {
74 if ( $this->namespaceId === null ) {
75 throw new RuntimeException(
76 "Attempted to call getNamespaceId when the namespace ID is not known" );
77 }
78 return $this->namespaceId;
79 }
80
82 public function getNamespaceName() {
83 return $this->namespaceName;
84 }
85
87 public function getText() {
88 return $this->pageName;
89 }
90
92 public function getFullText() {
93 $result = '';
94 if ( $this->namespaceName ) {
95 $result .= $this->namespaceName . ':';
96 }
97 $result .= $this->pageName;
98 return $result;
99 }
100
109 public function __toString() {
110 $name = '';
111 if ( $this->isNamespaceIdKnown() ) {
112 $name .= '{ns' . $this->namespaceId . '}';
113 } else {
114 $name .= '{ns??}';
115 }
116 $name .= $this->namespaceName . ':' . $this->pageName;
117
118 return $name;
119 }
120}
121
123class_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.