* so that a lack of error-handling will be explicit.
*/
class Status extends StatusValue {
- /** @var callable */
+ /** @var callable|false */
public $cleanCallback = false;
/**
function __get( $name ) {
if ( $name === 'ok' ) {
return $this->isOK();
- } elseif ( $name === 'errors' ) {
+ }
+ if ( $name === 'errors' ) {
return $this->getErrors();
}
* the error messages, and one that contains the warnings, only. The returned array is
* defined as:
* [
- * 0 => object(Status) # the Status with error messages, only
+ * 0 => object(Status) # The Status with error messages, only
* 1 => object(Status) # The Status with warning messages, only
* ]
*
}
/**
- * @param string|Language|null $lang Language to use for processing
+ * @param string|Language|null|StubUserLang $lang Language to use for processing
* messages, or null to default to the user language.
- * @return Language
+ * @return Language|StubUserLang
*/
protected function languageFromParam( $lang ) {
- global $wgLang;
-
if ( $lang === null ) {
- // @todo: Use RequestContext::getMain()->getLanguage() instead
- return $wgLang;
- } elseif ( $lang instanceof Language || $lang instanceof StubUserLang ) {
+ return RequestContext::getMain()->getLanguage();
+ }
+ if ( $lang instanceof Language || $lang instanceof StubUserLang ) {
return $lang;
- } else {
- return Language::factory( $lang );
}
+ return Language::factory( $lang );
}
/**
* @param string|bool $shortContext A short enclosing context message name, to
* be used when there is a single error
* @param string|bool $longContext A long enclosing context message name, for a list
- * @param string|Language|null $lang Language to use for processing messages
+ * @param string|Language|null|StubUserLang $lang Language to use for processing messages
* @return string
*/
public function getWikiText( $shortContext = false, $longContext = false, $lang = null ) {
$lang = $this->languageFromParam( $lang );
$rawErrors = $this->getErrors();
- if ( count( $rawErrors ) == 0 ) {
+ if ( count( $rawErrors ) === 0 ) {
if ( $this->isOK() ) {
$this->fatal( 'internalerror_info',
__METHOD__ . " called for a good result, this is incorrect\n" );
}
$rawErrors = $this->getErrors(); // just added a fatal
}
- if ( count( $rawErrors ) == 1 ) {
+ if ( count( $rawErrors ) === 1 ) {
$s = $this->getErrorMessage( $rawErrors[0], $lang )->plain();
if ( $shortContext ) {
$s = wfMessage( $shortContext, $s )->inLanguage( $lang )->plain();
$lang = $this->languageFromParam( $lang );
$rawErrors = $this->getErrors();
- if ( count( $rawErrors ) == 0 ) {
+ if ( count( $rawErrors ) === 0 ) {
if ( $this->isOK() ) {
$this->fatal( 'internalerror_info',
__METHOD__ . " called for a good result, this is incorrect\n" );
}
$rawErrors = $this->getErrors(); // just added a fatal
}
- if ( count( $rawErrors ) == 1 ) {
+ if ( count( $rawErrors ) === 1 ) {
$s = $this->getErrorMessage( $rawErrors[0], $lang );
if ( $shortContext ) {
$s = wfMessage( $shortContext, $s )->inLanguage( $lang );
} elseif ( is_string( $error ) ) {
$msg = wfMessage( $error );
} else {
- throw new UnexpectedValueException( "Got " . get_class( $error ) . " for key." );
+ throw new UnexpectedValueException( 'Got ' . get_class( $error ) . ' for key.' );
}
$msg->inLanguage( $this->languageFromParam( $lang ) );