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
21 * @author This, that and the other
25 * A simple, immutable structure to hold the title of a page on a foreign
26 * MediaWiki installation.
31 * Null if we don't know the namespace ID (e.g. interwiki links)
33 protected $namespaceId;
35 protected $namespaceName;
40 * Creates a new ForeignTitle object.
42 * @param int|null $namespaceId Null if the namespace ID is unknown (e.g.
44 * @param string $namespaceName
45 * @param string $pageName
47 public function __construct( $namespaceId, $namespaceName, $pageName ) {
48 if ( is_null( $namespaceId ) ) {
49 $this->namespaceId
= null;
51 $this->namespaceId
= intval( $namespaceId );
53 $this->namespaceName
= str_replace( ' ', '_', $namespaceName );
54 $this->pageName
= str_replace( ' ', '_', $pageName );
58 * Do we know the namespace ID of the page on the foreign wiki?
61 public function isNamespaceIdKnown() {
62 return !is_null( $this->namespaceId
);
67 * @throws MWException If isNamespaceIdKnown() is false, it does not make
68 * sense to call this function.
70 public function getNamespaceId() {
71 if ( is_null( $this->namespaceId
) ) {
72 throw new MWException(
73 "Attempted to call getNamespaceId when the namespace ID is not known" );
75 return $this->namespaceId
;
79 public function getNamespaceName() {
80 return $this->namespaceName
;
84 public function getText() {
85 return $this->pageName
;
89 public function getFullText() {
91 if ( $this->namespaceName
) {
92 $result .= $this->namespaceName
. ':';
94 $result .= $this->pageName
;
99 * Returns a string representation of the title, for logging. This is purely
100 * informative and must not be used programmatically. Use the appropriate
101 * ImportTitleFactory to generate the correct string representation for a
106 public function __toString() {
108 if ( $this->isNamespaceIdKnown() ) {
109 $name .= '{ns' . $this->namespaceId
. '}';
113 $name .= $this->namespaceName
. ':' . $this->pageName
;