Do not allow a user to delete a page they can't edit
[mediawiki.git] / includes / content / WikitextContentHandler.php
blob5ae3e25d6e6fd96b1679e304f3e54745a6b18829
1 <?php
2 /**
3 * Content handler for wiki text pages.
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.
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.
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
20 * @since 1.21
22 * @file
23 * @ingroup Content
26 /**
27 * Content handler for wiki text pages.
29 * @ingroup Content
31 class WikitextContentHandler extends TextContentHandler {
33 public function __construct( $modelId = CONTENT_MODEL_WIKITEXT ) {
34 parent::__construct( $modelId, array( CONTENT_FORMAT_WIKITEXT ) );
37 public function unserializeContent( $text, $format = null ) {
38 $this->checkFormat( $format );
40 return new WikitextContent( $text );
43 /**
44 * @return Content A new WikitextContent object with empty text.
46 * @see ContentHandler::makeEmptyContent
48 public function makeEmptyContent() {
49 return new WikitextContent( '' );
52 /**
53 * Returns a WikitextContent object representing a redirect to the given destination page.
55 * @param Title $destination The page to redirect to.
56 * @param string $text Text to include in the redirect, if possible.
58 * @return Content
60 * @see ContentHandler::makeRedirectContent
62 public function makeRedirectContent( Title $destination, $text = '' ) {
63 $optionalColon = '';
65 if ( $destination->getNamespace() == NS_CATEGORY ) {
66 $optionalColon = ':';
67 } else {
68 $iw = $destination->getInterwiki();
69 if ( $iw && Language::fetchLanguageName( $iw, null, 'mw' ) ) {
70 $optionalColon = ':';
74 $mwRedir = MagicWord::get( 'redirect' );
75 $redirectText = $mwRedir->getSynonym( 0 ) .
76 ' [[' . $optionalColon . $destination->getFullText() . ']]';
78 if ( $text != '' ) {
79 $redirectText .= "\n" . $text;
82 return new WikitextContent( $redirectText );
85 /**
86 * Returns true because wikitext supports redirects.
88 * @return bool Always true.
90 * @see ContentHandler::supportsRedirects
92 public function supportsRedirects() {
93 return true;
96 /**
97 * Returns true because wikitext supports sections.
99 * @return bool Always true.
101 * @see ContentHandler::supportsSections
103 public function supportsSections() {
104 return true;
108 * Returns true, because wikitext supports caching using the
109 * ParserCache mechanism.
111 * @since 1.21
113 * @return bool Always true.
115 * @see ContentHandler::isParserCacheSupported
117 public function isParserCacheSupported() {
118 return true;