36 private $contentLanguage;
39 private $languageFactory;
42 private $languageNameUtils;
45 private $localisationCache;
48 private $messageCache;
68 parent::__construct( $query, $moduleName,
'am' );
69 $this->contentLanguage = $contentLanguage;
70 $this->languageFactory = $languageFactory;
71 $this->languageNameUtils = $languageNameUtils;
72 $this->localisationCache = $localisationCache;
73 $this->messageCache = $messageCache;
78 if ( $params[
'lang'] ===
null ) {
80 } elseif ( !$this->languageNameUtils->isValidCode( $params[
'lang'] ) ) {
82 [
'apierror-invalidlang', $this->
encodeParamName(
'lang' ) ],
'invalidlang'
85 $langObj = $this->languageFactory->getLanguage( $params[
'lang'] );
88 if ( $params[
'enableparser'] ) {
89 if ( $params[
'title'] !==
null ) {
90 $title = Title::newFromText( $params[
'title'] );
95 $title = Title::newFromText(
'API' );
99 $prop = array_fill_keys( (array)$params[
'prop'],
true );
102 if ( in_array(
'*', $params[
'messages'] ) ) {
103 $message_names = $this->localisationCache->getSubitemList( $langObj->getCode(),
'messages' ) ?? [];
104 if ( $params[
'includelocal'] ) {
105 $message_names = array_unique( array_merge(
111 $this->messageCache->getAllMessageKeys( $this->contentLanguage->getCode() )
114 sort( $message_names );
115 $messages_target = $message_names;
117 $messages_target = $params[
'messages'];
122 if ( isset( $params[
'prefix'] ) ) {
124 $messages_filtered = [];
125 foreach ( $messages_target as $message ) {
126 if ( str_starts_with( $message, $params[
'prefix'] ) ) {
130 $messages_filtered[] = $message;
135 $messages_target = $messages_filtered;
139 if ( isset( $params[
'filter'] ) ) {
140 $messages_filtered = [];
141 foreach ( $messages_target as $message ) {
142 if ( str_contains( $message, $params[
'filter'] ) ) {
143 $messages_filtered[] = $message;
146 $messages_target = $messages_filtered;
150 $customiseFilterEnabled = $params[
'customised'] !==
'all';
151 if ( $customiseFilterEnabled ) {
154 [ $langObj,
'ucfirst' ],
158 !$langObj->equals( $this->contentLanguage ),
162 $customised = $params[
'customised'] ===
'modified';
166 $skip = $params[
'from'] !==
null;
167 $useto = $params[
'to'] !==
null;
169 foreach ( $messages_target as $message ) {
171 if ( $skip && $message === $params[
'from'] ) {
175 if ( $useto && $message > $params[
'to'] ) {
186 if ( isset( $params[
'args'] ) && count( $params[
'args'] ) != 0 ) {
187 $args = $params[
'args'];
190 if ( $customiseFilterEnabled ) {
191 $messageIsCustomised = isset( $customisedMessages[
'pages'][$langObj->ucfirst( $message )] );
193 if ( $customised === $messageIsCustomised ) {
196 $a[
'customised'] =
true;
203 $msg = $this->
msg( $message, $args )->inLanguage( $langObj );
205 if ( !$msg->exists() ) {
206 $a[
'missing'] =
true;
209 if ( $params[
'enableparser'] ) {
211 $msgString = $msg->page(
$title )->text();
213 $msgString = $msg->plain();
215 if ( !$params[
'nocontent'] ) {
218 if ( isset( $prop[
'default'] ) ) {
219 $default = $this->
msg( $message )->inLanguage( $langObj )->useDatabase(
false );
220 if ( !$default->exists() ) {
221 $a[
'defaultmissing'] =
true;
222 } elseif ( $default->plain() != $msgString ) {
223 $a[
'default'] = $default->plain();
227 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $a );
234 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'message' );
238 if ( $params[
'lang'] ===
null ) {
240 return 'anon-public-user-private';
241 } elseif ( $params[
'enableparser'] ) {
243 return 'anon-public-user-private';
253 ParamValidator::PARAM_DEFAULT =>
'*',
254 ParamValidator::PARAM_ISMULTI =>
true,
257 ParamValidator::PARAM_ISMULTI =>
true,
258 ParamValidator::PARAM_TYPE => [
262 'enableparser' =>
false,
263 'nocontent' =>
false,
264 'includelocal' =>
false,
266 ParamValidator::PARAM_ISMULTI =>
true,
267 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
271 ParamValidator::PARAM_DEFAULT =>
'all',
272 ParamValidator::PARAM_TYPE => [
288 'action=query&meta=allmessages&refix=ipb-'
289 =>
'apihelp-query+allmessages-example-ipb',
290 'action=query&meta=allmessages&ammessages=august|mainpage&amlang=de'
291 =>
'apihelp-query+allmessages-example-de',
296 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allmessages';
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
A query action to return messages from site message cache.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName, Language $contentLanguage, LanguageFactory $languageFactory, LanguageNameUtils $languageNameUtils, LocalisationCache $localisationCache, MessageCache $messageCache)
getExamplesMessages()
Returns usage examples for this module.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
This is the main query class.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Base class for language-specific code.
Caching for the contents of localisation files.
Cache messages that are defined by MediaWiki-namespace pages or by hooks.
static normalizeKey( $key)
Normalize message key input.