X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FgenerateJsonI18n.php;h=b9c07fbe4dd4760f52f05548cf241c9484c7e07b;hb=25bb740e50d5f4f967e80f5d6a373405e5ef187a;hp=22d9940532d41a936c2f9162070c35a5e822ea34;hpb=fea832ae52ad17bd68637559134942f57a35c925;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/generateJsonI18n.php b/maintenance/generateJsonI18n.php index 22d9940532..b9c07fbe4d 100644 --- a/maintenance/generateJsonI18n.php +++ b/maintenance/generateJsonI18n.php @@ -39,11 +39,8 @@ class GenerateJsonI18n extends Maintenance { $this->addArg( 'phpfile', 'PHP file defining a $messages array', false ); $this->addArg( 'jsondir', 'Directory to write JSON files to', false ); - $this->addOption( 'langcode', 'Language code; only needed for converting core i18n files', - false, true ); $this->addOption( 'extension', 'Perform default conversion on an extension', false, true ); - $this->addOption( 'shim-only', 'Only create or update the backward-compatibility shim' ); $this->addOption( 'supplementary', 'Find supplementary i18n files in subdirs and convert those', false, false ); } @@ -58,13 +55,13 @@ class GenerateJsonI18n extends Maintenance { if ( $extension ) { if ( $phpfile ) { - $this->error( "The phpfile is already specified, conflicts with --extension.\n", 1 ); + $this->error( "The phpfile is already specified, conflicts with --extension.", 1 ); } $phpfile = "$IP/extensions/$extension/$extension.i18n.php"; } if ( !$phpfile ) { - $this->error( "I'm here for an argument!\n" ); + $this->error( "I'm here for an argument!" ); $this->maybeHelp( true ); // dies. } @@ -104,47 +101,32 @@ class GenerateJsonI18n extends Maintenance { $this->output( "Creating directory $jsondir.\n" ); $success = mkdir( $jsondir ); if ( !$success ) { - $this->error( "Could not create directory $jsondir\n", 1 ); + $this->error( "Could not create directory $jsondir", 1 ); } } - if ( $this->hasOption( 'shim-only' ) ) { - $this->shimOnly( $phpfile, $jsondir ); - - return; - } - - if ( $jsondir === null ) { - $this->error( 'Argument [jsondir] is required unless --shim-only is specified.' ); - $this->maybeHelp( true ); - } - if ( !is_readable( $phpfile ) ) { - $this->error( "Error reading $phpfile\n", 1 ); + $this->error( "Error reading $phpfile", 1 ); } include $phpfile; $phpfileContents = file_get_contents( $phpfile ); if ( !isset( $messages ) ) { - $this->error( "PHP file $phpfile does not define \$messages array\n", 1 ); + $this->error( "PHP file $phpfile does not define \$messages array", 1 ); + } + + if ( !$messages ) { + $this->error( "PHP file $phpfile contains an empty \$messages array. " . + "Maybe it was already converted?", 1 ); } - $extensionStyle = true; if ( !isset( $messages['en'] ) || !is_array( $messages['en'] ) ) { - if ( !$this->hasOption( 'langcode' ) ) { - $this->error( "PHP file $phpfile does not set language codes, --langcode " . - "is required.\n", 1 ); - } - $extensionStyle = false; - $langcode = $this->getOption( 'langcode' ); - $messages = array( $langcode => $messages ); - } elseif ( $this->hasOption( 'langcode' ) ) { - $this->output( "Warning: --langcode option set but will not be used.\n" ); + $this->error( "PHP file $phpfile does not set language codes", 1 ); } foreach ( $messages as $langcode => $langmsgs ) { $authors = $this->getAuthorsFromComment( $this->findCommentBefore( - $extensionStyle ? "\$messages['$langcode'] =" : '$messages =', + "\$messages['$langcode'] =", $phpfileContents ) ); // Make sure the @metadata key is the first key in the output @@ -164,89 +146,15 @@ class GenerateJsonI18n extends Maintenance { $this->output( "$jsonfile\n" ); } - if ( !$this->hasOption( 'langcode' ) ) { - $shim = $this->doShim( $jsondir ); - file_put_contents( $phpfile, $shim ); - } - - $this->output( "All done.\n" ); - $this->output( "Also add \$wgMessagesDirs['YourExtension'] = __DIR__ . '/i18n';\n" ); - } - - protected function shimOnly( $phpfile, $jsondir ) { - if ( file_exists( $phpfile ) ) { - if ( !is_readable( $phpfile ) ) { - $this->error( "Error reading $phpfile\n", 1 ); - } - - $phpfileContents = file_get_contents( $phpfile ); - $m = array(); - if ( !preg_match( '!"/([^"$]+)/\$csCode.json";!', $phpfileContents, $m ) ) { - $this->error( "Cannot recognize $phpfile as a shim.\n", 1 ); - } - - if ( $jsondir === null ) { - $jsondir = $m[1]; - } - - $this->output( "Updating existing shim $phpfile\n" ); - } elseif ( $jsondir === null ) { - $this->error( "$phpfile does not exist.\n" . - "Argument [jsondir] is required in order to create a new shim.\n", 1 ); - } else { - $this->output( "Creating new shim $phpfile\n" ); - } - - $shim = $this->doShim( $jsondir ); - file_put_contents( $phpfile, $shim ); - $this->output( "All done.\n" ); - } - - protected function doShim( $jsondir ) { - $shim = <<<'PHP' -output( + "All done. To complete the conversion, please do the following:\n" . + "* Add \$wgMessagesDirs['YourExtension'] = __DIR__ . '/i18n';\n" . + "* Remove \$wgExtensionMessagesFiles['YourExtension']\n" . + "* Delete the old PHP message file\n" . + "This script no longer generates backward compatibility shims! If you need\n" . + "compatibility with MediaWiki 1.22 and older, use the MediaWiki 1.23 version\n" . + "of this script instead, or create a shim manually.\n" + ); } /**