15 private ?
string $openingText =
null;
16 private ?
string $allText =
null;
18 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 = [
67 private readonly array $additionalExcludedSelectors = [],
90 $tocData = $this->parserOutput->getTOCData();
91 if ( $tocData ===
null ) {
94 $ignoredHeadings = $this->getIgnoredHeadings();
95 foreach ( $tocData->getSections() as $heading ) {
96 $heading = $heading->line;
100 $heading = preg_replace(
'/<\/?span>/',
'', $heading );
102 $heading = preg_replace( [
'/[/',
'/]/' ], [
'[',
']' ], $heading );
103 $heading = preg_replace(
'/<sup>\s*\[\s*\d+\s*\]\s*<\/sup>/i',
'', $heading );
106 $heading = trim( Sanitizer::stripAllTags( $heading ) );
110 if ( !in_array( $heading, $ignoredHeadings ) ) {
111 $headings[] = $heading;
127 $lines = explode(
"\n", $message );
129 $lines = preg_replace(
'/#.*$/',
'', $lines );
131 $lines = array_map( trim( ... ), $lines );
134 return array_filter( $lines );
142 private function getIgnoredHeadings() {
143 static $ignoredHeadings =
null;
144 if ( $ignoredHeadings ===
null ) {
145 $ignoredHeadings = [];
147 if ( !
$source->isDisabled() ) {
150 $ignoredHeadings = $lines;
154 return $ignoredHeadings;
160 private function extractWikitextParts() {
161 if ( $this->allText !==
null ) {
164 $text = $this->parserOutput->getContentHolderText();
165 if ( $text ===
'' ) {
172 $this->openingText = $this->extractTextBeforeFirstHeading( $text );
174 $doc = DOMUtils::parseHTML( $text );
177 foreach ( array_merge( self::EXCLUDED_ELEMENT_SELECTORS, $this->additionalExcludedSelectors ) as $selector ) {
178 foreach ( DOMCompat::querySelectorAll( $doc, $selector ) as $element ) {
179 $element->parentNode->removeChild( $element );
186 foreach ( self::AUXILIARY_ELEMENT_SELECTORS as $selector ) {
187 foreach ( DOMCompat::querySelectorAll( $doc, $selector ) as $element ) {
188 $this->auxText[] = trim( Sanitizer::stripAllTags( DOMCompat::getInnerHTML( $element ) ) );
189 $element->parentNode->removeChild( $element );
193 $this->allText = trim( Sanitizer::stripAllTags( DOMCompat::getInnerHTML( DOMCompat::getBody( $doc ) ) ) );
203 private function extractTextBeforeFirstHeading( $text ) {
205 if ( !preg_match(
'/<h[123456]\b/', $text, $matches, PREG_OFFSET_CAPTURE ) ) {
210 $text = substr( $text, 0, $matches[ 0 ][ 1 ] );
217 $doc = DOMUtils::parseHTML( $text );
218 $excludedSelectors = array_merge( self::EXCLUDED_ELEMENT_SELECTORS,
219 self::AUXILIARY_ELEMENT_SELECTORS, $this->additionalExcludedSelectors );
220 foreach ( $excludedSelectors as $selector ) {
221 foreach ( DOMCompat::querySelectorAll( $doc, $selector ) as $element ) {
222 $element->parentNode->removeChild( $element );
226 $text = trim( Sanitizer::stripAllTags( DOMCompat::getInnerHTML( DOMCompat::getBody( $doc ) ) ) );
241 $this->extractWikitextParts();
243 return $this->openingText;
250 $this->extractWikitextParts();
252 return $this->allText;
259 $this->extractWikitextParts();
261 return $this->auxText;
270 $sort = $this->parserOutput->getPageProperty(
'defaultsort' );
271 if ( $sort ===
false ) {