Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / content / TextContentHandler.php
blobe7f41e18b81f3510004671662c17f94910a15057
1 <?php
2 /**
3 * Base content handler class for flat text contents.
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 * Base content handler implementation for flat text contents.
29 * @ingroup Content
31 class TextContentHandler extends ContentHandler {
33 public function __construct( $modelId = CONTENT_MODEL_TEXT, $formats = array( CONTENT_FORMAT_TEXT ) ) {
34 parent::__construct( $modelId, $formats );
37 /**
38 * Returns the content's text as-is.
40 * @param $content Content
41 * @param $format string|null
42 * @return mixed
44 public function serializeContent( Content $content, $format = null ) {
45 $this->checkFormat( $format );
46 return $content->getNativeData();
49 /**
50 * Attempts to merge differences between three versions. Returns a new
51 * Content object for a clean merge and false for failure or a conflict.
53 * All three Content objects passed as parameters must have the same
54 * content model.
56 * This text-based implementation uses wfMerge().
58 * @param $oldContent Content|string String
59 * @param $myContent Content|string String
60 * @param $yourContent Content|string String
62 * @return Content|Bool
64 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
65 $this->checkModelID( $oldContent->getModel() );
66 $this->checkModelID( $myContent->getModel() );
67 $this->checkModelID( $yourContent->getModel() );
69 $format = $this->getDefaultFormat();
71 $old = $this->serializeContent( $oldContent, $format );
72 $mine = $this->serializeContent( $myContent, $format );
73 $yours = $this->serializeContent( $yourContent, $format );
75 $ok = wfMerge( $old, $mine, $yours, $result );
77 if ( !$ok ) {
78 return false;
81 if ( !$result ) {
82 return $this->makeEmptyContent();
85 $mergedContent = $this->unserializeContent( $result, $format );
86 return $mergedContent;
89 /**
90 * Unserializes a Content object of the type supported by this ContentHandler.
92 * @since 1.21
94 * @param $text string serialized form of the content
95 * @param $format null|String the format used for serialization
97 * @return Content the TextContent object wrapping $text
99 public function unserializeContent( $text, $format = null ) {
100 $this->checkFormat( $format );
102 return new TextContent( $text );
106 * Creates an empty TextContent object.
108 * @since 1.21
110 * @return Content
112 public function makeEmptyContent() {
113 return new TextContent( '' );