- $array[$wgContLang->lc($syn)] = $value;
- }
- }
-
- function isCaseSensitive() {
- return $this->mCaseSensitive;
- }
-
- function getId() {
- return $this->mId;
- }
-}
-
-/**
- * Class for handling an array of magic words
- */
-class MagicWordArray {
- var $names = array();
- var $hash;
- var $baseRegex, $regex;
-
- function __construct( $names = array() ) {
- $this->names = $names;
- }
-
- /**
- * Add a magic word by name
- */
- public function add( $name ) {
- global $wgContLang;
- $this->names[] = $name;
- $this->hash = $this->baseRegex = $this->regex = null;
- }
-
- /**
- * Add a number of magic words by name
- */
- public function addArray( $names ) {
- $this->names = array_merge( $this->names, array_values( $names ) );
- $this->hash = $this->baseRegex = $this->regex = null;
- }
-
- /**
- * Get a 2-d hashtable for this array
- */
- function getHash() {
- if ( is_null( $this->hash ) ) {
- global $wgContLang;
- $this->hash = array( 0 => array(), 1 => array() );
- foreach ( $this->names as $name ) {
- $magic = MagicWord::get( $name );
- $case = intval( $magic->isCaseSensitive() );
- foreach ( $magic->getSynonyms() as $syn ) {
- if ( !$case ) {
- $syn = $wgContLang->lc( $syn );
- }
- $this->hash[$case][$syn] = $name;
- }
- }
- }
- return $this->hash;
- }
-
- /**
- * Get the base regex
- */
- function getBaseRegex() {
- if ( is_null( $this->baseRegex ) ) {
- $this->baseRegex = array( 0 => '', 1 => '' );
- foreach ( $this->names as $name ) {
- $magic = MagicWord::get( $name );
- $case = intval( $magic->isCaseSensitive() );
- foreach ( $magic->getSynonyms() as $i => $syn ) {
- $group = "(?P<{$i}_{$name}>" . preg_quote( $syn, '/' ) . ')';
- if ( $this->baseRegex[$case] === '' ) {
- $this->baseRegex[$case] = $group;
- } else {
- $this->baseRegex[$case] .= '|' . $group;
- }
- }
- }
- }
- return $this->baseRegex;
- }
-
- /**
- * Get an unanchored regex
- */
- function getRegex() {
- if ( is_null( $this->regex ) ) {
- $base = $this->getBaseRegex();
- $this->regex = array( '', '' );
- if ( $this->baseRegex[0] !== '' ) {
- $this->regex[0] = "/{$base[0]}/iuS";
- }
- if ( $this->baseRegex[1] !== '' ) {
- $this->regex[1] = "/{$base[1]}/S";
- }