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
27 * Base content handler implementation for flat text contents.
31 class TextContentHandler
extends ContentHandler
{
32 public function __construct( $modelId = CONTENT_MODEL_TEXT
,
33 $formats = array( CONTENT_FORMAT_TEXT
)
35 parent
::__construct( $modelId, $formats );
39 * Returns the content's text as-is.
41 * @param $content Content
42 * @param $format string|null
45 public function serializeContent( Content
$content, $format = null ) {
46 $this->checkFormat( $format );
48 return $content->getNativeData();
52 * Attempts to merge differences between three versions. Returns a new
53 * Content object for a clean merge and false for failure or a conflict.
55 * All three Content objects passed as parameters must have the same
58 * This text-based implementation uses wfMerge().
60 * @param $oldContent Content|string String
61 * @param $myContent Content|string String
62 * @param $yourContent Content|string String
64 * @return Content|Bool
66 public function merge3( Content
$oldContent, Content
$myContent, Content
$yourContent ) {
67 $this->checkModelID( $oldContent->getModel() );
68 $this->checkModelID( $myContent->getModel() );
69 $this->checkModelID( $yourContent->getModel() );
71 $format = $this->getDefaultFormat();
73 $old = $this->serializeContent( $oldContent, $format );
74 $mine = $this->serializeContent( $myContent, $format );
75 $yours = $this->serializeContent( $yourContent, $format );
77 $ok = wfMerge( $old, $mine, $yours, $result );
84 return $this->makeEmptyContent();
87 $mergedContent = $this->unserializeContent( $result, $format );
89 return $mergedContent;
93 * Unserializes a Content object of the type supported by this ContentHandler.
97 * @param $text string serialized form of the content
98 * @param $format null|String the format used for serialization
100 * @return Content the TextContent object wrapping $text
102 public function unserializeContent( $text, $format = null ) {
103 $this->checkFormat( $format );
105 return new TextContent( $text );
109 * Creates an empty TextContent object.
115 public function makeEmptyContent() {
116 return new TextContent( '' );