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 ( 'ApiBase.php' );
00029 }
00030
00048 class ApiMain extends ApiBase {
00049
00053 const API_DEFAULT_FORMAT = 'xmlfm';
00054
00058 private static $Modules = array (
00059 'login' => 'ApiLogin',
00060 'logout' => 'ApiLogout',
00061 'query' => 'ApiQuery',
00062 'expandtemplates' => 'ApiExpandTemplates',
00063 'parse' => 'ApiParse',
00064 'opensearch' => 'ApiOpenSearch',
00065 'feedwatchlist' => 'ApiFeedWatchlist',
00066 'help' => 'ApiHelp',
00067 'paraminfo' => 'ApiParamInfo',
00068
00069
00070 'purge' => 'ApiPurge',
00071 'rollback' => 'ApiRollback',
00072 'delete' => 'ApiDelete',
00073 'undelete' => 'ApiUndelete',
00074 'protect' => 'ApiProtect',
00075 'block' => 'ApiBlock',
00076 'unblock' => 'ApiUnblock',
00077 'move' => 'ApiMove',
00078 'edit' => 'ApiEditPage',
00079 'upload' => 'ApiUpload',
00080 'emailuser' => 'ApiEmailUser',
00081 'watch' => 'ApiWatch',
00082 'patrol' => 'ApiPatrol',
00083 'import' => 'ApiImport',
00084 'userrights' => 'ApiUserrights',
00085 );
00086
00090 private static $Formats = array (
00091 'json' => 'ApiFormatJson',
00092 'jsonfm' => 'ApiFormatJson',
00093 'php' => 'ApiFormatPhp',
00094 'phpfm' => 'ApiFormatPhp',
00095 'wddx' => 'ApiFormatWddx',
00096 'wddxfm' => 'ApiFormatWddx',
00097 'xml' => 'ApiFormatXml',
00098 'xmlfm' => 'ApiFormatXml',
00099 'yaml' => 'ApiFormatYaml',
00100 'yamlfm' => 'ApiFormatYaml',
00101 'rawfm' => 'ApiFormatJson',
00102 'txt' => 'ApiFormatTxt',
00103 'txtfm' => 'ApiFormatTxt',
00104 'dbg' => 'ApiFormatDbg',
00105 'dbgfm' => 'ApiFormatDbg'
00106 );
00107
00114 private static $mRights = array( 'writeapi' => array(
00115 'msg' => 'Use of the write API',
00116 'params' => array()
00117 ),
00118 'apihighlimits' => array(
00119 'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.',
00120 'params' => array ( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 )
00121 )
00122 );
00123
00124
00125 private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
00126 private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
00127 private $mInternalMode, $mSquidMaxage, $mModule;
00128
00129 private $mCacheMode = 'private';
00130 private $mCacheControl = array();
00131
00138 public function __construct( $request, $enableWrite = false ) {
00139
00140 $this->mInternalMode = ( $request instanceof FauxRequest );
00141
00142
00143 parent :: __construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
00144
00145 if ( !$this->mInternalMode ) {
00146
00147
00148
00149
00150 global $wgUser;
00151
00152 if ( $request->getVal( 'callback' ) !== null ) {
00153
00154
00155 wfDebug( "API: stripping user credentials for JSON callback\n" );
00156 $wgUser = new User();
00157 }
00158 }
00159
00160 global $wgAPIModules;
00161 $this->mModules = $wgAPIModules + self :: $Modules;
00162
00163 $this->mModuleNames = array_keys( $this->mModules );
00164 $this->mFormats = self :: $Formats;
00165 $this->mFormatNames = array_keys( $this->mFormats );
00166
00167 $this->mResult = new ApiResult( $this );
00168 $this->mShowVersions = false;
00169 $this->mEnableWrite = $enableWrite;
00170
00171 $this->mRequest = & $request;
00172
00173 $this->mSquidMaxage = - 1;
00174 $this->mCommit = false;
00175 }
00176
00180 public function isInternalMode() {
00181 return $this->mInternalMode;
00182 }
00183
00187 public function getRequest() {
00188 return $this->mRequest;
00189 }
00190
00194 public function getResult() {
00195 return $this->mResult;
00196 }
00197
00201 public function getModule() {
00202 return $this->mModule;
00203 }
00204
00209 public function requestWriteMode() {
00210 if ( !$this->mEnableWrite )
00211 $this->dieUsageMsg( array( 'writedisabled' ) );
00212 if ( wfReadOnly() )
00213 $this->dieUsageMsg( array( 'readonlytext' ) );
00214 }
00215
00219 public function setCacheMaxAge( $maxage ) {
00220 $this->setCacheControl( array(
00221 'max-age' => $maxage,
00222 's-maxage' => $maxage
00223 ) );
00224 }
00225
00251 public function setCacheMode( $mode ) {
00252 if ( !in_array( $mode, array( 'private', 'public', 'anon-public-user-private' ) ) ) {
00253 wfDebug( __METHOD__.": unrecognised cache mode \"$mode\"\n" );
00254
00255 return;
00256 }
00257
00258 if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) {
00259
00260 if ( $mode !== 'private' ) {
00261 wfDebug( __METHOD__.": ignoring request for $mode cache mode, private wiki\n" );
00262 return;
00263 }
00264 }
00265
00266 wfDebug( __METHOD__.": setting cache mode $mode\n" );
00267 $this->mCacheMode = $mode;
00268 }
00269
00275 public function setCachePrivate() {
00276 $this->setCacheMode( 'private' );
00277 }
00278
00287 public function setCacheControl( $directives ) {
00288 $this->mCacheControl = $directives + $this->mCacheControl;
00289 }
00290
00301 public function setVaryCookie() {
00302 $this->setCacheMode( 'anon-public-user-private' );
00303 }
00304
00308 public function createPrinterByName( $format ) {
00309 if ( !isset( $this->mFormats[$format] ) )
00310 $this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' );
00311 return new $this->mFormats[$format] ( $this, $format );
00312 }
00313
00317 public function execute() {
00318 $this->profileIn();
00319 if ( $this->mInternalMode )
00320 $this->executeAction();
00321 else
00322 $this->executeActionWithErrorHandling();
00323
00324 $this->profileOut();
00325 }
00326
00331 protected function executeActionWithErrorHandling() {
00332
00333
00334
00335 ob_start();
00336
00337 try {
00338 $this->executeAction();
00339 } catch ( Exception $e ) {
00340
00341 if ( $e instanceof MWException ) {
00342 wfDebugLog( 'exception', $e->getLogMessage() );
00343 }
00344
00345
00346
00347
00348
00349
00350
00351 $errCode = $this->substituteResultWithError( $e );
00352
00353
00354 $this->setCacheMode( 'private' );
00355
00356 $headerStr = 'MediaWiki-API-Error: ' . $errCode;
00357 if ( $e->getCode() === 0 )
00358 header( $headerStr );
00359 else
00360 header( $headerStr, true, $e->getCode() );
00361
00362
00363 ob_clean();
00364
00365
00366 $this->mPrinter->safeProfileOut();
00367 $this->printResult( true );
00368 }
00369
00370
00371
00372 $this->sendCacheHeaders();
00373
00374 if ( $this->mPrinter->getIsHtml() ) {
00375 echo wfReportTime();
00376 }
00377
00378 ob_end_flush();
00379 }
00380
00381 protected function sendCacheHeaders() {
00382 if ( $this->mCacheMode == 'private' ) {
00383 header( 'Cache-Control: private' );
00384 return;
00385 }
00386
00387 if ( $this->mCacheMode == 'anon-public-user-private' ) {
00388 global $wgUseXVO, $wgOut;
00389 header( 'Vary: Accept-Encoding, Cookie' );
00390 if ( $wgUseXVO ) {
00391 header( $wgOut->getXVO() );
00392 if ( $wgOut->haveCacheVaryCookies() ) {
00393
00394 header( 'Cache-Control: private' );
00395 return;
00396 }
00397
00398 } elseif ( session_id() != '' ) {
00399
00400
00401 header( 'Cache-Control: private' );
00402 return;
00403 }
00404 } else {
00405
00406 global $wgUser;
00407 if ( !( $wgUser instanceof StubUser ) ) {
00408 wfDebug( __METHOD__." \$wgUser is unstubbed on a public request!\n" );
00409 }
00410 }
00411
00412
00413 if ( !isset( $this->mCacheControl['s-maxage'] ) ) {
00414 $this->mCacheControl['s-maxage'] = $this->getParameter( 'smaxage' );
00415 }
00416 if ( !isset( $this->mCacheControl['max-age'] ) ) {
00417 $this->mCacheControl['max-age'] = $this->getParameter( 'maxage' );
00418 }
00419
00420 if ( !$this->mCacheControl['s-maxage'] && !$this->mCacheControl['max-age'] ) {
00421
00422
00423
00424 header( 'Cache-Control: private' );
00425 return;
00426 }
00427
00428 $this->mCacheControl['public'] = true;
00429
00430
00431 $maxAge = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] );
00432 $expiryUnixTime = ( $maxAge == 0 ? 1 : time() + $maxAge );
00433 header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) );
00434
00435
00436 $ccHeader = '';
00437 $separator = '';
00438 foreach ( $this->mCacheControl as $name => $value ) {
00439 if ( is_bool( $value ) ) {
00440 if ( $value ) {
00441 $ccHeader .= $separator . $name;
00442 $separator = ', ';
00443 }
00444 } else {
00445 $ccHeader .= $separator . "$name=$value";
00446 $separator = ', ';
00447 }
00448 }
00449
00450 header( "Cache-Control: $ccHeader" );
00451 }
00452
00457 protected function substituteResultWithError( $e ) {
00458
00459
00460 if ( !isset ( $this->mPrinter ) ) {
00461
00462 $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
00463 if ( !in_array( $value, $this->mFormatNames ) )
00464 $value = self::API_DEFAULT_FORMAT;
00465
00466 $this->mPrinter = $this->createPrinterByName( $value );
00467 if ( $this->mPrinter->getNeedsRawData() )
00468 $this->getResult()->setRawMode();
00469 }
00470
00471 if ( $e instanceof UsageException ) {
00472
00473
00474
00475 $errMessage = $e->getMessageArray();
00476
00477
00478 if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' )
00479 ApiResult :: setContent( $errMessage, $this->makeHelpMsg() );
00480
00481 } else {
00482 global $wgShowSQLErrors, $wgShowExceptionDetails;
00483
00484
00485
00486 if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
00487 $info = "Database query error";
00488 } else {
00489 $info = "Exception Caught: {$e->getMessage()}";
00490 }
00491
00492 $errMessage = array (
00493 'code' => 'internal_api_error_' . get_class( $e ),
00494 'info' => $info,
00495 );
00496 ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" );
00497 }
00498
00499 $this->getResult()->reset();
00500 $this->getResult()->disableSizeCheck();
00501
00502 $requestid = $this->getParameter( 'requestid' );
00503 if ( !is_null( $requestid ) )
00504 $this->getResult()->addValue( null, 'requestid', $requestid );
00505 $this->getResult()->addValue( null, 'error', $errMessage );
00506
00507 return $errMessage['code'];
00508 }
00509
00513 protected function executeAction() {
00514
00515 $requestid = $this->getParameter( 'requestid' );
00516 if ( !is_null( $requestid ) )
00517 $this->getResult()->addValue( null, 'requestid', $requestid );
00518
00519 $params = $this->extractRequestParams();
00520
00521 $this->mShowVersions = $params['version'];
00522 $this->mAction = $params['action'];
00523
00524 if ( !is_string( $this->mAction ) ) {
00525 $this->dieUsage( "The API requires a valid action parameter", 'unknown_action' );
00526 }
00527
00528
00529 $module = new $this->mModules[$this->mAction] ( $this, $this->mAction );
00530 $this->mModule = $module;
00531
00532 $moduleParams = $module->extractRequestParams();
00533
00534
00535 $salt = $module->getTokenSalt();
00536 if ( $salt !== false && !isset( $moduleParams['gettoken'] ) )
00537 {
00538 if ( !isset( $moduleParams['token'] ) ) {
00539 $this->dieUsageMsg( array( 'missingparam', 'token' ) );
00540 } else {
00541 global $wgUser;
00542 if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt ) ) {
00543 $this->dieUsageMsg( array( 'sessionfailure' ) );
00544 }
00545 }
00546 }
00547
00548 if ( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) {
00549
00550 global $wgShowHostnames;
00551 $maxLag = $params['maxlag'];
00552 list( $host, $lag ) = wfGetLB()->getMaxLag();
00553 if ( $lag > $maxLag ) {
00554 header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
00555 header( 'X-Database-Lag: ' . intval( $lag ) );
00556 if ( $wgShowHostnames ) {
00557 $this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
00558 } else {
00559 $this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
00560 }
00561 return;
00562 }
00563 }
00564
00565 global $wgUser, $wgGroupPermissions;
00566 if ( $module->isReadMode() && !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) && !$wgUser->isAllowed( 'read' ) )
00567 $this->dieUsageMsg( array( 'readrequired' ) );
00568 if ( $module->isWriteMode() ) {
00569 if ( !$this->mEnableWrite )
00570 $this->dieUsageMsg( array( 'writedisabled' ) );
00571 if ( !$wgUser->isAllowed( 'writeapi' ) )
00572 $this->dieUsageMsg( array( 'writerequired' ) );
00573 if ( wfReadOnly() )
00574 $this->dieReadOnly();
00575 }
00576
00577 if ( !$this->mInternalMode ) {
00578
00579 if ( $module->mustBePosted() && !$this->mRequest->wasPosted() )
00580 $this->dieUsageMsg( array ( 'mustbeposted', $this->mAction ) );
00581
00582
00583 $this->mPrinter = $module->getCustomPrinter();
00584 if ( is_null( $this->mPrinter ) ) {
00585
00586 $this->mPrinter = $this->createPrinterByName( $params['format'] );
00587 }
00588
00589 if ( $this->mPrinter->getNeedsRawData() )
00590 $this->getResult()->setRawMode();
00591 }
00592
00593
00594 $module->profileIn();
00595 $module->execute();
00596 wfRunHooks( 'APIAfterExecute', array( &$module ) );
00597 $module->profileOut();
00598
00599 if ( !$this->mInternalMode ) {
00600
00601 $this->printResult( false );
00602 }
00603 }
00604
00608 protected function printResult( $isError ) {
00609 $this->getResult()->cleanUpUTF8();
00610 $printer = $this->mPrinter;
00611 $printer->profileIn();
00612
00613
00614
00615
00616 $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError )
00617 && $printer->getFormat() == 'XML' && $printer->getIsHtml() );
00618
00619 $printer->initPrinter( $isError );
00620
00621 $printer->execute();
00622 $printer->closePrinter();
00623 $printer->profileOut();
00624 }
00625
00626 public function isReadMode() {
00627 return false;
00628 }
00629
00633 public function getAllowedParams() {
00634 return array (
00635 'format' => array (
00636 ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT,
00637 ApiBase :: PARAM_TYPE => $this->mFormatNames
00638 ),
00639 'action' => array (
00640 ApiBase :: PARAM_DFLT => 'help',
00641 ApiBase :: PARAM_TYPE => $this->mModuleNames
00642 ),
00643 'version' => false,
00644 'maxlag' => array (
00645 ApiBase :: PARAM_TYPE => 'integer'
00646 ),
00647 'smaxage' => array (
00648 ApiBase :: PARAM_TYPE => 'integer',
00649 ApiBase :: PARAM_DFLT => 0
00650 ),
00651 'maxage' => array (
00652 ApiBase :: PARAM_TYPE => 'integer',
00653 ApiBase :: PARAM_DFLT => 0
00654 ),
00655 'requestid' => null,
00656 );
00657 }
00658
00662 public function getParamDescription() {
00663 return array (
00664 'format' => 'The format of the output',
00665 'action' => 'What action you would like to perform',
00666 'version' => 'When showing help, include version for each module',
00667 'maxlag' => 'Maximum lag',
00668 'smaxage' => 'Set the s-maxage header to this many seconds. Errors are never cached',
00669 'maxage' => 'Set the max-age header to this many seconds. Errors are never cached',
00670 'requestid' => 'Request ID to distinguish requests. This will just be output back to you',
00671 );
00672 }
00673
00677 public function getDescription() {
00678 return array (
00679 '',
00680 '',
00681 '******************************************************************',
00682 '** **',
00683 '** This is an auto-generated MediaWiki API documentation page **',
00684 '** **',
00685 '** Documentation and Examples: **',
00686 '** http://www.mediawiki.org/wiki/API **',
00687 '** **',
00688 '******************************************************************',
00689 '',
00690 'Status: All features shown on this page should be working, but the API',
00691 ' is still in active development, and may change at any time.',
00692 ' Make sure to monitor our mailing list for any updates.',
00693 '',
00694 'Documentation: http://www.mediawiki.org/wiki/API',
00695 'Mailing list: http://lists.wikimedia.org/mailman/listinfo/mediawiki-api',
00696 'Bugs & Requests: http://bugzilla.wikimedia.org/buglist.cgi?component=API&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&order=bugs.delta_ts',
00697 '',
00698 '',
00699 '',
00700 '',
00701 '',
00702 );
00703 }
00704
00705 public function getPossibleErrors() {
00706 return array_merge( parent::getPossibleErrors(), array(
00707 array( 'readonlytext' ),
00708 array( 'code' => 'unknown_format', 'info' => 'Unrecognized format: format' ),
00709 array( 'code' => 'unknown_action', 'info' => 'The API requires a valid action parameter' ),
00710 array( 'code' => 'maxlag', 'info' => 'Waiting for host: x seconds lagged' ),
00711 array( 'code' => 'maxlag', 'info' => 'Waiting for a database server: x seconds lagged' ),
00712 ) );
00713 }
00714
00718 protected function getCredits() {
00719 return array(
00720 'API developers:',
00721 ' Roan Kattouw <Firstname>.<Lastname>@home.nl (lead developer Sep 2007-present)',
00722 ' Victor Vasiliev - vasilvv at gee mail dot com',
00723 ' Bryan Tong Minh - bryan . tongminh @ gmail . com',
00724 ' Sam Reed - sam @ reedyboy . net',
00725 ' Yuri Astrakhan <Firstname><Lastname>@gmail.com (creator, lead developer Sep 2006-Sep 2007)',
00726 '',
00727 'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
00728 'or file a bug report at http://bugzilla.wikimedia.org/'
00729 );
00730 }
00731
00735 public function makeHelpMsg() {
00736 global $wgMemc, $wgAPICacheHelp, $wgAPICacheHelpTimeout;
00737 $this->mPrinter->setHelp();
00738
00739 $key = wfMemcKey( 'apihelp', $this->getModuleName(),
00740 SpecialVersion::getVersion( 'nodb' ) .
00741 $this->getMain()->getShowVersions() );
00742 if ( $wgAPICacheHelp ) {
00743 $cached = $wgMemc->get( $key );
00744 if ( $cached )
00745 return $cached;
00746 }
00747 $retval = $this->reallyMakeHelpMsg();
00748 if ( $wgAPICacheHelp )
00749 $wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout );
00750 return $retval;
00751 }
00752
00753 public function reallyMakeHelpMsg() {
00754
00755 $this->mPrinter->setHelp();
00756
00757
00758 $msg = parent :: makeHelpMsg();
00759
00760 $astriks = str_repeat( '*** ', 10 );
00761 $msg .= "\n\n$astriks Modules $astriks\n\n";
00762 foreach ( $this->mModules as $moduleName => $unused ) {
00763 $module = new $this->mModules[$moduleName] ( $this, $moduleName );
00764 $msg .= self::makeHelpMsgHeader( $module, 'action' );
00765 $msg2 = $module->makeHelpMsg();
00766 if ( $msg2 !== false )
00767 $msg .= $msg2;
00768 $msg .= "\n";
00769 }
00770
00771 $msg .= "\n$astriks Permissions $astriks\n\n";
00772 foreach ( self :: $mRights as $right => $rightMsg ) {
00773 $groups = User::getGroupsWithPermission( $right );
00774 $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg[ 'msg' ], $rightMsg[ 'params' ] ) .
00775 "\nGranted to:\n " . str_replace( "*", "all", implode( ", ", $groups ) ) . "\n";
00776
00777 }
00778
00779 $msg .= "\n$astriks Formats $astriks\n\n";
00780 foreach ( $this->mFormats as $formatName => $unused ) {
00781 $module = $this->createPrinterByName( $formatName );
00782 $msg .= self::makeHelpMsgHeader( $module, 'format' );
00783 $msg2 = $module->makeHelpMsg();
00784 if ( $msg2 !== false )
00785 $msg .= $msg2;
00786 $msg .= "\n";
00787 }
00788
00789 $msg .= "\n*** Credits: ***\n " . implode( "\n ", $this->getCredits() ) . "\n";
00790
00791
00792 return $msg;
00793 }
00794
00795 public static function makeHelpMsgHeader( $module, $paramName ) {
00796 $modulePrefix = $module->getModulePrefix();
00797 if ( strval( $modulePrefix ) !== '' )
00798 $modulePrefix = "($modulePrefix) ";
00799
00800 return "* $paramName={$module->getModuleName()} $modulePrefix*";
00801 }
00802
00803 private $mIsBot = null;
00804 private $mIsSysop = null;
00805 private $mCanApiHighLimits = null;
00806
00811 public function isBot() {
00812 if ( !isset ( $this->mIsBot ) ) {
00813 global $wgUser;
00814 $this->mIsBot = $wgUser->isAllowed( 'bot' );
00815 }
00816 return $this->mIsBot;
00817 }
00818
00824 public function isSysop() {
00825 if ( !isset ( $this->mIsSysop ) ) {
00826 global $wgUser;
00827 $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups() );
00828 }
00829
00830 return $this->mIsSysop;
00831 }
00832
00837 public function canApiHighLimits() {
00838 if ( !isset( $this->mCanApiHighLimits ) ) {
00839 global $wgUser;
00840 $this->mCanApiHighLimits = $wgUser->isAllowed( 'apihighlimits' );
00841 }
00842
00843 return $this->mCanApiHighLimits;
00844 }
00845
00850 public function getShowVersions() {
00851 return $this->mShowVersions;
00852 }
00853
00858 public function getVersion() {
00859 $vers = array ();
00860 $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
00861 $vers[] = __CLASS__ . ': $Id: ApiMain.php 70066 2010-07-28 05:52:32Z tstarling $';
00862 $vers[] = ApiBase :: getBaseVersion();
00863 $vers[] = ApiFormatBase :: getBaseVersion();
00864 $vers[] = ApiQueryBase :: getBaseVersion();
00865 return $vers;
00866 }
00867
00877 protected function addModule( $mdlName, $mdlClass ) {
00878 $this->mModules[$mdlName] = $mdlClass;
00879 }
00880
00889 protected function addFormat( $fmtName, $fmtClass ) {
00890 $this->mFormats[$fmtName] = $fmtClass;
00891 }
00892
00896 function getModules() {
00897 return $this->mModules;
00898 }
00899 }
00900
00907 class UsageException extends Exception {
00908
00909 private $mCodestr;
00910 private $mExtraData;
00911
00912 public function __construct( $message, $codestr, $code = 0, $extradata = null ) {
00913 parent :: __construct( $message, $code );
00914 $this->mCodestr = $codestr;
00915 $this->mExtraData = $extradata;
00916 }
00917 public function getCodeString() {
00918 return $this->mCodestr;
00919 }
00920 public function getMessageArray() {
00921 $result = array (
00922 'code' => $this->mCodestr,
00923 'info' => $this->getMessage()
00924 );
00925 if ( is_array( $this->mExtraData ) )
00926 $result = array_merge( $result, $this->mExtraData );
00927 return $result;
00928 }
00929 public function __toString() {
00930 return "{$this->getCodeString()}: {$this->getMessage()}";
00931 }
00932 }