MediaWiki  master
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 }
unserializeContent( $text, $format=null)
Unserializes a Content object of the type supported by this ContentHandler.
merge3(Content $oldContent, Content $myContent, Content $yourContent)
Attempts to merge differences between three versions.
wfMerge( $old, $mine, $yours, &$result, &$mergeAttemptResult=null)
wfMerge attempts to merge differences between three texts.
const CONTENT_MODEL_TEXT
Definition: Defines.php:218
getPageLanguage(Title $title, Content $content=null)
Get the language in which the content of the given page is written.
getContentClass()
Returns the name of the associated Content class, to be used when creating new objects.
checkModelID( $model_id)
const CONTENT_FORMAT_TEXT
Definition: Defines.php:236
getFieldsForSearchIndex(SearchEngine $engine)
getTitle()
Get the title object of the article.
Definition: WikiPage.php:298
makeSearchFieldMapping( $name, $type)
Create a search field definition.
checkFormat( $format)
Convenient for checking whether a format provided as a parameter is actually supported.
const INDEX_TYPE_KEYWORD
KEYWORD fields are indexed without any processing, so are appropriate for e.g.
getDataForSearchIndex(WikiPage $page, ParserOutput $output, SearchEngine $engine)
Base content handler implementation for flat text contents.
getContent( $audience=RevisionRecord::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition: WikiPage.php:820
$content
Definition: router.php:78
serializeContent(Content $content, $format=null)
Returns the content&#39;s text as-is.
getModel()
Returns the ID of the content model used by this Content object.
__construct( $modelId=CONTENT_MODEL_TEXT, $formats=[CONTENT_FORMAT_TEXT])
makeEmptyContent()
Creates an empty TextContent object.
getDefaultFormat()
The format used for serialization/deserialization by default by this ContentHandler.