summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/api/ApiQueryMessageGroups.php')
-rw-r--r--MLEB/Translate/api/ApiQueryMessageGroups.php188
1 files changed, 55 insertions, 133 deletions
diff --git a/MLEB/Translate/api/ApiQueryMessageGroups.php b/MLEB/Translate/api/ApiQueryMessageGroups.php
index a9484783..b916d3cb 100644
--- a/MLEB/Translate/api/ApiQueryMessageGroups.php
+++ b/MLEB/Translate/api/ApiQueryMessageGroups.php
@@ -5,9 +5,8 @@
* @file
* @author Niklas Laxström
* @author Harry Burt
- * @copyright Copyright © 2010-2013, Niklas Laxström
* @copyright Copyright © 2012-2013, Harry Burt
- * @license GPL-2.0+
+ * @license GPL-2.0-or-later
*/
/**
@@ -25,7 +24,7 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$params = $this->extractRequestParams();
$filter = $params['filter'];
- $groups = array();
+ $groups = [];
// Parameter root as all for all pages subgroups
if ( $params['root'] === 'all' ) {
@@ -43,16 +42,12 @@ class ApiQueryMessageGroups extends ApiQueryBase {
}
} 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
+ MediaWiki\suppressWarnings();
+ usort( $groups, [ 'MessageGroups', 'groupLabelSort' ] );
+ MediaWiki\restoreWarnings();
}
-
- // 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'] );
@@ -63,9 +58,15 @@ class ApiQueryMessageGroups extends ApiQueryBase {
}
} else {
$groups = MessageGroups::getGroupStructure();
- foreach ( MessageGroups::getDynamicGroups() as $id => $unused ) {
- $groups[$id] = MessageGroups::getGroup( $id );
+ }
+
+ if ( $params['root'] === '' ) {
+ $dynamicGroups = [];
+ foreach ( array_keys( MessageGroups::getDynamicGroups() ) as $id ) {
+ $dynamicGroups[$id] = MessageGroups::getGroup( $id );
}
+ // Have dynamic groups appear first in the list
+ $groups = $dynamicGroups + $groups;
}
// Do not list the sandbox group. The code that knows it
@@ -82,7 +83,7 @@ class ApiQueryMessageGroups extends ApiQueryBase {
* @var MessageGroup $mixed
*/
foreach ( $groups as $mixed ) {
- if ( $filter !== array() && !$matcher->match( $mixed->getId() ) ) {
+ if ( $filter !== [] && !$matcher->match( $mixed->getId() ) ) {
continue;
}
@@ -91,20 +92,15 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$result->setIndexedTagName( $a, 'group' );
// @todo Add a continue?
- $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $a );
+ $fit = $result->addValue( [ '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' );
- }
+ $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'group' );
}
/**
@@ -115,10 +111,11 @@ class ApiQueryMessageGroups extends ApiQueryBase {
*/
protected function formatGroup( $mixed, $props, $depth = 0 ) {
$params = $this->extractRequestParams();
+ $context = $this->getContext();
// Default
$g = $mixed;
- $subgroups = array();
+ $subgroups = [];
// Format = tree and has subgroups
if ( is_array( $mixed ) ) {
@@ -126,23 +123,20 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$subgroups = $mixed;
}
- wfProfileIn( __METHOD__ . '-' . get_class( $g ) );
-
- $a = array();
+ $a = [];
$groupId = $g->getId();
- wfProfileIn( __METHOD__ . '-basic' );
if ( isset( $props['id'] ) ) {
$a['id'] = $groupId;
}
if ( isset( $props['label'] ) ) {
- $a['label'] = $g->getLabel();
+ $a['label'] = $g->getLabel( $context );
}
if ( isset( $props['description'] ) ) {
- $a['description'] = $g->getDescription();
+ $a['description'] = $g->getDescription( $context );
}
if ( isset( $props['class'] ) ) {
@@ -152,24 +146,18 @@ class ApiQueryMessageGroups extends ApiQueryBase {
if ( isset( $props['namespace'] ) ) {
$a['namespace'] = $g->getNamespace();
}
- wfProfileOut( __METHOD__ . '-basic' );
- wfProfileIn( __METHOD__ . '-exists' );
if ( isset( $props['exists'] ) ) {
$a['exists'] = $g->exists();
}
- wfProfileOut( __METHOD__ . '-exists' );
- wfProfileIn( __METHOD__ . '-icon' );
if ( isset( $props['icon'] ) ) {
$formats = TranslateUtils::getIcon( $g, $params['iconsize'] );
if ( $formats ) {
$a['icon'] = $formats;
}
}
- wfProfileOut( __METHOD__ . '-icon' );
- wfProfileIn( __METHOD__ . '-priority' );
if ( isset( $props['priority'] ) ) {
$priority = MessageGroups::getPriority( $g );
$a['priority'] = $priority ?: 'default';
@@ -183,21 +171,16 @@ class ApiQueryMessageGroups extends ApiQueryBase {
if ( isset( $props['priorityforce'] ) ) {
$a['priorityforce'] = ( TranslateMetadata::get( $groupId, 'priorityforce' ) === 'on' );
}
- wfProfileOut( __METHOD__ . '-priority' );
- wfProfileIn( __METHOD__ . '-workflowstates' );
if ( isset( $props['workflowstates'] ) ) {
$a['workflowstates'] = $this->getWorkflowStates( $g );
}
- wfProfileOut( __METHOD__ . '-workflowstates' );
- wfRunHooks(
+ Hooks::run(
'TranslateProcessAPIMessageGroupsProperties',
- array( &$a, $props, $params, $g )
+ [ &$a, $props, $params, $g ]
);
- wfProfileOut( __METHOD__ . '-' . get_class( $g ) );
-
// Depth only applies to tree format
if ( $depth >= $params['depth'] && $params['format'] === 'tree' ) {
$a['groupcount'] = count( $subgroups );
@@ -207,7 +190,7 @@ class ApiQueryMessageGroups extends ApiQueryBase {
}
// Always empty array for flat format, only sometimes for tree format
- if ( $subgroups !== array() ) {
+ if ( $subgroups !== [] ) {
foreach ( $subgroups as $sg ) {
$a['groups'][] = $this->formatGroup( $sg, $props );
}
@@ -222,7 +205,7 @@ class ApiQueryMessageGroups extends ApiQueryBase {
* Get the workflow states applicable to the given message group
*
* @param MessageGroup $group
- * @return boolean|array Associative array with states as key and localized state
+ * @return bool|array Associative array with states as key and localized state
* labels as values
*/
protected function getWorkflowStates( MessageGroup $group ) {
@@ -232,7 +215,7 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$stateConfig = $group->getMessageGroupStates()->getStates();
- if ( !is_array( $stateConfig ) || $stateConfig === array() ) {
+ if ( !is_array( $stateConfig ) || $stateConfig === [] ) {
return false;
}
@@ -247,8 +230,11 @@ class ApiQueryMessageGroups extends ApiQueryBase {
$allowed = $user->isAllowed( $config['right'] );
}
- $stateConfig[$state]['_canchange'] = $allowed;
- $stateConfig[$state]['_name'] =
+ if ( $allowed ) {
+ $stateConfig[$state]['canchange'] = 1;
+ }
+
+ $stateConfig[$state]['name'] =
$this->msg( "translate-workflow-state-$state" )->text();
}
}
@@ -257,90 +243,46 @@ class ApiQueryMessageGroups extends ApiQueryBase {
}
public function getAllowedParams() {
- $allowedParams = array(
- 'depth' => array(
+ $allowedParams = [
+ 'depth' => [
ApiBase::PARAM_TYPE => 'integer',
- ApiBase::PARAM_DFLT => '100',
- ),
- 'filter' => array(
+ ApiBase::PARAM_DFLT => 100,
+ ],
+ 'filter' => [
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_DFLT => '',
ApiBase::PARAM_ISMULTI => true,
- ),
- 'format' => array(
- ApiBase::PARAM_TYPE => array( 'flat', 'tree' ),
+ ],
+ 'format' => [
+ ApiBase::PARAM_TYPE => [ 'flat', 'tree' ],
ApiBase::PARAM_DFLT => 'flat',
- ),
- 'iconsize' => array(
+ ],
+ 'iconsize' => [
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_DFLT => 64,
- ),
- 'prop' => array(
+ ],
+ 'prop' => [
ApiBase::PARAM_TYPE => array_keys( self::getPropertyList() ),
ApiBase::PARAM_DFLT => 'id|label|description|class|exists',
ApiBase::PARAM_ISMULTI => true,
- ),
- 'root' => array(
+ ],
+ 'root' => [
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_DFLT => '',
- ),
- );
- wfRunHooks( 'TranslateGetAPIMessageGroupsParameterList', array( &$allowedParams ) );
+ ],
+ ];
+ Hooks::run( 'TranslateGetAPIMessageGroupsParameterList', [ &$allowedParams ] );
return $allowedParams;
}
/**
- * @deprecated since MediaWiki core 1.25
- */
- public function getParamDescription() {
- $depth = <<<TEXT
-When using the tree format, limit the depth to this many levels. Value 0 means
-that no subgroups are shown. If the limit is reached, a prop groupcount is
-added and it states the number of direct children.
-TEXT;
- $root = <<<TEXT
-When using the tree format, instead of starting from top level start from the
-given message group, which must be an aggregate message group. When using flat
-format only the specified group is returned.
-TEXT;
- $filter = <<<TEXT
-Only return messages with IDs that match one or more of the input(s) given
-(case-insensitive, separated by pipes, * wildcard).
-TEXT;
-
- $propIntro = array( 'What translation-related information to get:' );
-
- $paramDescs = array(
- 'depth' => $depth,
- 'format' => 'In a tree format message groups can exist multiple places in the tree.',
- 'iconsize' => 'Preferred size of rasterised group icon',
- 'root' => $root,
- 'filter' => $filter,
- 'prop' => array_merge( $propIntro, self::getPropertyList() ),
- );
-
- $p = $this->getModulePrefix(); // Can be useful for documentation
- wfRunHooks( 'TranslateGetAPIMessageGroupsParameterDescs', array( &$paramDescs, $p ) );
-
- $indent = "\n" . str_repeat( ' ', 24 );
- $wrapWidth = 104 - 24;
- foreach ( $paramDescs as &$val ) {
- if ( is_string( $val ) ) {
- $val = wordwrap( str_replace( "\n", ' ', $val ), $wrapWidth, $indent );
- }
- }
-
- return $paramDescs;
- }
-
- /**
* Returns array of key value pairs of properties and their descriptions
*
* @return array
*/
protected static function getPropertyList() {
- $properties = array(
+ $properties = [
'id' => ' id - Include id of the group',
'label' => ' label - Include label of the group',
'description' => ' description - Include description of the group',
@@ -359,37 +301,17 @@ TEXT;
'setting forced',
'workflowstates' =>
' workflowstates - Include the workflow states for the message group',
- );
+ ];
- wfRunHooks( 'TranslateGetAPIMessageGroupsPropertyDescs', array( &$properties ) );
+ Hooks::run( 'TranslateGetAPIMessageGroupsPropertyDescs', [ &$properties ] );
return $properties;
}
- /**
- * @deprecated since MediaWiki core 1.25
- */
- public function getDescription() {
- return 'Return information about message groups. Note that uselang parameter ' .
- 'affects the output of language dependent parts.';
- }
-
- /**
- * @deprecated since MediaWiki core 1.25
- */
- protected function getExamples() {
- return array(
- 'api.php?action=query&meta=messagegroups',
- );
- }
-
- /**
- * @see ApiBase::getExamplesMessages()
- */
protected function getExamplesMessages() {
- return array(
+ return [
'action=query&meta=messagegroups'
=> 'apihelp-query+messagegroups-example-1',
- );
+ ];
}
}