20 private $auxText = [];
24 private $parserOutput;
29 private $excludedElementSelectors = [
39 'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
44 '.navigation-not-searchable',
46 '.wbmi-entityview-emptyCaption',
52 private $auxiliaryElementSelectors = [
69 $this->parserOutput = $parserOutput;
87 $ignoredHeadings = $this->getIgnoredHeadings();
88 foreach ( $this->parserOutput->getSections() as $heading ) {
89 $heading = $heading[
'line' ];
93 $heading = preg_replace(
'/<\/?span>/',
'', $heading );
95 $heading = preg_replace( [
'/[/',
'/]/' ], [
'[',
']' ], $heading );
96 $heading = preg_replace(
'/<sup>\s*\[\s*\d+\s*\]\s*<\/sup>/is',
'', $heading );
99 $heading = trim( Sanitizer::stripAllTags( $heading ) );
103 if ( !in_array( $heading, $ignoredHeadings ) ) {
104 $headings[] = $heading;
118 $lines = explode(
"\n", $message );
129 private function getIgnoredHeadings() {
130 static $ignoredHeadings =
null;
131 if ( $ignoredHeadings ===
null ) {
132 $ignoredHeadings = [];
136 $source =
wfMessage(
'cirrussearch-ignored-headings' )->inContentLanguage();
138 if ( !
$source->isDisabled() ) {
140 $ignoredHeadings =
$lines;
143 return $ignoredHeadings;
149 private function extractWikitextParts() {
150 if ( $this->allText !==
null ) {
153 $text = $this->parserOutput->getText( [
154 'enableSectionEditTokens' =>
false,
157 if ( $text ===
'' ) {
163 $this->openingText = $this->extractHeadingBeforeFirstHeading( $text );
165 $formatter =
new HtmlFormatter( $text );
168 $formatter->remove( $this->excludedElementSelectors );
169 $formatter->filterContent();
174 $formatter->remove( $this->auxiliaryElementSelectors );
175 $auxiliaryElements = $formatter->filterContent();
176 $this->allText = trim( Sanitizer::stripAllTags( $formatter->getText() ) );
177 foreach ( $auxiliaryElements as $auxiliaryElement ) {
179 trim( Sanitizer::stripAllTags( $formatter->getText( $auxiliaryElement ) ) );
188 private function extractHeadingBeforeFirstHeading( $text ) {
190 if ( !preg_match(
'/<h[123456]>/', $text,
$matches, PREG_OFFSET_CAPTURE ) ) {
195 $text = substr( $text, 0,
$matches[ 0 ][ 1 ] );
202 $formatter =
new HtmlFormatter( $text );
203 $formatter->remove( $this->excludedElementSelectors );
204 $formatter->remove( $this->auxiliaryElementSelectors );
205 $formatter->filterContent();
206 $text = trim( Sanitizer::stripAllTags( $formatter->getText() ) );
221 $this->extractWikitextParts();
222 return $this->openingText;
229 $this->extractWikitextParts();
230 return $this->allText;
237 $this->extractWikitextParts();
238 return $this->auxText;
246 return $this->parserOutput->getPageProperty(
'defaultsort' );
Class allowing to explore structure of parsed wikitext.
getDefaultSort()
Get the defaultsort property.
static parseSettingsInMessage( $message)
Parse a message content into an array.
headings()
Get headings on the page.
__construct(ParserOutput $parserOutput)