4 * Created on Dec 1, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * A query action to return messages from site message cache
36 class ApiQueryAllmessages
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'am');
42 public function execute() {
43 global $wgMessageCache;
44 $params = $this->extractRequestParams();
46 //Determine which messages should we print
47 $messages_target = array();
48 if( $params['messages'] == '*' ) {
49 $wgMessageCache->loadAllMessages();
50 $message_names = array_keys( array_merge( Language
::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) ) );
51 sort( $message_names );
52 $messages_target = $message_names;
54 $messages_target = explode( '|', $params['messages'] );
58 if( isset( $params['filter'] ) ) {
59 $messages_filtered = array();
60 foreach( $messages_target as $message ) {
61 if( strpos( $message, $params['filter'] ) !== false ) { //!== is used because filter can be at the beginnig of the string
62 $messages_filtered[] = $message;
65 $messages_target = $messages_filtered;
68 $wgMessageCache->disableTransform();
70 //Get all requested messages
72 foreach( $messages_target as $message ) {
73 $message = trim( $message ); //Message list can be formatted like "msg1 | msg2 | msg3", so let's trim() it
74 $messages[$message] = wfMsg( $message );
78 $result = $this->getResult();
79 $messages_out = array();
80 foreach( $messages as $name => $value ) {
82 $message['name'] = $name;
83 $result->setContent( $message, $value );
84 $messages_out[] = $message;
86 $result->setIndexedTagName( $messages_out, 'message' );
87 $result->addValue( null, $this->getModuleName(), $messages_out );
90 protected function getAllowedParams() {
93 ApiBase
:: PARAM_DFLT
=> '*',
99 protected function getParamDescription() {
101 'messages' => 'Which messages to output. "*" means all messages',
102 'filter' => 'Return only messages that contains specified string',
106 protected function getDescription() {
107 return 'Return messages from this site.';
110 protected function getExamples() {
112 'api.php?action=query&meta=allmessages&amfilter=ipb-',
113 'api.php?action=query&meta=allmessages&ammessages=august|mainpage',
117 public function getVersion() {
118 return __CLASS__
. ': $Id$';