MediaWiki REL1_34
TextContentHandler.php
Go to the documentation of this file.
1<?php
32
33 public function __construct( $modelId = CONTENT_MODEL_TEXT, $formats = [ CONTENT_FORMAT_TEXT ] ) {
34 parent::__construct( $modelId, $formats );
35 }
36
45 public function serializeContent( Content $content, $format = null ) {
46 $this->checkFormat( $format );
47
48 // @phan-suppress-next-line PhanUndeclaredMethod
49 return $content->getText();
50 }
51
67 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
68 $this->checkModelID( $oldContent->getModel() );
69 $this->checkModelID( $myContent->getModel() );
70 $this->checkModelID( $yourContent->getModel() );
71
72 $format = $this->getDefaultFormat();
73
74 $old = $this->serializeContent( $oldContent, $format );
75 $mine = $this->serializeContent( $myContent, $format );
76 $yours = $this->serializeContent( $yourContent, $format );
77
78 $ok = wfMerge( $old, $mine, $yours, $result );
79
80 if ( !$ok ) {
81 return false;
82 }
83
84 if ( !$result ) {
85 return $this->makeEmptyContent();
86 }
87
88 $mergedContent = $this->unserializeContent( $result, $format );
89
90 return $mergedContent;
91 }
92
102 protected function getContentClass() {
103 return TextContent::class;
104 }
105
116 public function unserializeContent( $text, $format = null ) {
117 $this->checkFormat( $format );
118
119 $class = $this->getContentClass();
120 return new $class( $text );
121 }
122
130 public function makeEmptyContent() {
131 $class = $this->getContentClass();
132 return new $class( '' );
133 }
134
140 public function supportsDirectEditing() {
141 return true;
142 }
143
144 public function getFieldsForSearchIndex( SearchEngine $engine ) {
145 $fields = parent::getFieldsForSearchIndex( $engine );
146 $fields['language'] =
148
149 return $fields;
150 }
151
152 public function getDataForSearchIndex(
153 WikiPage $page,
154 ParserOutput $output,
155 SearchEngine $engine
156 ) {
157 $fields = parent::getDataForSearchIndex( $page, $output, $engine );
158 $fields['language'] =
159 $this->getPageLanguage( $page->getTitle(), $page->getContent() )->getCode();
160 return $fields;
161 }
162
163}
wfMerge( $old, $mine, $yours, &$result, &$mergeAttemptResult=null)
wfMerge attempts to merge differences between three texts.
A content handler knows how do deal with a specific type of content on a wiki page.
checkModelID( $model_id)
checkFormat( $format)
Convenient for checking whether a format provided as a parameter is actually supported.
getPageLanguage(Title $title, Content $content=null)
Get the language in which the content of the given page is written.
getDefaultFormat()
The format used for serialization/deserialization by default by this ContentHandler.
Contain a class for special pages.
makeSearchFieldMapping( $name, $type)
Create a search field definition.
Base content handler implementation for flat text contents.
unserializeContent( $text, $format=null)
Unserializes a Content object of the type supported by this ContentHandler.
getDataForSearchIndex(WikiPage $page, ParserOutput $output, SearchEngine $engine)
Return fields to be indexed by search engine as representation of this document.
serializeContent(Content $content, $format=null)
Returns the content's text as-is.
getContentClass()
Returns the name of the associated Content class, to be used when creating new objects.
__construct( $modelId=CONTENT_MODEL_TEXT, $formats=[CONTENT_FORMAT_TEXT])
Constructor, initializing the ContentHandler instance with its model ID and a list of supported forma...
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
makeEmptyContent()
Creates an empty TextContent object.
merge3(Content $oldContent, Content $myContent, Content $yourContent)
Attempts to merge differences between three versions.
Class representing a MediaWiki article and history.
Definition WikiPage.php:47
getContent( $audience=RevisionRecord::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition WikiPage.php:820
getTitle()
Get the title object of the article.
Definition WikiPage.php:298
const CONTENT_FORMAT_TEXT
Definition Defines.php:245
const CONTENT_MODEL_TEXT
Definition Defines.php:227
Base interface for content objects.
Definition Content.php:34
getModel()
Returns the ID of the content model used by this Content object.
const INDEX_TYPE_KEYWORD
KEYWORD fields are indexed without any processing, so are appropriate for e.g.
$content
Definition router.php:78