38 $services = MediaWikiServices::getInstance();
39 if ( $params[
'lang'] ===
null ) {
41 } elseif ( !$services->getLanguageNameUtils()->isValidCode( $params[
'lang'] ) ) {
43 [
'apierror-invalidlang', $this->
encodeParamName(
'lang' ) ],
'invalidlang'
46 $langObj = $services->getLanguageFactory()->getLanguage( $params[
'lang'] );
49 if ( $params[
'enableparser'] ) {
50 if ( $params[
'title'] !==
null ) {
51 $title = Title::newFromText( $params[
'title'] );
56 $title = Title::newFromText(
'API' );
60 $prop = array_flip( (array)$params[
'prop'] );
63 if ( in_array(
'*', $params[
'messages'] ) ) {
64 $message_names = $services->getLocalisationCache()
65 ->getSubitemList( $langObj->getCode(),
'messages' );
66 if ( $params[
'includelocal'] ) {
67 $message_names = array_unique( array_merge(
73 $services->getMessageCache()
74 ->getAllMessageKeys( $this->getConfig()->get(
'LanguageCode' ) )
77 sort( $message_names );
78 $messages_target = $message_names;
80 $messages_target = $params[
'messages'];
85 if ( isset( $params[
'prefix'] ) ) {
87 $messages_filtered = [];
88 foreach ( $messages_target as $message ) {
90 if ( strpos( $message, $params[
'prefix'] ) === 0 ) {
94 $messages_filtered[] = $message;
99 $messages_target = $messages_filtered;
103 if ( isset( $params[
'filter'] ) ) {
104 $messages_filtered = [];
105 foreach ( $messages_target as $message ) {
107 if ( strpos( $message, $params[
'filter'] ) !==
false ) {
108 $messages_filtered[] = $message;
111 $messages_target = $messages_filtered;
115 $customiseFilterEnabled = $params[
'customised'] !==
'all';
116 if ( $customiseFilterEnabled ) {
119 [ $langObj,
'ucfirst' ],
123 !$langObj->equals( MediaWikiServices::getInstance()->getContentLanguage() )
126 $customised = $params[
'customised'] ===
'modified';
130 $skip = $params[
'from'] !==
null;
131 $useto = $params[
'to'] !==
null;
133 foreach ( $messages_target as $message ) {
135 if ( $skip && $message === $params[
'from'] ) {
139 if ( $useto && $message > $params[
'to'] ) {
146 'normalizedname' => MessageCache::normalizeKey( $message ),
150 if ( isset( $params[
'args'] ) && count( $params[
'args'] ) != 0 ) {
151 $args = $params[
'args'];
154 if ( $customiseFilterEnabled ) {
155 $messageIsCustomised = isset( $customisedMessages[
'pages'][$langObj->ucfirst( $message )] );
156 if ( $customised === $messageIsCustomised ) {
158 $a[
'customised'] =
true;
167 if ( !$msg->exists() ) {
168 $a[
'missing'] =
true;
171 if ( $params[
'enableparser'] ) {
172 $msgString = $msg->title(
$title )->text();
174 $msgString = $msg->plain();
176 if ( !$params[
'nocontent'] ) {
177 ApiResult::setContentValue( $a,
'content', $msgString );
179 if ( isset( $prop[
'default'] ) ) {
180 $default =
wfMessage( $message )->inLanguage( $langObj )->useDatabase(
false );
181 if ( !$default->exists() ) {
182 $a[
'defaultmissing'] =
true;
183 } elseif ( $default->plain() != $msgString ) {
184 $a[
'default'] = $default->plain();
188 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $a );
195 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'message' );