Implement static public Parser::getExternalLinkRel
[lhc/web/wiklou.git] / includes / content / TextContentHandler.php
1 <?php
2
3 /**
4 * @since 1.21
5 */
6 class TextContentHandler extends ContentHandler {
7
8 public function __construct( $modelId = CONTENT_MODEL_TEXT, $formats = array( CONTENT_FORMAT_TEXT ) ) {
9 parent::__construct( $modelId, $formats );
10 }
11
12 /**
13 * Returns the content's text as-is.
14 *
15 * @param $content Content
16 * @param $format string|null
17 * @return mixed
18 */
19 public function serializeContent( Content $content, $format = null ) {
20 $this->checkFormat( $format );
21 return $content->getNativeData();
22 }
23
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.
27 *
28 * All three Content objects passed as parameters must have the same
29 * content model.
30 *
31 * This text-based implementation uses wfMerge().
32 *
33 * @param $oldContent Content|string String
34 * @param $myContent Content|string String
35 * @param $yourContent Content|string String
36 *
37 * @return Content|Bool
38 */
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() );
43
44 $format = $this->getDefaultFormat();
45
46 $old = $this->serializeContent( $oldContent, $format );
47 $mine = $this->serializeContent( $myContent, $format );
48 $yours = $this->serializeContent( $yourContent, $format );
49
50 $ok = wfMerge( $old, $mine, $yours, $result );
51
52 if ( !$ok ) {
53 return false;
54 }
55
56 if ( !$result ) {
57 return $this->makeEmptyContent();
58 }
59
60 $mergedContent = $this->unserializeContent( $result, $format );
61 return $mergedContent;
62 }
63
64 /**
65 * Unserializes a Content object of the type supported by this ContentHandler.
66 *
67 * @since 1.21
68 *
69 * @param $text string serialized form of the content
70 * @param $format null|String the format used for serialization
71 *
72 * @return Content the TextContent object wrapping $text
73 */
74 public function unserializeContent( $text, $format = null ) {
75 $this->checkFormat( $format );
76
77 return new TextContent( $text );
78 }
79
80 /**
81 * Creates an empty TextContent object.
82 *
83 * @since 1.21
84 *
85 * @return Content
86 */
87 public function makeEmptyContent() {
88 return new TextContent( '' );
89 }
90 }