diff options
Diffstat (limited to 'www/wiki/extensions/Translate/insertables/TranslatablePageInsertablesSuggester.php')
-rw-r--r-- | www/wiki/extensions/Translate/insertables/TranslatablePageInsertablesSuggester.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/www/wiki/extensions/Translate/insertables/TranslatablePageInsertablesSuggester.php b/www/wiki/extensions/Translate/insertables/TranslatablePageInsertablesSuggester.php new file mode 100644 index 00000000..61582606 --- /dev/null +++ b/www/wiki/extensions/Translate/insertables/TranslatablePageInsertablesSuggester.php @@ -0,0 +1,36 @@ +<?php +/** + * @file + * @author Niklas Laxström + * @license GPL-2.0-or-later + */ + +/** + * Special insertables for translatable pages. + * @since 2013.11 + */ +class TranslatablePageInsertablesSuggester extends MediaWikiInsertablesSuggester { + public function getInsertables( $text ) { + $insertables = parent::getInsertables( $text ); + + // Translatable pages allow naming the variables. Basically anything is + // allowed in a variable name, but here we are stricter to avoid too many + // false positives. + $matches = []; + preg_match_all( '/\$([a-zA-Z0-9-_]+)/', $text, $matches, PREG_SET_ORDER ); + + $new = array_map( function ( $match ) { + // Numerical ones are already handled by parent + if ( ctype_digit( $match[1] ) ) { + return null; + } + + return new Insertable( $match[0], $match[0] ); + }, $matches ); + + $new = array_filter( $new ); + $insertables = array_merge( $insertables, $new ); + + return $insertables; + } +} |