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