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