Fixes for the phan upgrade, part 1

Mainly, document some parameters as non-empty-array so that phan knows
the list of arguments won't be empty when unpacking.

In EditPage, account for hooks potentially unsetting the copyright
notice.

Also rewrite some code in LogPager, so it's hopefully easier for phan to
understand what's going on.

Change-Id: Ic0638571554424098d0743db32dd46723a08e103
This commit is contained in:
Daimona Eaytoy 2022-10-08 14:15:06 +02:00
parent 5faf4d2b5e
commit 350e9b88c1
11 changed files with 26 additions and 6 deletions

View file

@ -4096,6 +4096,9 @@ class EditPage implements IEditObject {
$title = Title::castFromPageReference( $page );
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable $title is not null because $page isn't
Hooks::runner()->onEditPageCopyrightWarning( $title, $copywarnMsg );
if ( !$copywarnMsg ) {
return '';
}
$msg = $localizer->msg( ...$copywarnMsg )->page( $page );
return Html::rawElement( 'div', [ 'id' => 'editpage-copywarn' ], $msg->$format() );

View file

@ -3091,6 +3091,7 @@ class OutputPage extends ContextSource {
*
* @deprecated since 1.36. Use ::formatPermissionStatus instead
* @param array $errors Array of arrays returned by PermissionManager::getPermissionErrors
* @phan-param non-empty-array[] $errors
* @param string|null $action Action that was denied or null if unknown
* @return string The wikitext error-messages, formatted into a list.
*/

View file

@ -334,6 +334,7 @@ class PermissionManager {
* whose corresponding errors may be ignored.
*
* @return array[] Array of arrays of the arguments to wfMessage to explain permissions problems.
* @phan-return non-empty-array[]
*/
public function getPermissionErrors(
$action,

View file

@ -351,6 +351,7 @@ class Status extends StatusValue {
*
* @return array[] A list in which each entry is an array with a message key as its first element.
* The remaining array elements are the message parameters.
* @phan-return non-empty-array[]
* @deprecated since 1.25
*/
public function getErrorsArray() {
@ -362,6 +363,7 @@ class Status extends StatusValue {
*
* @return array[] A list in which each entry is an array with a message key as its first element.
* The remaining array elements are the message parameters.
* @phan-return non-empty-array[]
* @deprecated since 1.25
*/
public function getWarningsArray() {

View file

@ -1213,6 +1213,7 @@ abstract class ApiBase extends ContextSource {
*
* @since 1.25
* @param string|array|Message $msg
* @phan-param string|non-empty-array|Message $msg
* @param IContextSource $context
* @param array|null $params
* @return Message|null

View file

@ -102,14 +102,14 @@ class ButtonAuthenticationRequest extends AuthenticationRequest {
$data['label'] = new RawMessage( '$1', $data['name'] );
} elseif ( is_string( $data['label'] ) ) {
$data['label'] = new Message( $data['label'] );
} elseif ( is_array( $data['label'] ) ) {
} elseif ( is_array( $data['label'] ) && $data['label'] ) {
$data['label'] = Message::newFromKey( ...$data['label'] );
}
if ( !isset( $data['help'] ) ) {
$data['help'] = new RawMessage( '$1', $data['name'] );
} elseif ( is_string( $data['help'] ) ) {
$data['help'] = new Message( $data['help'] );
} elseif ( is_array( $data['help'] ) ) {
} elseif ( is_array( $data['help'] ) && $data['help'] ) {
$data['help'] = Message::newFromKey( ...$data['help'] );
}
$ret = new static( $data['name'], $data['label'], $data['help'] );

View file

@ -113,7 +113,9 @@ class ResetPasswordSecondaryAuthenticationProvider extends AbstractSecondaryAuth
);
}
/** @var PasswordAuthenticationRequest $req */
$req = AuthenticationRequest::getRequestByClass( $reqs, get_class( $needReq ) );
'@phan-var PasswordAuthenticationRequest $req';
if ( !$req || !array_key_exists( 'retype', $req->getFieldInfo() ) ) {
return AuthenticationResponse::newUI( $needReqs, $data->msg, 'warning' );
}

View file

@ -428,6 +428,7 @@ abstract class AbstractBlock implements Block {
* @return array A message array: either a list of strings, the first of which
* is the message key and the remaining ones the parameters, or an array with
* a single MessageSpecifier object.
* @phan-return non-empty-array
*/
public function getPermissionsError( IContextSource $context ) {
$message = MediaWikiServices::getInstance()

View file

@ -1308,6 +1308,7 @@ class DifferenceEngine extends ContextSource {
* @since 1.31
*
* @return string[]
* @phan-return non-empty-array<string>
* @throws MWException
*/
protected function getDiffBodyCacheKeyParams() {

View file

@ -214,6 +214,10 @@ class HTMLForm extends ContextSource {
protected $mCancelTarget;
protected $mSubmitCallback;
/**
* @var array[]
* @phan-var non-empty-array[]
*/
protected $mValidationErrorMessage;
protected $mPre = '';
@ -768,8 +772,9 @@ class HTMLForm extends ContextSource {
/**
* Set a message to display on a validation error.
*
* @param array $msg Array of valid inputs to wfMessage()
* @param array[] $msg Array of valid inputs to wfMessage()
* (so each entry must itself be an array of arguments)
* @phan-param non-empty-array[] $msg
*
* @return HTMLForm $this for chaining calls (since 1.20)
*/

View file

@ -292,11 +292,14 @@ class LogPager extends ReverseChronologicalPager {
$params = [ $name . $interwikiDelimiter ];
// @phan-suppress-next-next-line PhanPossiblyUndeclaredVariable $database is set when reached here
// @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal $database is set when reached here
foreach ( explode( '*', $database ) as $databasepart ) {
$databaseParts = explode( '*', $database );
$databasePartCount = count( $databaseParts );
foreach ( $databaseParts as $i => $databasepart ) {
$params[] = $databasepart;
$params[] = $db->anyString();
if ( $i < $databasePartCount - 1 ) {
$params[] = $db->anyString();
}
}
array_pop( $params ); // Get rid of the last % we added.
$this->mConds[] = 'log_title' . $db->buildLike( ...$params );
} elseif ( $pattern && !$this->getConfig()->get( MainConfigNames::MiserMode ) ) {
$this->mConds[] = 'log_title' . $db->buildLike( $page->getDBkey(), $db->anyString() );