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;
 }
 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');
     }
 }
Example #3
0
 /**
  * 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;
 }
 /**
  * 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;
 }