/** * Create a new TitleBlacklistEntry from a line of text * * @param $line String containing a line of blacklist text * @return TitleBlacklistEntry */ public static function newFromString($line, $source) { $raw = $line; // Keep line for raw data $options = array(); // Strip comments $line = preg_replace("/^\\s*([^#]*)\\s*((.*)?)\$/", "\\1", $line); $line = trim($line); // Parse the rest of message preg_match('/^(.*?)(\\s*<([^<>]*)>)?$/', $line, $pockets); @(list($full, $regex, $null, $opts_str) = $pockets); $regex = trim($regex); $regex = str_replace('_', ' ', $regex); // We'll be matching against text form $opts_str = trim($opts_str); // Parse opts $opts = preg_split('/\\s*\\|\\s*/', $opts_str); foreach ($opts as $opt) { $opt2 = strtolower($opt); if ($opt2 == 'autoconfirmed') { $options['autoconfirmed'] = true; } if ($opt2 == 'moveonly') { $options['moveonly'] = true; } if ($opt2 == 'newaccountonly') { $options['newaccountonly'] = true; } if ($opt2 == 'noedit') { $options['noedit'] = true; } if ($opt2 == 'casesensitive') { $options['casesensitive'] = true; } if ($opt2 == 'reupload') { $options['reupload'] = true; } if (preg_match('/errmsg\\s*=\\s*(.+)/i', $opt, $matches)) { $options['errmsg'] = $matches[1]; } if ($opt2 == 'antispoof') { $options['antispoof'] = true; } } // Process magic words preg_match_all('/{{\\s*([a-z]+)\\s*:\\s*(.+?)\\s*}}/', $regex, $magicwords, PREG_SET_ORDER); foreach ($magicwords as $mword) { global $wgParser; // Functions we're calling don't need, nevertheless let's use it switch (strtolower($mword[1])) { case 'ns': $cpf_result = CoreParserFunctions::ns($wgParser, $mword[2]); if (is_string($cpf_result)) { $regex = str_replace($mword[0], $cpf_result, $regex); // All result will have the same value, so we can just use str_seplace() } break; case 'int': $cpf_result = wfMessage($mword[2])->inContentLanguage()->text(); if (is_string($cpf_result)) { $regex = str_replace($mword[0], $cpf_result, $regex); } } } // Return result if ($regex) { return new TitleBlacklistEntry($regex, $options, $raw, $source); } else { return null; } }