public function execute()
 {
     if (!is_writable($this->getOption('target'))) {
         $this->error('Target directory is not writable.', 1);
     }
     $langs = TranslateUtils::parseLanguageCodes($this->getOption('lang', '*'));
     $group = MessageGroups::getGroup('core');
     $type = $this->getOption('type');
     foreach ($langs as $l) {
         $o = null;
         switch ($type) {
             case 'special':
                 $o = new SpecialPageAliasesCM($l);
                 break;
             case 'magic':
                 $o = new MagicWordsCM($l);
                 break;
             case 'namespace':
                 $o = new NamespaceCM($l);
                 break;
             default:
                 $this->error('Invalid type: Must be one of special, magic, namespace.', 1);
         }
         $export = $o->export('core');
         if ($export === '') {
             continue;
         }
         $matches = array();
         preg_match('~^(\\$[a-zA-Z]+)\\s*=~m', $export, $matches);
         if (!isset($matches[1])) {
             continue;
         }
         # remove useles comment
         $export = preg_replace("~^# .*\$\n~m", '', $export);
         if (strpos($export, '#!!') !== false) {
             $this->error("There are warnings with {$l}.");
         }
         $variable = preg_quote($matches[1], '~');
         /** @var FileBasedMessageGroup $group */
         $file = $group->getSourceFilePath($l);
         // bandage
         $real = Language::getFileName('/messages/Messages', $l);
         $file = preg_replace('~/i18n/(.+)\\.json$~', $real, $file);
         if (!file_exists($file)) {
             $this->error("File {$file} does not exist!");
             continue;
         }
         $data = file_get_contents($file);
         $export = trim($export) . "\n";
         $escExport = addcslashes($export, '\\$');
         # Darn backreferences
         $outFile = $this->getOption('target') . '/' . $group->getTargetFilename($l);
         $outFile = preg_replace('~/i18n/(.+)\\.json$~', $real, $outFile);
         $count = 0;
         $data = preg_replace("~{$variable}\\s*=.*?\n\\);\n~s", $escExport, $data, 1, $count);
         if ($count) {
             file_put_contents($outFile, $data);
         } else {
             $this->error("Adding new entry to {$outFile}, please double check location.");
             $pos = strpos($data, "*/");
             if ($pos === false) {
                 $this->error(". FAILED! Totally new file? No header?");
             } else {
                 $pos += 3;
             }
             $data = substr($data, 0, $pos) . "\n" . $export . substr($data, $pos);
             file_put_contents($outFile, $data);
         }
     }
 }
 /**
  * The special page running code
  */
 public function execute($parameters)
 {
     $this->setup($parameters);
     $this->setHeaders();
     $out = $this->getOutput();
     TranslateUtils::addSpecialHelpLink($out, '//translatewiki.net/wiki/FAQ#Special:AdvancedTranslate', true);
     $out->addHTML($this->getForm());
     if (!$this->options['module']) {
         return;
     }
     switch ($this->options['module']) {
         case 'alias':
         case self::MODULE_SPECIAL:
             $o = new SpecialPageAliasesCM($this->options['language']);
             break;
         case self::MODULE_MAGIC:
             $o = new MagicWordsCM($this->options['language']);
             break;
         case self::MODULE_NAMESPACE:
             $o = new NamespaceCM($this->options['language']);
             break;
         default:
             throw new MWException("Unknown module {$this->options['module']}");
     }
     $request = $this->getRequest();
     if ($request->wasPosted() && $this->options['savetodb']) {
         if (!$this->getUser()->isAllowed('translate')) {
             throw new PermissionsError('translate');
         }
         $errors = array();
         $o->loadFromRequest($request);
         $o->validate($errors);
         if ($errors) {
             $out->wrapWikiMsg('<div class="error">$1</div>', 'translate-magic-notsaved');
             $this->outputErrors($errors);
             $out->addHTML($o->output());
             return;
         } else {
             $o->save($request);
             $out->wrapWikiMsg('<strong>$1</strong>', 'translate-magic-saved');
             $out->addHTML($o->output());
             return;
         }
     }
     if ($this->options['export']) {
         $output = $o->export();
         if ($output === '') {
             $out->addWikiMsg('translate-magic-nothing-to-export');
             return;
         }
         $result = Xml::element('textarea', array('rows' => '30'), $output);
         $out->addHTML($result);
         return;
     }
     $out->addWikiMsg('translate-magic-help');
     $errors = array();
     $o->validate($errors);
     if ($errors) {
         $this->outputErrors($errors);
     }
     $out->addHTML($o->output());
 }
$langs = Cli::parseLanguageCodes( $options['lang'] );

$group = MessageGroups::getGroup( 'core' );

foreach ( $langs as $l ) {
	$o = null;

	switch ( $options['type'] ) {
		case 'special':
			$o = new SpecialPageAliasesCM( $l );
			break;
		case 'magic':
			$o = new MagicWordsCM( $l );
			break;
		case 'namespace':
			$o = new NamespaceCM( $l );
			break;
		default:
			STDERR( "Invalid type: must be one of special, magic, namespace." );
			exit( 1 );
	}

	$export = $o->export( 'core' );
	if ( $export === '' ) {
		continue;
	}

	$matches = array();
	preg_match( '~^(\$[a-zA-Z]+)\s*=~m', $export, $matches );

	if ( !isset( $matches[1] ) ) {