API: (bug 16740) Adding list=protectedtitles to list create-protected titles
[lhc/web/wiklou.git] / includes / api / ApiMain.php
1 <?php
2
3 /*
4 * Created on Sep 4, 2006
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 ('ApiBase.php');
29 }
30
31 /**
32 * @defgroup API API
33 */
34
35 /**
36 * This is the main API class, used for both external and internal processing.
37 * When executed, it will create the requested formatter object,
38 * instantiate and execute an object associated with the needed action,
39 * and use formatter to print results.
40 * In case of an exception, an error message will be printed using the same formatter.
41 *
42 * To use API from another application, run it using FauxRequest object, in which
43 * case any internal exceptions will not be handled but passed up to the caller.
44 * After successful execution, use getResult() for the resulting data.
45 *
46 * @ingroup API
47 */
48 class ApiMain extends ApiBase {
49
50 /**
51 * When no format parameter is given, this format will be used
52 */
53 const API_DEFAULT_FORMAT = 'xmlfm';
54
55 /**
56 * List of available modules: action name => module class
57 */
58 private static $Modules = array (
59 'login' => 'ApiLogin',
60 'logout' => 'ApiLogout',
61 'query' => 'ApiQuery',
62 'expandtemplates' => 'ApiExpandTemplates',
63 'parse' => 'ApiParse',
64 'opensearch' => 'ApiOpenSearch',
65 'feedwatchlist' => 'ApiFeedWatchlist',
66 'help' => 'ApiHelp',
67 'paraminfo' => 'ApiParamInfo',
68 'purge' => 'ApiPurge',
69 );
70
71 private static $WriteModules = array (
72 'rollback' => 'ApiRollback',
73 'delete' => 'ApiDelete',
74 'undelete' => 'ApiUndelete',
75 'protect' => 'ApiProtect',
76 'block' => 'ApiBlock',
77 'unblock' => 'ApiUnblock',
78 'move' => 'ApiMove',
79 'edit' => 'ApiEditPage',
80 'emailuser' => 'ApiEmailUser',
81 'watch' => 'ApiWatch',
82 'patrol' => 'ApiPatrol',
83 'import' => 'ApiImport',
84 );
85
86 /**
87 * List of available formats: format name => format class
88 */
89 private static $Formats = array (
90 'json' => 'ApiFormatJson',
91 'jsonfm' => 'ApiFormatJson',
92 'php' => 'ApiFormatPhp',
93 'phpfm' => 'ApiFormatPhp',
94 'wddx' => 'ApiFormatWddx',
95 'wddxfm' => 'ApiFormatWddx',
96 'xml' => 'ApiFormatXml',
97 'xmlfm' => 'ApiFormatXml',
98 'yaml' => 'ApiFormatYaml',
99 'yamlfm' => 'ApiFormatYaml',
100 'rawfm' => 'ApiFormatJson',
101 'txt' => 'ApiFormatTxt',
102 'txtfm' => 'ApiFormatTxt',
103 'dbg' => 'ApiFormatDbg',
104 'dbgfm' => 'ApiFormatDbg'
105 );
106
107 /**
108 * List of user roles that are specifically relevant to the API.
109 * array( 'right' => array ( 'msg' => 'Some message with a $1',
110 * 'params' => array ( $someVarToSubst ) ),
111 * );
112 */
113 private static $mRights = array('writeapi' => array(
114 'msg' => 'Use of the write API',
115 'params' => array()
116 ),
117 'apihighlimits' => array(
118 '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.',
119 'params' => array (ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2)
120 )
121 );
122
123
124 private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
125 private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage;
126
127 /**
128 * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
129 *
130 * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs
131 * @param $enableWrite bool should be set to true if the api may modify data
132 */
133 public function __construct($request, $enableWrite = false) {
134
135 $this->mInternalMode = ($request instanceof FauxRequest);
136
137 // Special handling for the main module: $parent === $this
138 parent :: __construct($this, $this->mInternalMode ? 'main_int' : 'main');
139
140 if (!$this->mInternalMode) {
141
142 // Impose module restrictions.
143 // If the current user cannot read,
144 // Remove all modules other than login
145 global $wgUser;
146
147 if( $request->getVal( 'callback' ) !== null ) {
148 // JSON callback allows cross-site reads.
149 // For safety, strip user credentials.
150 wfDebug( "API: stripping user credentials for JSON callback\n" );
151 $wgUser = new User();
152 }
153
154 if (!$wgUser->isAllowed('read')) {
155 self::$Modules = array(
156 'login' => self::$Modules['login'],
157 'logout' => self::$Modules['logout'],
158 'help' => self::$Modules['help'],
159 );
160 }
161 }
162
163 global $wgAPIModules, $wgEnableWriteAPI; // extension modules
164 $this->mModules = $wgAPIModules + self :: $Modules;
165 if($wgEnableWriteAPI)
166 $this->mModules += self::$WriteModules;
167
168 $this->mModuleNames = array_keys($this->mModules);
169 $this->mFormats = self :: $Formats;
170 $this->mFormatNames = array_keys($this->mFormats);
171
172 $this->mResult = new ApiResult($this);
173 $this->mShowVersions = false;
174 $this->mEnableWrite = $enableWrite;
175
176 $this->mRequest = & $request;
177
178 $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
179 $this->mCommit = false;
180 }
181
182 /**
183 * Return true if the API was started by other PHP code using FauxRequest
184 */
185 public function isInternalMode() {
186 return $this->mInternalMode;
187 }
188
189 /**
190 * Return the request object that contains client's request
191 */
192 public function getRequest() {
193 return $this->mRequest;
194 }
195
196 /**
197 * Get the ApiResult object asscosiated with current request
198 */
199 public function getResult() {
200 return $this->mResult;
201 }
202
203 /**
204 * This method will simply cause an error if the write mode was disabled
205 * or if the current user doesn't have the right to use it
206 */
207 public function requestWriteMode() {
208 global $wgUser;
209 if (!$this->mEnableWrite)
210 $this->dieUsage('Editing of this wiki through the API' .
211 ' is disabled. Make sure the $wgEnableWriteAPI=true; ' .
212 'statement is included in the wiki\'s ' .
213 'LocalSettings.php file', 'noapiwrite');
214 if (!$wgUser->isAllowed('writeapi'))
215 $this->dieUsage('You\'re not allowed to edit this ' .
216 'wiki through the API', 'writeapidenied');
217 if (wfReadOnly())
218 $this->dieUsageMsg(array('readonlytext'));
219 }
220
221 /**
222 * Set how long the response should be cached.
223 */
224 public function setCacheMaxAge($maxage) {
225 $this->mSquidMaxage = $maxage;
226 }
227
228 /**
229 * Create an instance of an output formatter by its name
230 */
231 public function createPrinterByName($format) {
232 if( !isset( $this->mFormats[$format] ) )
233 $this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' );
234 return new $this->mFormats[$format] ($this, $format);
235 }
236
237 /**
238 * Execute api request. Any errors will be handled if the API was called by the remote client.
239 */
240 public function execute() {
241 $this->profileIn();
242 if ($this->mInternalMode)
243 $this->executeAction();
244 else
245 $this->executeActionWithErrorHandling();
246
247 $this->profileOut();
248 }
249
250 /**
251 * Execute an action, and in case of an error, erase whatever partial results
252 * have been accumulated, and replace it with an error message and a help screen.
253 */
254 protected function executeActionWithErrorHandling() {
255
256 // In case an error occurs during data output,
257 // clear the output buffer and print just the error information
258 ob_start();
259
260 try {
261 $this->executeAction();
262 } catch (Exception $e) {
263 // Log it
264 if ( $e instanceof MWException ) {
265 wfDebugLog( 'exception', $e->getLogMessage() );
266 }
267
268 //
269 // Handle any kind of exception by outputing properly formatted error message.
270 // If this fails, an unhandled exception should be thrown so that global error
271 // handler will process and log it.
272 //
273
274 $errCode = $this->substituteResultWithError($e);
275
276 // Error results should not be cached
277 $this->setCacheMaxAge(0);
278
279 $headerStr = 'MediaWiki-API-Error: ' . $errCode;
280 if ($e->getCode() === 0)
281 header($headerStr);
282 else
283 header($headerStr, true, $e->getCode());
284
285 // Reset and print just the error message
286 ob_clean();
287
288 // If the error occured during printing, do a printer->profileOut()
289 $this->mPrinter->safeProfileOut();
290 $this->printResult(true);
291 }
292
293 if($this->mSquidMaxage == -1)
294 {
295 # Nobody called setCacheMaxAge(), use the (s)maxage parameters
296 $smaxage = $this->getParameter('smaxage');
297 $maxage = $this->getParameter('maxage');
298 }
299 else
300 $smaxage = $maxage = $this->mSquidMaxage;
301
302 // Set the cache expiration at the last moment, as any errors may change the expiration.
303 // if $this->mSquidMaxage == 0, the expiry time is set to the first second of unix epoch
304 $exp = min($smaxage, $maxage);
305 $expires = ($exp == 0 ? 1 : time() + $exp);
306 header('Expires: ' . wfTimestamp(TS_RFC2822, $expires));
307 header('Cache-Control: s-maxage=' . $smaxage . ', must-revalidate, max-age=' . $maxage);
308
309 if($this->mPrinter->getIsHtml())
310 echo wfReportTime();
311
312 ob_end_flush();
313 }
314
315 /**
316 * Replace the result data with the information about an exception.
317 * Returns the error code
318 */
319 protected function substituteResultWithError($e) {
320
321 // Printer may not be initialized if the extractRequestParams() fails for the main module
322 if (!isset ($this->mPrinter)) {
323 // The printer has not been created yet. Try to manually get formatter value.
324 $value = $this->getRequest()->getVal('format', self::API_DEFAULT_FORMAT);
325 if (!in_array($value, $this->mFormatNames))
326 $value = self::API_DEFAULT_FORMAT;
327
328 $this->mPrinter = $this->createPrinterByName($value);
329 if ($this->mPrinter->getNeedsRawData())
330 $this->getResult()->setRawMode();
331 }
332
333 if ($e instanceof UsageException) {
334 //
335 // User entered incorrect parameters - print usage screen
336 //
337 $errMessage = array (
338 'code' => $e->getCodeString(),
339 'info' => $e->getMessage());
340
341 // Only print the help message when this is for the developer, not runtime
342 if ($this->mPrinter->getIsHtml() || $this->mAction == 'help')
343 ApiResult :: setContent($errMessage, $this->makeHelpMsg());
344
345 } else {
346 global $wgShowSQLErrors, $wgShowExceptionDetails;
347 //
348 // Something is seriously wrong
349 //
350 if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
351 $info = "Database query error";
352 } else {
353 $info = "Exception Caught: {$e->getMessage()}";
354 }
355
356 $errMessage = array (
357 'code' => 'internal_api_error_'. get_class($e),
358 'info' => $info,
359 );
360 ApiResult :: setContent($errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" );
361 }
362
363 $this->getResult()->reset();
364 $this->getResult()->disableSizeCheck();
365 // Re-add the id
366 $requestid = $this->getParameter('requestid');
367 if(!is_null($requestid))
368 $this->getResult()->addValue(null, 'requestid', $requestid);
369 $this->getResult()->addValue(null, 'error', $errMessage);
370
371 return $errMessage['code'];
372 }
373
374 /**
375 * Execute the actual module, without any error handling
376 */
377 protected function executeAction() {
378 // First add the id to the top element
379 $requestid = $this->getParameter('requestid');
380 if(!is_null($requestid))
381 $this->getResult()->addValue(null, 'requestid', $requestid);
382
383 $params = $this->extractRequestParams();
384
385 $this->mShowVersions = $params['version'];
386 $this->mAction = $params['action'];
387
388 if( !is_string( $this->mAction ) ) {
389 $this->dieUsage( "The API requires a valid action parameter", 'unknown_action' );
390 }
391
392 // Instantiate the module requested by the user
393 $module = new $this->mModules[$this->mAction] ($this, $this->mAction);
394
395 if( $module->shouldCheckMaxlag() && isset( $params['maxlag'] ) ) {
396 // Check for maxlag
397 global $wgShowHostnames;
398 $maxLag = $params['maxlag'];
399 list( $host, $lag ) = wfGetLB()->getMaxLag();
400 if ( $lag > $maxLag ) {
401 header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
402 header( 'X-Database-Lag: ' . intval( $lag ) );
403 // XXX: should we return a 503 HTTP error code like wfMaxlagError() does?
404 if( $wgShowHostnames ) {
405 $this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
406 } else {
407 $this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
408 }
409 return;
410 }
411 }
412
413 if (!$this->mInternalMode) {
414 // Ignore mustBePosted() for internal calls
415 if($module->mustBePosted() && !$this->mRequest->wasPosted())
416 $this->dieUsage("The {$this->mAction} module requires a POST request", 'mustbeposted');
417
418 // See if custom printer is used
419 $this->mPrinter = $module->getCustomPrinter();
420 if (is_null($this->mPrinter)) {
421 // Create an appropriate printer
422 $this->mPrinter = $this->createPrinterByName($params['format']);
423 }
424
425 if ($this->mPrinter->getNeedsRawData())
426 $this->getResult()->setRawMode();
427 }
428
429 // Execute
430 $module->profileIn();
431 $module->execute();
432 wfRunHooks('APIAfterExecute', array(&$module));
433 $module->profileOut();
434
435 if (!$this->mInternalMode) {
436 // Print result data
437 $this->printResult(false);
438 }
439 }
440
441 /**
442 * Print results using the current printer
443 */
444 protected function printResult($isError) {
445 $this->getResult()->cleanUpUTF8();
446 $printer = $this->mPrinter;
447 $printer->profileIn();
448
449 /* If the help message is requested in the default (xmlfm) format,
450 * tell the printer not to escape ampersands so that our links do
451 * not break. */
452 $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError )
453 && $printer->getFormat() == 'XML' && $printer->getIsHtml() );
454
455 $printer->initPrinter($isError);
456
457 $printer->execute();
458 $printer->closePrinter();
459 $printer->profileOut();
460 }
461
462 /**
463 * See ApiBase for description.
464 */
465 public function getAllowedParams() {
466 return array (
467 'format' => array (
468 ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT,
469 ApiBase :: PARAM_TYPE => $this->mFormatNames
470 ),
471 'action' => array (
472 ApiBase :: PARAM_DFLT => 'help',
473 ApiBase :: PARAM_TYPE => $this->mModuleNames
474 ),
475 'version' => false,
476 'maxlag' => array (
477 ApiBase :: PARAM_TYPE => 'integer'
478 ),
479 'smaxage' => array (
480 ApiBase :: PARAM_TYPE => 'integer',
481 ApiBase :: PARAM_DFLT => 0
482 ),
483 'maxage' => array (
484 ApiBase :: PARAM_TYPE => 'integer',
485 ApiBase :: PARAM_DFLT => 0
486 ),
487 'requestid' => null,
488 );
489 }
490
491 /**
492 * See ApiBase for description.
493 */
494 public function getParamDescription() {
495 return array (
496 'format' => 'The format of the output',
497 'action' => 'What action you would like to perform',
498 'version' => 'When showing help, include version for each module',
499 'maxlag' => 'Maximum lag',
500 'smaxage' => 'Set the s-maxage header to this many seconds. Errors are never cached',
501 'maxage' => 'Set the max-age header to this many seconds. Errors are never cached',
502 'requestid' => 'Request ID to distinguish requests. This will just be output back to you',
503 );
504 }
505
506 /**
507 * See ApiBase for description.
508 */
509 public function getDescription() {
510 return array (
511 '',
512 '',
513 '******************************************************************',
514 '** **',
515 '** This is an auto-generated MediaWiki API documentation page **',
516 '** **',
517 '** Documentation and Examples: **',
518 '** http://www.mediawiki.org/wiki/API **',
519 '** **',
520 '******************************************************************',
521 '',
522 'Status: All features shown on this page should be working, but the API',
523 ' is still in active development, and may change at any time.',
524 ' Make sure to monitor our mailing list for any updates.',
525 '',
526 'Documentation: http://www.mediawiki.org/wiki/API',
527 'Mailing list: http://lists.wikimedia.org/mailman/listinfo/mediawiki-api',
528 'Bugs & Requests: http://bugzilla.wikimedia.org/buglist.cgi?component=API&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&order=bugs.delta_ts',
529 '',
530 '',
531 '',
532 '',
533 '',
534 );
535 }
536
537 /**
538 * Returns an array of strings with credits for the API
539 */
540 protected function getCredits() {
541 return array(
542 'API developers:',
543 ' Roan Kattouw <Firstname>.<Lastname>@home.nl (lead developer Sep 2007-present)',
544 ' Victor Vasiliev - vasilvv at gee mail dot com',
545 ' Bryan Tong Minh - bryan . tongminh @ gmail . com',
546 ' Yuri Astrakhan <Firstname><Lastname>@gmail.com (creator, lead developer Sep 2006-Sep 2007)',
547 '',
548 'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
549 'or file a bug report at http://bugzilla.wikimedia.org/'
550 );
551 }
552
553 /**
554 * Override the parent to generate help messages for all available modules.
555 */
556 public function makeHelpMsg() {
557
558 $this->mPrinter->setHelp();
559
560 // Use parent to make default message for the main module
561 $msg = parent :: makeHelpMsg();
562
563 $astriks = str_repeat('*** ', 10);
564 $msg .= "\n\n$astriks Modules $astriks\n\n";
565 foreach( $this->mModules as $moduleName => $unused ) {
566 $module = new $this->mModules[$moduleName] ($this, $moduleName);
567 $msg .= self::makeHelpMsgHeader($module, 'action');
568 $msg2 = $module->makeHelpMsg();
569 if ($msg2 !== false)
570 $msg .= $msg2;
571 $msg .= "\n";
572 }
573
574 $msg .= "\n$astriks Permissions $astriks\n\n";
575 foreach ( self :: $mRights as $right => $rightMsg ) {
576 $groups = User::getGroupsWithPermission( $right );
577 $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg[ 'msg' ], $rightMsg[ 'params' ] ) .
578 "\nGranted to:\n " . str_replace( "*", "all", implode( ", ", $groups ) ) . "\n";
579
580 }
581
582 $msg .= "\n$astriks Formats $astriks\n\n";
583 foreach( $this->mFormats as $formatName => $unused ) {
584 $module = $this->createPrinterByName($formatName);
585 $msg .= self::makeHelpMsgHeader($module, 'format');
586 $msg2 = $module->makeHelpMsg();
587 if ($msg2 !== false)
588 $msg .= $msg2;
589 $msg .= "\n";
590 }
591
592 $msg .= "\n*** Credits: ***\n " . implode("\n ", $this->getCredits()) . "\n";
593
594
595 return $msg;
596 }
597
598 public static function makeHelpMsgHeader($module, $paramName) {
599 $modulePrefix = $module->getModulePrefix();
600 if (strval($modulePrefix) !== '')
601 $modulePrefix = "($modulePrefix) ";
602
603 return "* $paramName={$module->getModuleName()} $modulePrefix*";
604 }
605
606 private $mIsBot = null;
607 private $mIsSysop = null;
608 private $mCanApiHighLimits = null;
609
610 /**
611 * Returns true if the currently logged in user is a bot, false otherwise
612 * OBSOLETE, use canApiHighLimits() instead
613 */
614 public function isBot() {
615 if (!isset ($this->mIsBot)) {
616 global $wgUser;
617 $this->mIsBot = $wgUser->isAllowed('bot');
618 }
619 return $this->mIsBot;
620 }
621
622 /**
623 * Similar to isBot(), this method returns true if the logged in user is
624 * a sysop, and false if not.
625 * OBSOLETE, use canApiHighLimits() instead
626 */
627 public function isSysop() {
628 if (!isset ($this->mIsSysop)) {
629 global $wgUser;
630 $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups());
631 }
632
633 return $this->mIsSysop;
634 }
635
636 /**
637 * Check whether the current user is allowed to use high limits
638 * @return bool
639 */
640 public function canApiHighLimits() {
641 if (!isset($this->mCanApiHighLimits)) {
642 global $wgUser;
643 $this->mCanApiHighLimits = $wgUser->isAllowed('apihighlimits');
644 }
645
646 return $this->mCanApiHighLimits;
647 }
648
649 /**
650 * Check whether the user wants us to show version information in the API help
651 * @return bool
652 */
653 public function getShowVersions() {
654 return $this->mShowVersions;
655 }
656
657 /**
658 * Returns the version information of this file, plus it includes
659 * the versions for all files that are not callable proper API modules
660 */
661 public function getVersion() {
662 $vers = array ();
663 $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
664 $vers[] = __CLASS__ . ': $Id$';
665 $vers[] = ApiBase :: getBaseVersion();
666 $vers[] = ApiFormatBase :: getBaseVersion();
667 $vers[] = ApiQueryBase :: getBaseVersion();
668 $vers[] = ApiFormatFeedWrapper :: getVersion(); // not accessible with format=xxx
669 return $vers;
670 }
671
672 /**
673 * Add or overwrite a module in this ApiMain instance. Intended for use by extending
674 * classes who wish to add their own modules to their lexicon or override the
675 * behavior of inherent ones.
676 *
677 * @access protected
678 * @param $mdlName String The identifier for this module.
679 * @param $mdlClass String The class where this module is implemented.
680 */
681 protected function addModule( $mdlName, $mdlClass ) {
682 $this->mModules[$mdlName] = $mdlClass;
683 }
684
685 /**
686 * Add or overwrite an output format for this ApiMain. Intended for use by extending
687 * classes who wish to add to or modify current formatters.
688 *
689 * @access protected
690 * @param $fmtName The identifier for this format.
691 * @param $fmtClass The class implementing this format.
692 */
693 protected function addFormat( $fmtName, $fmtClass ) {
694 $this->mFormats[$fmtName] = $fmtClass;
695 }
696
697 /**
698 * Get the array mapping module names to class names
699 */
700 function getModules() {
701 return $this->mModules;
702 }
703 }
704
705 /**
706 * This exception will be thrown when dieUsage is called to stop module execution.
707 * The exception handling code will print a help screen explaining how this API may be used.
708 *
709 * @ingroup API
710 */
711 class UsageException extends Exception {
712
713 private $mCodestr;
714
715 public function __construct($message, $codestr, $code = 0) {
716 parent :: __construct($message, $code);
717 $this->mCodestr = $codestr;
718 }
719 public function getCodeString() {
720 return $this->mCodestr;
721 }
722 public function __toString() {
723 return "{$this->getCodeString()}: {$this->getMessage()}";
724 }
725 }