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