| 1 | <?php |
| 2 | /** |
| 3 | * A title formatter service for MediaWiki. |
| 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 Daniel Kinzler |
| 22 | */ |
| 23 | |
| 24 | namespace MediaWiki\Title; |
| 25 | |
| 26 | use MediaWiki\Linker\LinkTarget; |
| 27 | use MediaWiki\Page\PageReference; |
| 28 | |
| 29 | /** |
| 30 | * A title formatter service for MediaWiki. |
| 31 | * |
| 32 | * This is designed to encapsulate knowledge about conventions for the title |
| 33 | * forms to be used in the database, in urls, in wikitext, etc. |
| 34 | * |
| 35 | * @see https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue |
| 36 | * @since 1.23 |
| 37 | */ |
| 38 | interface TitleFormatter { |
| 39 | /** |
| 40 | * Returns the title formatted for display. |
| 41 | * By default, this includes the namespace but not the fragment. |
| 42 | * |
| 43 | * @note Normalization is applied if $title is not in TitleValue::TITLE_FORM. |
| 44 | * |
| 45 | * @param int|bool $namespace The namespace ID (or false, if the namespace should be ignored) |
| 46 | * @param string $text The page title |
| 47 | * @param string $fragment The fragment name (may be empty). |
| 48 | * @param string $interwiki The interwiki prefix (may be empty). |
| 49 | * |
| 50 | * @return string |
| 51 | */ |
| 52 | public function formatTitle( $namespace, $text, $fragment = '', $interwiki = '' ); |
| 53 | |
| 54 | /** |
| 55 | * Returns the title text formatted for display, without namespace or fragment. |
| 56 | * |
| 57 | * @param LinkTarget|PageReference $title The title to format |
| 58 | * |
| 59 | * @return string |
| 60 | */ |
| 61 | public function getText( $title ); |
| 62 | |
| 63 | /** |
| 64 | * Returns the title formatted for display, including the namespace name. |
| 65 | * |
| 66 | * @param LinkTarget|PageReference $title The title to format |
| 67 | * |
| 68 | * @return string |
| 69 | */ |
| 70 | public function getPrefixedText( $title ); |
| 71 | |
| 72 | /** |
| 73 | * Return the title in prefixed database key form, with interwiki |
| 74 | * and namespace. |
| 75 | * |
| 76 | * @since 1.27 |
| 77 | * |
| 78 | * @param LinkTarget|PageReference $target |
| 79 | * |
| 80 | * @return string |
| 81 | */ |
| 82 | public function getPrefixedDBkey( $target ); |
| 83 | |
| 84 | /** |
| 85 | * Returns the title formatted for display, with namespace and fragment. |
| 86 | * |
| 87 | * @param LinkTarget|PageReference $title The title to format |
| 88 | * |
| 89 | * @return string |
| 90 | */ |
| 91 | public function getFullText( $title ); |
| 92 | |
| 93 | /** |
| 94 | * Returns the name of the namespace for the given title. |
| 95 | * |
| 96 | * @note This must take into account gender sensitive namespace names. |
| 97 | * @todo Move this to a separate interface |
| 98 | * |
| 99 | * @param int $namespace |
| 100 | * @param string $text |
| 101 | * |
| 102 | * @return string Namespace name with underscores (not spaces), e.g. 'User_talk' |
| 103 | */ |
| 104 | public function getNamespaceName( $namespace, $text ); |
| 105 | } |
| 106 | |
| 107 | /** @deprecated class alias since 1.41 */ |
| 108 | class_alias( TitleFormatter::class, 'TitleFormatter' ); |