23 public function execute() {
24 $params = $this->extractRequestParams();
26 $title = Title::newFromText( $params[
'title'] );
28 $this->dieWithError( [
'apierror-invalidtitle', wfEscapeWikiText( $params[
'title'] ) ] );
32 if ( !$handle->isValid() ) {
33 $this->dieWithError(
'apierror-translate-nomessagefortitle',
'nomessagefortitle' );
36 if ( (
string)$params[
'group'] !==
'' ) {
37 $group = MessageGroups::getGroup( $params[
'group'] );
39 $group = $handle->getGroup();
43 $this->dieWithError(
'apierror-translate-invalidgroup',
'invalidgroup' );
49 $props = $params[
'prop'];
54 $props = array_intersect( $props, array_keys( $types ) );
56 $result = $this->getResult();
67 if ( !$dataProvider->hasDefinition() ) {
68 LoggerFactory::getInstance(
'Translate' )->warning(
69 'Message definition is empty! Title: {title}, group: {group}, key: {key}',
71 'title' => $handle->getTitle()->getPrefixedText(),
72 'group' => $group->getId(),
73 'key' => $handle->getKey()
78 foreach ( $props as $type ) {
80 if ( !isset( $types[$type] ) ) {
81 $types[$type] = UnsupportedTranslationAid::class;
84 $class = $types[$type];
85 $obj =
new $class( $group, $handle, $this, $dataProvider );
88 $obj->setQueryAggregator( $aggregator );
90 $obj->populateQueries();
92 $data[$type] = [
'error' => $e->getMessage() ];
102 $start = microtime(
true );
104 $times[
'query_aggregator'] = round( microtime(
true ) - $start, 3 );
107 foreach ( $aids as $type => $obj ) {
108 $start = microtime(
true );
111 $aid = $obj->getData();
113 $aid = [
'error' => $e->getMessage() ];
116 if ( isset( $aid[
'**'] ) ) {
117 $result->setIndexedTagName( $aid, $aid[
'**'] );
122 $times[$type] = round( microtime(
true ) - $start, 3 );
125 $result->addValue(
null,
'helpers', $data );
126 $result->addValue(
null,
'times', $times );
129 protected function getAllowedParams(): array {
134 ParamValidator::PARAM_TYPE =>
'string',
135 ParamValidator::PARAM_REQUIRED =>
true,
138 ParamValidator::PARAM_TYPE =>
'string',
141 ParamValidator::PARAM_DEFAULT => implode(
'|', $props ),
142 ParamValidator::PARAM_TYPE => $props,
143 ParamValidator::PARAM_ISMULTI =>
true,
148 protected function getExamplesMessages() {
150 'action=translationaids&title=MediaWiki:January/fi'
151 =>
'apihelp-translationaids-example-1',