Seb35 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/331643 )

Change subject: [WIP] Use the parser to get each template parameter in the 
Index: namespace
......................................................................

[WIP] Use the parser to get each template parameter in the Index: namespace

This should be more robust than the current regexes, and should avoid bugs
like T119330, which is fixed.

In the current state, this commit is not usable since it is not idempotent for
each syntaxes (e.g. <pagelist /> is transformed to 
'"`UNIQ--pagelist-00000000-QINU`").
Although it correctly render the syntax in bug T119330.

Bug: T119330
Change-Id: Ie6322c40d1143e068ded259b420d2fee325de0dc
---
M includes/index/ProofreadIndexPage.php
1 file changed, 16 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/43/331643/1

diff --git a/includes/index/ProofreadIndexPage.php 
b/includes/index/ProofreadIndexPage.php
index fd6f63d..17f9155 100644
--- a/includes/index/ProofreadIndexPage.php
+++ b/includes/index/ProofreadIndexPage.php
@@ -235,14 +235,27 @@
         * @return array of ProofreadIndexEntry
         */
        public function getIndexEntries() {
+               global $wgUser, $wgContLang, $wgParser;
                if ( $this->entries === null ) {
                        $text = $this->getText();
                        $values = [];
+
+                       $parser = $wgParser;
+                       $options = new ParserOptions( $wgUser, $wgContLang );
+                       $parser->startExternalParse( $this->title, $options, 
Parser::OT_PLAIN, true );
+
+                       $dom = $parser->preprocessToDom( $text );
+                       $frame = $parser->getPreprocessor()->newFrame();
+                       $dom = $dom->getFirstChild();
+                       $childframe = $frame->newChild( 
$dom->getChildrenOfType( 'part' ) );
+
                        foreach ( $this->config as $varName => $property ) {
-                               $tagPattern = "/\n\|" . preg_quote( $varName, 
'/' ) . "=(.*?)\n(\||\}\})/is";
-                               if ( preg_match( $tagPattern, $text, $matches ) 
) {
-                                       $values[$varName] = $matches[1];
+                               if ( !array_key_exists( $varName, 
$childframe->namedArgs ) ) {
+                                       continue;
                                }
+                               $values[$varName] = 
$parser->getPreprocessor()->newFrame()->expand(
+                                       $childframe->namedArgs[$varName], 
PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES
+                               );
                        }
                        $this->entries = 
$this->getIndexEntriesFromIndexContent( $values );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/331643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6322c40d1143e068ded259b420d2fee325de0dc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Seb35 <se...@seb35.fr>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to