mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-27 17:40:11 +00:00
Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage
Use CacheKeyHelper to collect status of captchas that was activated instead of set random properties on page object. Bug: T275710 Change-Id: I7942ccd6b58584f436f872bf7c9deb63ab84482a
This commit is contained in:
parent
dc405747ad
commit
87c1b07038
|
@ -21,7 +21,4 @@ $cfg['exclude_analysis_directory_list'] = array_merge(
|
|||
]
|
||||
);
|
||||
|
||||
// WikiPage->ConfirmEdit_ActivateCaptcha
|
||||
$cfg['suppress_issue_types'][] = 'PhanUndeclaredProperty';
|
||||
|
||||
return $cfg;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue