MediaWiki REL1_35
WikitextContentHandler.php
Go to the documentation of this file.
1<?php
28
35
36 public function __construct( $modelId = CONTENT_MODEL_WIKITEXT ) {
37 parent::__construct( $modelId, [ CONTENT_FORMAT_WIKITEXT ] );
38 }
39
40 protected function getContentClass() {
41 return WikitextContent::class;
42 }
43
54 public function makeRedirectContent( Title $destination, $text = '' ) {
55 $optionalColon = '';
56
57 $services = MediaWikiServices::getInstance();
58 if ( $destination->getNamespace() == NS_CATEGORY ) {
59 $optionalColon = ':';
60 } else {
61 $iw = $destination->getInterwiki();
62 if ( $iw && $services
63 ->getLanguageNameUtils()
64 ->getLanguageName( $iw,
65 LanguageNameUtils::AUTONYMS,
66 LanguageNameUtils::DEFINED )
67 ) {
68 $optionalColon = ':';
69 }
70 }
71
72 $mwRedir = $services->getMagicWordFactory()->get( 'redirect' );
73 $redirectText = $mwRedir->getSynonym( 0 ) .
74 ' [[' . $optionalColon . $destination->getFullText() . ']]';
75
76 if ( $text != '' ) {
77 $redirectText .= "\n" . $text;
78 }
79
80 $class = $this->getContentClass();
81 return new $class( $redirectText );
82 }
83
91 public function supportsRedirects() {
92 return true;
93 }
94
102 public function supportsSections() {
103 return true;
104 }
105
116 public function isParserCacheSupported() {
117 return true;
118 }
119
124 protected function getFileHandler() {
125 return new FileContentHandler();
126 }
127
128 public function getFieldsForSearchIndex( SearchEngine $engine ) {
129 $fields = parent::getFieldsForSearchIndex( $engine );
130
131 $fields['heading'] =
132 $engine->makeSearchFieldMapping( 'heading', SearchIndexField::INDEX_TYPE_TEXT );
133 $fields['heading']->setFlag( SearchIndexField::FLAG_SCORING );
134
135 $fields['auxiliary_text'] =
136 $engine->makeSearchFieldMapping( 'auxiliary_text', SearchIndexField::INDEX_TYPE_TEXT );
137
138 $fields['opening_text'] =
139 $engine->makeSearchFieldMapping( 'opening_text', SearchIndexField::INDEX_TYPE_TEXT );
140 $fields['opening_text']->setFlag(
141 SearchIndexField::FLAG_SCORING | SearchIndexField::FLAG_NO_HIGHLIGHT
142 );
143 // Until we have full first-class content handler for files, we invoke it explicitly here
144 $fields = array_merge( $fields, $this->getFileHandler()->getFieldsForSearchIndex( $engine ) );
145
146 return $fields;
147 }
148
149 public function getDataForSearchIndex(
150 WikiPage $page,
151 ParserOutput $parserOutput,
152 SearchEngine $engine
153 ) {
154 $fields = parent::getDataForSearchIndex( $page, $parserOutput, $engine );
155
156 $structure = new WikiTextStructure( $parserOutput );
157 $fields['heading'] = $structure->headings();
158 // text fields
159 $fields['opening_text'] = $structure->getOpeningText();
160 $fields['text'] = $structure->getMainText(); // overwrites one from ContentHandler
161 $fields['auxiliary_text'] = $structure->getAuxiliaryText();
162 $fields['defaultsort'] = $structure->getDefaultSort();
163
164 // Until we have full first-class content handler for files, we invoke it explicitly here
165 if ( $page->getTitle()->getNamespace() == NS_FILE ) {
166 $fields = array_merge( $fields,
167 $this->getFileHandler()->getDataForSearchIndex( $page, $parserOutput, $engine ) );
168 }
169 return $fields;
170 }
171
180 public function serializeContent( Content $content, $format = null ) {
181 $this->checkFormat( $format );
182
183 // NOTE: MessageContent also uses CONTENT_MODEL_WIKITEXT, but it's not a TextContent!
184 // Perhaps MessageContent should use a separate ContentHandler instead.
185 if ( $content instanceof MessageContent ) {
186 return $content->getMessage()->plain();
187 }
188
189 return parent::serializeContent( $content, $format );
190 }
191
192}
checkFormat( $format)
Convenient for checking whether a format provided as a parameter is actually supported.
Content handler for File: files TODO: this handler s not used directly now, but instead manually call...
A service that provides utilities to do with language names and codes.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Wrapper allowing us to handle a system message as a Content object.
Contain a class for special pages Stable to extend.
makeSearchFieldMapping( $name, $type)
Create a search field definition.
Base content handler implementation for flat text contents.
Represents a title within MediaWiki.
Definition Title.php:42
getNamespace()
Get the namespace index, i.e.
Definition Title.php:1041
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
Definition Title.php:1883
getInterwiki()
Get the interwiki prefix.
Definition Title.php:942
Class representing a MediaWiki article and history.
Definition WikiPage.php:51
getTitle()
Get the title object of the article.
Definition WikiPage.php:318
Class allowing to explore structure of parsed wikitext.
Content handler for wiki text pages.
getContentClass()
Returns the name of the associated Content class, to be used when creating new objects.
supportsRedirects()
Returns true because wikitext supports redirects.
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
makeRedirectContent(Title $destination, $text='')
Returns a WikitextContent object representing a redirect to the given destination page.
isParserCacheSupported()
Returns true, because wikitext supports caching using the ParserCache mechanism.
__construct( $modelId=CONTENT_MODEL_WIKITEXT)
serializeContent(Content $content, $format=null)
Returns the content's text as-is.
supportsSections()
Returns true because wikitext supports sections.
getDataForSearchIndex(WikiPage $page, ParserOutput $parserOutput, SearchEngine $engine)
Return fields to be indexed by search engine as representation of this document.
const NS_FILE
Definition Defines.php:76
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:225
const CONTENT_FORMAT_WIKITEXT
Definition Defines.php:240
const NS_CATEGORY
Definition Defines.php:84
Base interface for content objects.
Definition Content.php:35
$content
Definition router.php:76