00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if ( !defined( 'MEDIAWIKI' ) ) {
00027
00028 require_once ( 'ApiQueryBase.php' );
00029 }
00030
00036 class ApiQueryAllmessages extends ApiQueryBase {
00037
00038 public function __construct( $query, $moduleName ) {
00039 parent :: __construct( $query, $moduleName, 'am' );
00040 }
00041
00042 public function execute() {
00043 $params = $this->extractRequestParams();
00044
00045 if ( !is_null( $params['lang'] ) )
00046 {
00047 global $wgLang;
00048 $wgLang = Language::factory( $params['lang'] );
00049 }
00050
00051 $prop = array_flip( (array)$params['prop'] );
00052
00053
00054 $messages_target = array();
00055 if ( in_array( '*', $params['messages'] ) ) {
00056 $message_names = array_keys( Language::getMessagesFor( 'en' ) );
00057 sort( $message_names );
00058 $messages_target = $message_names;
00059 } else {
00060 $messages_target = $params['messages'];
00061 }
00062
00063
00064 if ( isset( $params['filter'] ) ) {
00065 $messages_filtered = array();
00066 foreach ( $messages_target as $message ) {
00067 if ( strpos( $message, $params['filter'] ) !== false ) {
00068 $messages_filtered[] = $message;
00069 }
00070 }
00071 $messages_target = $messages_filtered;
00072 }
00073
00074
00075 $messages = array();
00076 $skip = !is_null( $params['from'] );
00077 $result = $this->getResult();
00078 foreach ( $messages_target as $message ) {
00079
00080 if ( $skip && $message === $params['from'] )
00081 $skip = false;
00082
00083 if ( !$skip ) {
00084 $a = array( 'name' => $message );
00085 $args = null;
00086 if ( isset( $params['args'] ) && count( $params['args'] ) != 0 ) {
00087 $args = $params['args'];
00088 }
00089
00090 if ( $params['enableparser'] ) {
00091 $msg = wfMsgExt( $message, array( 'parsemag' ), $args );
00092 } else if ( $args ) {
00093 $msgString = wfMsgGetKey( $message, true, false, false );
00094 $msg = wfMsgReplaceArgs( $msgString, $args );
00095 } else {
00096 $msg = wfMsgGetKey( $message, true, false, false );
00097 }
00098
00099 if ( wfEmptyMsg( $message, $msg ) )
00100 $a['missing'] = '';
00101 else {
00102 ApiResult::setContent( $a, $msg );
00103 if ( isset( $prop['default'] ) ) {
00104 $default = wfMsgGetKey( $message, false, false, false );
00105 if ( $default !== $msg ) {
00106 if ( wfEmptyMsg( $message, $default ) )
00107 $a['defaultmissing'] = '';
00108 else
00109 $a['default'] = $default;
00110 }
00111 }
00112 }
00113 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $a );
00114 if ( !$fit ) {
00115 $this->setContinueEnumParameter( 'from', $name );
00116 break;
00117 }
00118 }
00119 }
00120 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' );
00121 }
00122
00123 public function getCacheMode( $params ) {
00124 if ( is_null( $params['lang'] ) ) {
00125
00126 return 'anon-public-user-private';
00127 } elseif ( $params['enableparser'] ) {
00128
00129 return 'anon-public-user-private';
00130 } else {
00131
00132 return 'public';
00133 }
00134 }
00135
00136 public function getAllowedParams() {
00137 return array (
00138 'messages' => array (
00139 ApiBase :: PARAM_DFLT => '*',
00140 ApiBase :: PARAM_ISMULTI => true,
00141 ),
00142 'prop' => array(
00143 ApiBase :: PARAM_ISMULTI => true,
00144 ApiBase :: PARAM_TYPE => array(
00145 'default'
00146 )
00147 ),
00148 'enableparser' => false,
00149 'args' => array(
00150 ApiBase :: PARAM_ISMULTI => true
00151 ),
00152 'filter' => array(),
00153 'lang' => null,
00154 'from' => null,
00155 );
00156 }
00157
00158 public function getParamDescription() {
00159 return array (
00160 'messages' => 'Which messages to output. "*" means all messages',
00161 'prop' => 'Which properties to get',
00162 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
00163 'Will substitute magic words, handle templates etc.' ),
00164 'args' => 'Arguments to be substituted into message',
00165 'filter' => 'Return only messages that contain this string',
00166 'lang' => 'Return messages in this language',
00167 'from' => 'Return messages starting at this message',
00168 );
00169 }
00170
00171 public function getDescription() {
00172 return 'Return messages from this site.';
00173 }
00174
00175 protected function getExamples() {
00176 return array(
00177 'api.php?action=query&meta=allmessages&amfilter=ipb-',
00178 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
00179 );
00180 }
00181
00182 public function getVersion() {
00183 return __CLASS__ . ': $Id: ApiQueryAllmessages.php 69932 2010-07-26 08:03:21Z tstarling $';
00184 }
00185 }