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 groupSelector()
 {
     $groups = MessageGroups::getAllGroups();
     uasort($groups, array('MessageGroups', 'groupLabelSort'));
     $dynamic = MessageGroups::getDynamicGroups();
     $groups = array_keys(array_merge($dynamic, $groups));
     $selected = $this->options['group'];
     $selector = new XmlSelect('group', 'group');
     $selector->setDefault($selected);
     foreach ($groups as $id) {
         $group = MessageGroups::getGroup($id);
         $hide = MessageGroups::getPriority($group) === 'discouraged';
         if (!$group->exists() || $hide && $id !== $selected) {
             continue;
         }
         $selector->addOption($group->getLabel(), $id);
     }
     return $selector->getHTML();
 }
Esempio n. 3
0
 protected function groupSelector()
 {
     $activeId = false;
     if ($this->group) {
         $activeId = $this->group->getId();
     }
     $groups = MessageGroups::getAllGroups();
     $dynamic = MessageGroups::getDynamicGroups();
     $groups = array_keys(array_merge($groups, $dynamic));
     $selected = $this->options['group'];
     $selector = new XmlSelect('group', 'group');
     $selector->setDefault($selected);
     foreach ($groups as $id) {
         if ($id === $activeId) {
             $activeId = false;
         }
         $group = MessageGroups::getGroup($id);
         $hide = MessageGroups::getPriority($group) === 'discouraged';
         if (!$group->exists() || $hide) {
             continue;
         }
         $selector->addOption($group->getLabel(), $id);
     }
     if ($activeId) {
         $selector->addOption($this->group->getLabel(), $activeId);
     }
     return $selector->getHTML();
 }