* (bug 20131) PHP Notice: Undfined index: page_latest in includes/ChangesList.php...
[lhc/web/wiklou.git] / includes / api / ApiQueryAllmessages.php
1 <?php
2
3 /*
4 * Created on Dec 1, 2007
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 *
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.
14 *
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.
19 *
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
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
29 }
30
31 /**
32 * A query action to return messages from site message cache
33 *
34 * @ingroup API
35 */
36 class ApiQueryAllmessages extends ApiQueryBase {
37
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'am');
40 }
41
42 public function execute() {
43 $params = $this->extractRequestParams();
44
45 if(!is_null($params['lang']))
46 {
47 global $wgLang;
48 $wgLang = Language::factory($params['lang']);
49 }
50
51
52 //Determine which messages should we print
53 $messages_target = array();
54 if( $params['messages'] == '*' ) {
55 $message_names = array_keys( Language::getMessagesFor( 'en' ) );
56 sort( $message_names );
57 $messages_target = $message_names;
58 } else {
59 $messages_target = explode( '|', $params['messages'] );
60 }
61
62 //Filter messages
63 if( isset( $params['filter'] ) ) {
64 $messages_filtered = array();
65 foreach( $messages_target as $message ) {
66 if( strpos( $message, $params['filter'] ) !== false ) { //!== is used because filter can be at the beginnig of the string
67 $messages_filtered[] = $message;
68 }
69 }
70 $messages_target = $messages_filtered;
71 }
72
73 //Get all requested messages
74 $messages = array();
75 $skip = !is_null($params['from']);
76 foreach( $messages_target as $message ) {
77 // Skip all messages up to $params['from']
78 if($skip && $message === $params['from'])
79 $skip = false;
80 if(!$skip)
81 $messages[$message] = wfMsg( $message );
82 }
83
84 //Print the result
85 $result = $this->getResult();
86 $messages_out = array();
87 foreach( $messages as $name => $value ) {
88 $message = array();
89 $message['name'] = $name;
90 if( wfEmptyMsg( $name, $value ) ) {
91 $message['missing'] = '';
92 } else {
93 $result->setContent( $message, $value );
94 }
95 $fit = $result->addValue(array('query', $this->getModuleName()), null, $message);
96 if(!$fit)
97 {
98 $this->setContinueEnumParameter('from', $name);
99 break;
100 }
101 }
102 $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'message');
103 }
104
105 public function getAllowedParams() {
106 return array (
107 'messages' => array (
108 ApiBase :: PARAM_DFLT => '*',
109 ),
110 'filter' => array(),
111 'lang' => null,
112 'from' => null,
113 );
114 }
115
116 public function getParamDescription() {
117 return array (
118 'messages' => 'Which messages to output. "*" means all messages',
119 'filter' => 'Return only messages that contain this string',
120 'lang' => 'Return messages in this language',
121 'from' => 'Return messages starting at this message',
122 );
123 }
124
125 public function getDescription() {
126 return 'Return messages from this site.';
127 }
128
129 protected function getExamples() {
130 return array(
131 'api.php?action=query&meta=allmessages&amfilter=ipb-',
132 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
133 );
134 }
135
136 public function getVersion() {
137 return __CLASS__ . ': $Id$';
138 }
139 }