removed x-codeBlob functions and modified blob handling acordingly
[mediawiki.git] / includes / api / ApiQueryAllmessages.php
blob971c25187b969aa17b1a8b506f44c3c06dcc4d5b
1 <?php
3 /*
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');
31 /**
32 * A query action to return messages from site message cache
34 * @ingroup API
36 class ApiQueryAllmessages extends ApiQueryBase {
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'am');
42 public function execute() {
43 $params = $this->extractRequestParams();
45 if(!is_null($params['lang']))
47 global $wgLang;
48 $wgLang = Language::factory($params['lang']);
51 $prop = array_flip( (array)$params['prop'] );
53 //Determine which messages should we print
54 $messages_target = array();
55 if( in_array( '*', $params['messages'] ) ) {
56 $message_names = array_keys( Language::getMessagesFor( 'en' ) );
57 sort( $message_names );
58 $messages_target = $message_names;
59 } else {
60 $messages_target = $params['messages'];
63 //Filter messages
64 if( isset( $params['filter'] ) ) {
65 $messages_filtered = array();
66 foreach( $messages_target as $message ) {
67 if( strpos( $message, $params['filter'] ) !== false ) { //!== is used because filter can be at the beginnig of the string
68 $messages_filtered[] = $message;
71 $messages_target = $messages_filtered;
74 //Get all requested messages and print the result
75 $messages = array();
76 $skip = !is_null($params['from']);
77 $result = $this->getResult();
78 foreach( $messages_target as $message ) {
79 // Skip all messages up to $params['from']
80 if($skip && $message === $params['from'])
81 $skip = false;
82 if(!$skip) {
83 $a = array( 'name' => $message );
84 $msg = wfMsgGetKey( $message, true, false, false );
85 if ( wfEmptyMsg( $message, $msg ) )
86 $a['missing'] = '';
87 else {
88 ApiResult::setContent( $a, $msg );
89 if ( isset( $prop['default'] ) ) {
90 $default = wfMsgGetKey( $message, false, false, false );
91 if ( $default !== $msg ) {
92 if ( wfEmptyMsg( $message, $default ) )
93 $a['defaultmissing'] = '';
94 else
95 $a['default'] = $default;
99 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $a );
100 if( !$fit ) {
101 $this->setContinueEnumParameter( 'from', $name );
102 break;
106 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' );
109 public function getAllowedParams() {
110 return array (
111 'messages' => array (
112 ApiBase :: PARAM_DFLT => '*',
113 ApiBase :: PARAM_ISMULTI => true,
115 'prop' => array(
116 ApiBase :: PARAM_ISMULTI => true,
117 ApiBase :: PARAM_TYPE => array(
118 'default'
121 'filter' => array(),
122 'lang' => null,
123 'from' => null,
127 public function getParamDescription() {
128 return array (
129 'messages' => 'Which messages to output. "*" means all messages',
130 'prop' => 'Which properties to get',
131 'filter' => 'Return only messages that contain this string',
132 'lang' => 'Return messages in this language',
133 'from' => 'Return messages starting at this message',
137 public function getDescription() {
138 return 'Return messages from this site.';
141 protected function getExamples() {
142 return array(
143 'api.php?action=query&meta=allmessages&amfilter=ipb-',
144 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
148 public function getVersion() {
149 return __CLASS__ . ': $Id$';