MediaWiki REL1_41
ForeignTitle.php
Go to the documentation of this file.
1<?php
25
26use MWException;
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
74 public function getNamespaceId() {
75 if ( $this->namespaceId === null ) {
76 throw new MWException(
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
127class_alias( ForeignTitle::class, 'ForeignTitle' );
MediaWiki exception.
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.