diff --git a/README.md b/README.md index 959af89..7b0a055 100644 --- a/README.md +++ b/README.md @@ -1,142 +1,151 @@ # Italian Wikipedia Deletion Bot (BotCancellazioni) This is the software used by the Italian Wikipedia bot "BotCancellazioni" since 2018, running 24/7: https://it.wikipedia.org/wiki/Utente:BotCancellazioni The bot "BotCancellazioni" keeps updated the public deletion logs of Italian Wikipedia pages: https://it.wikipedia.org/wiki/Wikipedia:Pagine_da_cancellare ## Bug Reports / Feature Requests All Italian users are encouraged to discuss in the talk page, on-wiki: https://it.wikipedia.org/wiki/Discussioni_utente:BotCancellazioni All English users, or technical users, are encouraged to file a task in Wikimedia Phabricator, under the column "BotCancellazioni": https://phabricator.wikimedia.org/tag/tool-itwiki/ ## Installation To install this software in your computer, run these commands: ``` sudo apt install git php-cli git clone --recursive https://gitlab.wikimedia.org/valeriobozzolan/itwiki-deletions-info-bot.git ``` ## Update To pull latest changes, run these commands: ``` git pull git submodule update --init --recursive ``` ## Configuration The bot supports a configuration wizard. To start the configuration wizard, just execute the bot at least once (look at "Usage"). If you need to manually configure your bot instead: 1. Open the file `config-example.php` with a text editor 2. Save-as `config.php` 3. Fill your bot credentials using a modern "bot password" - https://it.wikipedia.org/wiki/Speciale:BotPasswords ## Usage -Run on today: +To list all available options: + +``` +$ ./bot.php --help + +usage: ./bot.php [OPTIONS] + --days=DAYS how many days to be processed (default: 1) + --from=YYYY-MM-DD starting date (default: today) + --minutes-ago=N quits if the last edit was below N minutes ago (default: 5) + --ask ask before saving + --verbose verbose mode + --no-term-wrap do not automatically wrap output lines to stay inside your terminal + -h --help show this help and exit +``` + +To run the bot on today: ``` ./bot.php ``` -Run on the latest 10 days from today: +To run on the latest 10 days from today: ``` ./bot.php --days=10 ``` -Run on a specific date (year-month-day): +To run on a specific date (year-month-day): ``` ./bot.php --from=2018-03-13 ``` -Run on a specific date and for 10 days before it: +To run on a specific date and for 10 days before it: ``` ./bot.php --days=10 --from=2018-03-13 ``` -Quit if someone was running the bot just `5` minutes ago (that is the default behaviour): +To quit if someone was running the bot just `5` minutes ago (that is the default behaviour): ``` ./bot.php --minutes-ago=5 ``` -Ask before saving and enable verbose mode: +To ask before saving and enable verbose mode: ``` ./bot.php --ask --verbose ``` -Help: - -``` -./bot.php --help -``` - ## Hacking Most of the behaviours — as the content of the categories, the pages, their edit summaries, etc. — can be changed simply hacking the content of the files from the [/templates](/templates) directory. Trust me, you are able to do it. Start becoming familiar with their structure: ``` This is the place for some documentation, expecially about "placeholders". This is the place for a specific example This is the place for the most important part of this file. This part is what this template will generates. It uses stuff like "$1" or "%1%02d" as generic placeholders. ``` To be honest: everything above the `` line it's pure documentation sugar. It's written to help you. I've spent some minutes on them. Please RTFM. asd A non-traumatic template example can be found [here](templates/CATEGORY_YEAR.content.tpl). It describes the generation of the yearly category. ## Framework You may not want to know this: HTTP connections, MediaWiki APIs (including login and tokens etc.), and other stuff, are handled by the [boz-mw](https://gitpull.it/w/first_steps_with_boz-mw/) framework. ## License Copyright (C) 2018-2026 [Valerio Bozzolan](https://it.wikipedia.org/wiki/Utente:Valerio_Bozzolan), contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Original files released under [Creative Commons BY-SA 3.0 International](https://creativecommons.org/licenses/by-sa/3.0/) and [WMF terms](https://wikimediafoundation.org/wiki/Special:MyLanguage/Terms_of_Use/it) by [Mauro742](https://it.wikipedia.org/wiki/Utente:Mauro742)/[MauroBot](https://it.wikipedia.org/wiki/Utente:MauroBot): * https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/main.js * https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/bot.js * https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/category.js * https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/dateFunctions.js * https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/core.js * https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/globals.js * https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/gui.js diff --git a/bot.php b/bot.php index 225a862..be29834 100755 --- a/bot.php +++ b/bot.php @@ -1,105 +1,112 @@ #!/usr/bin/env php . namespace itwikidelbot; // autoload classes require __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'autoload.php'; use cli\Log; use \Throwable; // Load credentials. // If the file does not exist, a wizard starts. config_wizard( __DIR__ . DIRECTORY_SEPARATOR . 'config.php' ); // the bot must be in sync with the italian community date_default_timezone_set( Page::COMMUNITY_TIMEZONE ); // allowed only from command line interface if( ! isset( $argv[ 0 ] ) ) { exit( 1 ); } // command line arguments $opts = getopt( 'h', [ 'ask', 'days:', 'from:', 'help', 'minutes-ago:', 'verbose', + 'no-term-wrap', ] ); // help message if( isset( $opts[ 'help' ] ) || isset( $opts[ 'h' ] ) ) { printf( "usage: %s [OPTIONS]\n", $argv[ 0 ] ); echo " --days=DAYS how many days to be processed (default: 1)\n"; echo " --from=YYYY-MM-DD starting date (default: today)\n"; echo " --minutes-ago=N quits if the last edit was below N minutes ago (default: 5)\n"; echo " --ask ask before saving\n"; echo " --verbose verbose mode\n"; + echo " --no-term-wrap do not automatically wrap output lines to stay inside your terminal\n"; echo " -h --help show this help and exit\n"; exit( 0 ); } // days to be processed from now to the past $DAYS = isset( $opts[ 'days' ] ) ? (int) $opts[ 'days' ] : 1; // starting date formatted as 'YYYY-MM-DD' $DATE = isset( $opts[ 'from' ] ) ? $opts[ 'from' ] : 'now'; // minimum last edit age $MINUTES = isset( $opts[ 'minutes-ago' ] ) ? (int) $opts[ 'minutes-ago' ] : 5; // ask for every edit if( isset( $opts[ 'ask' ] ) ) { Page::$ASK_BEFORE_SAVING = true; } // verbose mode if( isset( $opts[ 'verbose' ] ) ) { Log::$DEBUG = true; } +// do not fill the terminal columns +if( isset( $opts[ 'no-term-wrap' ] ) ) { + Log::doNotFillTerminalColumns(); +} + Log::info( 'start' ); try { $bot = Bot::createFromString( $DATE ); if( $MINUTES < 1 || $bot->isLasteditOlderThanMinutes( $MINUTES ) ) { for( $i = 0; $i < $DAYS; $i++ ) { $bot->run()->previousDay(); } } else { // do not insist Log::info( sprintf( 'skip: someone running less than %d minutes ago', $MINUTES ) ); } } catch( Throwable $e ) { // Log the exact time of this crash and throw it as-is Log::error( 'unexpected crash:' ); throw $e; } Log::info( 'end' ); diff --git a/includes/boz-mw b/includes/boz-mw index a2f0fad..510084e 160000 --- a/includes/boz-mw +++ b/includes/boz-mw @@ -1 +1 @@ -Subproject commit a2f0fad757c30a9841ee7ba1adff40bcaea614cf +Subproject commit 510084ef0557a02eb9a3148aa59d850577dddf31