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
21 namespace MediaWiki\Linker
;
24 use Wikimedia\Parsoid\Core\LinkTarget
as ParsoidLinkTarget
;
27 * Represents the target of a wiki link.
29 * @see https://www.mediawiki.org/wiki/Manual:Modeling_pages
33 interface LinkTarget
extends Stringable
, ParsoidLinkTarget
{
36 * Get the namespace index.
39 * @return int Namespace index
41 public function getNamespace(): int;
44 * Convenience function to check if the target is in a given namespace.
50 public function inNamespace( int $ns ): bool;
53 * Get the link fragment in text form (i.e. the bit after the hash `#`).
56 * @return string link fragment
58 public function getFragment(): string;
61 * Whether the link target has a fragment.
66 public function hasFragment(): bool;
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
78 public function getDBkey(): string;
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.
94 public function getText(): string;
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.
103 * @param string $fragment The fragment override, or "" to remove it.
106 public function createFragmentTarget( string $fragment );
109 * Whether this LinkTarget has an interwiki component.
114 public function isExternal(): bool;
117 * The interwiki component of this LinkTarget.
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.
131 * @param ParsoidLinkTarget $other
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.
142 public function __toString(): string;