Adding hlist module to mediawiki
[lhc/web/wiklou.git] / includes / content / WikitextContentHandler.php
1 <?php
2 /**
3 * Content handler for wiki text pages.
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 * @since 1.21
21 *
22 * @file
23 * @ingroup Content
24 */
25
26 /**
27 * Content handler for wiki text pages.
28 *
29 * @ingroup Content
30 */
31 class WikitextContentHandler extends TextContentHandler {
32
33 public function __construct( $modelId = CONTENT_MODEL_WIKITEXT ) {
34 parent::__construct( $modelId, array( CONTENT_FORMAT_WIKITEXT ) );
35 }
36
37 public function unserializeContent( $text, $format = null ) {
38 $this->checkFormat( $format );
39
40 return new WikitextContent( $text );
41 }
42
43 /**
44 * @see ContentHandler::makeEmptyContent
45 *
46 * @return Content
47 */
48 public function makeEmptyContent() {
49 return new WikitextContent( '' );
50 }
51
52 /**
53 * Returns a WikitextContent object representing a redirect to the given destination page.
54 *
55 * @see ContentHandler::makeRedirectContent
56 *
57 * @param Title $destination the page to redirect to.
58 * @param string $text text to include in the redirect, if possible.
59 *
60 * @return Content
61 */
62 public function makeRedirectContent( Title $destination, $text = '' ) {
63 $optionalColon = '';
64
65 if ( $destination->getNamespace() == NS_CATEGORY ) {
66 $optionalColon = ':';
67 } else {
68 $iw = $destination->getInterwiki();
69 if ( $iw && Language::fetchLanguageName( $iw, null, 'mw' ) ) {
70 $optionalColon = ':';
71 }
72 }
73
74 $mwRedir = MagicWord::get( 'redirect' );
75 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $optionalColon . $destination->getFullText() . ']]';
76 if ( $text != '' ) {
77 $redirectText .= "\n" . $text;
78 }
79
80 return new WikitextContent( $redirectText );
81 }
82
83 /**
84 * Returns true because wikitext supports redirects.
85 *
86 * @see ContentHandler::supportsRedirects
87 *
88 * @return boolean whether redirects are supported.
89 */
90 public function supportsRedirects() {
91 return true;
92 }
93
94 /**
95 * Returns true because wikitext supports sections.
96 *
97 * @return boolean whether sections are supported.
98 */
99 public function supportsSections() {
100 return true;
101 }
102
103 /**
104 * Returns true, because wikitext supports caching using the
105 * ParserCache mechanism.
106 *
107 * @since 1.21
108 * @return bool
109 */
110 public function isParserCacheSupported() {
111 return true;
112 }
113 }