コード例 #1
0
 /**
  * @dataProvider problematicMessageKeyProvider
  */
 public function testKeyManglingWithPrefixing($key, $comment)
 {
     $matcher = new StringMatcher('prefix', array('*'));
     $mangled = $matcher->mangle($key);
     $title = Title::makeTitleSafe(NS_MEDIAWIKI, $mangled);
     $this->assertInstanceOf('Title', $title, "Key '{$mangled}' did not produce a valid title");
     $unmangled = $matcher->unMangle($mangled);
     $this->assertEquals($key, $unmangled, 'Mangling is reversible');
 }
 public function getMangler()
 {
     if (!isset($this->mangler)) {
         $this->mangler = StringMatcher::emptyMatcher();
     }
     return $this->mangler;
 }
 public function testGenerateMessageBlock()
 {
     $ffs = MessageGroupBase::factory($this->conf)->getFFS();
     $obj = new ReflectionObject($ffs);
     $method = $obj->getMethod('generateMessageBlock');
     $method->setAccessible(true);
     $collection = new MockMessageCollectionForExport();
     $mangler = StringMatcher::emptyMatcher();
     $result = $method->invoke($ffs, $collection, $mangler);
     $expected = "\n\t'translatedmsg' => 'translation',\n\t'fuzzymsg' => 'translation', # Fuzzy\n";
     $this->assertEquals($expected, $result);
 }
コード例 #4
0
 /**
  * Creates MediaWikiExtensionMessageGroup objects from parsed data.
  * @param string $id unique group id already prefixed
  * @param array $info array of group info
  * @return MediaWikiExtensionMessageGroup
  */
 protected function createMessageGroup($id, $info)
 {
     $conf = array();
     $conf['BASIC']['class'] = 'MediaWikiExtensionMessageGroup';
     $conf['BASIC']['id'] = $id;
     $conf['BASIC']['namespace'] = $this->namespace;
     $conf['BASIC']['label'] = $info['name'];
     if (isset($info['desc'])) {
         $conf['BASIC']['description'] = $info['desc'];
     } else {
         $conf['BASIC']['descriptionmsg'] = $info['descmsg'];
         $conf['BASIC']['extensionurl'] = $info['url'];
     }
     if ($info['format'] === 'json') {
         $conf['FILES']['class'] = 'JsonFFS';
     } else {
         $conf['FILES']['class'] = 'MediaWikiExtensionFFS';
     }
     $conf['FILES']['sourcePattern'] = $this->path . '/' . $info['file'];
     // @todo Find a better way
     if (isset($info['aliasfile'])) {
         $conf['FILES']['aliasFileSource'] = $this->path . '/' . $info['aliasfile'];
         $conf['FILES']['aliasFile'] = $info['aliasfile'];
     }
     if (isset($info['magicfile'])) {
         $conf['FILES']['magicFileSource'] = $this->path . '/' . $info['magicfile'];
         $conf['FILES']['magicFile'] = $info['magicfile'];
     }
     if (isset($info['prefix'])) {
         $conf['MANGLER']['class'] = 'StringMatcher';
         $conf['MANGLER']['prefix'] = $info['prefix'];
         $conf['MANGLER']['patterns'] = $info['mangle'];
         $mangler = new StringMatcher($info['prefix'], $info['mangle']);
         if (isset($info['ignored'])) {
             $info['ignored'] = $mangler->mangle($info['ignored']);
         }
         if (isset($info['optional'])) {
             $info['optional'] = $mangler->mangle($info['optional']);
         }
     }
     $conf['CHECKER']['class'] = 'MediaWikiMessageChecker';
     $conf['CHECKER']['checks'] = array('pluralCheck', 'pluralFormsCheck', 'wikiParameterCheck', 'wikiLinksCheck', 'XhtmlCheck', 'braceBalanceCheck', 'pagenameMessagesCheck', 'miscMWChecks');
     $conf['INSERTABLES']['class'] = 'MediaWikiInsertablesSuggester';
     if (isset($info['optional'])) {
         $conf['TAGS']['optional'] = $info['optional'];
     }
     if (isset($info['ignored'])) {
         $conf['TAGS']['ignored'] = $info['ignored'];
     }
     return MessageGroupBase::factory($conf);
 }
コード例 #5
0
 protected function parseTags($patterns)
 {
     $messageKeys = $this->getKeys();
     $matches = array();
     /**
      * Collect exact keys, no point running them trough string matcher
      */
     foreach ($patterns as $index => $pattern) {
         if (strpos($pattern, '*') === false) {
             $matches[] = $pattern;
             unset($patterns[$index]);
         }
     }
     if (count($patterns)) {
         /**
          * Rest of the keys contain wildcards.
          */
         $mangler = new StringMatcher('', $patterns);
         /**
          * Use mangler to find messages that match.
          */
         foreach ($messageKeys as $key) {
             if ($mangler->match($key)) {
                 $matches[] = $key;
             }
         }
     }
     return $matches;
 }
