Siebrand has uploaded a new change for review.
https://gerrit.wikimedia.org/r/89129
Change subject: Update fuzzy.php to use Maintenance class
......................................................................
Update fuzzy.php to use Maintenance class
Change-Id: Iaf57e2c912466260abdc92ec62e038fb3dc2c68c
---
M scripts/fuzzy.php
1 file changed, 76 insertions(+), 51 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/29/89129/1
diff --git a/scripts/fuzzy.php b/scripts/fuzzy.php
index f42bc63..f29fe3f 100644
--- a/scripts/fuzzy.php
+++ b/scripts/fuzzy.php
@@ -4,59 +4,74 @@
*
* @file
* @author Niklas Laxström
- * @copyright Copyright © 2007-2009, Niklas Laxström
+ * @author Siebrand Mazeland
+ * @copyright Copyright © 2007-2013, Niklas Laxström, Siebrand Mazeland
* @license GPL-2.0+
*/
-/// @cond
+// Standard boilerplate to define $IP
+if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
+ $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+ $dir = __DIR__;
+ $IP = "$dir/../../..";
+}
+require_once "$IP/maintenance/Maintenance.php";
-require __DIR__ . '/cli.inc';
-
-# Override the memory limit for wfShellExec, 100 MB seems to be too little
+# Override the memory limit for wfShellExec, 100 MB appears to be too little
$wgMaxShellMemory = 1024 * 200;
-function showUsage() {
- STDERR( <<<EOT
-Fuzzy bot command line script
+class Fuzzy extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = 'Fuzzy bot command line script';
+ $this->addArg(
+ 'messages',
+ 'Messages to fuzzy' // How can this be an array of
string?
+ );
+ $this->addOption(
+ 'really',
+ 'Really fuzzy, no dry-run'
+ );
+ $this->addOption(
+ 'skiplanguages',
+ 'Skip some languages (comma separated)',
+ false, /*required*/
+ true /*has arg*/
+ );
+ $this->addOption(
+ 'comment',
+ 'Comment for updating',
+ false, /*required*/
+ true /*has arg*/
+ );
+ }
-Usage: php fuzzy.php [options...] <messages>
+ public function execute() {
+ $bot = new FuzzyScript( $this->getArg( 'messages' ), $this );
-Options:
- --really Really fuzzy, no dry-run
- --skiplanguages Skip some languages (comma separated)
- --comment Comment for updating
+ if ( $this->hasOption('skiplanguages' ) ) {
+ $bot->skipLanguages = array_map(
+ 'trim',
+ explode( ',', $this->getOption('skiplanguages'
) )
+ );
+ }
-EOT
- );
- exit( 1 );
+ $bot->comment = $this->getOption( 'comment' );
+ $bot->dryrun = !$this->hasOption( 'really' );
+ $bot->execute();
+ }
+
+ /**
+ * Public alternative for protected Maintenance::output() as we need to
get
+ * messages from the ChangeSyncer class to the commandline.
+ * @param string $out The text to show to the user
+ * @param string $channel Unique identifier for the channel.
+ */
+ public function myOutput( $out, $channel = null ) {
+ $this->output( $out, $channel );
+ }
}
-
-if ( isset( $options['help'] ) ) {
- showUsage();
-}
-
-$bot = new FuzzyScript( $args );
-
-if ( isset( $options['skiplanguages'] ) ) {
- $_skipLanguages = array();
- $_skipLanguages = array_map( 'trim', explode( ',',
$options['skiplanguages'] ) );
- $bot->skipLanguages = $_skipLanguages;
-}
-if ( isset( $options['norc'] ) ) {
- $cs->norc = true;
-}
-
-if ( isset( $options['comment'] ) ) {
- $bot->comment = $options['comment'];
-}
-
-if ( isset( $options['really'] ) ) {
- $bot->dryrun = false;
-}
-
-$bot->execute();
-
-/// @endcond
/**
* Class for marking translation fuzzy.
@@ -88,10 +103,17 @@
public $skipLanguages = array();
/**
- * @param string[] $titles
+ * @var Fuzzy
*/
- public function __construct( $titles ) {
+ public $caller;
+
+ /**
+ * @param string[] $titles
+ * @param Fuzzy $caller
+ */
+ public function __construct( $titles, Fuzzy $caller = null ) {
$this->titles = $titles;
+ $this->caller = $caller;
$this->allclear = true;
}
@@ -102,7 +124,7 @@
$msgs = $this->getPages();
$count = count( $msgs );
- STDOUT( "Found $count pages to update." );
+ $this->caller->myOutput( "Found $count pages to update." );
foreach ( $msgs as $phpIsStupid ) {
list( $title, $text ) = $phpIsStupid;
@@ -174,22 +196,22 @@
private function updateMessage( $title, $text, $dryrun, $comment = null
) {
global $wgTranslateDocumentationLanguageCode;
- STDOUT( "Updating {$title->getPrefixedText()}... ", $title );
+ $this->caller->myOutput( "Updating
{$title->getPrefixedText()}... ", $title );
if ( !$title instanceof Title ) {
- STDOUT( "INVALID TITLE!", $title );
+ $this->caller->myOutput( "INVALID TITLE!", $title );
return;
}
$items = explode( '/', $title->getText(), 2 );
if ( isset( $items[1] ) && $items[1] ===
$wgTranslateDocumentationLanguageCode ) {
- STDOUT( "IGNORED!", $title );
+ $this->caller->myOutput( "IGNORED!", $title );
return;
}
if ( $dryrun ) {
- STDOUT( "DRY RUN!", $title );
+ $this->caller->myOutput( "DRY RUN!", $title );
return;
}
@@ -205,6 +227,9 @@
);
$success = $status === true || ( is_object( $status ) &&
$status->isOK() );
- STDOUT( $success ? 'OK' : 'FAILED', $title );
+ $this->caller->myOutput( $success ? 'OK' : 'FAILED', $title );
}
}
+
+$maintClass = 'Fuzzy';
+require_once RUN_MAINTENANCE_IF_MAIN;
--
To view, visit https://gerrit.wikimedia.org/r/89129
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf57e2c912466260abdc92ec62e038fb3dc2c68c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits