14 private ?
string $openingText =
null;
15 private ?
string $allText =
null;
17 private array $auxText = [];
23 private const EXCLUDED_ELEMENT_SELECTORS = [
33 'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
38 '.navigation-not-searchable',
40 '.wbmi-entityview-emptyCaption',
46 private const AUXILIARY_ELEMENT_SELECTORS = [
64 $this->parserOutput = $parserOutput;
86 $tocData = $this->parserOutput->getTOCData();
87 if ( $tocData ===
null ) {
90 $ignoredHeadings = $this->getIgnoredHeadings();
91 foreach ( $tocData->getSections() as $heading ) {
92 $heading = $heading->line;
96 $heading = preg_replace(
'/<\/?span>/',
'', $heading );
98 $heading = preg_replace( [
'/[/',
'/]/' ], [
'[',
']' ], $heading );
99 $heading = preg_replace(
'/<sup>\s*\[\s*\d+\s*\]\s*<\/sup>/i',
'', $heading );
102 $heading = trim( Sanitizer::stripAllTags( $heading ) );
106 if ( !in_array( $heading, $ignoredHeadings ) ) {
107 $headings[] = $heading;
123 $lines = explode(
"\n", $message );
130 return array_filter(
$lines );
138 private function getIgnoredHeadings() {
139 static $ignoredHeadings =
null;
140 if ( $ignoredHeadings ===
null ) {
141 $ignoredHeadings = [];
143 if ( !
$source->isDisabled() ) {
146 $ignoredHeadings =
$lines;
150 return $ignoredHeadings;
156 private function extractWikitextParts() {
157 if ( $this->allText !==
null ) {
160 $text = $this->parserOutput->getRawText();
161 if ( $text ===
'' ) {
168 $this->openingText = $this->extractTextBeforeFirstHeading( $text );
170 $formatter =
new HtmlFormatter( $text );
173 $formatter->remove( self::EXCLUDED_ELEMENT_SELECTORS );
174 $formatter->filterContent();
179 $formatter->remove( self::AUXILIARY_ELEMENT_SELECTORS );
180 $auxiliaryElements = $formatter->filterContent();
181 $this->allText = trim( Sanitizer::stripAllTags( $formatter->getText() ) );
182 foreach ( $auxiliaryElements as $auxiliaryElement ) {
184 trim( Sanitizer::stripAllTags( $formatter->getText( $auxiliaryElement ) ) );
195 private function extractTextBeforeFirstHeading( $text ) {
197 if ( !preg_match(
'/<h[123456]\b/', $text,
$matches, PREG_OFFSET_CAPTURE ) ) {
202 $text = substr( $text, 0,
$matches[ 0 ][ 1 ] );
209 $formatter =
new HtmlFormatter( $text );
210 $formatter->remove( self::EXCLUDED_ELEMENT_SELECTORS );
211 $formatter->remove( self::AUXILIARY_ELEMENT_SELECTORS );
212 $formatter->filterContent();
213 $text = trim( Sanitizer::stripAllTags( $formatter->getText() ) );
228 $this->extractWikitextParts();
230 return $this->openingText;
237 $this->extractWikitextParts();
239 return $this->allText;
246 $this->extractWikitextParts();
248 return $this->auxText;
257 $sort = $this->parserOutput->getPageProperty(
'defaultsort' );
258 if ( $sort ===
false ) {