2011-04-23 11:44:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ConfirmEditHooks {
|
2011-04-24 11:41:49 +00:00
|
|
|
/**
|
|
|
|
* Get the global Captcha instance
|
|
|
|
*
|
2014-02-18 02:13:12 +00:00
|
|
|
* @return SimpleCaptcha
|
2011-04-24 11:41:49 +00:00
|
|
|
*/
|
2011-04-23 11:44:47 +00:00
|
|
|
static function getInstance() {
|
|
|
|
global $wgCaptcha, $wgCaptchaClass;
|
2012-01-12 08:58:40 +00:00
|
|
|
|
2011-04-23 11:44:47 +00:00
|
|
|
static $done = false;
|
2012-01-12 08:58:40 +00:00
|
|
|
|
2011-04-23 11:44:47 +00:00
|
|
|
if ( !$done ) {
|
|
|
|
$done = true;
|
|
|
|
$wgCaptcha = new $wgCaptchaClass;
|
|
|
|
}
|
2012-01-12 08:58:40 +00:00
|
|
|
|
2011-04-23 11:44:47 +00:00
|
|
|
return $wgCaptcha;
|
|
|
|
}
|
|
|
|
|
Use the shared parse on API edit
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
2014-12-05 04:48:13 +00:00
|
|
|
static function confirmEditMerged( $context, $content, $status, $summary, $user, $minorEdit ) {
|
|
|
|
return self::getInstance()->confirmEditMerged( $context, $content, $status, $summary,
|
|
|
|
$user, $minorEdit );
|
2011-04-23 11:44:47 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 14:33:05 +00:00
|
|
|
static function confirmEditPage( $editpage, $buttons, $tabindex ) {
|
|
|
|
self::getInstance()->editShowCaptcha( $editpage );
|
|
|
|
}
|
|
|
|
|
2011-04-23 11:44:47 +00:00
|
|
|
static function confirmEditAPI( $editPage, $newtext, &$resultArr ) {
|
|
|
|
return self::getInstance()->confirmEditAPI( $editPage, $newtext, $resultArr );
|
|
|
|
}
|
Use the shared parse on API edit
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
2014-12-05 04:48:13 +00:00
|
|
|
|
|
|
|
static function showEditFormFields( &$editPage, &$out ) {
|
|
|
|
return self::getInstance()->showEditFormFields( $editPage, $out );
|
|
|
|
}
|
2014-01-10 23:16:34 +00:00
|
|
|
|
|
|
|
static function addNewAccountApiForm( $apiModule, $loginForm ) {
|
|
|
|
return self::getInstance()->addNewAccountApiForm( $apiModule, $loginForm );
|
|
|
|
}
|
2014-05-30 14:33:05 +00:00
|
|
|
|
2014-01-10 23:16:34 +00:00
|
|
|
static function addNewAccountApiResult( $apiModule, $loginPage, &$result ) {
|
|
|
|
return self::getInstance()->addNewAccountApiResult( $apiModule, $loginPage, $result );
|
|
|
|
}
|
2011-04-23 11:44:47 +00:00
|
|
|
|
|
|
|
static function injectUserCreate( &$template ) {
|
|
|
|
return self::getInstance()->injectUserCreate( $template );
|
|
|
|
}
|
|
|
|
|
2014-01-17 20:56:56 +00:00
|
|
|
static function confirmUserCreate( $u, &$message, &$status = null ) {
|
|
|
|
return self::getInstance()->confirmUserCreate( $u, $message, $status );
|
2011-04-23 11:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2011-11-23 19:09:57 +00:00
|
|
|
|
2013-03-16 15:42:51 +00:00
|
|
|
// Default $flags to 1 for backwards-compatible behavior
|
|
|
|
public static function APIGetAllowedParams( &$module, &$params, $flags = 1 ) {
|
|
|
|
return self::getInstance()->APIGetAllowedParams( $module, $params, $flags );
|
2011-11-23 19:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function APIGetParamDescription( &$module, &$desc ) {
|
|
|
|
return self::getInstance()->APIGetParamDescription( $module, $desc );
|
|
|
|
}
|
2014-12-30 19:15:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook to add PHPUnit test cases.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList
|
|
|
|
*
|
|
|
|
* @param array &$files
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function onUnitTestsList( array &$files ) {
|
|
|
|
// @codeCoverageIgnoreStart
|
|
|
|
$directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var SplFileInfo $fileInfo
|
|
|
|
*/
|
|
|
|
$ourFiles = array();
|
|
|
|
foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
|
|
|
|
if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
|
|
|
|
$ourFiles[] = $fileInfo->getPathname();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$files = array_merge( $files, $ourFiles );
|
|
|
|
return true;
|
|
|
|
// @codeCoverageIgnoreEnd
|
|
|
|
}
|
2011-04-23 11:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class CaptchaSpecialPage extends UnlistedSpecialPage {
|
2012-01-12 08:58:40 +00:00
|
|
|
public function __construct() {
|
2011-04-23 11:44:47 +00:00
|
|
|
parent::__construct( 'Captcha' );
|
|
|
|
}
|
2012-01-12 08:58:40 +00:00
|
|
|
|
2011-04-23 11:44:47 +00:00
|
|
|
function execute( $par ) {
|
|
|
|
$this->setHeaders();
|
2012-01-12 08:58:40 +00:00
|
|
|
|
2011-04-23 11:44:47 +00:00
|
|
|
$instance = ConfirmEditHooks::getInstance();
|
2012-01-12 08:58:40 +00:00
|
|
|
|
2011-04-23 11:44:47 +00:00
|
|
|
switch( $par ) {
|
2012-01-12 08:58:40 +00:00
|
|
|
case "image":
|
|
|
|
if ( method_exists( $instance, 'showImage' ) ) {
|
|
|
|
return $instance->showImage();
|
|
|
|
}
|
|
|
|
case "help":
|
|
|
|
default:
|
|
|
|
return $instance->showHelp();
|
2011-04-23 11:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|