From 203f8c866f0d093f77693b5a95a2f0f62507d4c8 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 13 Mar 2022 12:14:32 +0100 Subject: [PATCH] Add 'verbose' option to commandline script. Addresses #61, #48. --- NEWS.md | 4 ++++ README.md | 9 ++++++++- linktitles-cli.php | 24 +++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index b2f2566..c1bcef6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,10 @@ For changes prior to version 6.0.0, please see [`NEWS.old`](news.old). ## Unreleased +### New + +- Added a `--verbose` (`-v`) option to the command line script. + ### Fixed - Ensure compatibility with the PageForms extension (#58) diff --git a/README.md b/README.md index c057045..fe3282a 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ line to `LocalSettings.php`. -#### Maintenance script +#### Commandline If you have access to a shell on the server that runs your wiki, and are allowed to execute `/bin/php` on the command line, you can use the extension's @@ -215,6 +215,13 @@ page that was processed (e.g., 37), and use the maintenance script with the php linktitles-cli.php -s 37 +For more verbose output that also includes the page title, use the `--verbose` +option (or short `-v`): + + php linktitles-cli.php -s 37 -v + +In verbose mode, the script will output all page titles one by one. + See all available options with: php linktitles-cli.php -h diff --git a/linktitles-cli.php b/linktitles-cli.php index 2c96ffe..d9b3c55 100755 --- a/linktitles-cli.php +++ b/linktitles-cli.php @@ -79,6 +79,13 @@ class Cli extends \Maintenance { true, // requires argument "p" ); + $this->addOption( + "verbose", + "print detailed progress information", + false, // not required + false, // does not require an argument + "v" + ); // TODO: Add back logging options. // TODO: Add configuration options. // $this->addOption( @@ -153,6 +160,7 @@ class Cli extends \Maintenance { */ private function allPages( $index = 0 ) { $config = new Config(); + $verbose = $this->hasOption( 'verbose' ); // Retrieve page names from the database. $dbr = $this->getDB( DB_REPLICA ); @@ -178,7 +186,21 @@ class Cli extends \Maintenance { $title = \Title::makeTitleSafe( $row->page_namespace, $row->page_title ); $numProcessed += 1; $index += 1; - $this->output( sprintf( "\rPage #%d (%02.0f%%) ", $index, $numProcessed / $numPages * 100 ) ); + if ( $verbose ) { + $this->output( + sprintf( + "%s - processed %5d of %5d (%2.0f%%) - index %5d - %s", + date("c", time()), + $numProcessed, + $numPages, + $numProcessed / $numPages * 100, + $index, + $title + ) + ); + } else { + $this->output( sprintf( "\rPage #%d (%02.0f%%) ", $index, $numProcessed / $numPages * 100 ) ); + } Extension::processPage( $title, $context ); }