ApiBase::dieUsageMsg() now also accept being given a single element as a string.
authorAntoine Musso <hashar@users.mediawiki.org>
Sat, 14 May 2011 11:19:59 +0000 (11:19 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sat, 14 May 2011 11:19:59 +0000 (11:19 +0000)
So the old:
  $api->dieUsageMsg( array( 'nologging' ) );

Can now be written:
  $api->dieUsageMsg( 'nologging' );

Saves up a few keystrokes.

includes/api/ApiBase.php

index 1c3da74..961d401 100644 (file)
@@ -1110,9 +1110,14 @@ abstract class ApiBase {
 
        /**
         * Output the error message related to a certain array
-        * @param $error array Element of a getUserPermissionsErrors()-style array
+        * @param $error (array|string) Element of a getUserPermissionsErrors()-style array
         */
        public function dieUsageMsg( $error ) {
+               # most of the time we send a 1 element, so we might as well send it as
+               # a string and make this an array here.
+               if( is_string( $error ) ) {
+                       $error = array( $error );
+               }
                $parsed = $this->parseMsg( $error );
                $this->dieUsage( $parsed['info'], $parsed['code'] );
        }