Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / linker / LinkTarget.php
blobe2e2c813a8fdd6ae922403dc3091f26643be4533
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @author Addshore
21 namespace MediaWiki\Linker;
23 use Stringable;
24 use Wikimedia\Parsoid\Core\LinkTarget as ParsoidLinkTarget;
26 /**
27 * Represents the target of a wiki link.
29 * @see https://www.mediawiki.org/wiki/Manual:Modeling_pages
31 * @since 1.27
33 interface LinkTarget extends Stringable, ParsoidLinkTarget {
35 /**
36 * Get the namespace index.
38 * @since 1.27
39 * @return int Namespace index
41 public function getNamespace(): int;
43 /**
44 * Convenience function to check if the target is in a given namespace.
46 * @since 1.27
47 * @param int $ns
48 * @return bool
50 public function inNamespace( int $ns ): bool;
52 /**
53 * Get the link fragment in text form (i.e. the bit after the hash `#`).
55 * @since 1.27
56 * @return string link fragment
58 public function getFragment(): string;
60 /**
61 * Whether the link target has a fragment.
63 * @since 1.27
64 * @return bool
66 public function hasFragment(): bool;
68 /**
69 * Get the main part of the link target, in canonical database form.
71 * The main part is the link target without namespace prefix or hash fragment.
72 * The database form means that spaces become underscores, this is also
73 * used for URLs.
75 * @since 1.27
76 * @return string
78 public function getDBkey(): string;
80 /**
81 * Get the main part of the link target, in text form.
83 * The main part is the link target without namespace prefix or hash fragment.
84 * The text form is used for display purposes.
86 * This is computed from the DB key by replacing any underscores with spaces.
88 * @note To get a title string that includes the namespace and/or fragment,
89 * use a TitleFormatter.
91 * @since 1.27
92 * @return string
94 public function getText(): string;
96 /**
97 * Create a new LinkTarget with a different fragment on the same page.
99 * It is expected that the same type of object will be returned, but the
100 * only requirement is that it is a LinkTarget.
102 * @since 1.27
103 * @param string $fragment The fragment override, or "" to remove it.
104 * @return LinkTarget
106 public function createFragmentTarget( string $fragment );
109 * Whether this LinkTarget has an interwiki component.
111 * @since 1.27
112 * @return bool
114 public function isExternal(): bool;
117 * The interwiki component of this LinkTarget.
119 * @since 1.27
120 * @return string
122 public function getInterwiki(): string;
125 * Check whether the given LinkTarget refers to the same target as this LinkTarget.
127 * Two link targets are considered the same if they have the same interwiki prefix,
128 * are in the same namespace, have the same main part, and the same fragment.
130 * @since 1.36
131 * @param ParsoidLinkTarget $other
132 * @return bool
134 public function isSameLinkAs( ParsoidLinkTarget $other ): bool;
137 * Return an informative human-readable representation of the link target,
138 * for use in logging and debugging.
140 * @return string
142 public function __toString(): string;