Use ParserOutput stateless transforms
[lhc/web/wiklou.git] / includes / content / WikiTextStructure.php
index 9768d36..0eadc3c 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
 use HtmlFormatter\HtmlFormatter;
-use MediaWiki\Logger\LoggerFactory;
 
 /**
  * Class allowing to explore structure of parsed wikitext.
@@ -28,30 +27,38 @@ class WikiTextStructure {
         * @var string[] selectors to elements that are excluded entirely from search
         */
        private $excludedElementSelectors = [
-               'audio', 'video',       // "it looks like you don't have javascript enabled..."
-                                       // do not need to index
-               'sup.reference',        // The [1] for references
-               '.mw-cite-backlink',    // The ↑ next to references in the references section
-               'h1', 'h2', 'h3',       // Headings are already indexed in their own field.
-               'h5', 'h6', 'h4',
-               '.autocollapse',        // Collapsed fields are hidden by default so we don't want them
-                                                               // showing up.
+               // "it looks like you don't have javascript enabled..." – do not need to index
+               'audio', 'video',
+               // The [1] for references
+               'sup.reference',
+               // The ↑ next to references in the references section
+               '.mw-cite-backlink',
+               // Headings are already indexed in their own field.
+               'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
+               // Collapsed fields are hidden by default so we don't want them showing up.
+               '.autocollapse',
+               // Content explicitly decided to be not searchable by editors such
+               // as custom navigation templates.
+               '.navigation-not-searchable'
        ];
 
        /**
         * @var string[] selectors to elements that are considered auxiliary to article text for search
         */
        private $auxiliaryElementSelectors = [
-               '.thumbcaption',        // Thumbnail captions aren't really part of the text proper
-               'table',                // Neither are tables
-               '.rellink',             // Common style for "See also:".
-               '.dablink',             // Common style for calling out helpful links at the top
-                                                               // of the article.
-               '.searchaux',           // New class users can use to mark stuff as auxiliary to searches.
+               // Thumbnail captions aren't really part of the text proper
+               '.thumbcaption',
+               // Neither are tables
+               'table',
+               // Common style for "See also:".
+               '.rellink',
+               // Common style for calling out helpful links at the top of the article.
+               '.dablink',
+               // New class users can use to mark stuff as auxiliary to searches.
+               '.searchaux',
        ];
 
        /**
-        * WikiTextStructure constructor.
         * @param ParserOutput $parserOutput
         */
        public function __construct( ParserOutput $parserOutput ) {
@@ -78,7 +85,7 @@ class WikiTextStructure {
                        $heading = $heading[ 'line' ];
 
                        // Some wikis wrap the brackets in a span:
-                       // http://en.wikipedia.org/wiki/MediaWiki:Cite_reference_link
+                       // https://en.wikipedia.org/wiki/MediaWiki:Cite_reference_link
                        $heading = preg_replace( '/<\/?span>/', '', $heading );
                        // Normalize [] so the following regexp would work.
                        $heading = preg_replace( [ '/&#91;/', '/&#93;/' ], [ '[', ']' ], $heading );
@@ -139,9 +146,10 @@ class WikiTextStructure {
                if ( !is_null( $this->allText ) ) {
                        return;
                }
-               $this->parserOutput->setEditSectionTokens( false );
-               $this->parserOutput->setTOCEnabled( false );
-               $text = $this->parserOutput->getText();
+               $text = $this->parserOutput->getText( [
+                       'enableSectionEditTokens' => false,
+                       'allowTOC' => false,
+               ] );
                if ( strlen( $text ) == 0 ) {
                        $this->allText = "";
                        // empty text - nothing to seek here
@@ -233,4 +241,12 @@ class WikiTextStructure {
                $this->extractWikitextParts();
                return $this->auxText;
        }
+
+       /**
+        * Get the defaultsort property
+        * @return string|null
+        */
+       public function getDefaultSort() {
+               return $this->parserOutput->getProperty( 'defaultsort' );
+       }
 }