コード例 #6
0
ファイル: Groups.php プロジェクト: schwarer2006/wikia
 /**
  * If the list of group ids contains wildcards, this function will match
  * them against the list of all supported groups and return matched group
  * names.
  * @param $ids \list{String}
  * @return \list{String}
  */
 protected function expandWildcards($ids)
 {
     $hasWild = false;
     foreach ($ids as $id) {
         if (strpos($id, '*') !== false) {
             $hasWild = true;
             break;
         }
     }
     if (!$hasWild) {
         return $ids;
     }
     $matcher = new StringMatcher('', $ids);
     $all = array();
     foreach (MessageGroups::singleton()->getGroups() as $id => $_) {
         if ($matcher->match($id)) {
             $all[] = $id;
         }
     }
     return $all;
 }
コード例 #7
0
ファイル: MessageGroups.php プロジェクト: schwarer2006/wikia
 public function __construct()
 {
     $this->mangler = StringMatcher::emptyMatcher();
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $filter = $params['filter'];
     $groups = array();
     // Parameter root as all for all pages subgroups
     if ($params['root'] === 'all') {
         $allGroups = MessageGroups::getAllGroups();
         foreach ($allGroups as $group) {
             if ($group instanceof WikiPageMessageGroup) {
                 $groups[] = $group;
             }
         }
     } elseif ($params['format'] === 'flat') {
         if ($params['root'] !== '') {
             $group = MessageGroups::getGroup($params['root']);
             if ($group) {
                 $groups[$params['root']] = $group;
             }
         } else {
             $groups = MessageGroups::getAllGroups();
             foreach (MessageGroups::getDynamicGroups() as $id => $unused) {
                 $groups[$id] = MessageGroups::getGroup($id);
             }
         }
         // Not sorted by default, so do it now
         // Work around php bug: https://bugs.php.net/bug.php?id=50688
         wfSuppressWarnings();
         usort($groups, array('MessageGroups', 'groupLabelSort'));
         wfRestoreWarnings();
     } elseif ($params['root'] !== '') {
         // format=tree from now on, as it is the only other valid option
         $group = MessageGroups::getGroup($params['root']);
         if ($group instanceof AggregateMessageGroup) {
             $groups = MessageGroups::subGroups($group);
             // The parent group is the first, ignore it
             array_shift($groups);
         }
     } else {
         $groups = MessageGroups::getGroupStructure();
         foreach (MessageGroups::getDynamicGroups() as $id => $unused) {
             $groups[$id] = MessageGroups::getGroup($id);
         }
     }
     // Do not list the sandbox group. The code that knows it
     // exists can access it directly.
     if (isset($groups['!sandbox'])) {
         unset($groups['!sandbox']);
     }
     $props = array_flip($params['prop']);
     $result = $this->getResult();
     $matcher = new StringMatcher('', $filter);
     /**
      * @var MessageGroup $mixed
      */
     foreach ($groups as $mixed) {
         if ($filter !== array() && !$matcher->match($mixed->getId())) {
             continue;
         }
         $a = $this->formatGroup($mixed, $props);
         $result->setIndexedTagName($a, 'group');
         // @todo Add a continue?
         $fit = $result->addValue(array('query', $this->getModuleName()), null, $a);
         if (!$fit) {
             $this->setWarning('Could not fit all groups in the resultset.');
             // Even if we're not going to give a continue, no point carrying on
             // if the result is full
             break;
         }
     }
     if (defined('ApiResult::META_CONTENT')) {
         $result->addIndexedTagName(array('query', $this->getModuleName()), 'group');
     } else {
         $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'group');
     }
 }
 protected function generateMessageBlock(MessageCollection $collection, StringMatcher $mangler)
 {
     $block = '';
     /**
      * @var TMessage $m
      */
     foreach ($collection as $key => $m) {
         $value = $m->translation();
         if ($value === null) {
             continue;
         }
         $key = $mangler->unmangle($key);
         $value = str_replace(TRANSLATE_FUZZY, '', $value);
         $fuzzy = $m->hasTag('fuzzy') ? ' # Fuzzy' : '';
         $key = self::quote($key);
         $value = self::quote($value);
         $block .= "\t{$key} => {$value},{$fuzzy}\n";
     }
     // Do not create empty sections
     if ($block === '') {
         return false;
     }
     return "\n{$block}";
 }
コード例 #10
0
 /**
  * If the list of message group ids contains wildcards, this function will match
  * them against the list of all supported message groups and return matched
  * message group ids.
  * @param string[]|string $ids
  * @return string[]
  * @since 2012-02-13
  */
 public static function expandWildcards($ids)
 {
     $all = array();
     $matcher = new StringMatcher('', (array) $ids);
     foreach (self::getAllGroups() as $id => $_) {
         if ($matcher->match($id)) {
             $all[] = $id;
         }
     }
     return $all;
 }
コード例 #11
0
ファイル: StringHelper.php プロジェクト: 1271281914/pspider
 /**
  * 根据标记快速查找字符串列表
  * @param string $buf
  * @param array $config
  * array(
  *   array(key1, arg1, arg2, ...),
  *   array(key2, arg1, arg2, ...),
  * ),
  * @return array
  * @see StringMatcher::find
  */
 public static function finds($buf, $config, &$error = null)
 {
     $obj = new StringMatcher($buf);
     return $obj->finds($config, $error);
 }