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, array(), array('time' => 0));
         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);
         $this->output("Copying the new captchas to storage...\n");
         foreach ($iter as $fileInfo) {
             if (!$fileInfo->isFile()) {
                 continue;
             }
             list($salt, $hash) = $instance->hashFromImageName($fileInfo->getBasename());
             $dest = $instance->imagePath($salt, $hash);
             $backend->prepare(array('dir' => dirname($dest)));
             $status = $backend->quickStore(array('src' => $fileInfo->getPathname(), 'dst' => $dest));
             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");
 }
 function execute($par)
 {
     $this->setHeaders();
     $instance = ConfirmEditHooks::getInstance();
     switch ($par) {
         case "image":
             return $instance->showImage();
         case "help":
         default:
             return $instance->showHelp();
     }
 }
 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();
     }
 }
	public static function getInstance() {
		if ( !self::$initialized ) {
			self::$initialized = true;
			if ( class_exists( 'ConfirmEditHooks' ) ) {
				$captcha = ConfirmEditHooks::getInstance();
				if ( $captcha instanceof SimpleCaptcha ) {
					self::$instance = new WlCaptchaAdapter( $captcha );
				} else {
					$classname = get_class( $captcha );
					trigger_error( "Only captchas derived from SimpleCaptcha " .
						"are compatible with Wikilog. The current captcha, " .
						"{$classname}, isn't compatible.", E_USER_WARNING );
				}
			}
		}
		return self::$instance;
	}
 private function getCaptchaObj()
 {
     $captchaObj = null;
     if (!empty($this->wg->WikiaEnableConfirmEditExt)) {
         $captchaObj = ConfirmEditHooks::getInstance();
     }
     return $captchaObj;
 }
 /**
  * @param User $target
  */
 function __construct($target, $par)
 {
     global $wgRequest, $wgUser;
     $this->wasPosted = $wgRequest->wasPosted();
     $this->formType = $wgRequest->getText('formtype', $par);
     # Check for type in [[Special:Contact/type]]: change pagetext and prefill form fields
     if ($this->formType != '') {
         $message = 'contactpage-pagetext-' . $this->formType;
         $text = wfMsgExt($message, 'parse');
         if (!wfEmptyMsg($message, $text)) {
             $this->formularText = $text;
         } else {
             $this->formularText = wfMsgExt('contactpage-pagetext', 'parse');
         }
         $message = 'contactpage-subject-' . $this->formType;
         $text = wfMsgForContentNoTrans($message);
         if (!wfEmptyMsg($message, $text)) {
             $this->subject = $wgRequest->getText('wpSubject', $text);
         } else {
             $this->subject = $wgRequest->getText('wpSubject');
         }
         $message = 'contactpage-text-' . $this->formType;
         $text = wfMsgForContentNoTrans($message);
         if (!wfEmptyMsg($message, $text)) {
             $this->text = $wgRequest->getText('wpText', $text);
         } else {
             $this->text = $wgRequest->getText('wpText');
         }
     } else {
         $this->formularText = wfMsgExt('contactpage-pagetext', 'parse');
         $this->text = $wgRequest->getText('wpText');
         $this->subject = $wgRequest->getText('wpSubject');
     }
     $this->target = $target;
     $this->cc_me = $wgRequest->getBool('wpCCMe');
     $this->includeIP = $wgRequest->getBool('wpIncludeIP');
     $this->fromname = $wgRequest->getText('wpFromName');
     $this->fromaddress = $wgRequest->getText('wpFromAddress');
     if ($wgUser->isLoggedIn()) {
         if (!$this->fromname) {
             $this->fromname = $wgUser->getName();
         }
         if (!$this->fromaddress) {
             $this->fromaddress = $wgUser->getEmail();
         }
     }
     // prepare captcha if applicable
     if ($this->useCaptcha()) {
         $captcha = ConfirmEditHooks::getInstance();
         $captcha->trigger = 'contactpage';
         $captcha->action = 'contact';
     }
 }
 /**
  * @param User $target
  */
 function __construct($target)
 {
     global $wgRequest, $wgUser;
     $this->target = $target;
     $this->text = $wgRequest->getText('wpText');
     $this->subject = $wgRequest->getText('wpSubject');
     $this->cc_me = $wgRequest->getBool('wpCCMe');
     $this->fromname = $wgRequest->getText('wpFromName');
     $this->fromaddress = $wgRequest->getText('wpFromAddress');
     if ($wgUser->isLoggedIn()) {
         if (!$this->fromname) {
             $this->fromname = $wgUser->getName();
         }
         if (!$this->fromaddress) {
             $this->fromaddress = $wgUser->getEmail();
         }
     }
     //prepare captcha if applicable
     if ($this->useCaptcha()) {
         $captcha = ConfirmEditHooks::getInstance();
         $captcha->trigger = 'contactpage';
         $captcha->action = 'contact';
     }
 }