$langObj = Language::factory( $params['lang'] );
}
+ if ( $params['enableparser'] ) {
+ if ( !is_null( $params['title'] ) ) {
+ $title = Title::newFromText( $params['title'] );
+ if ( !$title ) {
+ $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+ }
+ } else {
+ $title = Title::newFromText( 'API' );
+ }
+ }
+
$prop = array_flip( (array)$params['prop'] );
// Determine which messages should we print
$messages_target = $params['messages'];
}
- // Filter messages
+ // Filter messages that have the specified prefix
+ // Because we sorted the message array earlier, they will appear in a clump:
+ if ( isset( $params['prefix'] ) ) {
+ $skip = false;
+ $messages_filtered = array();
+ foreach ( $messages_target as $message ) {
+ // === 0: must be at beginning of string (position 0)
+ if ( strpos( $message, $params['prefix'] ) === 0 ) {
+ if( !$skip ) {
+ $skip = true;
+ }
+ $messages_filtered[] = $message;
+ } else if ( $skip ) {
+ break;
+ }
+ }
+ $messages_target = $messages_filtered;
+ }
+
+ // Filter messages that contain specified string
if ( isset( $params['filter'] ) ) {
$messages_filtered = array();
foreach ( $messages_target as $message ) {
$messages_target = $messages_filtered;
}
+ // Whether we have any sort of message customisation filtering
+ $customiseFilterEnabled = $params['customised'] !== 'all';
+ if ( $customiseFilterEnabled ) {
+ global $wgContLang;
+ $lang = $langObj->getCode();
+
+ $customisedMessages = AllmessagesTablePager::getCustomisedStatuses(
+ array_map( array( $langObj, 'ucfirst'), $messages_target ), $lang, $lang != $wgContLang->getCode() );
+
+ $customised = $params['customised'] === 'modified';
+ }
+
// Get all requested messages and print the result
$skip = !is_null( $params['from'] );
$useto = !is_null( $params['to'] );
$args = $params['args'];
}
+ if ( $customiseFilterEnabled ) {
+ $messageIsCustomised = isset( $customisedMessages['pages'][ $langObj->ucfirst( $message ) ] );
+ if ( $customised === $messageIsCustomised ) {
+ if ( $customised ) {
+ $a['customised'] = '';
+ }
+ } else {
+ continue;
+ }
+ }
+
$msg = wfMessage( $message, $args )->inLanguage( $langObj );
if ( !$msg->exists() ) {
} else {
// Check if the parser is enabled:
if ( $params['enableparser'] ) {
- $msgString = $msg->text();
+ $msgString = $msg->title( $title )->text();
} else {
$msgString = $msg->plain();
}
ApiBase::PARAM_ISMULTI => true
),
'filter' => array(),
+ 'customised' => array(
+ ApiBase::PARAM_DFLT => 'all',
+ ApiBase::PARAM_TYPE => array(
+ 'all',
+ 'modified',
+ 'unmodified'
+ )
+ ),
'lang' => null,
'from' => null,
'to' => null,
+ 'title' => null,
+ 'prefix' => null,
);
}
public function getParamDescription() {
return array(
- 'messages' => 'Which messages to output. "*" means all messages',
+ 'messages' => 'Which messages to output. "*" (default) means all messages',
'prop' => 'Which properties to get',
'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
'Will substitute magic words, handle templates etc.' ),
+ 'title' => 'Page name to use as context when parsing message (for enableparser option)',
'args' => 'Arguments to be substituted into message',
- 'filter' => 'Return only messages that contain this string',
+ 'prefix' => 'Return messages with this prefix',
+ 'filter' => 'Return only messages with names that contain this string',
+ 'customised' => 'Return only messages in this customisation state',
'lang' => 'Return messages in this language',
'from' => 'Return messages starting at this message',
'to' => 'Return messages ending at this message',
protected function getExamples() {
return array(
- 'api.php?action=query&meta=allmessages&amfilter=ipb-',
+ 'api.php?action=query&meta=allmessages&refix=ipb-',
'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
);
}