From 63601400e476c6cf43d985f3e7b9864681695ed4 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Jan 2013 16:46:04 +0100 Subject: Update to MediaWiki 1.20.2 this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024 --- .../maintenance/GenerateFancyCaptchas.php | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 extensions/ConfirmEdit/maintenance/GenerateFancyCaptchas.php (limited to 'extensions/ConfirmEdit/maintenance/GenerateFancyCaptchas.php') diff --git a/extensions/ConfirmEdit/maintenance/GenerateFancyCaptchas.php b/extensions/ConfirmEdit/maintenance/GenerateFancyCaptchas.php new file mode 100644 index 00000000..e5620753 --- /dev/null +++ b/extensions/ConfirmEdit/maintenance/GenerateFancyCaptchas.php @@ -0,0 +1,128 @@ +addOption( "wordlist", 'A list of words', true, true ); + $this->addOption( "font", "The font to use", true, true ); + $this->addOption( "font-size", "The font size ", false, true ); + $this->addOption( "blacklist", "A blacklist of words that should not be used", false, true ); + $this->addOption( "fill", "Fill the captcha container to N files", true, true ); + $this->addOption( "verbose", "Show debugging information" ); + $this->mDescription = "Generate new captchas and move them into storage"; + } + + public function execute() { + global $wgCaptchaSecret, $wgCaptchaDirectoryLevels; + + $instance = ConfirmEditHooks::getInstance(); + if ( !( $instance instanceof FancyCaptcha ) ) { + $this->error( "\$wgCaptchaClass is not FancyCaptcha.\n", 1 ); + } + $backend = $instance->getBackend(); + + $countAct = $instance->estimateCaptchaCount(); + $this->output( "Estimated number of captchas is $countAct.\n" ); + + $countGen = (int)$this->getOption( 'fill' ) - $countAct; + if ( $countGen <= 0 ) { + $this->output( "No need to generate anymore captchas.\n" ); + return; + } + + $tmpDir = wfTempDir() . '/mw-fancycaptcha-' . time() . '-' . wfRandomString( 6 ); + if ( !wfMkdirParents( $tmpDir ) ) { + $this->error( "Could not create temp directory.\n", 1 ); + } + + $e = null; // exception + try { + $cmd = sprintf( "python %s --key %s --output %s --count %s --dirs %s", + wfEscapeShellArg( __DIR__ . '/../captcha.py' ), + wfEscapeShellArg( $wgCaptchaSecret ), + wfEscapeShellArg( $tmpDir ), + wfEscapeShellArg( $countGen ), + wfEscapeShellArg( $wgCaptchaDirectoryLevels ) + ); + foreach ( array( 'wordlist', 'font', 'font-size', 'blacklist', 'verbose' ) as $par ) { + if ( $this->hasOption( $par ) ) { + $cmd .= " --$par " . wfEscapeShellArg( $this->getOption( $par ) ); + } + } + + $this->output( "Generating $countGen new captchas...\n" ); + $retVal = 1; + wfShellExec( $cmd, $retVal ); + if ( $retVal != 0 ) { + wfRecursiveRemoveDir( $tmpDir ); + $this->error( "Could not run generation script.\n", 1 ); + } + + $flags = FilesystemIterator::SKIP_DOTS; + $iter = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( $tmpDir, $flags ), + RecursiveIteratorIterator::CHILD_FIRST // include dirs + ); + + $this->output( "Copying the new captchas to storage...\n" ); + foreach ( $iter as $fileInfo ) { + if ( !$fileInfo->isFile() ) { + continue; + } + list( $salt, $hash ) = $instance->hashFromImageName( $fileInfo->getBasename() ); + $status = $backend->quickStore( array( + 'src' => $fileInfo->getPathname(), + 'dst' => $instance->imagePath( $salt, $hash ) + ) ); + if ( !$status->isOK() ) { + $this->error( "Could not save file '{$fileInfo->getPathname()}'.\n" ); + } + } + } catch ( Exception $e ) { + wfRecursiveRemoveDir( $tmpDir ); + throw $e; + } + + $this->output( "Removing temporary files...\n" ); + wfRecursiveRemoveDir( $tmpDir ); + $this->output( "Done.\n" ); + } +} + +$maintClass = "GenerateFancyCaptchas"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- cgit v1.2.3-54-g00ecf