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