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