3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
24 class TextContentHandler
extends ContentHandler
{
26 public function __construct( $modelId = CONTENT_MODEL_TEXT
, $formats = array( CONTENT_FORMAT_TEXT
) ) {
27 parent
::__construct( $modelId, $formats );
31 * Returns the content's text as-is.
33 * @param $content Content
34 * @param $format string|null
37 public function serializeContent( Content
$content, $format = null ) {
38 $this->checkFormat( $format );
39 return $content->getNativeData();
43 * Attempts to merge differences between three versions. Returns a new
44 * Content object for a clean merge and false for failure or a conflict.
46 * All three Content objects passed as parameters must have the same
49 * This text-based implementation uses wfMerge().
51 * @param $oldContent Content|string String
52 * @param $myContent Content|string String
53 * @param $yourContent Content|string String
55 * @return Content|Bool
57 public function merge3( Content
$oldContent, Content
$myContent, Content
$yourContent ) {
58 $this->checkModelID( $oldContent->getModel() );
59 $this->checkModelID( $myContent->getModel() );
60 $this->checkModelID( $yourContent->getModel() );
62 $format = $this->getDefaultFormat();
64 $old = $this->serializeContent( $oldContent, $format );
65 $mine = $this->serializeContent( $myContent, $format );
66 $yours = $this->serializeContent( $yourContent, $format );
68 $ok = wfMerge( $old, $mine, $yours, $result );
75 return $this->makeEmptyContent();
78 $mergedContent = $this->unserializeContent( $result, $format );
79 return $mergedContent;
83 * Unserializes a Content object of the type supported by this ContentHandler.
87 * @param $text string serialized form of the content
88 * @param $format null|String the format used for serialization
90 * @return Content the TextContent object wrapping $text
92 public function unserializeContent( $text, $format = null ) {
93 $this->checkFormat( $format );
95 return new TextContent( $text );
99 * Creates an empty TextContent object.
105 public function makeEmptyContent() {
106 return new TextContent( '' );