public function testAPIFilterAccuracy() { $ids = array('MadeUpGroup'); $ids += array_keys(MessageGroups::getAllGroups()); foreach ($ids as $id) { list($data) = $this->doApiRequest(array('action' => 'query', 'meta' => 'messagegroups', 'mgprop' => 'id|label|class|namespace|exists', 'mgfilter' => $id, 'continue' => '')); if ($id === 'MadeUpGroup') { // Check structure (shouldn't find anything) $this->assertArrayNotHasKey('warnings', $data); $this->assertArrayHasKey('query', $data); $this->assertCount(1, $data['query']); $this->assertArrayHasKey('messagegroups', $data['query']); $this->assertCount(0, $data['query']['messagegroups']); continue; } // Check structure (filter is unique given these names) $this->assertArrayNotHasKey('warnings', $data); $this->assertArrayHasKey('query', $data); $this->assertCount(1, $data['query']); $this->assertArrayHasKey('messagegroups', $data['query']); $this->assertCount(1, $data['query']['messagegroups']); // Check content $item = $data['query']['messagegroups'][0]; $this->assertCount(5, $item); $this->assertSame($item['id'], $id); $this->assertSame($item['label'], 'thelabel'); $this->assertSame($item['exists'], true); $this->assertStringEndsWith('id', $item['id']); // theid, anotherid $this->assertSame($item['namespace'], 5); $this->assertSame($item['class'], 'WikiMessageGroup'); } }
public function execute($parameters) { $this->setHeaders(); $out = $this->getOutput(); // Check permissions if ($this->getUser()->isAllowed('translate-manage')) { $this->hasPermission = true; } $groups = MessageGroups::getAllGroups(); uasort($groups, array('MessageGroups', 'groupLabelSort')); $aggregates = array(); $pages = array(); foreach ($groups as $group) { if ($group instanceof WikiPageMessageGroup) { $pages[] = $group; } elseif ($group instanceof AggregateMessageGroup) { $subgroups = TranslateMetadata::getSubgroups($group->getId()); if ($subgroups !== false) { $aggregates[] = $group; } } } if (!count($pages)) { // @todo Use different message $out->addWikiMsg('tpt-list-nopages'); return; } $this->showAggregateGroups($aggregates, $pages); }
public function getDefinitions() { $groups = MessageGroups::getAllGroups(); $keys = array(); /** * @var $g MessageGroup */ foreach ($groups as $g) { $states = $g->getMessageGroupStates()->getStates(); foreach (array_keys($states) as $state) { $keys["Translate-workflow-state-{$state}"] = $state; } } $defs = TranslateUtils::getContents(array_keys($keys), $this->getNamespace()); foreach ($keys as $key => $state) { if (!isset($defs[$key])) { // @todo Use jobqueue $title = Title::makeTitleSafe($this->getNamespace(), $key); $page = new WikiPage($title); $content = ContentHandler::makeContent($state, $title); $page->doEditContent($content, wfMessage('translate-workflow-autocreated-summary', $state)->inContentLanguage()->text(), 0, false, FuzzyBot::getUser()); } else { // Use the wiki translation as definition if available. // getContents returns array( content, last author ) list($content, ) = $defs[$key]; $keys[$key] = $content; } } return $keys; }
public function execute() { $groups = MessageGroups::getAllGroups(); $result = $this->getResult(); foreach ($groups as $id => $g) { $a = array(); $a['id'] = $id; $a['label'] = $g->getLabel(); $a['description'] = $g->getDescription(); $a['class'] = get_class($g); $a['exists'] = $g->exists(); // TODO: Add a continue? $fit = $result->addValue(array('query', $this->getModuleName()), null, $a); if (!$fit) { // Even if we're not going to give a continue, no point carrying on if the result is full break; } } $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'group'); }
public function getExamples() { global $wgTranslateWorkflowStates; $groups = MessageGroups::getAllGroups(); $group = key($groups); $state = current((array) $wgTranslateWorkflowStates); return array("api.php?action=groupreview&group={$group}&language=de&state={$state}"); }
public function getExamples() { $groups = MessageGroups::getAllGroups(); $group = key($groups); return array("api.php?action=query&meta=messagegroupstats&mgsgroup={$group} List of translation completion statistics for group {$group}"); }
public function getExamples() { $groups = MessageGroups::getAllGroups(); $group = key($groups); return array('api.php?action=query&meta=siteinfo&siprop=languages List of supported languages', "api.php?action=query&list=messagecollection&mcgroup={$group} List of non-optional message definitions for group {$group}", "api.php?action=query&list=messagecollection&mcgroup={$group}&mclanguage=fi&mcprop=definition|translation|tags&mcfilter=optional List of optional messages in Finnish with tags for group {$group}", "api.php?action=query&generator=messagecollection&gmcgroup={$group}&gmclanguage=nl&prop=revisions More information about latest translation revisions for group {$group}"); }
protected function clearMetadata() { // remove the entries from metadata table. $groupId = $this->page->getMessageGroupId(); TranslateMetadata::set($groupId, 'prioritylangs', false); TranslateMetadata::set($groupId, 'priorityforce', false); TranslateMetadata::set($groupId, 'priorityreason', false); // remove the page from aggregate groups, if present in any of them. $groups = MessageGroups::getAllGroups(); foreach ($groups as $group) { if ($group instanceof AggregateMessageGroup) { $subgroups = TranslateMetadata::get($group->getId(), 'subgroups'); if ($subgroups !== false) { $subgroups = explode(',', $subgroups); $subgroups = array_flip($subgroups); if (isset($subgroups[$groupId])) { unset($subgroups[$groupId]); $subgroups = array_flip($subgroups); TranslateMetadata::set($group->getId(), 'subgroups', implode(',', $subgroups)); } } } } }
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(); }
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'); } }
public static function groupSelector( $default = false ) { $groups = MessageGroups::getAllGroups(); $selector = new XmlSelect( 'group', 'group', $default ); foreach ( $groups as $id => $class ) { if ( MessageGroups::getGroup( $id )->exists() ) { $selector->addOption( $class->getLabel(), $id ); } } return $selector; }
protected function moveMetadata($oldGroupId, $newGroupId) { $prioritylangs = TranslateMetadata::get($oldGroupId, 'prioritylangs'); $priorityforce = TranslateMetadata::get($oldGroupId, 'priorityforce'); $priorityreason = TranslateMetadata::get($oldGroupId, 'priorityreason'); TranslateMetadata::set($oldGroupId, 'prioritylangs', false); TranslateMetadata::set($oldGroupId, 'priorityforce', false); TranslateMetadata::set($oldGroupId, 'priorityreason', false); if ($prioritylangs) { TranslateMetadata::set($newGroupId, 'prioritylangs', $prioritylangs); } if ($priorityforce) { TranslateMetadata::set($newGroupId, 'priorityforce', $priorityforce); } if ($priorityreason !== false) { TranslateMetadata::set($newGroupId, 'priorityreason', $priorityreason); } // make the changes in aggregate groups metadata, if present in any of them. $groups = MessageGroups::getAllGroups(); foreach ($groups as $group) { if ($group instanceof AggregateMessageGroup) { $subgroups = TranslateMetadata::get($group->getId(), 'subgroups'); if ($subgroups !== false) { $subgroups = explode(',', $subgroups); $subgroups = array_flip($subgroups); if (isset($subgroups[$oldGroupId])) { $subgroups[$newGroupId] = $subgroups[$oldGroupId]; unset($subgroups[$oldGroupId]); $subgroups = array_flip($subgroups); TranslateMetadata::set($group->getId(), 'subgroups', implode(',', $subgroups)); } } } } }
public static function getAllPages() { $groups = MessageGroups::getAllGroups(); $pages = array(); foreach ($groups as $group) { if ($group instanceof WikiPageMessageGroup) { $pages[$group->getId()] = $group->getTitle()->getPrefixedText(); } } return $pages; }
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(); }
protected function getAllowedValues() { $groups = MessageGroups::getAllGroups(); return array_keys( $groups ); }