mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-24 00:04:15 +00:00
40c7e9c9aa
ConfirmEdit was tripling the API save time, because it was parsing the entire content twice to evaluate whether the addurl trigger is hit. While I was here, I stopped using the deprecated non-Content hooks. The new hook, EditEditFilterMergedContent, does not pass an EditPage object, which means that Title or WikiPage objects need to be passed around instead. Also, since EditPage::showEditForm() cannot be called with no EditPage object, use a EditPage::showEditForm:fields hook instead. If non-wikitext content is edited, assume that the regex trigger is not hit. For further architectural details, see the associated core change: I4b4270dd868a . MW_EDITFILTERMERGED_SUPPORTS_API is a constant introduced to detect the presence of the associated core change. Also, in APIGetAllowedParams, set the allowed parameters even if we are not on the help screen. This allows API users to submit their CAPTCHA answer without it failing with an "unrecognized parameter" error. Compatibility with MediaWiki 1.21 is retained, compatibility before that is dropped. Change-Id: I9529b7e8d3fc9301c754b28fda185aa3ab36f13e
102 lines
2.8 KiB
PHP
102 lines
2.8 KiB
PHP
<?php
|
|
|
|
class ConfirmEditHooks {
|
|
/**
|
|
* Get the global Captcha instance
|
|
*
|
|
* @return SimpleCaptcha
|
|
*/
|
|
static function getInstance() {
|
|
global $wgCaptcha, $wgCaptchaClass;
|
|
|
|
static $done = false;
|
|
|
|
if ( !$done ) {
|
|
$done = true;
|
|
$wgCaptcha = new $wgCaptchaClass;
|
|
}
|
|
|
|
return $wgCaptcha;
|
|
}
|
|
|
|
static function confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit ) {
|
|
return self::getInstance()->confirmEditMerged( $context, $content, $status, $summary,
|
|
$user, $minorEdit );
|
|
}
|
|
|
|
static function confirmEditAPI( $editPage, $newtext, &$resultArr ) {
|
|
return self::getInstance()->confirmEditAPI( $editPage, $newtext, $resultArr );
|
|
}
|
|
|
|
static function showEditFormFields( &$editPage, &$out ) {
|
|
return self::getInstance()->showEditFormFields( $editPage, $out );
|
|
}
|
|
|
|
static function addNewAccountApiForm( $apiModule, $loginForm ) {
|
|
return self::getInstance()->addNewAccountApiForm( $apiModule, $loginForm );
|
|
}
|
|
|
|
static function addNewAccountApiResult( $apiModule, $loginPage, &$result ) {
|
|
return self::getInstance()->addNewAccountApiResult( $apiModule, $loginPage, $result );
|
|
}
|
|
|
|
static function injectUserCreate( &$template ) {
|
|
return self::getInstance()->injectUserCreate( $template );
|
|
}
|
|
|
|
static function confirmUserCreate( $u, &$message, &$status = null ) {
|
|
return self::getInstance()->confirmUserCreate( $u, $message, $status );
|
|
}
|
|
|
|
static function triggerUserLogin( $user, $password, $retval ) {
|
|
return self::getInstance()->triggerUserLogin( $user, $password, $retval );
|
|
}
|
|
|
|
static function injectUserLogin( &$template ) {
|
|
return self::getInstance()->injectUserLogin( $template );
|
|
}
|
|
|
|
static function confirmUserLogin( $u, $pass, &$retval ) {
|
|
return self::getInstance()->confirmUserLogin( $u, $pass, $retval );
|
|
}
|
|
|
|
static function injectEmailUser( &$form ) {
|
|
return self::getInstance()->injectEmailUser( $form );
|
|
}
|
|
|
|
static function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
|
|
return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error );
|
|
}
|
|
|
|
// Default $flags to 1 for backwards-compatible behavior
|
|
public static function APIGetAllowedParams( &$module, &$params, $flags = 1 ) {
|
|
return self::getInstance()->APIGetAllowedParams( $module, $params, $flags );
|
|
}
|
|
|
|
public static function APIGetParamDescription( &$module, &$desc ) {
|
|
return self::getInstance()->APIGetParamDescription( $module, $desc );
|
|
}
|
|
}
|
|
|
|
class CaptchaSpecialPage extends UnlistedSpecialPage {
|
|
public function __construct() {
|
|
parent::__construct( 'Captcha' );
|
|
}
|
|
|
|
function execute( $par ) {
|
|
$this->setHeaders();
|
|
|
|
$instance = ConfirmEditHooks::getInstance();
|
|
|
|
switch( $par ) {
|
|
case "image":
|
|
if ( method_exists( $instance, 'showImage' ) ) {
|
|
return $instance->showImage();
|
|
}
|
|
case "help":
|
|
default:
|
|
return $instance->showHelp();
|
|
}
|
|
}
|
|
}
|