Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / title / ForeignTitle.php
blobf826f636a2da533ede46a5e005aa70c63e29a9d9
1 <?php
2 /**
3 * A structure to hold the title of a page on a foreign MediaWiki installation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author This, that and the other
24 namespace MediaWiki\Title;
26 use RuntimeException;
27 use Stringable;
29 /**
30 * A simple, immutable structure to hold the title of a page on a foreign
31 * MediaWiki installation.
33 class ForeignTitle implements Stringable {
34 /**
35 * @var int|null
36 * Null if we don't know the namespace ID (e.g. interwiki links)
38 private $namespaceId;
39 /** @var string */
40 private $namespaceName;
41 /** @var string */
42 private $pageName;
44 /**
45 * Creates a new ForeignTitle object.
47 * @param int|null $namespaceId Null if the namespace ID is unknown (e.g.
48 * interwiki links)
49 * @param string $namespaceName
50 * @param string $pageName
52 public function __construct( $namespaceId, $namespaceName, $pageName ) {
53 if ( $namespaceId === null ) {
54 $this->namespaceId = null;
55 } else {
56 $this->namespaceId = intval( $namespaceId );
58 $this->namespaceName = str_replace( ' ', '_', $namespaceName );
59 $this->pageName = str_replace( ' ', '_', $pageName );
62 /**
63 * Do we know the namespace ID of the page on the foreign wiki?
64 * @return bool
66 public function isNamespaceIdKnown() {
67 return $this->namespaceId !== null;
70 /**
71 * @note Callers should make sure that isNamespaceIdKnown() is true before calling this method.
72 * @return int
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" );
79 return $this->namespaceId;
82 /** @return string */
83 public function getNamespaceName() {
84 return $this->namespaceName;
87 /** @return string */
88 public function getText() {
89 return $this->pageName;
92 /** @return string */
93 public function getFullText() {
94 $result = '';
95 if ( $this->namespaceName ) {
96 $result .= $this->namespaceName . ':';
98 $result .= $this->pageName;
99 return $result;
103 * Returns a string representation of the title, for logging. This is purely
104 * informative and must not be used programmatically. Use the appropriate
105 * ImportTitleFactory to generate the correct string representation for a
106 * given use.
108 * @return string
110 public function __toString() {
111 $name = '';
112 if ( $this->isNamespaceIdKnown() ) {
113 $name .= '{ns' . $this->namespaceId . '}';
114 } else {
115 $name .= '{ns??}';
117 $name .= $this->namespaceName . ':' . $this->pageName;
119 return $name;
123 /** @deprecated class alias since 1.41 */
124 class_alias( ForeignTitle::class, 'ForeignTitle' );