mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-24 00:04:15 +00:00
build: Updating mediawiki/mediawiki-codesniffer to 0.7.1
Also added "composer fix" command. Change-Id: Ibda3fd002c577c7f7c41920d67ec44fedbd27cb8
This commit is contained in:
parent
86f8e7647a
commit
9ea898ba2a
|
@ -12,7 +12,7 @@ class ApiFancyCaptchaReload extends ApiBase {
|
|||
$captchaIndex = $captcha->getCaptchaIndex();
|
||||
|
||||
$result = $this->getResult();
|
||||
$result->addValue( null, $this->getModuleName(), array( 'index' => $captchaIndex ) );
|
||||
$result->addValue( null, $this->getModuleName(), [ 'index' => $captchaIndex ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,23 +24,23 @@ class ApiFancyCaptchaReload extends ApiBase {
|
|||
}
|
||||
|
||||
public function getAllowedParams() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since MediaWiki core 1.25
|
||||
*/
|
||||
public function getExamples() {
|
||||
return array( 'api.php?action=fancycaptchareload&format=xml' );
|
||||
return [ 'api.php?action=fancycaptchareload&format=xml' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ApiBase::getExamplesMessages()
|
||||
*/
|
||||
protected function getExamplesMessages() {
|
||||
return array(
|
||||
return [
|
||||
'action=fancycaptchareload'
|
||||
=> 'apihelp-fancycaptchareload-example-1',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
} else {
|
||||
static $backend = null;
|
||||
if ( !$backend ) {
|
||||
$backend = new FSFileBackend( array(
|
||||
$backend = new FSFileBackend( [
|
||||
'name' => 'captcha-backend',
|
||||
'wikiId' => wfWikiId(),
|
||||
'lockManager' => new NullLockManager( array() ),
|
||||
'containerPaths' => array( 'captcha-render' => $wgCaptchaDirectory ),
|
||||
'lockManager' => new NullLockManager( [] ),
|
||||
'containerPaths' => [ 'captcha-render' => $wgCaptchaDirectory ],
|
||||
'fileMode' => 777
|
||||
) );
|
||||
] );
|
||||
}
|
||||
return $backend;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
}
|
||||
|
||||
$count = 0;
|
||||
foreach ( $this->getBackend()->getFileList( array( 'dir' => $sampleDir ) ) as $file ) {
|
||||
foreach ( $this->getBackend()->getFileList( [ 'dir' => $sampleDir ] ) as $file ) {
|
||||
++$count;
|
||||
}
|
||||
|
||||
|
@ -105,9 +105,9 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
|
||||
$captchaReload = Html::element(
|
||||
'small',
|
||||
array(
|
||||
[
|
||||
'class' => 'confirmedit-captcha-reload fancycaptcha-reload'
|
||||
),
|
||||
],
|
||||
wfMessage( 'fancycaptcha-reload-text' )->text()
|
||||
);
|
||||
} else {
|
||||
|
@ -115,21 +115,21 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
}
|
||||
|
||||
$form = Html::openElement( 'div' ) .
|
||||
Html::element( 'label', array(
|
||||
Html::element( 'label', [
|
||||
'for' => 'wpCaptchaWord',
|
||||
),
|
||||
],
|
||||
parent::getMessage( 'label' ) . ' ' . wfMessage( 'fancycaptcha-captcha' )->text()
|
||||
) .
|
||||
Html::openElement( 'div', array( 'class' => 'fancycaptcha-captcha-container' ) ) .
|
||||
Html::openElement( 'div', array( 'class' => 'fancycaptcha-captcha-and-reload' ) ) .
|
||||
Html::openElement( 'div', array( 'class' => 'fancycaptcha-image-container' ) ) .
|
||||
Html::element( 'img', array(
|
||||
Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-container' ] ) .
|
||||
Html::openElement( 'div', [ 'class' => 'fancycaptcha-captcha-and-reload' ] ) .
|
||||
Html::openElement( 'div', [ 'class' => 'fancycaptcha-image-container' ] ) .
|
||||
Html::element( 'img', [
|
||||
'class' => 'fancycaptcha-image',
|
||||
'src' => $title->getLocalUrl( 'wpCaptchaId=' . urlencode( $index ) ),
|
||||
'alt' => ''
|
||||
)
|
||||
]
|
||||
) . $captchaReload . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n" .
|
||||
Html::element( 'input', array(
|
||||
Html::element( 'input', [
|
||||
'name' => 'wpCaptchaWord',
|
||||
'class' => 'mw-ui-input',
|
||||
'id' => 'wpCaptchaWord',
|
||||
|
@ -141,21 +141,21 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
'required' => 'required',
|
||||
'tabindex' => $tabIndex,
|
||||
'placeholder' => wfMessage( 'fancycaptcha-imgcaptcha-ph' )
|
||||
)
|
||||
]
|
||||
); // tab in before the edit textarea
|
||||
if ( $this->action == 'usercreate' ) {
|
||||
// use raw element, because the message can contain links or some other html
|
||||
$form .= Html::rawElement( 'small', array(
|
||||
$form .= Html::rawElement( 'small', [
|
||||
'class' => 'mw-createacct-captcha-assisted'
|
||||
), wfMessage( 'createacct-imgcaptcha-help' )->parse()
|
||||
], wfMessage( 'createacct-imgcaptcha-help' )->parse()
|
||||
);
|
||||
}
|
||||
$form .= Html::element( 'input', array(
|
||||
$form .= Html::element( 'input', [
|
||||
'type' => 'hidden',
|
||||
'name' => 'wpCaptchaId',
|
||||
'id' => 'wpCaptchaId',
|
||||
'value' => $index
|
||||
)
|
||||
]
|
||||
) . Html::closeElement( 'div' ) . Html::closeElement( 'div' ) . "\n";
|
||||
|
||||
return $form;
|
||||
|
@ -209,8 +209,8 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
$key = "fancycaptcha:dirlist:{$backend->getWikiId()}:" . sha1( $directory );
|
||||
$dirs = $wgMemc->get( $key ); // check cache
|
||||
if ( !is_array( $dirs ) || !count( $dirs ) ) { // cache miss
|
||||
$dirs = array(); // subdirs actually present...
|
||||
foreach ( $backend->getTopDirectoryList( array( 'dir' => $directory ) ) as $entry ) {
|
||||
$dirs = []; // subdirs actually present...
|
||||
foreach ( $backend->getTopDirectoryList( [ 'dir' => $directory ] ) as $entry ) {
|
||||
if ( ctype_xdigit( $entry ) && strlen( $entry ) == 1 ) {
|
||||
$dirs[] = $entry;
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
|
||||
if ( !count( $dirs ) ) {
|
||||
// Remove this directory if empty so callers don't keep looking here
|
||||
$backend->clean( array( 'dir' => $directory ) );
|
||||
$backend->clean( [ 'dir' => $directory ] );
|
||||
return false; // none found
|
||||
}
|
||||
|
||||
|
@ -257,8 +257,8 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
$key = "fancycaptcha:filelist:{$backend->getWikiId()}:" . sha1( $directory );
|
||||
$files = $wgMemc->get( $key ); // check cache
|
||||
if ( !is_array( $files ) || !count( $files ) ) { // cache miss
|
||||
$files = array(); // captcha files
|
||||
foreach ( $backend->getTopFileList( array( 'dir' => $directory ) ) as $entry ) {
|
||||
$files = []; // captcha files
|
||||
foreach ( $backend->getTopFileList( [ 'dir' => $directory ] ) as $entry ) {
|
||||
$files[] = $entry;
|
||||
if ( count( $files ) >= 500 ) { // sanity
|
||||
wfDebug( 'Skipping some captchas; $wgCaptchaDirectoryLevels set too low?.' );
|
||||
|
@ -273,7 +273,7 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
|
||||
if ( !count( $files ) ) {
|
||||
// Remove this directory if empty so callers don't keep looking here
|
||||
$backend->clean( array( 'dir' => $directory ) );
|
||||
$backend->clean( [ 'dir' => $directory ] );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -313,17 +313,17 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
continue; // could not acquire (skip it to avoid race conditions)
|
||||
}
|
||||
}
|
||||
if ( !$backend->fileExists( array( 'src' => "$directory/$entry" ) ) ) {
|
||||
if ( !$backend->fileExists( [ 'src' => "$directory/$entry" ] ) ) {
|
||||
if ( ++$misses >= 5 ) { // too many files in the listing don't exist
|
||||
break; // listing cache too stale? break out so it will be cleared
|
||||
}
|
||||
continue; // try next file
|
||||
}
|
||||
return array(
|
||||
return [
|
||||
'salt' => $matches[1],
|
||||
'hash' => $matches[2],
|
||||
'viewed' => false,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,10 +344,10 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
$salt = $info['salt'];
|
||||
$hash = $info['hash'];
|
||||
|
||||
return $this->getBackend()->streamFile( array(
|
||||
return $this->getBackend()->streamFile( [
|
||||
'src' => $this->imagePath( $salt, $hash ),
|
||||
'headers' => array( "Cache-Control: private, s-maxage=0, max-age=3600" )
|
||||
) )->isOK();
|
||||
'headers' => [ "Cache-Control: private, s-maxage=0, max-age=3600" ]
|
||||
] )->isOK();
|
||||
}
|
||||
|
||||
wfHttpError( 400, 'Request Error', 'Requested bogus captcha image' );
|
||||
|
@ -378,7 +378,7 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
*/
|
||||
public function hashFromImageName( $basename ) {
|
||||
if ( preg_match( '/^image_([0-9a-f]+)_([0-9a-f]+)\\.png$/', $basename, $matches ) ) {
|
||||
return array( $matches[1], $matches[2] );
|
||||
return [ $matches[1], $matches[2] ];
|
||||
} else {
|
||||
throw new Exception( "Invalid filename '$basename'.\n" );
|
||||
}
|
||||
|
@ -410,9 +410,9 @@ class FancyCaptcha extends SimpleCaptcha {
|
|||
$pass = parent::passCaptcha();
|
||||
|
||||
if ( $pass && $wgCaptchaDeleteOnSolve ) {
|
||||
$this->getBackend()->quickDelete( array(
|
||||
$this->getBackend()->quickDelete( [
|
||||
'src' => $this->imagePath( $info['salt'], $info['hash'] )
|
||||
) );
|
||||
] );
|
||||
}
|
||||
|
||||
return $pass;
|
||||
|
|
|
@ -9,7 +9,7 @@ class MathCaptcha extends SimpleCaptcha {
|
|||
|
||||
function addCaptchaAPI( &$resultArr ) {
|
||||
list( $sum, $answer ) = $this->pickSum();
|
||||
$index = $this->storeCaptcha( array( 'answer' => $answer ) );
|
||||
$index = $this->storeCaptcha( [ 'answer' => $answer ] );
|
||||
$resultArr['captcha']['type'] = 'math';
|
||||
$resultArr['captcha']['mime'] = 'text/tex';
|
||||
$resultArr['captcha']['id'] = $index;
|
||||
|
@ -22,18 +22,18 @@ class MathCaptcha extends SimpleCaptcha {
|
|||
*/
|
||||
function getForm( OutputPage $out, $tabIndex = 1 ) {
|
||||
list( $sum, $answer ) = $this->pickSum();
|
||||
$index = $this->storeCaptcha( array( 'answer' => $answer ) );
|
||||
$index = $this->storeCaptcha( [ 'answer' => $answer ] );
|
||||
|
||||
$form = '<table><tr><td>' . $this->fetchMath( $sum ) . '</td>';
|
||||
$form .= '<td>' . Html::input(
|
||||
'wpCaptchaWord',
|
||||
false,
|
||||
false,
|
||||
array(
|
||||
[
|
||||
'tabindex' => $tabIndex,
|
||||
'autocomplete' => 'off',
|
||||
'required'
|
||||
)
|
||||
]
|
||||
) . '</td></tr></table>';
|
||||
$form .= Html::hidden( 'wpCaptchaId', $index );
|
||||
return $form;
|
||||
|
@ -46,13 +46,13 @@ class MathCaptcha extends SimpleCaptcha {
|
|||
$op = mt_rand( 0, 1 ) ? '+' : '-';
|
||||
$sum = "{$a} {$op} {$b} = ";
|
||||
$ans = $op == '+' ? ( $a + $b ) : ( $a - $b );
|
||||
return array( $sum, $ans );
|
||||
return [ $sum, $ans ];
|
||||
}
|
||||
|
||||
/** Fetch the math */
|
||||
function fetchMath( $sum ) {
|
||||
if ( class_exists( 'MathRenderer' ) ) {
|
||||
$math = MathRenderer::getRenderer( $sum, array(), MW_MATH_PNG );
|
||||
$math = MathRenderer::getRenderer( $sum, [], MW_MATH_PNG );
|
||||
} else {
|
||||
throw new Exception(
|
||||
'MathCaptcha requires the Math extension for MediaWiki versions 1.18 and above.'
|
||||
|
|
|
@ -38,7 +38,7 @@ class QuestyCaptcha extends SimpleCaptcha {
|
|||
|
||||
$question = array_rand( $wgCaptchaQuestions, 1 );
|
||||
$answer = $wgCaptchaQuestions[ $question ];
|
||||
return array( 'question' => $question, 'answer' => $answer );
|
||||
return [ 'question' => $question, 'answer' => $answer ];
|
||||
}
|
||||
|
||||
function getForm( OutputPage $out, $tabIndex = 1 ) {
|
||||
|
@ -50,19 +50,19 @@ class QuestyCaptcha extends SimpleCaptcha {
|
|||
}
|
||||
$index = $this->storeCaptcha( $captcha );
|
||||
return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> " .
|
||||
Html::element( 'input', array(
|
||||
Html::element( 'input', [
|
||||
'name' => 'wpCaptchaWord',
|
||||
'id' => 'wpCaptchaWord',
|
||||
'class' => 'mw-ui-input',
|
||||
'required',
|
||||
'autocomplete' => 'off',
|
||||
'tabindex' => $tabIndex ) ) . // tab in before the edit textarea
|
||||
'tabindex' => $tabIndex ] ) . // tab in before the edit textarea
|
||||
"</p>\n" .
|
||||
Xml::element( 'input', array(
|
||||
Xml::element( 'input', [
|
||||
'type' => 'hidden',
|
||||
'name' => 'wpCaptchaId',
|
||||
'id' => 'wpCaptchaId',
|
||||
'value' => $index ) );
|
||||
'value' => $index ] );
|
||||
}
|
||||
|
||||
function getMessage( $action ) {
|
||||
|
|
|
@ -14,7 +14,7 @@ class ReCaptcha extends SimpleCaptcha {
|
|||
|
||||
$useHttps = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' );
|
||||
$js = 'var RecaptchaOptions = ' . Xml::encodeJsVar(
|
||||
array( 'theme' => $wgReCaptchaTheme, 'tabindex' => $tabIndex )
|
||||
[ 'theme' => $wgReCaptchaTheme, 'tabindex' => $tabIndex ]
|
||||
);
|
||||
|
||||
return Html::inlineScript(
|
||||
|
@ -93,12 +93,12 @@ class ReCaptcha extends SimpleCaptcha {
|
|||
public function APIGetAllowedParams( &$module, &$params, $flags ) {
|
||||
if ( $flags && $this->isAPICaptchaModule( $module ) ) {
|
||||
if ( defined( 'ApiBase::PARAM_HELP_MSG' ) ) {
|
||||
$params['recaptcha_challenge_field'] = array(
|
||||
$params['recaptcha_challenge_field'] = [
|
||||
ApiBase::PARAM_HELP_MSG => 'recaptcha-apihelp-param-recaptcha_challenge_field',
|
||||
);
|
||||
$params['recaptcha_response_field'] = array(
|
||||
];
|
||||
$params['recaptcha_response_field'] = [
|
||||
ApiBase::PARAM_HELP_MSG => 'recaptcha-apihelp-param-recaptcha_response_field',
|
||||
);
|
||||
];
|
||||
} else {
|
||||
// @todo: Remove this branch when support for MediaWiki < 1.25 is dropped
|
||||
$params['recaptcha_challenge_field'] = null;
|
||||
|
|
|
@ -16,13 +16,13 @@ class ReCaptchaNoCaptcha extends SimpleCaptcha {
|
|||
'g-recaptchascript',
|
||||
"<script src=\"https://www.google.com/recaptcha/api.js?hl={$lang}\" async defer></script>"
|
||||
);
|
||||
$output = Html::element( 'div', array(
|
||||
'class' => array(
|
||||
$output = Html::element( 'div', [
|
||||
'class' => [
|
||||
'g-recaptcha',
|
||||
'mw-confirmedit-captcha-fail' => !!$this->error,
|
||||
),
|
||||
],
|
||||
'data-sitekey' => $wgReCaptchaSiteKey
|
||||
) );
|
||||
] );
|
||||
$htmlUrlencoded = htmlspecialchars( urlencode( $wgReCaptchaSiteKey ) );
|
||||
$output .= <<<HTML
|
||||
<noscript>
|
||||
|
@ -76,15 +76,15 @@ HTML;
|
|||
|
||||
$url = 'https://www.google.com/recaptcha/api/siteverify';
|
||||
// Build data to append to request
|
||||
$data = array(
|
||||
$data = [
|
||||
'secret' => $wgReCaptchaSecretKey,
|
||||
'response' => $wgRequest->getVal( 'g-recaptcha-response' ),
|
||||
);
|
||||
];
|
||||
if ( $wgReCaptchaSendRemoteIP ) {
|
||||
$data['remoteip'] = $wgRequest->getIP();
|
||||
}
|
||||
$url = wfAppendQuery( $url, $data );
|
||||
$request = MWHttpRequest::factory( $url, array( 'method' => 'GET' ) );
|
||||
$request = MWHttpRequest::factory( $url, [ 'method' => 'GET' ] );
|
||||
$status = $request->execute();
|
||||
if ( !$status->isOK() ) {
|
||||
$this->error = 'http';
|
||||
|
@ -136,9 +136,9 @@ HTML;
|
|||
public function APIGetAllowedParams( &$module, &$params, $flags ) {
|
||||
if ( $flags && $this->isAPICaptchaModule( $module ) ) {
|
||||
if ( defined( 'ApiBase::PARAM_HELP_MSG' ) ) {
|
||||
$params['g-recaptcha-response'] = array(
|
||||
$params['g-recaptcha-response'] = [
|
||||
ApiBase::PARAM_HELP_MSG => 'renocaptcha-apihelp-param-g-recaptcha-response',
|
||||
);
|
||||
];
|
||||
} else {
|
||||
// @todo: Remove this branch when support for MediaWiki < 1.25 is dropped
|
||||
$params['g-recaptcha-response'] = null;
|
||||
|
|
|
@ -18,7 +18,7 @@ class SimpleCaptcha {
|
|||
// directionality.
|
||||
$test = "$a$op$b";
|
||||
$answer = ( $op == '+' ) ? ( $a + $b ) : ( $a - $b );
|
||||
return array( 'question' => $test, 'answer' => $answer );
|
||||
return [ 'question' => $test, 'answer' => $answer ];
|
||||
}
|
||||
|
||||
function addCaptchaAPI( &$resultArr ) {
|
||||
|
@ -44,19 +44,19 @@ class SimpleCaptcha {
|
|||
$index = $this->storeCaptcha( $captcha );
|
||||
|
||||
return "<p><label for=\"wpCaptchaWord\">{$captcha['question']} = </label>" .
|
||||
Xml::element( 'input', array(
|
||||
Xml::element( 'input', [
|
||||
'name' => 'wpCaptchaWord',
|
||||
'class' => 'mw-ui-input',
|
||||
'id' => 'wpCaptchaWord',
|
||||
'size' => 5,
|
||||
'autocomplete' => 'off',
|
||||
'tabindex' => $tabIndex ) ) . // tab in before the edit textarea
|
||||
'tabindex' => $tabIndex ] ) . // tab in before the edit textarea
|
||||
"</p>\n" .
|
||||
Xml::element( 'input', array(
|
||||
Xml::element( 'input', [
|
||||
'type' => 'hidden',
|
||||
'name' => 'wpCaptchaId',
|
||||
'id' => 'wpCaptchaId',
|
||||
'value' => $index ) );
|
||||
'value' => $index ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,10 +146,10 @@ class SimpleCaptcha {
|
|||
wfDebug( "ConfirmEdit: user group allows skipping captcha on account creation\n" );
|
||||
return true;
|
||||
}
|
||||
LoggerFactory::getInstance( 'authmanager' )->info( 'Captcha shown on account creation', array(
|
||||
LoggerFactory::getInstance( 'authmanager' )->info( 'Captcha shown on account creation', [
|
||||
'event' => 'captcha.display',
|
||||
'type' => 'accountcreation',
|
||||
) );
|
||||
] );
|
||||
$captcha = "<div class='captcha'>" .
|
||||
$wgOut->parse( $this->getMessage( 'createaccount' ) ) .
|
||||
// FIXME: Hardcoded tab index
|
||||
|
@ -161,7 +161,7 @@ class SimpleCaptcha {
|
|||
$this->getForm( $wgOut, 8 ) .
|
||||
"</div>\n";
|
||||
// for older MediaWiki versions
|
||||
if ( is_callable( array( $template, 'extend' ) ) ) {
|
||||
if ( is_callable( [ $template, 'extend' ] ) ) {
|
||||
$template->extend( 'extrafields', $captcha );
|
||||
} else {
|
||||
$template->set( 'header', $captcha );
|
||||
|
@ -191,19 +191,19 @@ class SimpleCaptcha {
|
|||
if ( $perIPTriggered || $perUserTriggered ) {
|
||||
global $wgOut;
|
||||
|
||||
LoggerFactory::getInstance( 'authmanager' )->info( 'Captcha shown on login', array(
|
||||
LoggerFactory::getInstance( 'authmanager' )->info( 'Captcha shown on login', [
|
||||
'event' => 'captcha.display',
|
||||
'type' => 'login',
|
||||
'perIp' => $perIPTriggered,
|
||||
'perUser' => $perUserTriggered
|
||||
) );
|
||||
] );
|
||||
$this->action = 'badlogin';
|
||||
$captcha = "<div class='captcha'>" .
|
||||
$wgOut->parse( $this->getMessage( 'badlogin' ) ) .
|
||||
$this->getForm( $wgOut ) .
|
||||
"</div>\n";
|
||||
// for older MediaWiki versions
|
||||
if ( is_callable( array( $template, 'extend' ) ) ) {
|
||||
if ( is_callable( [ $template, 'extend' ] ) ) {
|
||||
$template->extend( 'extrafields', $captcha );
|
||||
} else {
|
||||
$template->set( 'header', $captcha );
|
||||
|
@ -355,7 +355,7 @@ class SimpleCaptcha {
|
|||
$ips = array_map( 'trim', $input );
|
||||
$ips = array_filter( $ips );
|
||||
|
||||
$validIPs = array();
|
||||
$validIPs = [];
|
||||
foreach ( $ips as $ip ) {
|
||||
if ( IP::isIPAddress( $ip ) ) {
|
||||
$validIPs[] = $ip;
|
||||
|
@ -386,7 +386,6 @@ class SimpleCaptcha {
|
|||
return wfGlobalCacheKey( 'captcha', 'badlogin', 'user', md5( $username ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the submitted form matches the captcha session data provided
|
||||
* by the plugin when the form was generated.
|
||||
|
@ -411,8 +410,9 @@ class SimpleCaptcha {
|
|||
function captchaTriggers( $title, $action ) {
|
||||
global $wgCaptchaTriggers, $wgCaptchaTriggersOnNamespace;
|
||||
// Special config for this NS?
|
||||
if ( isset( $wgCaptchaTriggersOnNamespace[$title->getNamespace()][$action] ) )
|
||||
if ( isset( $wgCaptchaTriggersOnNamespace[$title->getNamespace()][$action] ) ) {
|
||||
return $wgCaptchaTriggersOnNamespace[$title->getNamespace()][$action];
|
||||
}
|
||||
|
||||
return ( !empty( $wgCaptchaTriggers[$action] ) ); // Default
|
||||
}
|
||||
|
@ -504,7 +504,7 @@ class SimpleCaptcha {
|
|||
if ( $editInfo->output ) {
|
||||
$newLinks = array_keys( $editInfo->output->getExternalLinks() );
|
||||
} else {
|
||||
$newLinks = array();
|
||||
$newLinks = [];
|
||||
}
|
||||
} else {
|
||||
// Get link changes in the slowest way known to man
|
||||
|
@ -513,7 +513,7 @@ class SimpleCaptcha {
|
|||
$newLinks = $this->findLinks( $title, $newtext );
|
||||
}
|
||||
|
||||
$unknownLinks = array_filter( $newLinks, array( &$this, 'filterLink' ) );
|
||||
$unknownLinks = array_filter( $newLinks, [ &$this, 'filterLink' ] );
|
||||
$addedLinks = array_diff( $unknownLinks, $oldLinks );
|
||||
$numLinks = count( $addedLinks );
|
||||
|
||||
|
@ -539,9 +539,9 @@ class SimpleCaptcha {
|
|||
$oldtext = isset( $oldtext ) ? $oldtext : $this->loadText( $title, $section );
|
||||
|
||||
foreach ( $wgCaptchaRegexes as $regex ) {
|
||||
$newMatches = array();
|
||||
$newMatches = [];
|
||||
if ( preg_match_all( $regex, $newtext, $newMatches ) ) {
|
||||
$oldMatches = array();
|
||||
$oldMatches = [];
|
||||
preg_match_all( $regex, $oldtext, $oldMatches );
|
||||
|
||||
$addedMatches = array_diff( $newMatches[0], $oldMatches[0] );
|
||||
|
@ -578,7 +578,7 @@ class SimpleCaptcha {
|
|||
$source = wfMessage( 'captcha-addurl-whitelist' )->inContentLanguage();
|
||||
|
||||
$regexes = $source->isDisabled()
|
||||
? array()
|
||||
? []
|
||||
: $this->buildRegexes( explode( "\n", $source->plain() ) );
|
||||
|
||||
if ( $wgCaptchaWhitelist !== false ) {
|
||||
|
@ -611,26 +611,26 @@ class SimpleCaptcha {
|
|||
# No lines, don't make a regex which will match everything
|
||||
if ( count( $lines ) == 0 ) {
|
||||
wfDebug( "No lines\n" );
|
||||
return array();
|
||||
return [];
|
||||
} else {
|
||||
# Make regex
|
||||
# It's faster using the S modifier even though it will usually only be run once
|
||||
// $regex = 'http://+[a-z0-9_\-.]*(' . implode( '|', $lines ) . ')';
|
||||
// return '/' . str_replace( '/', '\/', preg_replace('|\\\*/|', '/', $regex) ) . '/Si';
|
||||
$regexes = array();
|
||||
$regexStart = array(
|
||||
$regexes = [];
|
||||
$regexStart = [
|
||||
'normal' => '/^(?:https?:)?\/\/+[a-z0-9_\-.]*(?:',
|
||||
'noprotocol' => '/^(?:',
|
||||
);
|
||||
$regexEnd = array(
|
||||
];
|
||||
$regexEnd = [
|
||||
'normal' => ')/Si',
|
||||
'noprotocol' => ')/Si',
|
||||
);
|
||||
];
|
||||
$regexMax = 4096;
|
||||
$build = array();
|
||||
$build = [];
|
||||
foreach ( $lines as $line ) {
|
||||
# Extract flags from the line
|
||||
$options = array();
|
||||
$options = [];
|
||||
if ( preg_match( '/^(.*?)\s*<([^<>]*)>$/', $line, $matches ) ) {
|
||||
if ( $matches[1] === '' ) {
|
||||
wfDebug( "Line with empty regex\n" );
|
||||
|
@ -677,9 +677,9 @@ class SimpleCaptcha {
|
|||
function getLinksFromTracker( $title ) {
|
||||
$dbr = wfGetDB( DB_SLAVE );
|
||||
$id = $title->getArticleID(); // should be zero queries
|
||||
$res = $dbr->select( 'externallinks', array( 'el_to' ),
|
||||
array( 'el_from' => $id ), __METHOD__ );
|
||||
$links = array();
|
||||
$res = $dbr->select( 'externallinks', [ 'el_to' ],
|
||||
[ 'el_from' => $id ], __METHOD__ );
|
||||
$links = [];
|
||||
foreach ( $res as $row ) {
|
||||
$links[] = $row->el_to;
|
||||
}
|
||||
|
@ -754,7 +754,7 @@ class SimpleCaptcha {
|
|||
$status->fatal( 'hookaborted' );
|
||||
}
|
||||
$status->value = EditPage::AS_HOOK_ERROR_EXPECTED;
|
||||
$status->apiHookResult = array();
|
||||
$status->apiHookResult = [];
|
||||
// give an error message for the user to know, what goes wrong here.
|
||||
// this can't be done for addurl trigger, because this requires one "free" save
|
||||
// for the user, which we don't know, when he did it.
|
||||
|
@ -763,7 +763,7 @@ class SimpleCaptcha {
|
|||
new RawMessage(
|
||||
Html::element(
|
||||
'div',
|
||||
array( 'class' => 'errorbox' ),
|
||||
[ 'class' => 'errorbox' ],
|
||||
$context->msg( 'captcha-edit-fail' )->text()
|
||||
)
|
||||
)
|
||||
|
@ -799,11 +799,11 @@ class SimpleCaptcha {
|
|||
$success = $this->passCaptchaLimited();
|
||||
LoggerFactory::getInstance(
|
||||
'authmanager'
|
||||
)->info( 'Captcha submitted on account creation', array(
|
||||
)->info( 'Captcha submitted on account creation', [
|
||||
'event' => 'captcha.submit',
|
||||
'type' => 'accountcreation',
|
||||
'successful' => $success,
|
||||
) );
|
||||
] );
|
||||
if ( !$success ) {
|
||||
// For older MediaWiki
|
||||
$message = wfMessage( 'captcha-createaccount-fail' )->text();
|
||||
|
@ -850,16 +850,17 @@ class SimpleCaptcha {
|
|||
*/
|
||||
function confirmUserLogin( $u, $pass, &$retval ) {
|
||||
if ( $this->isBadLoginTriggered() || $this->isBadLoginPerUserTriggered( $u ) ) {
|
||||
if ( $this->isIPWhitelisted() )
|
||||
if ( $this->isIPWhitelisted() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->trigger = "post-badlogin login '" . $u->getName() . "'";
|
||||
$success = $this->passCaptchaLimited();
|
||||
LoggerFactory::getInstance( 'authmanager' )->info( 'Captcha submitted on login', array(
|
||||
LoggerFactory::getInstance( 'authmanager' )->info( 'Captcha submitted on login', [
|
||||
'event' => 'captcha.submit',
|
||||
'type' => 'login',
|
||||
'successful' => $success,
|
||||
) );
|
||||
] );
|
||||
if ( !$success ) {
|
||||
// Emulate a bad-password return to confuse the shit out of attackers
|
||||
$retval = LoginForm::WRONG_PASS;
|
||||
|
@ -885,8 +886,9 @@ class SimpleCaptcha {
|
|||
wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" );
|
||||
return true;
|
||||
}
|
||||
if ( $this->isIPWhitelisted() )
|
||||
if ( $this->isIPWhitelisted() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( defined( 'MW_API' ) ) {
|
||||
# API mode
|
||||
|
@ -920,12 +922,12 @@ class SimpleCaptcha {
|
|||
public function APIGetAllowedParams( &$module, &$params, $flags ) {
|
||||
if ( $this->isAPICaptchaModule( $module ) ) {
|
||||
if ( defined( 'ApiBase::PARAM_HELP_MSG' ) ) {
|
||||
$params['captchaword'] = array(
|
||||
$params['captchaword'] = [
|
||||
ApiBase::PARAM_HELP_MSG => 'captcha-apihelp-param-captchaword',
|
||||
);
|
||||
$params['captchaid'] = array(
|
||||
];
|
||||
$params['captchaid'] = [
|
||||
ApiBase::PARAM_HELP_MSG => 'captcha-apihelp-param-captchaid',
|
||||
);
|
||||
];
|
||||
} else {
|
||||
// @todo: Remove this branch when support for MediaWiki < 1.25 is dropped
|
||||
$params['captchaword'] = null;
|
||||
|
@ -1158,10 +1160,10 @@ class SimpleCaptcha {
|
|||
|
||||
LoggerFactory::getInstance(
|
||||
'authmanager'
|
||||
)->info( 'Captcha data added in account creation API', array(
|
||||
)->info( 'Captcha data added in account creation API', [
|
||||
'event' => 'captcha.display',
|
||||
'type' => 'accountcreation',
|
||||
) );
|
||||
] );
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"jakub-onderka/php-parallel-lint": "0.9.2",
|
||||
"mediawiki/mediawiki-codesniffer": "0.4.0"
|
||||
"mediawiki/mediawiki-codesniffer": "0.7.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
"parallel-lint . --exclude vendor",
|
||||
"phpcs -p -s"
|
||||
],
|
||||
"fix": [
|
||||
"phpcbf"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ class ConfirmEditHooks {
|
|||
/**
|
||||
* @var SplFileInfo $fileInfo
|
||||
*/
|
||||
$ourFiles = array();
|
||||
$ourFiles = [];
|
||||
foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) {
|
||||
if ( substr( $fileInfo->getFilename(), -8 ) === 'Test.php' ) {
|
||||
$ourFiles[] = $fileInfo->getPathname();
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
||||
$IP = getenv( 'MW_INSTALL_PATH' );
|
||||
} else {
|
||||
$IP = dirname( __FILE__ ).'/../../..';
|
||||
$IP = __DIR__.'/../../..';
|
||||
}
|
||||
|
||||
require_once ( "$IP/maintenance/Maintenance.php" );
|
||||
|
@ -79,7 +79,7 @@ class GenerateFancyCaptchas extends Maintenance {
|
|||
wfEscapeShellArg( $countGen ),
|
||||
wfEscapeShellArg( $wgCaptchaDirectoryLevels )
|
||||
);
|
||||
foreach ( array( 'wordlist', 'font', 'font-size', 'blacklist', 'verbose' ) as $par ) {
|
||||
foreach ( [ 'wordlist', 'font', 'font-size', 'blacklist', 'verbose' ] as $par ) {
|
||||
if ( $this->hasOption( $par ) ) {
|
||||
$cmd .= " --$par " . wfEscapeShellArg( $this->getOption( $par ) );
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class GenerateFancyCaptchas extends Maintenance {
|
|||
|
||||
$this->output( "Generating $countGen new captchas...\n" );
|
||||
$retVal = 1;
|
||||
wfShellExec( $cmd, $retVal, array(), array( 'time' => 0 ) );
|
||||
wfShellExec( $cmd, $retVal, [], [ 'time' => 0 ] );
|
||||
if ( $retVal != 0 ) {
|
||||
wfRecursiveRemoveDir( $tmpDir );
|
||||
$this->error( "Could not run generation script.\n", 1 );
|
||||
|
@ -106,11 +106,11 @@ class GenerateFancyCaptchas extends Maintenance {
|
|||
}
|
||||
list( $salt, $hash ) = $instance->hashFromImageName( $fileInfo->getBasename() );
|
||||
$dest = $instance->imagePath( $salt, $hash );
|
||||
$backend->prepare( array( 'dir' => dirname( $dest ) ) );
|
||||
$status = $backend->quickStore( array(
|
||||
$backend->prepare( [ 'dir' => dirname( $dest ) ] );
|
||||
$status = $backend->quickStore( [
|
||||
'src' => $fileInfo->getPathname(),
|
||||
'dst' => $dest
|
||||
) );
|
||||
] );
|
||||
if ( !$status->isOK() ) {
|
||||
$this->error( "Could not save file '{$fileInfo->getPathname()}'.\n" );
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ class QuestyCaptchaTest extends MediaWikiTestCase {
|
|||
|
||||
# setMwGlobals() requires $wgCaptchaQuestion to be set
|
||||
if ( !isset( $GLOBALS['wgCaptchaQuestions'] ) ) {
|
||||
$GLOBALS['wgCaptchaQuestions'] = array();
|
||||
$GLOBALS['wgCaptchaQuestions'] = [];
|
||||
}
|
||||
$this->setMwGlobals( 'wgCaptchaQuestions', $config );
|
||||
$this->mergeMwGlobalArrayValue(
|
||||
'wgAutoloadClasses',
|
||||
array( 'QuestyCaptcha' => __DIR__ . '/../QuestyCaptcha/QuestyCaptcha.class.php' )
|
||||
[ 'QuestyCaptcha' => __DIR__ . '/../QuestyCaptcha/QuestyCaptcha.class.php' ]
|
||||
);
|
||||
|
||||
$qc = new QuestyCaptcha();
|
||||
|
@ -22,28 +22,28 @@ class QuestyCaptchaTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
public static function provideGetCaptcha() {
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
[
|
||||
[
|
||||
'question' => 'FooBar',
|
||||
'answer' => 'Answer!',
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'question' => 'FooBar',
|
||||
'answer' => 'Answer!',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'FooBar' => 'Answer!',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'question' => 'FooBar',
|
||||
'answer' => 'Answer!',
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue