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