MediaWiki  1.34.0
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,
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 }
SearchIndexField\INDEX_TYPE_KEYWORD
const INDEX_TYPE_KEYWORD
KEYWORD fields are indexed without any processing, so are appropriate for e.g.
Definition: SearchIndexField.php:23
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:55
TextContentHandler\__construct
__construct( $modelId=CONTENT_MODEL_TEXT, $formats=[CONTENT_FORMAT_TEXT])
Constructor, initializing the ContentHandler instance with its model ID and a list of supported forma...
Definition: TextContentHandler.php:33
ParserOutput
Definition: ParserOutput.php:25
TextContentHandler\unserializeContent
unserializeContent( $text, $format=null)
Unserializes a Content object of the type supported by this ContentHandler.
Definition: TextContentHandler.php:116
wfMerge
wfMerge( $old, $mine, $yours, &$result, &$mergeAttemptResult=null)
wfMerge attempts to merge differences between three texts.
Definition: GlobalFunctions.php:2225
ContentHandler\checkModelID
checkModelID( $model_id)
Definition: ContentHandler.php:484
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:47
TextContentHandler\supportsDirectEditing
supportsDirectEditing()
Definition: TextContentHandler.php:140
TextContentHandler\serializeContent
serializeContent(Content $content, $format=null)
Returns the content's text as-is.
Definition: TextContentHandler.php:45
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:298
CONTENT_FORMAT_TEXT
const CONTENT_FORMAT_TEXT
Definition: Defines.php:236
TextContentHandler\merge3
merge3(Content $oldContent, Content $myContent, Content $yourContent)
Attempts to merge differences between three versions.
Definition: TextContentHandler.php:67
$output
$output
Definition: SyntaxHighlight.php:335
TextContentHandler\getFieldsForSearchIndex
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
Definition: TextContentHandler.php:144
ContentHandler\getPageLanguage
getPageLanguage(Title $title, Content $content=null)
Get the language in which the content of the given page is written.
Definition: ContentHandler.php:684
$content
$content
Definition: router.php:78
ContentHandler\getDefaultFormat
getDefaultFormat()
The format used for serialization/deserialization by default by this ContentHandler.
Definition: ContentHandler.php:516
TextContentHandler\getDataForSearchIndex
getDataForSearchIndex(WikiPage $page, ParserOutput $output, SearchEngine $engine)
Return fields to be indexed by search engine as representation of this document.
Definition: TextContentHandler.php:152
TextContentHandler
Base content handler implementation for flat text contents.
Definition: TextContentHandler.php:31
TextContentHandler\makeEmptyContent
makeEmptyContent()
Creates an empty TextContent object.
Definition: TextContentHandler.php:130
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:34
Content
Base interface for content objects.
Definition: Content.php:34
SearchEngine\makeSearchFieldMapping
makeSearchFieldMapping( $name, $type)
Create a search field definition.
Definition: SearchEngine.php:744
ContentHandler\checkFormat
checkFormat( $format)
Convenient for checking whether a format provided as a parameter is actually supported.
Definition: ContentHandler.php:548
TextContentHandler\getContentClass
getContentClass()
Returns the name of the associated Content class, to be used when creating new objects.
Definition: TextContentHandler.php:102
Content\getModel
getModel()
Returns the ID of the content model used by this Content object.
CONTENT_MODEL_TEXT
const CONTENT_MODEL_TEXT
Definition: Defines.php:218
WikiPage\getContent
getContent( $audience=RevisionRecord::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition: WikiPage.php:820