Go to the documentation of this file.
18 global $wgCaptchaFileBackend, $wgCaptchaDirectory;
20 if ( $wgCaptchaFileBackend ) {
23 static $backend =
null;
26 'name' =>
'captcha-backend',
29 'containerPaths' => [
'captcha-render' => $wgCaptchaDirectory ],
31 'obResetFunc' =>
'wfResetOutputBuffers',
32 'streamMimeFunc' => [
'StreamFile',
'contentTypeFromPath' ]
53 $files = $backend->getFileList(
54 [
'dir' => $backend->getRootStoragePath() .
'/captcha-render' ]
57 return iterator_count( $files );
68 protected function keyMatch( $answer, $info ) {
69 global $wgCaptchaSecret;
71 $digest = $wgCaptchaSecret . $info[
'salt'] . $answer . $wgCaptchaSecret . $info[
'salt'];
72 $answerHash = substr( md5( $digest ), 0, 16 );
74 if ( $answerHash == $info[
'hash'] ) {
75 wfDebug(
"FancyCaptcha: answer hash matches expected {$info['hash']}\n" );
78 wfDebug(
"FancyCaptcha: answer hashes to $answerHash, expected {$info['hash']}\n" );
89 $resultArr[
'captcha'][
'error'] =
'Out of images';
95 $resultArr[
'captcha'][
'id'] = $index;
96 $resultArr[
'captcha'][
'url'] =
$title->getLocalURL(
'wpCaptchaId=' . urlencode( $index ) );
105 'mime' =>
'image/png',
121 $modules[] =
'ext.confirmEdit.fancyCaptcha';
126 'class' =>
'confirmedit-captcha-reload fancycaptcha-reload'
133 'for' =>
'wpCaptchaWord',
141 'class' =>
'fancycaptcha-image',
142 'src' =>
$title->getLocalURL(
'wpCaptchaId=' . urlencode( $index ) ),
147 'name' =>
'wpCaptchaWord',
148 'class' =>
'mw-ui-input',
149 'id' =>
'wpCaptchaWord',
153 'autocomplete' =>
'off',
154 'autocorrect' =>
'off',
155 'autocapitalize' =>
'off',
156 'required' =>
'required',
158 'tabindex' => $tabIndex,
159 'placeholder' =>
wfMessage(
'fancycaptcha-imgcaptcha-ph' )->
text()
162 if ( $this->
action ==
'createaccount' ) {
165 'class' =>
'mw-createacct-captcha-assisted'
166 ],
wfMessage(
'createacct-imgcaptcha-help' )->parse()
171 'name' =>
'wpCaptchaId',
172 'id' =>
'wpCaptchaId',
181 'modulestyles' => [
'mediawiki.ui.input',
'ext.confirmEdit.fancyCaptcha.styles' ],
190 global $wgCaptchaDirectoryLevels;
194 $baseDir = $this->
getBackend()->getRootStoragePath() .
'/captcha-render';
195 return $this->
pickImageDir( $baseDir, $wgCaptchaDirectoryLevels, $lockouts );
207 if ( $levels <= 0 ) {
214 $key =
"fancycaptcha:dirlist:{$backend->getWikiId()}:" . sha1( $directory );
221 foreach ( $backend->getTopDirectoryList( [
'dir' => $directory ] )
as $entry ) {
222 if ( ctype_xdigit( $entry ) && strlen( $entry ) == 1 ) {
226 wfDebug(
"Cache miss for $directory subdirectory listing.\n" );
234 $backend->clean( [
'dir' => $directory ] );
243 for ( $j = 0; $j < $fancyCount; $j++ ) {
245 $info = $this->
pickImageDir(
"$directory/$char", $levels - 1, $lockouts );
250 wfDebug(
"Could not find captcha in $directory.\n" );
270 $key =
"fancycaptcha:filelist:{$backend->getWikiId()}:" . sha1( $directory );
273 if ( !is_array( $files ) || !
count( $files ) ) {
276 foreach ( $backend->getTopFileList( [
'dir' => $directory ] )
as $entry ) {
278 if (
count( $files ) >= 500 ) {
280 wfDebug(
'Skipping some captchas; $wgCaptchaDirectoryLevels set too low?.' );
284 if (
count( $files ) ) {
285 $wgMemc->set( $key, $files, 86400 );
287 wfDebug(
"Cache miss for $directory captcha listing.\n" );
290 if ( !
count( $files ) ) {
292 $backend->clean( [
'dir' => $directory ] );
298 wfDebug(
"Could not find captcha in $directory.\n" );
313 global
$wgMemc, $wgCaptchaDeleteOnSolve;
315 if ( !
count( $files ) ) {
322 $place = mt_rand( 0,
count( $files ) - 1 );
325 $fancyImageCount =
count( $files );
326 for ( $j = 0; $j < $fancyImageCount; $j++ ) {
327 $entry = $files[( $place + $j ) %
count( $files )];
328 if ( preg_match(
'/^image_([0-9a-f]+)_([0-9a-f]+)\\.png$/', $entry,
$matches ) ) {
329 if ( $wgCaptchaDeleteOnSolve ) {
331 $key =
"fancycaptcha:filelock:{$backend->getWikiId()}:" . sha1( $entry );
333 if ( ++$lockouts <= 10 && !$wgMemc->
add( $key,
'1', 600 ) ) {
338 if ( !$backend->fileExists( [
'src' =>
"$directory/$entry" ] ) ) {
339 if ( ++$misses >= 5 ) {
371 $info[
'viewed'] = $timestamp->getTimestamp();
374 $salt = $info[
'salt'];
375 $hash = $info[
'hash'];
378 'src' => $this->
imagePath( $salt, $hash ),
379 'headers' => [
"Cache-Control: private, s-maxage=0, max-age=3600" ]
383 wfHttpError( 400,
'Request Error',
'Requested bogus captcha image' );
393 global $wgCaptchaDirectoryLevels;
395 $file = $this->
getBackend()->getRootStoragePath() .
'/captcha-render/';
396 for ( $i = 0; $i < $wgCaptchaDirectoryLevels; $i++ ) {
397 $file .= $hash{ $i } .
'/';
399 $file .=
"image_{$salt}_{$hash}.png";
410 if ( preg_match(
'/^image_([0-9a-f]+)_([0-9a-f]+)\\.png$/', $basename,
$matches ) ) {
413 throw new Exception(
"Invalid filename '$basename'.\n" );
422 global $wgCaptchaDeleteOnSolve;
426 $pass = parent::passCaptcha( $index, $word );
428 if ( $pass && $wgCaptchaDeleteOnSolve ) {
430 'src' => $this->
imagePath( $info[
'salt'], $info[
'hash'] )
446 throw new UnderflowException(
'Ran out of captcha images' );
458 return $title->getLocalURL(
'wpCaptchaId=' . urlencode( $id ) );
472 AuthenticationRequest::getRequestByClass(
$requests,
485 'showCreateHelp' => in_array(
$action, [
486 AuthManager::ACTION_CREATE,
487 AuthManager::ACTION_CREATE_CONTINUE
Library for creating and parsing MW-style timestamps.
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
pickImageFromDir( $directory, &$lockouts)
pickImageFromList( $directory, array $files, &$lockouts)
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
this hook is for auditing only $req
An extension or a will often add custom code to the function with or without a global variable For someone wanting email notification when an article is shown may add
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getCaptchaInfo( $captchaData, $id)
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead & $formDescriptor
string $action
Used to select the right message.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
pickImage()
Select a previously generated captcha image from the queue.
static closeElement( $element)
Returns "</$element>".
namespace and then decline to actually register it file or subcat img or subcat $title
Simple version of LockManager that does nothing.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
addCaptchaAPI(&$resultArr)
pickImageDir( $directory, $levels, &$lockouts)
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getCaptcha()
Returns an array with 'salt' and 'hash' keys.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
keyMatch( $answer, $info)
Check if the submitted form matches the captcha session data provided by the plugin when the form was...
retrieveCaptcha( $index)
Fetch this session's captcha info.
FancyCaptcha for displaying captchas precomputed by captcha.py.
Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs.
storeCaptcha( $info)
Generate a captcha session ID and save the info in PHP's session storage.
hashFromImageName( $basename)
getMessage( $action)
Show a message asking the user to enter a captcha on edit The result will be treated as wiki text.
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
passCaptcha( $index, $word)
Delete a solved captcha image, if $wgCaptchaDeleteOnSolve is true.
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
Class for a file system (FS) based file backend.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead. & $feedLinks hooks can tweak the array to change how login etc forms should look $requests
getFormInformation( $tabIndex=1)
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
if(! $wgDBerrorLogTZ) $wgRequest
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<