mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Don't extract template parameters from <pre>
<pre> behaves very similar to <nowiki> in so far that whatever it contains doesn't get parsed as wikitext. It might contain {{{…}}} tripple brackets, but these aren't going to be activated as template parameters. Bug: T91326 Change-Id: I05c24e369d97c48161c565e2ef30969ec28c6a23
This commit is contained in:
parent
192691cdb4
commit
d3f00177ba
|
@ -216,9 +216,10 @@ class ApiTemplateData extends ApiBase {
|
|||
* @return array[] Parameter info in the same format as the templatedata 'params' key.
|
||||
*/
|
||||
private function getRawParams( string $wikitext ): array {
|
||||
// Ignore wikitext within nowiki tags and comments
|
||||
// Ignore non-wikitext content in comments and wikitext-escaping tags
|
||||
$wikitext = preg_replace( '/<!--.*?-->/s', '', $wikitext );
|
||||
$wikitext = preg_replace( '/<nowiki\s*>.*?<\/nowiki\s*>/s', '', $wikitext );
|
||||
$wikitext = preg_replace( '/<pre\s*>.*?<\/pre\s*>/s', '', $wikitext );
|
||||
|
||||
// This regex matches the one in ext.TemplateDataGenerator.sourceHandler.js
|
||||
if ( !preg_match_all( '/{{{+([^\n#={|}]*?)([<|]|}}})/m', $wikitext, $rawParams ) ) {
|
||||
|
|
|
@ -173,9 +173,10 @@ SourceHandler.prototype.extractParametersFromTemplateCode = function ( templateC
|
|||
// This regex matches the one in TemplateDataBlob.php
|
||||
paramExtractor = /{{{+([^\n#={|}]*?)([<|]|}}})/mg;
|
||||
|
||||
// Strip everything in nowiki tags and HTML comments
|
||||
// Ignore non-wikitext content in comments and wikitext-escaping tags
|
||||
templateCode = templateCode.replace( /<!--[\s\S]*?-->/g, '' )
|
||||
.replace( /<nowiki\s*>[\s\S]*?<\/nowiki\s*>/g, '' );
|
||||
.replace( /<nowiki\s*>[\s\S]*?<\/nowiki\s*>/g, '' )
|
||||
.replace( /<pre\s*>[\s\S]*?<\/pre\s*>/g, '' );
|
||||
|
||||
var matches;
|
||||
while ( ( matches = paramExtractor.exec( templateCode ) ) !== null ) {
|
||||
|
|
|
@ -1407,7 +1407,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
'Params within comments and nowiki tags' => [
|
||||
'Lorem <!-- {{{name}}} --> ipsum <nowiki > {{{middlename}}}' .
|
||||
'</nowiki> {{{surname}}}',
|
||||
'</nowiki> <pre>{{{pre}}}</pre> {{{surname}}}',
|
||||
[ 'surname' => [] ]
|
||||
],
|
||||
'Param within comments and param name outside with comment' => [
|
||||
|
|
Loading…
Reference in a new issue