MediaWiki REL1_30
TextContentHandler.php
Go to the documentation of this file.
1<?php
32
33 // @codingStandardsIgnoreStart T59585
34 public function __construct( $modelId = CONTENT_MODEL_TEXT, $formats = [ CONTENT_FORMAT_TEXT ] ) {
35 parent::__construct( $modelId, $formats );
36 }
37 // @codingStandardsIgnoreEnd
38
47 public function serializeContent( Content $content, $format = null ) {
48 $this->checkFormat( $format );
49
50 return $content->getNativeData();
51 }
52
68 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
69 $this->checkModelID( $oldContent->getModel() );
70 $this->checkModelID( $myContent->getModel() );
71 $this->checkModelID( $yourContent->getModel() );
72
73 $format = $this->getDefaultFormat();
74
75 $old = $this->serializeContent( $oldContent, $format );
76 $mine = $this->serializeContent( $myContent, $format );
77 $yours = $this->serializeContent( $yourContent, $format );
78
79 $ok = wfMerge( $old, $mine, $yours, $result );
80
81 if ( !$ok ) {
82 return false;
83 }
84
85 if ( !$result ) {
86 return $this->makeEmptyContent();
87 }
88
89 $mergedContent = $this->unserializeContent( $result, $format );
90
91 return $mergedContent;
92 }
93
103 protected function getContentClass() {
104 return TextContent::class;
105 }
106
117 public function unserializeContent( $text, $format = null ) {
118 $this->checkFormat( $format );
119
120 $class = $this->getContentClass();
121 return new $class( $text );
122 }
123
131 public function makeEmptyContent() {
132 $class = $this->getContentClass();
133 return new $class( '' );
134 }
135
141 public function supportsDirectEditing() {
142 return true;
143 }
144
146 $fields = parent::getFieldsForSearchIndex( $engine );
147 $fields['language'] =
148 $engine->makeSearchFieldMapping( 'language', SearchIndexField::INDEX_TYPE_KEYWORD );
149
150 return $fields;
151 }
152
153 public function getDataForSearchIndex(
154 WikiPage $page,
157 ) {
158 $fields = parent::getDataForSearchIndex( $page, $output, $engine );
159 $fields['language'] =
160 $this->getPageLanguage( $page->getTitle(), $page->getContent() )->getCode();
161 return $fields;
162 }
163
164}
wfMerge( $old, $mine, $yours, &$result)
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:37
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition WikiPage.php:666
getTitle()
Get the title object of the article.
Definition WikiPage.php:239
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2225
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition hooks.txt:2850
const CONTENT_FORMAT_TEXT
Definition Defines.php:257
const CONTENT_MODEL_TEXT
Definition Defines.php:239
Base interface for content objects.
Definition Content.php:34
getNativeData()
Returns native representation of the data.
getModel()
Returns the ID of the content model used by this Content object.