2007-12-01 17:04:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on Dec 1, 2007
|
|
|
|
|
*
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('MEDIAWIKI')) {
|
|
|
|
|
// Eclipse helper - will be ignored in production
|
|
|
|
|
require_once ('ApiQueryBase.php');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A query action to return messages from site message cache
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-12-01 17:04:13 +00:00
|
|
|
*/
|
|
|
|
|
class ApiQueryAllmessages extends ApiQueryBase {
|
|
|
|
|
|
|
|
|
|
public function __construct($query, $moduleName) {
|
|
|
|
|
parent :: __construct($query, $moduleName, 'am');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
global $wgMessageCache;
|
|
|
|
|
$params = $this->extractRequestParams();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-01-20 14:20:50 +00:00
|
|
|
if(!is_null($params['lang']))
|
|
|
|
|
{
|
|
|
|
|
global $wgLang;
|
|
|
|
|
$wgLang = Language::factory($params['lang']);
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-01 17:04:13 +00:00
|
|
|
|
|
|
|
|
//Determine which messages should we print
|
|
|
|
|
$messages_target = array();
|
|
|
|
|
if( $params['messages'] == '*' ) {
|
|
|
|
|
$wgMessageCache->loadAllMessages();
|
|
|
|
|
$message_names = array_keys( array_merge( Language::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) ) );
|
|
|
|
|
sort( $message_names );
|
|
|
|
|
$messages_target = $message_names;
|
|
|
|
|
} else {
|
|
|
|
|
$messages_target = explode( '|', $params['messages'] );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-01 17:04:13 +00:00
|
|
|
//Filter messages
|
|
|
|
|
if( isset( $params['filter'] ) ) {
|
|
|
|
|
$messages_filtered = array();
|
|
|
|
|
foreach( $messages_target as $message ) {
|
|
|
|
|
if( strpos( $message, $params['filter'] ) !== false ) { //!== is used because filter can be at the beginnig of the string
|
|
|
|
|
$messages_filtered[] = $message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$messages_target = $messages_filtered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Get all requested messages
|
|
|
|
|
$messages = array();
|
|
|
|
|
foreach( $messages_target as $message ) {
|
|
|
|
|
$messages[$message] = wfMsg( $message );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Print the result
|
|
|
|
|
$result = $this->getResult();
|
|
|
|
|
$messages_out = array();
|
|
|
|
|
foreach( $messages as $name => $value ) {
|
|
|
|
|
$message = array();
|
|
|
|
|
$message['name'] = $name;
|
2008-03-17 08:25:22 +00:00
|
|
|
if( wfEmptyMsg( $name, $value ) ) {
|
|
|
|
|
$message['missing'] = '';
|
|
|
|
|
} else {
|
|
|
|
|
$result->setContent( $message, $value );
|
|
|
|
|
}
|
2007-12-01 17:04:13 +00:00
|
|
|
$messages_out[] = $message;
|
|
|
|
|
}
|
|
|
|
|
$result->setIndexedTagName( $messages_out, 'message' );
|
2008-01-08 18:10:58 +00:00
|
|
|
$result->addValue( 'query', $this->getModuleName(), $messages_out );
|
2007-12-01 17:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2007-12-01 17:04:13 +00:00
|
|
|
return array (
|
|
|
|
|
'messages' => array (
|
|
|
|
|
ApiBase :: PARAM_DFLT => '*',
|
|
|
|
|
),
|
|
|
|
|
'filter' => array(),
|
2008-01-20 14:20:50 +00:00
|
|
|
'lang' => null,
|
2007-12-01 17:04:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2007-12-01 17:04:13 +00:00
|
|
|
return array (
|
|
|
|
|
'messages' => 'Which messages to output. "*" means all messages',
|
|
|
|
|
'filter' => 'Return only messages that contains specified string',
|
2008-01-20 14:20:50 +00:00
|
|
|
'lang' => 'Language code',
|
2007-12-01 17:04:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2007-12-01 17:04:13 +00:00
|
|
|
return 'Return messages from this site.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getExamples() {
|
|
|
|
|
return array(
|
|
|
|
|
'api.php?action=query&meta=allmessages&amfilter=ipb-',
|
2008-01-20 14:20:50 +00:00
|
|
|
'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
|
2007-12-01 17:04:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2007-12-01 17:04:13 +00:00
|
|
|
}
|
|
|
|
|
}
|