3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 * This exception will be thrown when dieUsage is called to stop module execution.
25 * @deprecated since 1.29, use ApiUsageException instead
27 class UsageException
extends MWException
{
37 * @param string $message
38 * @param string $codestr
40 * @param array|null $extradata
42 public function __construct( $message, $codestr, $code = 0, $extradata = null ) {
43 parent
::__construct( $message, $code );
44 $this->mCodestr
= $codestr;
45 $this->mExtraData
= $extradata;
47 if ( !$this instanceof ApiUsageException
) {
48 wfDeprecated( __METHOD__
, '1.29' );
51 // This should never happen, so throw an exception about it that will
52 // hopefully get logged with a backtrace (T138585)
53 if ( !is_string( $codestr ) ||
$codestr === '' ) {
54 throw new InvalidArgumentException( 'Invalid $codestr, was ' .
55 ( $codestr === '' ?
'empty string' : gettype( $codestr ) )
63 public function getCodeString() {
64 wfDeprecated( __METHOD__
, '1.29' );
65 return $this->mCodestr
;
71 public function getMessageArray() {
72 wfDeprecated( __METHOD__
, '1.29' );
74 'code' => $this->mCodestr
,
75 'info' => $this->getMessage()
77 if ( is_array( $this->mExtraData
) ) {
78 $result = array_merge( $result, $this->mExtraData
);
87 public function __toString() {
88 return "{$this->getCodeString()}: {$this->getMessage()}";