Merge "Swap isSpecialPage for canExist()"
[mediawiki.git] / includes / content / TextContentHandler.php
blob9c2ae356259510ef9df679bfaf3761bd0e947fad
1 <?php
3 /**
4 * @since 1.21
5 */
6 class TextContentHandler extends ContentHandler {
8 public function __construct( $modelId = CONTENT_MODEL_TEXT, $formats = array( CONTENT_FORMAT_TEXT ) ) {
9 parent::__construct( $modelId, $formats );
12 /**
13 * Returns the content's text as-is.
15 * @param $content Content
16 * @param $format string|null
17 * @return mixed
19 public function serializeContent( Content $content, $format = null ) {
20 $this->checkFormat( $format );
21 return $content->getNativeData();
24 /**
25 * Attempts to merge differences between three versions. Returns a new
26 * Content object for a clean merge and false for failure or a conflict.
28 * All three Content objects passed as parameters must have the same
29 * content model.
31 * This text-based implementation uses wfMerge().
33 * @param $oldContent Content|string String
34 * @param $myContent Content|string String
35 * @param $yourContent Content|string String
37 * @return Content|Bool
39 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
40 $this->checkModelID( $oldContent->getModel() );
41 $this->checkModelID( $myContent->getModel() );
42 $this->checkModelID( $yourContent->getModel() );
44 $format = $this->getDefaultFormat();
46 $old = $this->serializeContent( $oldContent, $format );
47 $mine = $this->serializeContent( $myContent, $format );
48 $yours = $this->serializeContent( $yourContent, $format );
50 $ok = wfMerge( $old, $mine, $yours, $result );
52 if ( !$ok ) {
53 return false;
56 if ( !$result ) {
57 return $this->makeEmptyContent();
60 $mergedContent = $this->unserializeContent( $result, $format );
61 return $mergedContent;
64 /**
65 * Unserializes a Content object of the type supported by this ContentHandler.
67 * @since 1.21
69 * @param $text string serialized form of the content
70 * @param $format null|String the format used for serialization
72 * @return Content the TextContent object wrapping $text
74 public function unserializeContent( $text, $format = null ) {
75 $this->checkFormat( $format );
77 return new TextContent( $text );
80 /**
81 * Creates an empty TextContent object.
83 * @since 1.21
85 * @return Content
87 public function makeEmptyContent() {
88 return new TextContent( '' );