Debian Codegraph @

vendor/wikimedia/parsoid/src/Core/LinkTarget.php

raw
1 <?php
2 declare( strict_types = 1 );
3
4 /**
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Addshore
22 */
23 namespace Wikimedia\Parsoid\Core;
24
25 /**
26 * Represents the target of a wiki link.
27 *
28 * @see https://www.mediawiki.org/wiki/Manual:Modeling_pages
29 */
30 interface LinkTarget {
31
32 /**
33 * Get the namespace index.
34 *
35 * @return int Namespace index
36 */
37 public function getNamespace(): int;
38
39 /**
40 * Convenience function to check if the target is in a given namespace.
41 *
42 * @param int $ns
43 * @return bool
44 */
45 public function inNamespace( int $ns ): bool;
46
47 /**
48 * Get the link fragment in text form (i.e. the bit after the hash `#`).
49 *
50 * @return string link fragment
51 */
52 public function getFragment(): string;
53
54 /**
55 * Whether the link target has a fragment.
56 *
57 * @return bool
58 */
59 public function hasFragment(): bool;
60
61 /**
62 * Get the main part of the link target, in canonical database form.
63 *
64 * The main part is the link target without namespace prefix or hash fragment.
65 * The database form means that spaces become underscores, this is also
66 * used for URLs.
67 *
68 * @return string
69 */
70 public function getDBkey(): string;
71
72 /**
73 * Get the main part of the link target, in text form.
74 *
75 * The main part is the link target without namespace prefix or hash fragment.
76 * The text form is used for display purposes.
77 *
78 * This is computed from the DB key by replacing any underscores with spaces.
79 *
80 * @note To get a title string that includes the namespace and/or fragment,
81 * use a TitleFormatter.
82 *
83 * @return string
84 */
85 public function getText(): string;
86
87 /**
88 * Create a new LinkTarget with a different fragment on the same page.
89 *
90 * It is expected that the same type of object will be returned, but the
91 * only requirement is that it is a LinkTarget.
92 *
93 * @param string $fragment The fragment override, or "" to remove it.
94 * @return LinkTarget
95 */
96 public function createFragmentTarget( string $fragment );
97
98 /**
99 * Whether this LinkTarget has an interwiki component.
100 *
101 * @return bool
102 */
103 public function isExternal(): bool;
104
105 /**
106 * The interwiki component of this LinkTarget.
107 *
108 * @return string
109 */
110 public function getInterwiki(): string;
111
112 /**
113 * Check whether the given LinkTarget refers to the same target as this LinkTarget.
114 *
115 * Two link targets are considered the same if they have the same interwiki prefix,
116 * are in the same namespace, have the same main part, and the same fragment.
117 *
118 * @param LinkTarget $other
119 * @return bool
120 */
121 public function isSameLinkAs( LinkTarget $other ): bool;
122
123 /**
124 * Return an informative human-readable representation of the link target,
125 * for use in logging and debugging.
126 *
127 * @return string
128 */
129 public function __toString(): string;
130
131 }