MediaWiki REL1_32
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 return $content->getNativeData();
49 }
50
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() );
70
71 $format = $this->getDefaultFormat();
72
73 $old = $this->serializeContent( $oldContent, $format );
74 $mine = $this->serializeContent( $myContent, $format );
75 $yours = $this->serializeContent( $yourContent, $format );
76
77 $ok = wfMerge( $old, $mine, $yours, $result );
78
79 if ( !$ok ) {
80 return false;
81 }
82
83 if ( !$result ) {
84 return $this->makeEmptyContent();
85 }
86
87 $mergedContent = $this->unserializeContent( $result, $format );
88
89 return $mergedContent;
90 }
91
101 protected function getContentClass() {
102 return TextContent::class;
103 }
104
115 public function unserializeContent( $text, $format = null ) {
116 $this->checkFormat( $format );
117
118 $class = $this->getContentClass();
119 return new $class( $text );
120 }
121
129 public function makeEmptyContent() {
130 $class = $this->getContentClass();
131 return new $class( '' );
132 }
133
139 public function supportsDirectEditing() {
140 return true;
141 }
142
144 $fields = parent::getFieldsForSearchIndex( $engine );
145 $fields['language'] =
146 $engine->makeSearchFieldMapping( 'language', SearchIndexField::INDEX_TYPE_KEYWORD );
147
148 return $fields;
149 }
150
151 public function getDataForSearchIndex(
152 WikiPage $page,
155 ) {
156 $fields = parent::getDataForSearchIndex( $page, $output, $engine );
157 $fields['language'] =
158 $this->getPageLanguage( $page->getTitle(), $page->getContent() )->getCode();
159 return $fields;
160 }
161
162}
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.
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:44
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition hooks.txt:2962
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2317
const CONTENT_FORMAT_TEXT
Definition Defines.php:256
const CONTENT_MODEL_TEXT
Definition Defines.php:238
Base interface for content objects.
Definition Content.php:34
getModel()
Returns the ID of the content model used by this Content object.
$content