Merge "Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage"

This commit is contained in:
jenkins-bot 2021-11-12 15:37:04 +00:00 committed by Gerrit Code Review
commit 99de268e3c
2 changed files with 23 additions and 10 deletions

View file

@ -21,7 +21,4 @@ $cfg['exclude_analysis_directory_list'] = array_merge(
]
);
// WikiPage->ConfirmEdit_ActivateCaptcha
$cfg['suppress_issue_types'][] = 'PhanUndeclaredProperty';
return $cfg;

View file

@ -1,6 +1,7 @@
<?php
use MediaWiki\Auth\AuthenticationRequest;
use MediaWiki\Cache\CacheKeyHelper;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionAccessException;
use MediaWiki\Revision\RevisionLookup;
@ -17,6 +18,9 @@ class SimpleCaptcha {
/** @var bool|null Was the CAPTCHA already passed and if yes, with which result? */
private $captchaSolved = null;
/** @var bool[] Activate captchas status list for a pages by key */
private $activatedCaptchas = [];
/**
* Used to select the right message.
* One of sendmail, createaccount, badlogin, edit, create, addurl.
@ -71,6 +75,14 @@ class SimpleCaptcha {
return [ 'question' => $test, 'answer' => $answer ];
}
/**
* Returns a list of activate captchas for a page by key.
* @return bool[]
*/
public function getActivatedCaptchas() {
return $this->activatedCaptchas;
}
/**
* @param array &$resultArr
*/
@ -231,12 +243,13 @@ class SimpleCaptcha {
public function showEditFormFields( EditPage $editPage, OutputPage $out ) {
$out->enableOOUI();
$page = $editPage->getArticle()->getPage();
if ( !isset( $page->ConfirmEdit_ActivateCaptcha ) ) {
$key = $key = CacheKeyHelper::getKeyForPage( $page );
if ( !isset( $this->activatedCaptchas[$key] ) ) {
return;
}
if ( $this->action !== 'edit' ) {
unset( $page->ConfirmEdit_ActivateCaptcha );
unset( $this->activatedCaptchas[$key] );
$out->addHTML( $this->getMessage( $this->action )->parseAsBlock() );
$this->addFormToOutput( $out );
}
@ -250,13 +263,14 @@ class SimpleCaptcha {
$context = $editPage->getArticle()->getContext();
$page = $editPage->getArticle()->getPage();
$out = $context->getOutput();
if ( isset( $page->ConfirmEdit_ActivateCaptcha ) ||
$key = CacheKeyHelper::getKeyForPage( $page );
if ( isset( $this->activatedCaptchas[$key] ) ||
$this->shouldCheck( $page, '', '', $context )
) {
$out->addHTML( $this->getMessage( $this->action )->parseAsBlock() );
$this->addFormToOutput( $out );
}
unset( $page->ConfirmEdit_ActivateCaptcha );
unset( $this->activatedCaptchas[$key] );
}
/**
@ -851,7 +865,8 @@ class SimpleCaptcha {
* @return bool
*/
public function confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit ) {
if ( !$context->canUseWikiPage() ) {
$title = $context->getTitle();
if ( !( $title->canExist() ) ) {
// we check WikiPage only
// try to get an appropriate title for this page
$title = $context->getTitle();
@ -867,7 +882,7 @@ class SimpleCaptcha {
wfDebug( __METHOD__ . ': Skipped ConfirmEdit check: No WikiPage for title ' . $title );
return true;
}
$page = $context->getWikiPage();
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
if ( !$this->doConfirmEdit( $page, $content, '', $context, $user ) ) {
$status->value = EditPage::AS_HOOK_ERROR_EXPECTED;
$status->apiHookResult = [];
@ -878,7 +893,8 @@ class SimpleCaptcha {
$status->fatal( 'captcha-edit-fail' );
}
$this->addCaptchaAPI( $status->apiHookResult );
$page->ConfirmEdit_ActivateCaptcha = true;
$key = CacheKeyHelper::getKeyForPage( $page );
$this->activatedCaptchas[$key] = true;
return false;
}
return true;