21 private $auxText = [];
25 private $parserOutput;
30 private $excludedElementSelectors = [
40 'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
45 '.navigation-not-searchable',
47 '.wbmi-entityview-emptyCaption',
53 private $auxiliaryElementSelectors = [
71 $this->parserOutput = $parserOutput;
89 $tocData = $this->parserOutput->getTOCData();
90 if ( $tocData ===
null ) {
93 $ignoredHeadings = $this->getIgnoredHeadings();
94 foreach ( $tocData->getSections() as $heading ) {
95 $heading = $heading->line;
99 $heading = preg_replace(
'/<\/?span>/',
'', $heading );
101 $heading = preg_replace( [
'/[/',
'/]/' ], [
'[',
']' ], $heading );
102 $heading = preg_replace(
'/<sup>\s*\[\s*\d+\s*\]\s*<\/sup>/i',
'', $heading );
105 $heading = trim( Sanitizer::stripAllTags( $heading ) );
109 if ( !in_array( $heading, $ignoredHeadings ) ) {
110 $headings[] = $heading;
124 $lines = explode(
"\n", $message );
135 private function getIgnoredHeadings() {
136 static $ignoredHeadings =
null;
137 if ( $ignoredHeadings ===
null ) {
138 $ignoredHeadings = [];
142 $source =
wfMessage(
'cirrussearch-ignored-headings' )->inContentLanguage();
144 if ( !
$source->isDisabled() ) {
146 $ignoredHeadings =
$lines;
149 return $ignoredHeadings;
155 private function extractWikitextParts() {
156 if ( $this->allText !==
null ) {
159 $text = $this->parserOutput->getText( [
160 'enableSectionEditTokens' =>
false,
163 if ( $text ===
'' ) {
169 $this->openingText = $this->extractTextBeforeFirstHeading( $text );
171 $formatter =
new HtmlFormatter( $text );
174 $formatter->remove( $this->excludedElementSelectors );
175 $formatter->filterContent();
180 $formatter->remove( $this->auxiliaryElementSelectors );
181 $auxiliaryElements = $formatter->filterContent();
182 $this->allText = trim( Sanitizer::stripAllTags( $formatter->getText() ) );
183 foreach ( $auxiliaryElements as $auxiliaryElement ) {
185 trim( Sanitizer::stripAllTags( $formatter->getText( $auxiliaryElement ) ) );
194 private function extractTextBeforeFirstHeading( $text ) {
196 if ( !preg_match(
'/<h[123456]>/', $text,
$matches, PREG_OFFSET_CAPTURE ) ) {
201 $text = substr( $text, 0,
$matches[ 0 ][ 1 ] );
208 $formatter =
new HtmlFormatter( $text );
209 $formatter->remove( $this->excludedElementSelectors );
210 $formatter->remove( $this->auxiliaryElementSelectors );
211 $formatter->filterContent();
212 $text = trim( Sanitizer::stripAllTags( $formatter->getText() ) );
227 $this->extractWikitextParts();
228 return $this->openingText;
235 $this->extractWikitextParts();
236 return $this->allText;
243 $this->extractWikitextParts();
244 return $this->auxText;
252 $sort = $this->parserOutput->getPageProperty(
'defaultsort' );
253 if ( $sort ===
false ) {
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)