12 private ?
string $openingText =
null;
13 private ?
string $allText =
null;
15 private array $auxText = [];
21 private const EXCLUDED_ELEMENT_SELECTORS = [
31 'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
36 '.navigation-not-searchable',
38 '.wbmi-entityview-emptyCaption',
44 private const AUXILIARY_ELEMENT_SELECTORS = [
62 $this->parserOutput = $parserOutput;
83 $tocData = $this->parserOutput->getTOCData();
84 if ( $tocData ===
null ) {
87 $ignoredHeadings = $this->getIgnoredHeadings();
88 foreach ( $tocData->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>/i',
'', $heading );
99 $heading = trim( Sanitizer::stripAllTags( $heading ) );
103 if ( !in_array( $heading, $ignoredHeadings ) ) {
104 $headings[] = $heading;
118 $lines = explode(
"\n", $message );
124 return array_filter(
$lines );
131 private function getIgnoredHeadings() {
132 static $ignoredHeadings =
null;
133 if ( $ignoredHeadings ===
null ) {
134 $ignoredHeadings = [];
138 $source =
wfMessage(
'cirrussearch-ignored-headings' )->inContentLanguage();
140 if ( !
$source->isDisabled() ) {
143 $ignoredHeadings =
$lines;
146 return $ignoredHeadings;
152 private function extractWikitextParts() {
153 if ( $this->allText !==
null ) {
156 $text = $this->parserOutput->getRawText();
157 if ( $text ===
'' ) {
163 $this->openingText = $this->extractTextBeforeFirstHeading( $text );
165 $formatter =
new HtmlFormatter( $text );
168 $formatter->remove( self::EXCLUDED_ELEMENT_SELECTORS );
169 $formatter->filterContent();
174 $formatter->remove( self::AUXILIARY_ELEMENT_SELECTORS );
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 extractTextBeforeFirstHeading( $text ) {
190 if ( !preg_match(
'/<h[123456]\b/', $text,
$matches, PREG_OFFSET_CAPTURE ) ) {
195 $text = substr( $text, 0,
$matches[ 0 ][ 1 ] );
202 $formatter =
new HtmlFormatter( $text );
203 $formatter->remove( self::EXCLUDED_ELEMENT_SELECTORS );
204 $formatter->remove( self::AUXILIARY_ELEMENT_SELECTORS );
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 $sort = $this->parserOutput->getPageProperty(
'defaultsort' );
247 if ( $sort ===
false ) {
Class allowing to explore the structure of parsed wikitext.
getDefaultSort()
Get the "defaultsort" property.
static parseSettingsInMessage( $message)
Parse a message content into an array.
headings()
Gets headings from the page.
__construct(ParserOutput $parserOutput)