Introducing TitleValue
[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 * @license GPL 2+
22 * @author Daniel Kinzler
23 */
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 */
33 interface TitleFormatter {
34
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 *
45 * @return string
46 */
47 public function formatTitle( $namespace, $text, $fragment = '' );
48
49 /**
50 * Returns the title text formatted for display, without namespace of fragment.
51 *
52 * @note: Only minimal normalization is applied. Consider using TitleValue::getText() directly.
53 *
54 * @param TitleValue $title the title to format
55 *
56 * @return string
57 */
58 public function getText( TitleValue $title );
59
60 /**
61 * Returns the title formatted for display, including the namespace name.
62 *
63 * @param TitleValue $title the title to format
64 *
65 * @return string
66 */
67 public function getPrefixedText( TitleValue $title );
68
69 /**
70 * Returns the title formatted for display, with namespace and fragment.
71 *
72 * @param TitleValue $title the title to format
73 *
74 * @return string
75 */
76 public function getFullText( TitleValue $title );
77
78 /**
79 * Returns the name of the namespace for the given title.
80 *
81 * @note This must take into account gender sensitive namespace names.
82 * @todo Move this to a separate interface
83 *
84 * @param int $namespace
85 * @param string $text
86 *
87 * @throws InvalidArgumentException
88 * @return String
89 */
90 public function getNamespaceName( $namespace, $text );
91 }