diff --git a/.gitmodules b/.gitmodules
index edf8a9c..e69de29 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +0,0 @@
-[submodule "includes/boz-mw"]
- path = includes/boz-mw
- url = https://github.com/valerio-bozzolan/boz-mw
diff --git a/README.md b/README.md
index 65c4c07..cbf2192 100644
--- a/README.md
+++ b/README.md
@@ -1,101 +1,37 @@
-# Italian Wikipedia Deletion Bot
+# MediaWiki Orphanizer bot
-This software is an Italian Wikipedia bot. It keeps updated the public deletion logs of Italian Wikipedia pages.
+This software is an Italian Wikipedia bot. It delinks the page titles.
-More informations here: https://it.wikipedia.org/wiki/Utente:BotCancellazioni
+Actually this is just a proof-of-concept from an idea of [Parma1983](https://it.wikipedia.org/wiki/Utente:Parma1983) and [.avgas](https://it.wikipedia.org/wiki/Utente:.avgas) and other awesome wikiguys.
## Installation
sudo apt install git php-cli
- git clone --recursive https://github.com/valerio-bozzolan/ItalianWikipediaDeletionBot
+ git clone --recursive https://github.com/valerio-bozzolan/MediaWikiOrphanizerBot.git
## Configuration
1. Open the file [`config-example.php`](config-example.php) with a text editor
2. Fill your bot credentials
3. Save-as `config.php`
## Usage
-Run on today:
-
- ./bot.php
-
-Run on the latest 10 days from today:
-
- ./bot.php --days=10
-
-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:
-
- ./bot.php --days=10 --from=2018-03-13
-
-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:
-
- ./bot.php --ask --verbose
-
-Help:
-
- ./bot.php --help
-
-## Update
-
-To fetch the updates:
-
- git pull --recurse-submodules
-
-## 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://github.com/valerio-bozzolan/boz-mw) framework.
+Please update this section.
## License
-Copyright (C) 2018 [Valerio Bozzolan](https://it.wikipedia.org/wiki/Utente:Valerio_Bozzolan)
+Copyright (C) 2019 [Valerio Bozzolan](https://it.wikipedia.org/wiki/Utente:Valerio_Bozzolan)
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
deleted file mode 100755
index 6d38286..0000000
--- a/bot.php
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/php
-.
-
-namespace itwikidelbot;
-
-// autoload classes
-require __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'autoload.php';
-
-use cli\Log;
-
-// load credentials
-require __DIR__ . DIRECTORY_SEPARATOR . 'config.php';
-
-// the bot must be in sync with the italian community
-date_default_timezone_set( 'Europe/Rome' );
-
-// 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',
-] );
-
-// 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 " -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;
-}
-
-Log::info( 'start' );
-
-$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
- ) );
-}
-
-Log::info( 'end' );
diff --git a/includes/autoload.php b/includes/autoload.php
index a7d2bb6..1bef3fe 100644
--- a/includes/autoload.php
+++ b/includes/autoload.php
@@ -1,30 +1,17 @@
.
-// autoload local classes
-spl_autoload_register( function( $name ) {
- $prefix = substr( $name, 0, 13 );
- if( 'itwikidelbot\\' === $prefix ) {
- $name = substr( $name, 13 );
- $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php";
- if( ! file_exists( $path ) ) {
- throw new Exception( "missing class $name" );
- }
- require __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php";
- }
-} );
-
// autoload boz-mw classes
-require __DIR__ . DIRECTORY_SEPARATOR . 'boz-mw' . DIRECTORY_SEPARATOR . 'autoload.php';
+require __DIR__ . '/boz-mw/autoload.php';
diff --git a/includes/class-Bot.php b/includes/class-Bot.php
deleted file mode 100644
index 341ee87..0000000
--- a/includes/class-Bot.php
+++ /dev/null
@@ -1,289 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use cli\Log;
-use DateTime;
-use DateInterval;
-use Exception;
-
-/**
- * The Bot class helps in running the bot
- */
-class Bot {
-
- /**
- * The date
- *
- * @var DateTime
- */
- private $dateTime;
-
- /**
- * A cache of already done dates.
- * It's an array of booleans like [year][month] = true.
- *
- * @var array
- */
- private $cache = [];
-
- /**
- * Construct
- *
- * @param $date DateTime
- */
- public function __construct( DateTime $date = null ) {
- if( ! $date ) {
- $date = new DateTime();
- }
- $this->setDate( $date );
- }
-
- /**
- * Static construct
- *
- * @param $date string
- */
- public static function createFromString( $date = 'now' ) {
- return new self( new DateTime( $date ) );
- }
-
- /**
- * Static construct
- *
- * @param $y int Year
- * @param $m int Month 1-12
- * @param $d int Day 1-31
- */
- public static function createFromYearMonthDay( $y, $m, $d ) {
- return new self( DateTime::createFromFormat( "Y m d", "$y $m $d") );
- }
-
- /**
- * Get the date
- *
- * @return DateTime
- */
- public function getDate() {
- return $this->dateTime;
- }
-
- /**
- * Set the date
- *
- * @param $date DateTime
- * @return self
- */
- public function setDate( DateTime $date ) {
- $this->dateTime = $date;
- }
-
- /**
- * Add a day
- *
- * @return self
- */
- public function nextDay() {
- return $this->addDays( 1 );
- }
-
- /**
- * Add a day
- *
- * @return self
- */
- public function previousDay() {
- return $this->subDays( 1 );
- }
-
- /**
- * Add a certain number of days
- *
- * @param $days int
- * @return self
- */
- public function addDays( $days ) {
- $this->getDate()->add( new DateInterval( sprintf(
- 'P%dD',
- $days
- ) ) );
- return $this;
- }
-
- /**
- * Subtract a certain number of days
- *
- * @param $days int
- * @return self
- */
- public function subDays( $days ) {
- $this->getDate()->sub( new DateInterval( sprintf(
- 'P%dD',
- $days
- ) ) );
- return $this;
- }
-
- /**
- * Fetch the last bot edit on the next page
- *
- * @return DateTime|null
- */
- public function fetchLastedit() {
- $lastedit = null;
- try {
- $lastedit = PageYearMonthDayPDCsCount::createFromDateTime( $this->getDate() )
- ->fetchLasteditDate();
-
- } catch( Exception $e ) {
- // Unexisting. OK.
- }
- return $lastedit;
- }
-
- /**
- * Is the last edit date older than some seconds? (on the next page)
- *
- * @param $seconds int
- * @return bool
- */
- public function isLasteditOlderThanSeconds( $seconds ) {
- $lastedit = $this->fetchLastedit();
- if( ! $lastedit ) {
- return true; // Unexisting. OK.
- }
- return time() - $lastedit->format( 'U' ) > $seconds;
- }
-
- /**
- * Is the last edit date older than some minutes? (on the next page)
- *
- * @param $minutes int
- * @return bool
- */
- public function isLasteditOlderThanMinutes( $minutes ) {
- return $this->isLasteditOlderThanSeconds( 60 * $minutes );
- }
-
- /**
- * Run the bot at the internal date
- *
- * @TODO: do not repeat twice the same yearly and montly categories
- * @return self
- */
- public function run() {
-
- $cache = & $this->cache;
-
- // date initialization
- $date = $this->getDate();
- $year = $date->format( 'Y' );
- $month = $date->format( 'n' ); // 1-12
- $day = $date->format( 'j' );
-
- // yearly category
- $y_category = new CategoryYear( $year );
-
- // monthly category
- $m_category = new CategoryYearMonth( $year, $month );
-
- // create all the PDC types
- $category_types = [];
- foreach( CategoryYearMonthDayTypes::all() as $CategoryType ) {
- $category_types[] = new $CategoryType( $year, $month, $day );
- }
-
- // all the categories
- $all_categories = $category_types;
- if( ! isset( $cache[ $month ] ) ) {
- $all_categories[] = $m_category;
- }
- if( ! isset( $cache[ $year ] ) ) {
- $all_categories[] = $y_category;
- }
-
- // check in bulk if the categories already exist
- Pages::populateWheneverTheyExist( $all_categories );
-
- // create the yearly category (once)
- if( ! isset( $cache[ $year ] ) ) {
- $cache[ $year ] = [];
- $y_category->saveIfNotExists();
- }
-
- // create the monthly category (once)
- $cache = & $cache[ $year ];
- if( ! isset( $cache[ $month ] ) ) {
- $cache[ $month ] = true;
- $m_category->saveIfNotExists();
- }
-
- Log::info( "work on $year/$month/$day" );
-
- // PDCs indexed by page ID
- $pdcs = [];
-
- // handle every PDC type
- foreach( $category_types as $category_type ) {
-
- // fetch PDCs from this type
- $category_type_pdcs = $category_type->fetchPDCs();
-
- // save the specific daily category type only if it's not empty
- // ...or only if it's the main category (that can be without pages)
- if( $category_type_pdcs || get_class( $category_type ) === CategoryYearMonthDay::class ) {
- $category_type->saveIfNotExists();
- }
-
- // merge the same PDCs into one
- foreach( $category_type_pdcs as $category_type_pdc ) {
- $id = $category_type_pdc->getID();
- if( isset( $pdcs[ $id ] ) ) {
- $pdcs[ $id ]->merge( $category_type_pdc );
- } else {
- $pdcs[ $id ] = $category_type_pdc;
- }
- }
- }
-
- // select only the PDCs that belong to this date
- $pdcs = PDCs::filterByDate( $pdcs, $date );
-
- Log::info( sprintf( sprintf(
- "found %d PDCs",
- count( $pdcs )
- ) ) );
-
- // populate missing informations
- PDCs::populateMissingInformations( $pdcs );
-
- // sort by creation date
- PDCs::sortByCreationDate( $pdcs );
-
- // index then by their PDC_TYPE
- $pdcs_by_type = PDCs::indexByType( $pdcs );
-
- // save the counting page
- PageYearMonthDayPDCsCount::createFromDateTimePDCs( $this->getDate(), $pdcs_by_type )
- ->save();
-
- // save the log page
- PageYearMonthDayPDCsLog::createFromDateTimePDCs( $this->getDate(), $pdcs_by_type )
- ->save();
-
- return $this;
- }
-}
diff --git a/includes/class-CategoryYear.php b/includes/class-CategoryYear.php
deleted file mode 100644
index d3efbfa..0000000
--- a/includes/class-CategoryYear.php
+++ /dev/null
@@ -1,40 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle a yearly category
- *
- * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_-_2017
- */
-class CategoryYear extends PageYear {
-
- /**
- * Template name of this category
- *
- * @override CategoryTemplated::TEMPLATE_NAME
- */
- const TEMPLATE_NAME = 'CATEGORY_YEAR';
-
-}
diff --git a/includes/class-CategoryYearMonth.php b/includes/class-CategoryYearMonth.php
deleted file mode 100644
index b4fc392..0000000
--- a/includes/class-CategoryYearMonth.php
+++ /dev/null
@@ -1,53 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle a monthly category
- *
- * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_-_aprile_2018
- */
-class CategoryYearMonth extends PageYearMonth {
-
- /**
- * Template name of this category
- *
- * @override CategoryTemplated::TEMPLATE_NAME
- */
- const TEMPLATE_NAME = 'CATEGORY_MONTH';
-
- /**
- * Template arguments
- *
- * @override CategoryTemplated::getTemplateArguments()
- */
- public function getTemplateArguments() {
- return array_merge( [
- ( new CategoryYear( $this->getYear() ) )
- ->getTemplatedTitle()
- ],
- parent::getTemplateArguments()
- );
- }
-}
diff --git a/includes/class-CategoryYearMonthDay.php b/includes/class-CategoryYearMonthDay.php
deleted file mode 100644
index 9c64791..0000000
--- a/includes/class-CategoryYearMonthDay.php
+++ /dev/null
@@ -1,289 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use \cli\Log;
-
-/**
- * Handle a daily category that directly contains semplified ("semplificate") PDC pages
- * It contains other sub-categories.
- *
- * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_del_19_febbraio_2018
- */
-class CategoryYearMonthDay extends PageYearMonthDay {
-
- /**
- * Template name
- *
- * @override CategoryTemplated::TEMPLATE_NAME
- */
- const TEMPLATE_NAME = 'CATEGORY_DAY';
-
- /**
- * PDC type
- *
- * The part of the category title that rappresent this type of PDC.
- */
- const PDC_TYPE = 'semplificate';
-
- /**
- * PDC type (in an human form)
- *
- * Abbreviation of the PDC_TYPE. It's used in the counting page.
- *
- * @var string
- */
- const PDC_TYPE_HUMAN = 'semplificata';
-
- /**
- * Title format
- *
- * Used to describe both the plain text title and its matching pattern.
- *
- * Don't use placeholders different from '%s'.
- *
- * Arguments:
- * 1: day
- * 2: month name
- * 3: year
- */
- const TITLE_FORMAT = 'Categoria:Cancellazioni del %s %s %s';
-
- /**
- * Title format arguments
- *
- * Arguments that can create this page title, when filling the title format.
- *
- * @return array Arguments for the TITLE_FORMAT
- */
- protected function getTitleFormatArguments() {
- return [
- $this->getDay(), // 1: day
- $this->getMonthName(), // 2: month name
- $this->getYear(), // 3: year
- ];
- }
-
- /**
- * Title format pattern groups
- *
- * Regex groups that can create a regex for this page title, when filling the title format.
- *
- * @return array Array of regex groups for the TITLE_FORMAT
- */
- protected static function titleFormatGroups() {
- return [
- '([0-9]{1,2})', // 1: day
- '([a-z]+)', // 2: month name
- '([0-9]{4})', // 3: year
- ];
- }
-
- /**
- * Title regex
- *
- * Complete regex that can match arguments (day, month, etc.) from a page title.
- *
- * @return string regex
- */
- protected static function titleRegex() {
- return '/^' . vsprintf( static::TITLE_FORMAT, static::titleFormatGroups() ) . '$/';
- }
-
- /**
- * Get the title of this page
- *
- * It's obtained filling the title format with its arguments.
- *
- * @override PageTemplated#getTemplatedTitle()
- * @return string
- */
- public function getTemplatedTitle() {
- return vsprintf( static::TITLE_FORMAT, $this->getTitleFormatArguments() );
- }
-
- /**
- * Static constructor
- *
- * Create an CategoryYearMonthDay object extracting informations from a specific page title (if it matches the title format).
- *
- * @param $title string Page title to be matched
- * @return self|false
- */
- public static function createParsingTitle( $title ) {
- if( 1 === preg_match( static::titleRegex(), $title, $matches ) ) {
-
- // discard the first match group: it's simply the $title itself
- array_shift( $matches );
-
- return static::createFromTitleFormatArguments( $matches );
- }
- return false;
- }
-
- /**
- * Static constructor
- *
- * Create a CategoryYearMonthDay object from its title format arguments
- *
- * @see self::createFromTitle()
- * @see PageYearMonth::__construct()
- * @param $arguments Arguments for the page title format
- * @return self
- */
- protected static function createFromTitleFormatArguments( $arguments ) {
- list( $day, $month_name, $year ) = $arguments;
- return new static(
- (int) $year,
- Months::name2number( $month_name ) + 1,
- (int) $day
- );
- }
-
- /**
- * Template arguments:
- *
- * 1: category title
- * 2: year
- * 3: month 1-12
- * 4: month name
- * 5: day 1-31
- *
- * @override CategoryYearMonth::getTemplateArguments()
- */
- public function getTemplateArguments() {
- return array_merge(
- [ ( new CategoryYearMonth( $this->getYear(), $this->getMonth() ) )
- ->getTemplatedTitle() ],
- parent::getTemplateArguments()
- );
- }
-
- /**
- * Fetch PDCs from this category
- *
- * @return array
- */
- public function fetchPDCs() {
- $api = self::api()->createQuery( [
- 'action' => 'query',
-
- // generator=categorymembers: get pages in category
- // gmtitle=: specify the category title
- // gmtype=page: get sub-pages
- // gmsort=timestamp: order by insertion date in that category
- // gmdir=asc: ascending order
- // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Bcategorymembers
- // Note: Generator parameter names must be prefixed with a 'g'
- 'generator' => 'categorymembers',
- 'gcmtitle' => $this->getTitle(),
-// 'gcmtype' => 'page', // Note: Ignored when cmsort=timestamp is set.
- 'gcmnamespace' => 4, // Wikipedia
- 'gcmlimit' => 100,
- 'gcmsort' => 'timestamp',
- 'gcmdir' => 'asc',
-//
- // for each page load infos, categories and latest revision
- // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Binfo
- // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Bcategories
- // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Brevisions
- // Note: probably the revisions parameter is unuseful for last update date (already provided by "touched").
- // Note: revisions can be still useful to know the creation date
- 'prop' => [ 'info' , 'categories'/*, 'revisions'*/ ],
-
- // inprop=protecion: list of the protection level of each page
- // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Bcategories
- 'inprop' => 'protection',
-
- // clprop=sortkey: adds the sortkey and sortkey prefix for the category
- // clprop=timestamp: adds the timestamp of when the page was included
- // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Binfo
- 'clprop' => [ 'sortkey', 'timestamp' ],
-
- // rvprop=timestamp: timestamp of the revision
- // rvlimit=1: only 1 revision
- // rvdir=older: order by oldest
- // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Brevisions
-// 'rvprop' => 'timestamp',
-// 'rvdir' => 'older',
-// 'rvlimit' => 1,
- ] );
-
- $all = [];
- while( $api->hasNext() ) {
- $next = $api->fetchNext();
-
- if( isset( $next->query->pages ) ) {
- foreach( $next->query->pages as $page ) {
-
- // multiple call will add more infos on the same page
- // https://www.mediawiki.org/wiki/API:Query#Generators_and_continuation
- // TODO: use batchcomplete for better memory usage
- $pageid = $page->pageid;
- if( isset( $all[ $pageid ] ) ) {
- foreach( $page as $property => $value ) {
- if( isset( $all[ $pageid ]->{$property} ) && is_array( $all[ $pageid ]->{$property} ) ) {
- // merge categories
- $all[ $pageid ]->{$property} = array_merge(
- $all[ $pageid ]->{$property},
- $value
- );
- } else {
- $all[ $pageid ]->{$property} = $value;
- }
- }
- } else {
- $all[ $pageid ] = $page;
- }
- }
- }
- }
-
- $pdcs = [];
- foreach( $all as $page ) {
- try {
- $pdcs[] = PDC::createFromRaw( $page );
- } catch( PDCException $e ) {
- Log::warn( sprintf(
- "exception in PDC '%s': %s",
- $page->title,
- $e->getMessage()
- ) );
- }
- }
-
- return $pdcs;
- }
-
- /**
- * Get a "genericity" score of this PDC category type.
- *
- * @see CategoryYearMonthDayTypes::genericityFromClass()
- * @return int
- */
- public static function genericity() {
- return CategoryYearMonthDayTypes::genericityFromClass( static::class );
- }
-
-}
diff --git a/includes/class-CategoryYearMonthDayType.php b/includes/class-CategoryYearMonthDayType.php
deleted file mode 100644
index fb9fb6f..0000000
--- a/includes/class-CategoryYearMonthDayType.php
+++ /dev/null
@@ -1,107 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Abstraction of a daily category with a specified PDC type
- */
-abstract class CategoryYearMonthDayType extends CategoryYearMonthDay {
-
- /**
- * Template name of this category
- *
- * @override CategoryTemplated::TEMPLATE_NAME
- */
- const TEMPLATE_NAME = 'CATEGORY_DAY_PDCTYPE';
-
- /**
- * Title format
- *
- * Used to describe both the plain text title and its matching pattern.
- *
- * Don't use placeholders different from '%s'.
- *
- * Arguments:
- * 1: PDC type
- * 4: day
- * 3: human month
- * 2: year
- *
- * @override CategoryYearMonthDay::TITLE_FORMAT
- */
- const TITLE_FORMAT = 'Categoria:Cancellazioni %s del %s %s %s';
-
- /**
- * Title format arguments
- *
- * Arguments that can create this page title, when filling the title format.
- *
- * @return array Arguments for the TITLE_FORMAT
- * @override CategoryYearMonthDay::getTitleFormatArguments()
- */
- protected function getTitleFormatArguments() {
- return [
- static::PDC_TYPE, // 1: PDC type
- $this->getDay(), // 2: day
- $this->getMonthName(), // 3: month name
- $this->getYear(), // 4: year
- ];
- }
-
- /**
- * Title format regex groups
- *
- * Regex groups that can create a regex for this page title, when filling the title format.
- *
- * @return array Array of regex groups for the TITLE_FORMAT
- * @override CategoryYearMonthDay::titleFormatGroups()
- */
- protected static function titleFormatGroups() {
- return [
- preg_quote( static::PDC_TYPE ), // 1: PDC type (it's correct that is not grouped)
- '([0-9]{1,2})', // 2: day
- '([a-z]+)', // 3: month name
- '([0-9]{4})', // 4: year
- ];
- }
-
- /**
- * Get template arguments
- *
- * 1: category title
- * 2: year
- * 3: month 1-12
- * 4: month name
- * 5: day 1-31
- * 6: PDC type
- *
- * @override CategoryTemplated::getTemplateArguments()
- */
- public function getTemplateArguments() {
- $parent_arguments = parent::getTemplateArguments();
- $parent_arguments[] = static::PDC_TYPE;
- return $parent_arguments;
- }
-
-}
diff --git a/includes/class-CategoryYearMonthDayTypeConsensual.php b/includes/class-CategoryYearMonthDayTypeConsensual.php
deleted file mode 100644
index 29f1ce1..0000000
--- a/includes/class-CategoryYearMonthDayTypeConsensual.php
+++ /dev/null
@@ -1,46 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle a daily consensual PDC category
- *
- * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_consensuali_del_13_aprile_2018
- */
-class CategoryYearMonthDayTypeConsensual extends CategoryYearMonthDayType {
-
- /**
- * PDC type
- *
- * @override CategoryYearMonthDay::PDC_TYPE
- */
- const PDC_TYPE = 'consensuali';
-
- /**
- * PDC human type
- *
- * @override CategoryYearMonthDay::PDC_TYPE_HUMAN
- */
- const PDC_TYPE_HUMAN = 'consensuale';
-}
diff --git a/includes/class-CategoryYearMonthDayTypeOrdinary.php b/includes/class-CategoryYearMonthDayTypeOrdinary.php
deleted file mode 100644
index 901f4ea..0000000
--- a/includes/class-CategoryYearMonthDayTypeOrdinary.php
+++ /dev/null
@@ -1,46 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle a daily ordinary PDC category
- *
- * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_ordinarie_del_25_giugno_2012
- */
-class CategoryYearMonthDayTypeOrdinary extends CategoryYearMonthDayType {
-
- /**
- * PDC type
- *
- * @override CategoryYearMonthDay::PDC_TYPE
- */
- const PDC_TYPE = 'ordinarie';
-
- /**
- * PDC human type
- *
- * @override CategoryYearMonthDay::PDC_TYPE_HUMAN
- */
- const PDC_TYPE_HUMAN = 'ordinaria';
-}
diff --git a/includes/class-CategoryYearMonthDayTypeProlonged.php b/includes/class-CategoryYearMonthDayTypeProlonged.php
deleted file mode 100644
index f61d3aa..0000000
--- a/includes/class-CategoryYearMonthDayTypeProlonged.php
+++ /dev/null
@@ -1,46 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle a daily prolonged PDC category
- *
- * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_consensuali_prorogate_del_11_aprile_2018
- */
-class CategoryYearMonthDayTypeProlonged extends CategoryYearMonthDayType {
-
- /**
- * PDC type
- *
- * @override CategoryYearMonthDayType::PDC_TYPE
- */
- const PDC_TYPE = 'consensuali prorogate';
-
- /**
- * PDC human type
- *
- * @override CategoryYearMonthDay::PDC_TYPE_HUMAN
- */
- const PDC_TYPE_HUMAN = 'consensuale prorogata';
-}
diff --git a/includes/class-CategoryYearMonthDayTypeVoting.php b/includes/class-CategoryYearMonthDayTypeVoting.php
deleted file mode 100644
index 3f22ed1..0000000
--- a/includes/class-CategoryYearMonthDayTypeVoting.php
+++ /dev/null
@@ -1,46 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle a daily voting PDC category
- *
- * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_con_votazione_del_13_maggio_2018
- */
-class CategoryYearMonthDayTypeVoting extends CategoryYearMonthDayType {
-
- /**
- * PDC type
- *
- * @override CategoryYearMonthDayType::PDC_TYPE
- */
- const PDC_TYPE = 'con votazione';
-
- /**
- * PDC human type
- *
- * @override CategoryYearMonthDay::PDC_TYPE_HUMAN
- */
- const PDC_TYPE_HUMAN = 'votazione';
-}
diff --git a/includes/class-CategoryYearMonthDayTypes.php b/includes/class-CategoryYearMonthDayTypes.php
deleted file mode 100644
index 38be17d..0000000
--- a/includes/class-CategoryYearMonthDayTypes.php
+++ /dev/null
@@ -1,156 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use InvalidArgumentException;
-
-/**
- * Handler of all the PDC type categories
- */
-class CategoryYearMonthDayTypes {
-
- /**
- * PDC types
- *
- * Categories in order of importance (I think)
- *
- * @var array
- */
- public static $TYPES = [
- CategoryYearMonthDayTypeVoting ::class, // voting
- CategoryYearMonthDayTypeOrdinary ::class, // ordinary
- CategoryYearMonthDayTypeProlonged ::class, // prolonged
- CategoryYearMonthDayTypeConsensual::class, // consensual
- CategoryYearMonthDay ::class, // simple
- ];
-
- /**
- * Other types of categories
- *
- * @var array
- */
- private static $OTHER_KNOWN_CATEGORIES = [
- 'Categoria:Procedure di cancellazione protette',
- 'Categoria:Procedure di cancellazione multiple in corso',
- 'Categoria:Pagine protette - scadute',
- 'Categoria:Pagine di servizio protette',
- ];
-
- /**
- * Get all the types
- *
- * @return array
- */
- public static function all() {
- return self::$TYPES;
- }
-
- /**
- * Create the corresponding category object from its title
- *
- * @param $title string Page title
- * @return CategoryYearMonthDay|false
- */
- public static function createParsingTitle( $title ) {
- foreach( self::all() as $Type ) {
- $category = $Type::createParsingTitle( $title );
- if( $category ) {
- return $category;
- }
- }
- if( ! in_array( $title, self::$OTHER_KNOWN_CATEGORIES, true ) ) {
- throw new PDCException( "unexpected PDC category '$title'" );
- }
- return false;
- }
-
- /**
- * Get a "genericity" score of a certain PDC category class name.
- *
- * Useful to comparate PDC types.
- *
- * E.g. a "simple" PDC has an higher score over a "consensual" PDC.
- *
- * @param $category string Class name
- * @return int 0-4
- */
- public static function genericityFromClass( $category_class_name ) {
- $i = array_search( $category_class_name, self::all(), true );
- if( false === $i ) {
- throw new InvalidArgumentException( "unknown class name $category_class_name" );
- }
- return $i;
- }
-
- /**
- * Get a "genericity" score of a certain PDC category instance.
- *
- * @see self::genericity()
- * @param $category CategoryYearMonthDay
- * @return int 0-4
- */
- public static function genericityFromObject( CategoryYearMonthDay $category ) {
- return self::genericityFromClass( get_class( $category ) );
- }
-
- /**
- * Find the best category (the most recent) from a list
- *
- * @param $categories CategoryYearMonthDay[]
- * @return CategoryYearMonthDay One of the $categories
- */
- public static function findBestCategory( $categories ) {
- $best = null;
- foreach( $categories as $category ) {
- if( ! $best ) {
- $best = $category;
- } elseif( $category->getDateTime()->format('Y-m-d') === $best->getDateTime()->format('Y-m-d') ) {
- // the day is the same: take the most precise
- if( self::genericityFromObject( $category ) < self::genericityFromObject( $best ) ) {
- $best = $category;
- }
- } elseif( $category->getDateTime() > $best->getDateTime() ) {
- // take the newest
- $best = $category;
- }
- }
- if( ! $best ) {
- throw new PDCException( 'cannot find the best categories' );
- }
- return $best;
- }
-
- /**
- *
- *
- * @param $year int
- * @param $month int
- * @param $day int
- * @return PDC[]
- */
- public static function fetchYearMonthDayPDCs( $year, $month, $day ) {
- $pdcs_by_id = [];
- }
-
-}
diff --git a/includes/class-Months.php b/includes/class-Months.php
deleted file mode 100644
index 33584c2..0000000
--- a/includes/class-Months.php
+++ /dev/null
@@ -1,90 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Singleton that handle months
- */
-class Months {
-
- /**
- * Months
- *
- * @var array
- */
- private static $_months;
-
- /**
- * Get the names of the months
- *
- * @return array Names of months
- */
- public static function months() {
- if( ! self::$_months ) {
- self::$_months = [
- 'gennaio',
- 'febbraio',
- 'marzo',
- 'aprile',
- 'maggio',
- 'giugno',
- 'luglio',
- 'agosto',
- 'settembre',
- 'ottobre',
- 'novembre',
- 'dicembre'
- ];
- }
- return self::$_months;
- }
-
- /**
- * Get a month number from a month name
- *
- * @param $month_name string Month name e.g. 'gennaio'
- * @return int Month number 0-11 e.g. 0
- */
- public static function name2number( $month_name ) {
- $i = array_search( $month_name, self::months(), true );
- if( false === $i ) {
- throw new \InvalidArgumentException( 'unexpected month name' );
- }
- return $i;
- }
-
- /**
- * Get a month name from a month number
- *
- * @param $month_number int Month number 0-11 e.g. 0
- * @return string Month name e.g. 'gennaio'
- */
- public static function number2name( $month_number ) {
- if( $month_number < 0 || $month_number > 11 ) {
- throw new \InvalidArgumentException( 'unexpected month number' );
- }
- $months = self::months();
- return $months[ $month_number ];
- }
-}
diff --git a/includes/class-PDC.php b/includes/class-PDC.php
deleted file mode 100644
index 441afa5..0000000
--- a/includes/class-PDC.php
+++ /dev/null
@@ -1,759 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use DateTime;
-
-/**
- * Handle a "Procedura di cancellazione"
- *
- * It is a page like "Wikipedia:Pagine da cancellare/ASD"
- */
-class PDC extends Page {
-
- /**
- * Prefix of every PDC
- */
- const PREFIX = 'Wikipedia:Pagine da cancellare/';
-
- /**
- * Prefix of every multiple PDC
- */
- const PREFIX_MULTIPLE = 'Wikipedia:Pagine da cancellare/multiple/';
-
- /**
- * Name for the category for running PDCs
- *
- * N.B. 'multiple' PDCs have also this category.
- */
- const RUNNING_CAT = 'Categoria:Procedure di cancellazione in corso';
-
- /**
- * Day threshold
- *
- * This is a number between 0 and 1. The more it is near to 0,
- * the more the PDC duration will be floored.
- */
- const DAY_THRESHOLD = 0.7; // 16:47~
-
- /**
- * PDC category type
- *
- * @var CategoryYearMonthDay
- */
- private $categoryType;
-
- /**
- * Page id
- *
- * @var int
- */
- private $id;
-
- /**
- * Title of the PDC subject page (the Wikipedia article title)
- *
- * Obtained from {{DEFAULTSORT}} category sortkey
- *
- * @var string
- */
- private $titleSubject;
-
- /**
- * Subject themes
- *
- * E.g. [ 'software libero', 'LGBT', 'società' ]
- *
- * @var array
- */
- private $subjectThemes = [];
-
- /**
- * Page length in bytes
- *
- * @var int
- */
- private $length;
-
- /**
- * Creation date
- *
- * @var date
- */
- private $creationDate;
-
- /**
- * Last update
- *
- * @var date
- */
- private $lasteditDate;
-
- /**
- * Is protected?
- *
- * @var bool
- */
- private $isProtected;
-
- /**
- * Is running?
- *
- * @var bool
- */
- private $isRunning;
-
- /**
- * Properties that the raw object must have
- *
- * @see self::createFromRaw()
- * @var array
- */
- private static $RAW_PROPERTIES = [
- 'pageid',
- 'title',
- 'length',
- 'touched',
- 'protection',
- 'categories',
- ];
-
- /**
- * Properties that a raw category must have
- *
- * @see self::createFromRaw()
- * @var array
- */
- private static $RAW_CATEGORY_PROPERTIES = [
- 'title',
- 'sortkeyprefix',
- 'timestamp', // TODO: remove as dependency if it's unuseful
- ];
-
- /**
- * Constructor
- *
- * @param $category_type CategoryYearMonthDay PDC category type
- * @param $id int PDC page id
- * @param $title string PDC title prefixed
- * @param $title_subject string Title of the subject page (the Wikipedia article title)
- * @param $length int PDC length
- * @param $creation DateTime|null PDC creation date
- * @param $is_protected bool Is the PDC protected?
- * @param $is_running bool Is the PDC running?
- * @see Page::__construct()
- * @throws PDCException
- */
- public function __construct( CategoryYearMonthDay $category_type, $id, $title, $title_subject, $length, $creation, $is_protected, $is_running ) {
- $this->id = $id;
- $this->titleSubject = $title_subject;
- $this->length = $length;
- $this->isProtected = $is_protected;
- $this->isRunning = $is_running;
- $this->setCreationDate( $creation );
- $this->setCategoryType( $category_type );
-
- parent::__construct( $title );
-
- // consistence checks
- if( ! $this->isTitlePrefixValid() ) {
- throw new PDCException( 'not a PDC' );
- }
- }
-
- /**
- * Static constructor
- *
- * @see YearMonthDayTypes::fetchPDCs()
- * @param $page mixed
- * @return self
- * @throws PDCException
- */
- public static function createFromRaw( $page ) {
-
- // verify the API response consistence
- foreach( self::$RAW_PROPERTIES as $property ) {
- if( ! isset( $page->$property ) ) {
- throw new PDCException( "missing property $property" );
- }
- }
- foreach( $page->categories as $category_raw ) {
- foreach( self::$RAW_CATEGORY_PROPERTIES as $property ) {
- if( ! isset( $category_raw->$property ) ) {
- throw new PDCException( "missing property $property in categories" );
- }
- }
- }
- if( 0 === count( $page->categories ) ) {
- throw new PDCException( "no category" );
- }
-
- // get the page title of the subject from the {{DEFAULTSORT:xxx}} value
- $title_subject = null;
- foreach( $page->categories as $category_raw ) {
- $title_subject = $category_raw->sortkeyprefix;
- break;
- }
-
- // is this PDC running?
- $is_running = false;
-
- // array of instances of the class CategoryYearMonthDay (and subclasses)
- // they also have the timestamp property
- $categories = [];
- foreach( $page->categories as $category_raw ) {
- if( self::RUNNING_CAT === $category_raw->title ) {
- $is_running = true;
- break;
- }
- $category = CategoryYearMonthDayTypes::createParsingTitle( $category_raw->title );
- if( $category ) {
- $category->timestamp = self::createDateTimeFromString( $category_raw->timestamp );
- $categories[] = $category;
- }
- }
-
- // creation date
- $creation = null;
- foreach( $categories as $category ) {
- if( get_class( $category ) === CategoryYearMonthDay::class ) {
- $creation_secure_unprecise = $category->getDateTime();
- $creation_unsecure_precise = $category->timestamp;
- if( $creation_secure_unprecise->format( 'Y-m-d' ) === $creation_unsecure_precise->format( 'Y-m-d' ) ) {
- $creation = $creation_unsecure_precise;
- }
- break;
- }
- }
-
- if( ! $categories ) {
- throw new PDCException( sprintf(
- "the PDC was in %d categories and/but no one was recognized",
- count( $page->categories )
- ) );
- }
-
- // find the best (the newest) category to be applied
- $best_category = CategoryYearMonthDayTypes::findBestCategory( $categories );
-
- // read protection status
- $is_protected = false;
- foreach( $page->protection as $protection ) {
- if( 'edit' === $protection->type && 'sysop' === $protection->level ) {
- $is_protected = true;
- break;
- }
- }
-
- return new self(
- $best_category,
- (int) $page->pageid,
- $page->title,
- $title_subject,
- (int) $page->length,
- $creation,
- $is_protected,
- $is_running
- );
- }
-
- /**
- * Get the page id
- *
- * @return int
- */
- public function getId() {
- return $this->id;
- }
-
- /**
- * Get the title of the subject page (the Wikipedia article title)
- *
- * Obtained from {{DEFAULTSORT}} category sortkey
- *
- * @return string
- */
- public function getTitleSubject() {
- return $this->titleSubject;
- }
-
- /**
- * Get the subject themes
- *
- * E.g. [ 'software libero', 'LGBT', 'società' ]
- *
- * @return array
- */
- public function getSubjectThemes() {
- return $this->subjectThemes;
- }
-
- /**
- * Ad a subject themes
- *
- * @param $theme string Subject theme e.g. 'software libero'
- * @return self
- */
- public function addSubjectTheme( $theme ) {
- $this->subjectThemes[] = $theme;
- return $this;
- }
-
- /**
- * Get the turnover number
- *
- * It's the '/2' number in the PDC title.
- *
- * @return int|false
- */
- public function getTurnover() {
- $safe_title = preg_quote( $this->getTitleSubject(), '@' );
- $pattern = "@$safe_title/([0-9]+)\$@";
- $found = preg_match( $pattern, $this->getTitle(), $matches );
- if( 1 === $found ) {
- return (int) $matches[ 1 ];
- }
- return false;
- }
-
- /**
- * Get the page length
- *
- * @return int
- */
- public function getLength() {
- return $this->length;
- }
-
- /**
- * Get the category type
- *
- * @return CategoryYearMonthDay
- */
- public function getCategoryType() {
- return $this->categoryType;
- }
-
- /**
- * Set the category type
- *
- * @param $category_type CategoryYearMonthDay
- * @return self
- */
- public function setCategoryType( CategoryYearMonthDay $category_type ) {
- $this->categoryType = $category_type;
- return $this;
- }
-
- /**
- * Get the start date of this PDC (of this type)
- *
- * @return DateTime
- */
- public function getStartDate() {
- return $this->getCategoryType()->getDateTime();
- }
-
- /**
- * It has the creation date cached?
- *
- * @return bool
- */
- public function hasCreationDate() {
- return isset( $this->creationDate );
- }
-
- /**
- * Get the creation date
- *
- * @return DateTime
- */
- public function getCreationDate() {
- if( ! $this->hasCreationDate() ) {
- $this->creationDate = $this->fetchCreationDate();
- }
- return $this->creationDate;
- }
-
- /**
- * Set the creation date
- *
- * @param $creation DateTime
- * @return self
- */
- public function setCreationDate( $creation ) {
- $this->creationDate = $creation;
- return $this;
- }
-
- /**
- * It has the latest update date cached?
- *
- * @return bool
- */
- public function hasLasteditDate() {
- return isset( $this->lasteditDate );
- }
-
- /**
- * Get the latest update date
- *
- * Note: this information can't be retrieved by the 'touched' API field
- * because it can be poisoned by purges.
- *
- * @return DateTime
- */
- public function getLasteditDate() {
- if( ! $this->hasLasteditDate() ) {
- $this->lasteditDate = $this->fetchLasteditDate();
- }
- return $this->lasteditDate;
- }
-
- /**
- * Set the lastedit date
- *
- * @param $lastedit DateTime
- * @return self
- */
- public function setLasteditDate( DateTime $lastedit ) {
- $this->lastedit = $lastedit;
- return $this;
- }
-
- /**
- * Get the PDC type class
- *
- * @return class
- */
- public function getTypeClass() {
- return get_class( $this->getCategoryType() );
- }
-
- /**
- * Get the PDC type class genericity
- *
- * @see CategoryYearMonthDay::genericity()
- * @return int
- */
- public function getCategoryGenericity() {
- $class_name = self::getTypeClass();
- return $class_name::genericity();
- }
-
- /**
- * Get the PDC type name
- *
- * @return string e.g. 'con votazioni'
- */
- public function getType() {
- $class = $this->getTypeClass();
- return $class::PDC_TYPE;
- }
-
- /**
- * Get the PDC human type
- *
- * @return string e.g. 'votazione'
- */
- public function getHumanType() {
- $class = $this->getTypeClass();
- return $class::PDC_TYPE_HUMAN;
- }
-
- /**
- * Check if this page is protected
- *
- * @return bool
- */
- public function isProtected() {
- return $this->isProtected;
- }
-
- /**
- * Check if this page is running
- *
- * @return bool
- */
- public function isRunning() {
- return $this->isRunning && ! $this->isProtected();
- }
-
- /**
- * Check if this PDC has a known prefix
- *
- * @return bool
- */
- private function isTitlePrefixValid() {
- return $this->titlehasPrefix( self::PREFIX );
- }
-
- /**
- * Check if this PDC involves multiple PDCs
- *
- * @return bool
- */
- public function isMultiple() {
- return $this->titleHasPrefix( self::PREFIX_MULTIPLE );
- }
-
- /**
- * Get the title prefix
- *
- * @return string
- */
- private function getTitlePrefix() {
- return $this->isMultiple()
- ? self::PREFIX_MULTIPLE
- : self::PREFIX;
- }
-
- /**
- * Get the title unprefixed
- *
- * @return string
- */
- public function getTitleUnprefixed() {
- return substr( $this->getTitle(), strlen( $this->getTitlePrefix() ) );
- }
-
- /**
- * Check if the title has a certain prefix
- *
- * @param $prefix string
- * @return bool
- */
- private function titleHasPrefix( $prefix ) {
- return 0 === strpos( $this->getTitle(), $prefix );
- }
-
- /**
- * Check if the title of the subject is consistent with the PDC title
- *
- * @return bool
- */
- public function isTitleSubjectConsistent() {
- // subject from {{DEFAULTSORT}} category prefix
- $subject = $this->getTitleSubject();
-
- // subject generated unprefixing page title
- $subject_gen = $this->getTitleUnprefixed();
-
- if( $subject !== $subject_gen ) {
- // Check if the PDC title ends with an enumeration e.g. 'asd/14'
- $status = preg_match( '@(.*)/[0-9]+$@', $subject_gen, $matches );
- if( 1 === $status ) {
- // Get the interesting part e.g. 'asd'
- $subject_gen = $matches[ 1 ];
- }
- }
- return $subject === $subject_gen;
- }
-
- /**
- * Get the PDC temperature
- *
- * The temperature is a value betweeen 0-100
- *
- * @return int
- */
- public function getTemperature() {
- $slope = null;
- $offset = null;
- switch( $this->getType() ) {
- case CategoryYearMonthDay::PDC_TYPE;
- $slope = 0.0365;
- $offset = -24.0;
- break;
- case CategoryYearMonthDayTypeConsensual::PDC_TYPE:
- $slope = 0.0075;
- $offset = -12.81;
- break;
- case CategoryYearMonthDayTypeProlonged::PDC_TYPE:
- $slope = 0.0035;
- $offset = -9.76;
- break;
- case CategoryYearMonthDayTypeOrdinary::PDC_TYPE:
- case CategoryYearMonthDayTypeVoting ::PDC_TYPE:
- $slope = 0.0025;
- $offset = -16.43;
- break;
- default:
- throw new PDCException( 'unexpected type' );
- }
-
- $temp = round( $slope * $this->getLength() + $offset );
- if ( $temp > 100 ) {
- $temp = 100;
- } elseif ( $temp < 0 ) {
- $temp = 0;
- }
- return $temp;
- }
-
- /**
- * Get the duration of this PDC expressed in days
- *
- * When the PDC is running the user basically wants a simple
- * difference from the creation date to the last edit date,
- * but when the PDC is protected it means that a sysop touched
- * this page at ~midnight so the last edit will be at ~midnight.
- * This is why - when a PDC is protected - the start date time should
- * be moved forward to ~midnight in order to balance the sysop touch.
- *
- * In other words this method gives a "precise duration" when the PDC
- * is running and "legal duration" when the PDC is ended.
- *
- * @see https://it.wikipedia.org/wiki/Wikipedia:Regole_per_la_cancellazione
- * @return int Duration days
- */
- public function getDurationDays() {
- $creation = $this->getCreationDate();
- $creation = clone $creation;
- $lastedit = $this->getLasteditDate();
-
- if( $this->isProtected() ) {
- // Moving forward the creation date to balance the sysop touch
- $creation->setTime( 23, 59, 59 );
- }
-
- $creation_s = $creation->format( 'U' );
- $lastedit_s = $lastedit->format( 'U' );
- $seconds = $lastedit_s - $creation_s;
-
- $days_f = $seconds / 86400;
- $days = (int) floor( $days_f );
- $day_mantissa = $days_f - $days;
- if( $day_mantissa > self::DAY_THRESHOLD ) {
- $days++;
- }
-
- if( $days < 0 ) {
- $days = 0;
- }
- return $days;
- }
-
- /**
- * Get an human rappresentation of the duration of this PDC
- *
- * @return string
- */
- public function getHumanDuration() {
- $days = $this->getDurationDays();
- if( 0 === $days ) {
- return Template::get( 'DURATION.hours' );
- }
- if( 1 === $days ) {
- return Template::get( 'DURATION.day' );
- }
- return Template::get( 'DURATION.days', [ $days ] );
- }
-
- /**
- * Merge a PDC with in this one
- *
- * @param $pdc PDC
- */
- public function merge( PDC $pdc ) {
- if( $this->getId() !== $pdc->getId() ) {
- throw new InvalidArgumentException( 'PDCs can be merged only if they are of the same type' );
- }
- $this->setCategoryType( CategoryYearMonthDayTypes::findBestCategory( [
- $this->getCategoryType(),
- $pdc ->getCategoryType()
- ] ) );
- }
-
- /**
- * Set subject themes scraping subject wikitext
- *
- * @param $page_content string
- * @return self
- */
- public function setSubjectThemesScrapingSubjectWikitext( $page_content ) {
- // Pattern to match spaces, newline, tabulations
- $_ = '[ \t\n]*';
-
- /*
- * Pattern to match a PDC turnover (actually this information is unuseful)
- *
- * {{cancellazione|9}}
- * or explicitly:
- * {{cancellazione|1 = 9}}
- */
- $PARAM_NUM =
- '(?:' .
- '\|' . $_ .
- '(?:' . '1' . $_ . '=' . $_ . ')?' . // 1 =
- '[0-9]+' . $_ . // turnover number
- ')?';
-
- /*
- * Pattern to match a PDC subject theme
- *
- * {{cancellazione|arg = something}}
- * or
- * {{cancellazione|arg2 = something}}
- * or
- * {{cancellazione|argomento = something}}
- * or
- * {{cancellazione|argomento2 = something}}
- */
- $PARAM_THEME =
- '(?:' .
- '\|' . $_ .
- 'arg(?:omento)?[0-9]?' . $_ .
- '=' . $_ .
- '([0-9a-zA-ZàèìòùÀÈÌÒÙ\-\/\'_. ]+?)' . $_ .
- ')?';
-
- /*
- * Complete pattern to match all the PDC arguments
- *
- * {{Cancellazione|9|arg=something|arg2=something}}
- * {{Cancella |9|arg=something|arg2=something}}
- *
- * This pattern is a bit repetitive because PCRE does not support to
- * match a group multiple times.
- * Yes, every group can be repeated, but it will be matched only once.
- *
- * @TODO: use a wikitext parser
- */
- $PATTERN = '/' .
- '{{' . $_ . '(?:[Cc]ancellazione|[Cc]ancella)' . $_ .
- $PARAM_NUM .
- $PARAM_THEME .
- $PARAM_THEME .
- '}}/';
-
- // run the regex and extrapulate the themes
- preg_match( $PATTERN, $page_content, $matches );
- for( $i = 1; $i < count( $matches ); $i++ ) {
- $this->addSubjectTheme( trim( $matches[ $i ] ) );
- }
-
- return $this;
- }
-}
diff --git a/includes/class-PDCException.php b/includes/class-PDCException.php
deleted file mode 100644
index bad8056..0000000
--- a/includes/class-PDCException.php
+++ /dev/null
@@ -1,21 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use Exception;
-
-class PDCException extends Exception {};
diff --git a/includes/class-PDCExpiredException.php b/includes/class-PDCExpiredException.php
deleted file mode 100644
index c85bc5f..0000000
--- a/includes/class-PDCExpiredException.php
+++ /dev/null
@@ -1,23 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Exceptions to be thrown when a PDC is not anymore of a certain type
- * because it expired.
- */
-class PDCExpiredException extends PDCException {};
diff --git a/includes/class-PDCs.php b/includes/class-PDCs.php
deleted file mode 100644
index 709b406..0000000
--- a/includes/class-PDCs.php
+++ /dev/null
@@ -1,167 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use DateTime;
-use mw\API\PageMatcher;
-
-/**
- * Handle some PDCs
- */
-class PDCs {
-
- /**
- * Sort some PDCs by creation date
- *
- * @param $pdcs array
- */
- public static function sortByCreationDate( & $pdcs ) {
- // sort PDCs by start date
- usort( $pdcs, function ( $a, $b ) {
- return $a->getCreationDate() > $b->getCreationDate();
- } );
- }
-
- /**
- * Index some PDCs by their type
- *
- * @param $pdcs array
- * @return array
- */
- public static function indexByType( $pdcs ) {
- $pdcs_by_type = [];
- foreach( CategoryYearMonthDayTypes::all() as $Type ) {
- $pdcs_by_type[ $Type::PDC_TYPE ] = [];
- }
- foreach( $pdcs as $pdc ) {
- $type = $pdc->getType();
- $pdcs_by_type[ $type ][] = $pdc;
- }
- return $pdcs_by_type;
- }
-
- /**
- * Discard all the PDCs that do not belong to a certain date
- *
- * @param $pdcs array
- * @param $date DateTime
- * @return array
- */
- public static function filterByDate( $pdcs, DateTime $date ) {
- $y_m_d = $date->format( 'Y-m-d' );
- return array_filter( $pdcs, function ( $pdc ) use ( $y_m_d ) {
- return $pdc->getStartDate()->format( 'Y-m-d' ) === $y_m_d;
- } );
- }
-
- /**
- * Discard all the PDCs that are not multiple
- *
- * @param $pdcs array
- * @return $pdcs
- */
- public static function filterNotMultiple( $pdcs ) {
- return array_filter( $pdcs, function ( $pdc ) {
- return ! $pdc->isMultiple();
- } );
- }
-
- /**
- * Get all the title subjects of the specified PDCs
- *
- * @param $pdcs array
- * @return array
- */
- public static function titleSubjects( $pdcs ) {
- return array_map( function ( $pdc ) {
- return $pdc->getTitleSubject();
- }, $pdcs );
- }
-
- /**
- * Populate the specified PDCs that miss informations
- *
- * This method is intended to do less API requests as possible.
- *
- * @param $pdcs array
- * @return array
- */
- public static function populateMissingInformations( $pdcs ) {
- self::populateMissingInformationsFromLastRevision( $pdcs );
- }
-
- /**
- * Populate the specified PDCs with missing informations that can
- * be obtained fetching the last revision.
- *
- * This method is intended to do less API requests as possible.
- *
- * @param $pdcs
- */
- private static function populateMissingInformationsFromLastRevision( $pdcs ) {
-
- if( ! $pdcs ) {
- return;
- }
-
- /*
- * fetch the last revision from all the PDCs
- *
- * @see https://it.wikipedia.org/w/api.php?action=help&modules=query%2Brevisions
- */
- $query = Page::api()->createQuery( [
- 'action' => 'query',
- 'titles' => self::titleSubjects( $pdcs ),
- 'prop' => 'revisions',
- 'rvprop' => [
- 'content',
- 'timestamp',
- ],
- 'rvslots' => 'main',
- 'rvsection' => '0',
- ] );
-
- // callback fired for every match between response pages and PDCs
- $matching_callback = function ( $page, $pdc ) {
- if( isset( $page->revisions[ 0 ] ) ) {
- // this is the only one
- $revision = $page->revisions[ 0 ];
-
- // populate the lastedit date
- $lastedit_date = Page::createDateTimeFromString( $revision->timestamp );
- $pdc->setLasteditDate( $lastedit_date );
-
- // populate the subject themes
- if( isset( $revision->slots->main ) ) {
- $pdc->setSubjectThemesScrapingSubjectWikitext( $revision->slots->main->{ '*' } );
- }
- }
- };
-
- // callback that returns the PDC page title
- $pdc_page_title_callback = function ( $pdc ) {
- return $pdc->getTitleSubject();
- };
-
- // query continuation
- foreach( $query->getGenerator() as $response ) {
- // match page results and PDCs by title
- ( new PageMatcher( $response->query, $pdcs ) )
- ->matchByTitle( $matching_callback, $pdc_page_title_callback );
- }
- }
-
-}
diff --git a/includes/class-Page.php b/includes/class-Page.php
deleted file mode 100644
index a10a758..0000000
--- a/includes/class-Page.php
+++ /dev/null
@@ -1,216 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use DateTime;
-use DateTimeZone;
-use cli\Input;
-use cli\Log;
-use wm\WikipediaIt;
-use mw\Tokens;
-
-/**
- * Handle a page
- */
-class Page {
-
- /**
- * Time zone of Italian Wikipedia community.
- *
- * @var string
- */
- const COMMUNITY_TIMEZONE = 'Europe/Rome';
-
- /**
- * Enable this flag to ask for every changes
- *
- * @var bool
- */
- public static $ASK_BEFORE_SAVING = false;
-
- /**
- * @var string Page title with prefix
- */
- private $title;
-
- /**
- * Cache for the existing status of this page
- *
- * @var bool
- */
- private $exists;
-
- /**
- * Construct a Page
- *
- * @param $title Page title with its prefix
- */
- public function __construct( $title ) {
- $this->title = $title;
- }
-
- /**
- * Get the page title with its prefix
- *
- * @return string
- */
- public function getTitle() {
- return $this->title;
- }
-
- /**
- * Save this page
- *
- * @param $content string Page content
- * @param $summary string Edit summary
- * @return mixed
- */
- public function saveByContentSummary( $content, $summary ) {
- $title = $this->getTitle();
- $api = self::api();
- $args = [
- 'action' => 'edit',
- 'title' => $title,
- 'text' => $content,
- 'summary' => $summary,
- 'token' => $api->login()->getToken( Tokens::CSRF ),
- 'bot' => 1,
- ];
-
- if( self::$ASK_BEFORE_SAVING ) {
- print_r( $args );
- if( 'y' !== Input::yesNoQuestion( "Save?" ) ) {
- return false;
- }
- }
-
- Log::info( "writing [[$title]]" );
-
- return $api->post( $args );
- }
-
- /**
- * Save this page if it does not exist
- *
- * @param $content string Page content
- * @param $summary string Edit summary
- * @return bool|mixed False if not created
- */
- public function saveByContentSummaryIfNotExists( $content, $summary ) {
- if( ! $this->exists() ) {
- return $this->saveByContentSummary( $content, $summary );
- }
- return false;
- }
-
- /**
- * Set internally if this page exists
- *
- * @param $exists bool
- * @return bool|mixed False if not created
- */
- public function setIfExists( $exists ) {
- $this->exists = $exists;
- }
-
- /**
- * Check if this page exists (the result is cached)
- *
- * @return bool
- */
- public function exists() {
- if( null === $this->exists ) {
- $result = self::api()->fetch( [
- 'action' => 'query',
- 'prop' => 'info',
- 'titles' => $this->getTitle(),
- ] );
- foreach( $result->query->pages as $pageid => $page ) {
- $this->exists = ! isset( $page->missing );
- }
- }
- return $this->exists;
- }
-
- /**
- * Fetch the first revision date by direction
- *
- * @param $dir string direction
- * @return DateTime
- */
- public function fetchFirstRevisionDateByDirection( $direction ) {
- $response = self::api()->fetch( [
- 'action' => 'query',
- 'titles' => $this->getTitle(),
- 'prop' => 'revisions',
- 'rvprop' => [
- 'timestamp'
- ],
- 'rvlimit' => 1,
- 'rvdir' => $direction,
- ] );
- foreach( $response->query->pages as $page ) {
- if( isset( $page->revisions ) ) {
- foreach( $page->revisions as $revision ) {
- return self::createDateTimeFromString( $revision->timestamp );
- }
- }
- }
- throw new \Exception( 'unable to fetch the creation date' );
- }
-
- /**
- * Fetch the creation date of this page
- *
- * @return DateTime
- */
- public function fetchCreationDate() {
- return $this->fetchFirstRevisionDateByDirection( 'newer' );
- }
-
- /**
- * Fetch the creation date of this page
- *
- * @return DateTime
- */
- public function fetchLasteditDate() {
- return $this->fetchFirstRevisionDateByDirection( 'older' );
- }
-
- /**
- * Get the API related to this page
- *
- * @return mw\API
- */
- public static function api() {
- return WikipediaIt::getInstance();
- }
-
- /**
- * Create a DateTime object from a MediaWiki formatted date
- *
- * MediaWiki dates are formatted following the ISO8601 standard
- * and you may want to specify your community timezone.
- *
- * @param $datetime string
- * @return DateTime
- */
- public static function createDateTimeFromString( $datetime ) {
- return DateTime::createFromFormat( DateTime::ISO8601, $datetime )
- ->setTimezone( new DateTimeZone( self::COMMUNITY_TIMEZONE ) );
- }
-}
diff --git a/includes/class-PageTemplated.php b/includes/class-PageTemplated.php
deleted file mode 100644
index 7c9ff59..0000000
--- a/includes/class-PageTemplated.php
+++ /dev/null
@@ -1,125 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle a generic page associated to a template
- */
-abstract class PageTemplated extends Page {
-
- /**
- * Template name of this page
- *
- * To be overrided
- */
- const TEMPLATE_NAME = 'EXAMPLE_NAME';
-
- /**
- * Constructor
- *
- * @param $args Template arguments
- */
- public function __construct() {
- parent::__construct( $this->getTemplatedTitle() );
- }
-
- /**
- * Get the name of the template
- *
- * @return string
- */
- public static function getTemplateName() {
- return static::TEMPLATE_NAME;
- }
-
- /**
- * Get the name of the template for the page title
- *
- * @return string
- */
- public static function getTemplateTitleName() {
- return static::getTemplateName() . '.title';
- }
-
- /**
- * Get the name of the template for the summary
- *
- * @return string
- */
- public static function getTemplateSummaryName() {
- return static::getTemplateName() . '.summary';
- }
-
- /**
- * Get the name of the template for the content
- */
- public static function getTemplateContentName() {
- return static::getTemplateName() . '.content';
- }
-
- /**
- * Get the template arguments
- *
- * @return array
- */
- public abstract function getTemplateArguments();
-
- /**
- * Get the edit summary for this page from its template
- *
- * @return string
- */
- public function getTemplatedSummary() {
- return Template::get( static::getTemplateSummaryName(), $this->getTemplateArguments() );
- }
-
- /**
- * Get the page title from its template
- *
- * @return string
- */
- public function getTemplatedTitle() {
- return Template::get( static::getTemplateTitleName(), $this->getTemplateArguments() );
- }
-
- /**
- * Get the page content for this page from its template
- *
- * @return string
- */
- public function getTemplatedContent() {
- return Template::get( static::getTemplateContentName(), $this->getTemplateArguments() );
- }
-
- /**
- * Save this page from the content of its template
- *
- * @return mixed
- */
- public function save() {
- return $this->saveByContentSummary( $this->getTemplatedContent(), $this->getTemplatedSummary() );
- }
-
- /**
- * Save this page from the content of its template if it does not exist
- *
- * @return mixed
- */
- public function saveIfNotExists() {
- return $this->saveByContentSummaryIfNotExists( $this->getTemplatedContent(), $this->getTemplatedSummary() );
- }
-}
diff --git a/includes/class-PageYear.php b/includes/class-PageYear.php
deleted file mode 100644
index bc0a82e..0000000
--- a/includes/class-PageYear.php
+++ /dev/null
@@ -1,60 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Abstraction of a page related to a year
- */
-abstract class PageYear extends PageTemplated {
-
- /**
- * Year
- *
- * @var int
- */
- private $year;
-
- /**
- * Constructor
- *
- * @param $year int
- * @see PageTemplated::__construct()
- */
- public function __construct( $year ) {
- $this->year = (int) $year;
- parent::__construct();
- }
-
- /**
- * Get the year
- *
- * @return int
- */
- public function getYear() {
- return $this->year;
- }
-
- /**
- * Template arguments
- *
- * @override CategoryTemplated::getTemplateArguments()
- */
- public function getTemplateArguments() {
- return [ $this->getYear() ];
- }
-
-}
diff --git a/includes/class-PageYearMonth.php b/includes/class-PageYearMonth.php
deleted file mode 100644
index 2f6713e..0000000
--- a/includes/class-PageYearMonth.php
+++ /dev/null
@@ -1,73 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Abstraction of a page related to a month (in a certain year)
- */
-abstract class PageYearMonth extends PageYear {
-
- /**
- * Month
- *
- * @var int 1-12
- */
- private $month;
-
- /**
- * Constructor
- *
- * @param $year int
- * @param $month int 1-12
- * @see PageYear::__construct()
- */
- public function __construct( $year, $month ) {
- $this->month = (int) $month;
- parent::__construct( $year );
- }
-
- /**
- * Get the month
- *
- * @return int 1-12
- */
- public function getMonth() {
- return $this->month;
- }
-
- /**
- * Get the month name
- *
- * @return string e.g. 'aprile'
- */
- public function getMonthName() {
- return Months::number2name( $this->getMonth() - 1 );
- }
-
- /**
- * Template arguments
- *
- * @override PageYear::getTemplateArguments()
- */
- public function getTemplateArguments() {
- return array_merge( parent::getTemplateArguments(), [
- $this->getMonth(),
- Months::number2name( $this->getMonth() - 1 ),
- ] );
- }
-
-}
diff --git a/includes/class-PageYearMonthDay.php b/includes/class-PageYearMonthDay.php
deleted file mode 100644
index 274f8ea..0000000
--- a/includes/class-PageYearMonthDay.php
+++ /dev/null
@@ -1,89 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use DateTime;
-
-/**
- * Abstraction of a page related to a day (in a certain month of a certain year)
- */
-abstract class PageYearMonthDay extends PageYearMonth {
-
- /**
- * Day
- *
- * @var int 1-31
- */
- private $day;
-
- /**
- * Constructor
- *
- * @param $year int
- * @param $month int 1-12
- * @param $day int 1-31
- * @see PageYearMonth::__construct()
- */
- public function __construct( $year, $month, $day ) {
- $this->day = (int) $day;
- parent::__construct( $year, $month );
- }
-
- /**
- * Static constructor
- *
- * @param $date_time DateTime
- */
- public static function createFromDateTime( DateTime $datetime ) {
- return new static( $datetime->format('Y'), $datetime->format('m'), $datetime->format('d') );
- }
-
- /**
- * Get the day
- *
- * @return int 1-13
- */
- public function getDay() {
- return $this->day;
- }
-
- /**
- * Get a DateTime object
- *
- * @return DateTime
- */
- public function getDateTime() {
- return DateTime::createFromFormat( 'Y-m-d', sprintf(
- '%d-%d-%d',
- $this->getYear(),
- $this->getMonth(),
- $this->getDay()
- ) );
- }
-
- /**
- * Template arguments
- *
- * @override PageYearMonth::getTemplateArguments()
- */
- public function getTemplateArguments() {
- return array_merge( parent::getTemplateArguments(), [
- $this->getDay()
- ] );
- }
-
-}
diff --git a/includes/class-PageYearMonthDayPDCs.php b/includes/class-PageYearMonthDayPDCs.php
deleted file mode 100644
index f7f5967..0000000
--- a/includes/class-PageYearMonthDayPDCs.php
+++ /dev/null
@@ -1,116 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Abstraction of a page containing PDCs of a day
- */
-abstract class PageYearMonthDayPDCs extends PageYearMonthDay {
-
- /**
- * PDCs indexed by type
- *
- * @var array
- */
- private $pdcsByType;
-
- /**
- * Constructor
- *
- * @param $year int
- * @param $month int 1-12
- * @param $day int 1-31
- * @param $pdcs_by_type array PDCs by type
- * @see PageYearMonthDay::__construct()
- */
- public function __construct( $year, $month, $day, $pdcs_by_type = [] ) {
- $this->pdcsByType = $pdcs_by_type;
- parent::__construct( $year, $month, $day );
- }
-
- /**
- * Static constructor
- *
- * @param $datetime DateTime
- * @param $pdcs_by_type PDCs by type
- * @return self
- */
- public static function createFromDateTimePDCs( $datetime, $pdcs_by_type = [] ) {
- return new static( $datetime->format('Y'), $datetime->format('m'), $datetime->format('d'), $pdcs_by_type );
- }
-
- /**
- * Get all the PDCs
- *
- * @return array
- */
- public function getPDCs() {
- $all = [];
- foreach( $this->pdcsByType as $pdcs ) {
- foreach( $pdcs as $pdc ) {
- $all[] = $pdc;
- }
- }
- return $all;
- }
-
- /**
- * Get the PDCs indexed by type
- *
- * @return array
- */
- public function getPDCsByType() {
- return $this->pdcsByType;
- }
-
- /**
- * Get the running PDCs indexed by type
- *
- * @return array
- */
- public function getRunningPDCsByType() {
- return $this->getPDCsByTypeFilteringRunning( true );
- }
-
- /**
- * Get the ended PDCs indexed by type
- *
- * @return array
- */
- public function getEndedPDCsByType() {
- return $this->getPDCsByTypeFilteringRunning( false );
- }
-
- /**
- * Get the PDCs indexed by type, but only which of them are running (or not)
- *
- * @param $is_running bool
- * @return array
- */
- private function getPDCsByTypeFilteringRunning( $is_running ) {
- $pdcs_by_type = $this->getPDCsByType();
- foreach( $pdcs_by_type as $type => $pdcs ) {
- foreach( $pdcs as $i => $pdc ) {
- if( $pdc->isRunning() !== $is_running ) {
- unset( $pdcs_by_type[ $type ][ $i ] );
- }
- }
- }
- return $pdcs_by_type;
- }
-
-}
diff --git a/includes/class-PageYearMonthDayPDCsCount.php b/includes/class-PageYearMonthDayPDCsCount.php
deleted file mode 100644
index d1a33ba..0000000
--- a/includes/class-PageYearMonthDayPDCsCount.php
+++ /dev/null
@@ -1,157 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Abstraction of a page containing PDCs' log of the day
- */
-class PageYearMonthDayPDCsCount extends PageYearMonthDayPDCs {
-
- /**
- * Template name of this page
- *
- * @override CategoryTemplated::TEMPLATE_NAME
- */
- const TEMPLATE_NAME = 'PAGE_COUNT';
-
- /**
- * Get the template arguments:
- * 1: page title
- * 2: temperature
- * 3: '1' if it's multiple
- * 4: color associated to the PDC e.g. '#fff'
- * 5: number of the row
- * 6: PDC type e.g. 'consensuale'
- * 7: duration e.g. 'un giorno'
- * 8: title of the log page
- * 9: human date 'year monthname day'
- *
- * @override PageTemplated::getTemplateArguments()
- * @return array
- */
- public function getTemplateArguments() {
-
- $sections = [];
-
- // runnings
- $i = 0;
- $entries = [];
- foreach( $this->getRunningPDCsByType() as $type => $pdcs ) {
- foreach( $pdcs as $pdc ) {
- $entries[] = $this->createPDCEntryContent( ++$i, $pdc );
- }
- }
- if( $entries ) {
- $sections[] = Template::get( self::TEMPLATE_NAME . '.RUNNING.section', [
- implode( "\n", $entries )
- ] );
- }
-
- // endeds
- $i = 0;
- $entries = [];
- foreach( $this->getEndedPDCsByType() as $type => $pdcs ) {
- foreach( $pdcs as $pdc ) {
- $entries[] = $this->createPDCEntryContent( ++$i, $pdc );
- }
- }
- if( $entries ) {
- $sections[] = Template::get( self::TEMPLATE_NAME . '.ENDED.section', [
- implode( "\n", $entries )
- ] );
- }
-
- // with some fixable errors
- $erroneous = [];
- foreach( $this->getPDCs() as $pdc ) {
- if( ! $pdc->isTitleSubjectConsistent() ) {
- $erroneous[] = self::createPDCErrorMessage( $pdc,
- Template::get( self::TEMPLATE_NAME . '.ERRONEOUS.msg.sortkey', [
- $pdc->getTitleSubject()
- ] )
- );
- }
- }
- if( $erroneous ) {
- $sections[] = Template::get( self::TEMPLATE_NAME . '.ERRONEOUS.section', [
- implode( "\n", $erroneous )
- ] );
- }
-
- $args = parent::getTemplateArguments();
-
- // Does it have content?
- if( $sections ) {
- $args[] = implode( "\n", $sections );
- } else {
- $args[] = Template::get( self::TEMPLATE_NAME . '.empty' );
- }
-
- return $args;
- }
-
- /**
- * Get the PDC entry content
- *
- * @param $pdc PDC
- * @param $i Ordinal number passed from the count page
- * @return string
- */
- public function createPDCEntryContent( $i, PDC $pdc ) {
-
- $template_name = self::TEMPLATE_NAME;
- $template_name .= $pdc->isRunning()
- ? '.RUNNING.entry'
- : '.ENDED.entry';
-
- $turnover = $pdc->getTurnover();
-
- return Template::get( $template_name, [
- $pdc->getTitleSubject(),
- $pdc->getTemperature(),
- $pdc->isMultiple(),
- '', // TODO: Ex color. Now unuseful.
- $i,
- $pdc->getHumanType(),
- $pdc->getHumanDuration(),
- $this->getTitle(),
- sprintf( '%d %s %d',
- $this->getYear(),
- $this->getMonthName(),
- $this->getDay()
- ),
- $turnover ? $turnover : '',
- implode( ', ', $pdc->getSubjectThemes() )
- ] );
-
- }
-
- /**
- * Create a PDC error message
- *
- * @param $pdc object
- * @param $message string
- * @return string
- */
- public static function createPDCErrorMessage( $pdc, $message ) {
- return Template::get( self::TEMPLATE_NAME . '.ERRONEOUS.entry', [
- $pdc->getTitle(),
- $message,
- ] );
- }
-
-}
diff --git a/includes/class-PageYearMonthDayPDCsLog.php b/includes/class-PageYearMonthDayPDCsLog.php
deleted file mode 100644
index ea3f29f..0000000
--- a/includes/class-PageYearMonthDayPDCsLog.php
+++ /dev/null
@@ -1,88 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Abstraction of a page containing PDCs daily log
- *
- * e.g. https://it.wikipedia.org/wiki/Wikipedia:Pagine_da_cancellare/Conta/2017_aprile_20
- */
-class PageYearMonthDayPDCsLog extends PageYearMonthDayPDCs {
-
- /**
- * Template name of this page
- *
- * @override CategoryTemplated::TEMPLATE_NAME
- */
- const TEMPLATE_NAME = 'PAGE_LOG';
-
- /**
- * Get the template arguments
- *
- * @override PageTemplated::getTemplateArguments()
- * @return array
- */
- public function getTemplateArguments() {
- $args = parent::getTemplateArguments();
-
- $closeds = [];
-
- // first running PDCs
- $sections = [];
- foreach( $this->getPDCsByType() as $pdcs ) {
- if( $pdcs ) {
- // call the entry template for each PDC
- $entries = [];
- foreach( $pdcs as $pdc ) {
- if( $pdc->isRunning() ) {
- $entries[] = "{{" . $pdc->getTitle() . "}}";
- } else {
- $closeds[] = $pdc;
- }
- }
-
- // call the section template for each PDC type
- if( $entries ) {
- $entries_txt = implode( "\n", $entries );
- $sections[] = Template::get( self::TEMPLATE_NAME . '.section', [
- $pdc->getType(),
- $entries_txt
- ] );
- }
- }
- }
-
- // then ended PDCs
- $entries = [];
- foreach( $closeds as $pdc ) {
- // call the entry template for each PDC
- $entries[] = "{{" . $pdc->getTitle() . "}}";
- }
- if( $entries ) {
- $entries_txt = implode( "\n", $entries );
- $sections[] = Template::get( self::TEMPLATE_NAME . '.section', [
- 'concluse/annullate',
- $entries_txt
- ] );
- }
-
- $args[] = implode( "\n", $sections );
-
- return $args;
- }
-
-}
diff --git a/includes/class-Pages.php b/includes/class-Pages.php
deleted file mode 100644
index ee5d748..0000000
--- a/includes/class-Pages.php
+++ /dev/null
@@ -1,74 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-use mw\API\PageMatcher;
-
-/**
- * Handle multiple pages
- */
-class Pages {
-
- /**
- * Get page titles from pages
- *
- * @param $pages array
- * @return array
- */
- public static function titles( $pages ) {
- return array_map( function ( $page ) {
- return $page->getTitle();
- }, $pages );
- }
-
- /*
- * Check if some pages exist
- *
- * This method is intended to do less API requests as possible.
- *
- * @param $pages array
- */
- public static function populateWheneverTheyExist( $pages ) {
-
- // API query to check if these pages exist
- $query = Page::api()->createQuery( [
- 'action' => 'query',
- 'prop' => 'info',
- 'titles' => self::titles( $pages ),
- ] );
-
- // callback to retrieve the page title
- $page_title_callback = function ( $page ) {
- return $page->getTitle();
- };
-
- // callback fired for every match between response pages and my pages
- $matching_callback = function ( $response_page, $my_page ) {
- $my_page->setIfExists(
- ! isset( $response_page->missing )
- );
- };
-
- // query continuation
- foreach( $query->getGenerator() as $response ) {
- // match response pages with my pages
- ( new PageMatcher( $response->query, $pages ) )
- ->matchByTitle( $matching_callback, $page_title_callback );
- }
- }
-
-}
diff --git a/includes/class-Template.php b/includes/class-Template.php
deleted file mode 100644
index d00e0c0..0000000
--- a/includes/class-Template.php
+++ /dev/null
@@ -1,71 +0,0 @@
-.
-
-namespace itwikidelbot;
-
-/**
- * Handle templates of text
- *
- * Template files are 'something.template' into the /template directory
- */
-class Template {
-
- /**
- * Placeholder used to mark where the template content starts
- */
- const START_PLACEHOLDER = "\n";
-
- /**
- * Get the content of a template passing its arguments
- *
- * @param $name string Template name
- * @param $args array Template arguments
- * @return string Template content
- */
- static function get( $name, $args = [] ) {
-
- // remove spaces
- $name = str_replace( ' ', '_', $name );
-
- // ../templates/$name.template
- $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $name . '.tpl';
- if( ! file_exists( $path ) ) {
- throw new \InvalidArgumentException( "unexisting template $name" );
- }
-
- // template content with also documentation
- $content = file_get_contents( $path );
-
- // stripping documentation etc.
- $pos = strpos( $content, self::START_PLACEHOLDER );
- if( false === $pos ) {
- throw new \Exception( 'missing header in template' );
- }
- $pos += strlen( self::START_PLACEHOLDER );
- $content = substr( $content, $pos );
-
- // text-editors usually put an unuseful newline before the EOF
- $content = rtrim( $content );
-
- // pass arguments
- $s = vsprintf( $content, $args );
-
- if( false === $s ) {
- throw new \Exception( "wrong number of arguments for template $name" );
- }
-
- return $s;
- }
-}
diff --git a/orphanize.php b/orphanize.php
index 6eac181..96e3331 100755
--- a/orphanize.php
+++ b/orphanize.php
@@ -1,265 +1,265 @@
#!/usr/bin/php
.
namespace itwikidelbot;
// die on whatever error
set_error_handler( function( $errno, $errstr, $errfile, $errline ) {
if( error_reporting() !==0 ) {
throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline );
}
} );
// autoload classes and configuration
-require __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'autoload.php';
-require __DIR__ . DIRECTORY_SEPARATOR . 'config.php';
+require __DIR__ . '/includes/autoload.php';
+require __DIR__ . '/config.php';
// how much titles at time requesting - this is a MediaWiki limit
define( 'MAX_TRANCHE_TITLES', 50 );
$TITLE_SOURCE = 'Utente:.avgas/Wikilink da orfanizzare';
// classes used
use \cli\Log;
use \cli\Input;
use \web\MediaWikis;
use \mw\Wikilink;
// wiki identifier
$wiki_uid = 'itwiki';
// wiki instance
$wiki = Mediawikis::findFromUid( $wiki_uid );
// query last revision
$revision =
$wiki->fetch( [
'action' => 'query',
'prop' => 'revisions',
'titles' => $TITLE_SOURCE,
'rvslots' => 'main',
'rvprop' => 'content',
'rvlimit' => 1,
] );
// array of page titles to be orphanized
$involved_pagetitles = [];
// associative array of page IDs as key and a boolean as value containg pages to be orphanized
$involved_pageids = [];
// for each page (well, just one)
foreach( $revision->query->pages as $sourcepage ) {
// for each revision (well, just one)
foreach( $sourcepage->revisions as $revision ) {
// pure wikitext
$wikitextRaw = $revision->slots->main->{ '*' };
// wikitext object
$wikitext = $wiki->createWikitext( $revision->slots->main->{ '*' } );
// identify wikilinks
$n = $wikitext->pregMatchAll( '~\[\[(.*?)\]\]~', $matches );
if( $n === false ) {
Log::error( 'wtf' );
exit( 1 );
}
// collect these titles
$titles_to_be_orphanized = [];
for( $i = 0; $i < $n; $i++ ) {
// can be both 'title' and 'title|alias'
$wlink = $matches[ 1 ][ $i ];
// just the page title
$title = explode( '|', $wlink )[0];
// normalize titles
$title = str_replace( '_', ' ', ucfirst( $title ) );
// append
$titles_to_be_orphanized[] = $title;
}
// drop duplicates
$titles_to_be_orphanized = array_unique( $titles_to_be_orphanized );
// order
sort( $titles_to_be_orphanized, SORT_STRING );
// keep a copy
$involved_pagetitles = $titles_to_be_orphanized;
// log titles
Log::info( "Pages to be orphanized:" );
foreach( $titles_to_be_orphanized as $title ) {
Log::info( $title );
}
// note that the API accepts a maximum trance of titles
while( $less_titles_to_be_orphanized = array_splice( $titles_to_be_orphanized, 0, MAX_TRANCHE_TITLES ) ) {
// for each of these titles, query linksto
$linksto =
$wiki->createQuery( [
'action' => 'query',
'titles' => $less_titles_to_be_orphanized,
'prop' => 'linkshere',
'lhprop' => 'pageid',
'lhnamespace' => 0,
'lhlimit' => 300,
] );
// cumulate the linkshere page ids
Log::info( "requesting linkshere..." );
foreach( $linksto as $response ) {
foreach( $response->query->pages as $page ) {
if( isset( $page->linkshere ) ) {
foreach( $page->linkshere as $linkingpage ) {
$pageid = (int) $linkingpage->pageid;
$involved_pageids[ $pageid ] = false;
}
}
}
}
}
}
}
// create a clean array or page ids
$involved_pageids = array_keys( $involved_pageids );
// count of involved pages
Log::info( sprintf(
"found %d pages containing the %d involved wlinks",
count( $involved_pageids ),
count( $involved_pagetitles )
) );
// note that the API accepts a maximum tranche of IDs
while( $less_involved_pageids = array_splice( $involved_pageids, 0, MAX_TRANCHE_TITLES ) ) {
// query last revision
$responses =
$wiki->createQuery( [
'action' => 'query',
'pageids' => $less_involved_pageids,
'prop' => 'revisions',
'rvslots' => 'main',
'rvprop' => [
'content',
'timestamp',
],
] );
// for each response
foreach( $responses as $response ) {
// for each page
foreach( $response->query->pages as $page ) {
// page ID to be edited
$pageid = $page->pageid;
// does it have a revision?
if( isset( $page->revisions[ 0 ] ) ) {
// the first revision
$revision = $page->revisions[ 0 ];
// timestamp of the revision
$timestamp = $revision->timestamp;
// wikitext from the main slot of this revision
$wikitext_raw = $revision->slots->main->{ '*' };
// create a Wikitext object
$wikitext = $wiki->createWikitext( $wikitext_raw );
// for each of the titles to be orphanized
foreach( $involved_pagetitles as $involved_pagetitle ) {
// parse the orphanizing title
$title = $wiki->createTitleParsing( $involved_pagetitle );
// a wikilink with and without alias
$wikilink_simple = $wiki->createWikilink( $title, Wikilink::NO_ALIAS );
$wikilink_alias = $wiki->createWikilink( $title, Wikilink::WHATEVER_ALIAS );
// sobstitute simple links e.g. [[Hello]]
$wikilink_regex_simple = $wikilink_simple->getRegex( [
'title-group-name' => 'title',
] );
// sobstitute links with alias e.g. [[Hello|whatever]]
$wikilink_regex_alias = $wikilink_alias->getRegex( [
'alias-group-name' => 'alias',
] );
Log::info( "Regex simple wikilink:" );
Log::info( $wikilink_regex_simple );
Log::info( "Regex wikilink aliased:" );
Log::info( $wikilink_regex_alias );
// convert '[[Hello]]' to 'Hello'
$wikitext->pregReplaceCallback( "/$wikilink_regex_simple/", function ( $matches ) {
return $matches[ 'title' ];
} );
// convert '[[Hello|world]]' to 'world'
$wikitext->pregReplaceCallback( "/$wikilink_regex_alias/", function ( $matches ) {
return $matches[ 'alias' ];
} );
}
// end loop titles to be orphanized
// check for changes and save
if( $wikitext->isChanged() ) {
Log::info( "Changes:" );
foreach( $wikitext->getHumanUniqueSobstitutions() as $sobstitution ) {
Log::info( "\t $sobstitution" );
}
if( 'n' !== Input::yesNoQuestion( "Confirm changes" ) ) {
$wiki->login()->edit( [
'pageid' => $pageid,
'text' => $wikitext->getWikitext(),
'summary' => "Bot TEST: orfanizzazione voci eliminate in seguito a [[WP:RPC|consenso cancellazione]]",
'timestamp' => $timestamp,
'minor' => 1,
'bot' => 1,
] );
}
// end confirmation
}
// end save
}
// end revision check
}
// end loop pages
}
// end loop responses
}
// end loop involved page IDs
diff --git a/templates/CATEGORY_DAY.content.tpl b/templates/CATEGORY_DAY.content.tpl
deleted file mode 100644
index c73885f..0000000
--- a/templates/CATEGORY_DAY.content.tpl
+++ /dev/null
@@ -1,21 +0,0 @@
-
-This is the template for the content of a daily category.
-
-Placeholders:
- %1$s: category title
- %2$d: year
- %3$d: month 1-12
- %3$02d: month 01-12
- %4$s: month name
- %5$d: day 1-31
- %5$02d: day 01-31
-
-
-{{Cancellazione/cat|2018/4/19}}
-
-[[Categoria:Cancellazioni - aprile 2018| 19022018]]
-
-
-{{Cancellazione/cat|%2$d/%3$d/%5$d}}
-
-[[Categoria:Cancellazioni - %4$s %2$d| %5$02d%3$02d%2$d]]
diff --git a/templates/CATEGORY_DAY.summary.tpl b/templates/CATEGORY_DAY.summary.tpl
deleted file mode 100644
index ffb7fbc..0000000
--- a/templates/CATEGORY_DAY.summary.tpl
+++ /dev/null
@@ -1,17 +0,0 @@
-
-This is the template for the edit summary of a daily category.
-
-Placeholders:
- %1$s: category title
- %2$d: year
- %3$d: month 1-12
- %3$02d: month 01-12
- %4$s: month name
- %5$d: day 1-31
- %5$02d: day 01-31
-
-
-Bot: creazione categoria di servizio giornaliera per il 19 aprile 2018
-
-
-Bot: creazione categoria di servizio giornaliera per il %5$d %4$s %2$d
diff --git a/templates/CATEGORY_DAY_PDCTYPE.content.tpl b/templates/CATEGORY_DAY_PDCTYPE.content.tpl
deleted file mode 100644
index 9047ee3..0000000
--- a/templates/CATEGORY_DAY_PDCTYPE.content.tpl
+++ /dev/null
@@ -1,22 +0,0 @@
-
-This is the template for the content of a daily subcategory.
-
-Placeholders:
- %1$s: category title
- %2$d: year
- %3$d: month 1-12
- %3$02d: month 01-12
- %4$s: month name
- %5$d: day 1-31
- %5$02d: day 01-31
- %6$s: PDC type
-
-
-{{Cancellazione/cat|2018/4/13}}
-
-[[Categoria:Cancellazioni del 13 aprile 2018| consensuale]]
-
-
-{{Cancellazione/cat|%2$d/%3$d/%5$d}}
-
-[[Categoria:Cancellazioni del %5$d %4$s %2$d| %6$s]]
diff --git a/templates/CATEGORY_DAY_PDCTYPE.summary.tpl b/templates/CATEGORY_DAY_PDCTYPE.summary.tpl
deleted file mode 100644
index ecc288f..0000000
--- a/templates/CATEGORY_DAY_PDCTYPE.summary.tpl
+++ /dev/null
@@ -1,18 +0,0 @@
-
-This is the template for the edit summary of a daily subcategory.
-
-Placeholders:
- %1$s: category title
- %2$d: year
- %3$d: month 1-12
- %3$02d: month 01-12
- %4$s: month name
- %5$d: day 1-31
- %5$02d: day 01-31
- %6$s: PDC type
-
-
-Bot: creazione categoria di servizio giornaliera per PDC tipo consensuale del 19 aprile 2018
-
-
-Bot: creazione categoria di servizio giornaliera per PDC tipo %6$s del %5$d %4$s %2$d
diff --git a/templates/CATEGORY_MONTH.content.tpl b/templates/CATEGORY_MONTH.content.tpl
deleted file mode 100644
index ac44f71..0000000
--- a/templates/CATEGORY_MONTH.content.tpl
+++ /dev/null
@@ -1,15 +0,0 @@
-
-This is the template for the content of a montly category.
-
-Placeholders:
- %1$s: category title
- %2$d: year
- %3$d: month 1-12
- %3$02s: month 01-12
- %4$s: month name
-
-
-[[Categoria:Cancellazioni - 2018| 04]]
-
-
-[[Categoria:Cancellazioni - %2$d| %3$02s]]
diff --git a/templates/CATEGORY_MONTH.summary.tpl b/templates/CATEGORY_MONTH.summary.tpl
deleted file mode 100644
index 7a611ac..0000000
--- a/templates/CATEGORY_MONTH.summary.tpl
+++ /dev/null
@@ -1,15 +0,0 @@
-
-This is the template for the edit summary of a montly category.
-
-Placeholders:
- %1$s: category title
- %2$d: year
- %3$d: month 1-12
- %3$02s: month 01-12
- %4$s: month name
-
-
-Bot: creazione categoria mensile di servizio per aprile 2018
-
-
-Bot: creazione categoria mensile di servizio per %4$s %2$d
diff --git a/templates/CATEGORY_MONTH.title.tpl b/templates/CATEGORY_MONTH.title.tpl
deleted file mode 100644
index 5a5e2de..0000000
--- a/templates/CATEGORY_MONTH.title.tpl
+++ /dev/null
@@ -1,15 +0,0 @@
-
-This is the template for the title of a montly category.
-
-Placeholders:
- %1$s: category title
- %2$d: year
- %3$d: month 1-12
- %3$02s: month 01-12
- %4$s: month name
-
-
-Categoria:Cancellazioni - aprile 2018
-
-
-Categoria:Cancellazioni - %4$s %2$d
diff --git a/templates/CATEGORY_YEAR.content.tpl b/templates/CATEGORY_YEAR.content.tpl
deleted file mode 100644
index d41a1a9..0000000
--- a/templates/CATEGORY_YEAR.content.tpl
+++ /dev/null
@@ -1,11 +0,0 @@
-
-This is the template for the content of a yearly category.
-
-Placeholders:
- %1$d: year
-
-
-[[Categoria:Pagine in cancellazione per anno| 2018]]
-
-
-[[Categoria:Pagine in cancellazione per anno| %1$d]]
diff --git a/templates/CATEGORY_YEAR.summary.tpl b/templates/CATEGORY_YEAR.summary.tpl
deleted file mode 100644
index 7d9922c..0000000
--- a/templates/CATEGORY_YEAR.summary.tpl
+++ /dev/null
@@ -1,11 +0,0 @@
-
-This is the template for the summary of a yearly category.
-
-Placeholders:
- %1$d: year
-
-
-Bot: creazione categoria annuale di servizio per il 2018
-
-
-Bot: creazione categoria annuale di servizio per il %1$d
diff --git a/templates/CATEGORY_YEAR.title.tpl b/templates/CATEGORY_YEAR.title.tpl
deleted file mode 100644
index 7d33317..0000000
--- a/templates/CATEGORY_YEAR.title.tpl
+++ /dev/null
@@ -1,11 +0,0 @@
-
-This is the template for the title of a yearly category.
-
-Placeholders:
- %1$d: year
-
-
-Categoria:Cancellazioni - 2018
-
-
-Categoria:Cancellazioni - %1$d
diff --git a/templates/DAILY_COUNT_CONTENT.template.stub b/templates/DAILY_COUNT_CONTENT.template.stub
deleted file mode 100644
index 20d7e5f..0000000
--- a/templates/DAILY_COUNT_CONTENT.template.stub
+++ /dev/null
@@ -1,42 +0,0 @@
-
-This is the template for the daily counting table.
-
-e.g.
-https://it.wikipedia.org/wiki/Wikipedia:Pagine_da_cancellare/Conta/2018_aprile_19
-
-
-{{#ifexpr:{{#timel:U}}-{{#timel:U|2018-4-20}}<8*24*3600
-| {{Utente:MauroBot/BotCancellazioni/Avvisi}}
-}}
-
-
- | [[File:Pictogram voting wait blue.svg|20px|link=]] |
- Cancellazioni in corso |
-
- Ultimo aggiornamento: 01:00, 20 apr 2018 (CEST)
- |
-
-
- | # |
- Modalità |
- |
- Titolo |
-
-
- | ''1'' |
- ''semplificata'' |
- {{Termometro|0}} |
-
- '''[[:Template:Videogiochi agricoltura]]'''
- ([[{{#ifeq:{{PAGENAME}}
- | Pagine da cancellare|Wikipedia:Pagine da cancellare/Template:Videogiochi agricoltura
- | Wikipedia:Pagine da cancellare/Log/2018 aprile 20#Template:Videogiochi agricoltura
- }}|vai alla proposta di cancellazione]])
- |
-
-
-__NOTOC__
-
-
-
-TODO :)
diff --git a/templates/DURATION.day.tpl b/templates/DURATION.day.tpl
deleted file mode 100644
index aa692c1..0000000
--- a/templates/DURATION.day.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-
-This is the template for the human duration of a PDC.
-
-Applied when the PDC is 1 day old.
-
-
-un giorno
diff --git a/templates/DURATION.days.tpl b/templates/DURATION.days.tpl
deleted file mode 100644
index 94ba777..0000000
--- a/templates/DURATION.days.tpl
+++ /dev/null
@@ -1,13 +0,0 @@
-
-This is the template for the human duration of a PDC.
-
-Applied when the PDC is more than 1 day old.
-
-Placeholder:
- %1$d: number of days
-
-
-2 giorni
-
-
-%1$d giorni
diff --git a/templates/DURATION.hours.tpl b/templates/DURATION.hours.tpl
deleted file mode 100644
index 6b15a69..0000000
--- a/templates/DURATION.hours.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-
-This is the template for the human duration of a PDC.
-
-Applied when the PDC is less than 1 day old.
-
-
-< un giorno
diff --git a/templates/PAGE_COUNT.ENDED.entry.tpl b/templates/PAGE_COUNT.ENDED.entry.tpl
deleted file mode 100644
index 927af64..0000000
--- a/templates/PAGE_COUNT.ENDED.entry.tpl
+++ /dev/null
@@ -1,20 +0,0 @@
-
-This is the template for a single ended PDC in the daily counting page.
-
-Placeholders:
- %1$s: page title
- %2$d: temperature
- %3$s: '1' if this PDC is multiple
- %4$s: color associated to the PDC e.g. #fff
- %5$d: number of the row
- %6$s: PDC type e.g. 'consensuale'
- %7$s: duration
- %8$s: title of the log page
- %9$s: date
- %10$s: turnover number e.g. 2 when '/2'
-
-
-{{Conteggio cancellazioni/Concluse/Voce|i = 0 |voce = ASD |turno = 2 |tipo = consensuale |data = %9$s |durata = 3 giorni |multipla = 1 }}
-
-
-{{Conteggio cancellazioni/Concluse/Voce|i = %5$d |voce = %1$s |turno = %10$s |tipo = %6$s |data = %9$s |durata = %7$s |multipla = %3$s }}
diff --git a/templates/PAGE_COUNT.ENDED.section.tpl b/templates/PAGE_COUNT.ENDED.section.tpl
deleted file mode 100644
index 01b5fe1..0000000
--- a/templates/PAGE_COUNT.ENDED.section.tpl
+++ /dev/null
@@ -1,13 +0,0 @@
-
-This is the template for a section of a daily counting page.
-
-This is the section for ended PDCs.
-
-Placeholders:
- %1$s: PDC rows
- %%: a literal '%'
-
-
-{{Conteggio cancellazioni/Concluse/Start|~~~~~}}
-%1$s
-{{Conteggio cancellazioni/Concluse/Stop}}
diff --git a/templates/PAGE_COUNT.ERRONEOUS.entry.tpl b/templates/PAGE_COUNT.ERRONEOUS.entry.tpl
deleted file mode 100644
index d8ec7cb..0000000
--- a/templates/PAGE_COUNT.ERRONEOUS.entry.tpl
+++ /dev/null
@@ -1,12 +0,0 @@
-
-This is the template for a single erroneous PDC entry.
-
-Placeholders:
- %1$s: PDC title
- %2$s: error message
-
-
-;[[Wikipedia:Pagine da cancellare/Esempio]]: Ricontrollare cose.
-
-
-;[[%1$s]]: %2$s
diff --git a/templates/PAGE_COUNT.ERRONEOUS.msg.sortkey.tpl b/templates/PAGE_COUNT.ERRONEOUS.msg.sortkey.tpl
deleted file mode 100644
index 7501697..0000000
--- a/templates/PAGE_COUNT.ERRONEOUS.msg.sortkey.tpl
+++ /dev/null
@@ -1,10 +0,0 @@
-
-This is the template for the error message of a PDC when it has a wrong category sortkey.
-
-Please do not insert newlines.
-
-Placeholders:
- %1$s: actual category sortkey
-
-
-Rilevata inconsistenza (forse dovuta ad uno spostamento). L'attuale valore di DEFAULTSORT è %s ma non corrisponde con il titolo della pagina. Correggi il valore di DEFAULTSORT ed eventualmente anche il valore del template {{Cancellazione/proposta}}.
diff --git a/templates/PAGE_COUNT.ERRONEOUS.section.tpl b/templates/PAGE_COUNT.ERRONEOUS.section.tpl
deleted file mode 100644
index 8b7b186..0000000
--- a/templates/PAGE_COUNT.ERRONEOUS.section.tpl
+++ /dev/null
@@ -1,10 +0,0 @@
-
-This is the template for a section of erroneous PDCs.
-
-Placeholders:
- %1$s: errors
-
-
-'''Attenzione:''' Sono state rilevate alcune PDC con errori:
-
-%1$s
diff --git a/templates/PAGE_COUNT.RUNNING.entry.tpl b/templates/PAGE_COUNT.RUNNING.entry.tpl
deleted file mode 100644
index d5cd961..0000000
--- a/templates/PAGE_COUNT.RUNNING.entry.tpl
+++ /dev/null
@@ -1,22 +0,0 @@
-
-This is the template for a single running PDC in the daily counting page.
-
-Placeholders:
- %1$s: page title
- %2$d: temperature
- %3$s: '1' if it's multiple
- %4$s: color associated to the PDC e.g. '#fff'
- %5%d: number of the row
- %6$s: PDC type e.g. 'consensuale'
- %7%s: duration e.g. 'un giorno'
- see the template DURATION_*.tpl
- %8%s: title of the log page
- %9$s: human date
- %10$s: turnover number e.g. 2 when '/2'
- %11$s: subject themes comma separated e.g. 'software libero, Abruzzo'
-
-
-{{Conteggio cancellazioni/In corso/Voce|i = 1 |voce = ASD |turno = 2 |tipo = votazione |data = 2018 maggio 3 |multipla = 1|argomenti = Abruzzo |temperatura = 42 }}
-
-
-{{Conteggio cancellazioni/In corso/Voce|i = %5$d |voce = %1$s |turno = %10$s |tipo = %6$s |data = %9$s |multipla = %3$s |argomenti = %11$s |temperatura = %2$d }}
diff --git a/templates/PAGE_COUNT.RUNNING.section.tpl b/templates/PAGE_COUNT.RUNNING.section.tpl
deleted file mode 100644
index 503f97a..0000000
--- a/templates/PAGE_COUNT.RUNNING.section.tpl
+++ /dev/null
@@ -1,12 +0,0 @@
-
-This is the template for a section of a daily counting page.
-
-This is the section for running PDCs.
-
-Placeholders:
- %1$s: PDC rows
-
-
-{{Conteggio cancellazioni/In corso/Start|~~~~~}}
-%1$s
-{{Conteggio cancellazioni/In corso/Stop}}
diff --git a/templates/PAGE_COUNT.content.tpl b/templates/PAGE_COUNT.content.tpl
deleted file mode 100644
index 4c83ff7..0000000
--- a/templates/PAGE_COUNT.content.tpl
+++ /dev/null
@@ -1,15 +0,0 @@
-
-This is the template for the content of a daily counting page.
-
-Placeholders:
- %1$d: year
- %2$d: month 1-12
- %2$02d: month 01-12
- %3$s: month name
- %4$d: day 1-31
- %4$02d: day 01-31
- %5$s: mega table of PDCs
-
-
-{{Conteggio cancellazioni}}
-%5$s
diff --git a/templates/PAGE_COUNT.empty.tpl b/templates/PAGE_COUNT.empty.tpl
deleted file mode 100644
index e43fa00..0000000
--- a/templates/PAGE_COUNT.empty.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-
-This is the template for an empty daily counting page.
-
-
-{{Conteggio cancellazioni/Vuoto|~~~~~}}
diff --git a/templates/PAGE_COUNT.summary.tpl b/templates/PAGE_COUNT.summary.tpl
deleted file mode 100644
index 18f4adb..0000000
--- a/templates/PAGE_COUNT.summary.tpl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-This is the template for the edit summary of a daily log page.
-
-Placeholders:
- %1$d: year
- %2$d: month 1-12
- %2$02d: month 01-12
- %3$s: month name
- %4$d: day 1-31
- %4$02d: day 01-31
-
-
-Bot: aggiornamento pagina di servizio giornaliera per i conteggi del 19 aprile 2018
-
-
-Bot: aggiornamento pagina di servizio giornaliera per i conteggi del %4$d %3$s %1$d
diff --git a/templates/PAGE_COUNT.title.tpl b/templates/PAGE_COUNT.title.tpl
deleted file mode 100644
index 962f325..0000000
--- a/templates/PAGE_COUNT.title.tpl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-This is the template for the title of a daily counting page.
-
-Placeholders:
- %1$d: year
- %2$d: month 1-12
- %2$02d: month 01-12
- %3$s: month name
- %4$d: day 1-31
- %4$02d: day 01-31
-
-
-Wikipedia:Pagine da cancellare/Conta/2017 aprile 20
-
-
-Wikipedia:Pagine da cancellare/Conta/%1$d %3$s %4$d
diff --git a/templates/PAGE_LOG.content.tpl b/templates/PAGE_LOG.content.tpl
deleted file mode 100644
index ca28fcc..0000000
--- a/templates/PAGE_LOG.content.tpl
+++ /dev/null
@@ -1,32 +0,0 @@
-
-This is the template for the content of a daily log page.
-
-Placeholders:
- %1$d: year
- %2$d: month 1-12
- %2$02d: month 01-12
- %3$s: month name
- %4$d: day 1-31
- %4$02d: day 01-31
- %5$s: PDC informations
- They are generated looping through the "PAGE_LOG.section.tpl" template
-
-
-{{Paginecancellare}}
-== 20 aprile ==
-{{Wikipedia:Pagine da cancellare/Conta/2017 aprile 20}}
-
-
-{{Wikipedia:Pagine da cancellare/ASD}}
-{{Wikipedia:Pagine da cancellare/DSA}}
-
-
-{{Wikipedia:Pagine da cancellare/GGH}}
-{{Wikipedia:Pagine da cancellare/HGG}}
-
-
-{{Paginecancellare}}
-== %4$d %3$s ==
-{{Wikipedia:Pagine da cancellare/Conta/%1$d %3$s %4$d}}
-
-%5$s
diff --git a/templates/PAGE_LOG.section.tpl b/templates/PAGE_LOG.section.tpl
deleted file mode 100644
index 4a05492..0000000
--- a/templates/PAGE_LOG.section.tpl
+++ /dev/null
@@ -1,18 +0,0 @@
-
-This is the template for a section of the daily log page.
-
-This template will call multiple times the "PAGE_LOG.entry.tpl" template.
-
-Placeholders:
- %1$s: PDC type e.g. 'con votazione'
- %2$s: PDC entries
-
-
-
-{{Wikipedia:Pagine da cancellare/ASD}}
-{{Wikipedia:Pagine da cancellare/DSA}}
-{{Wikipedia:Pagine da cancellare/ASD}}
-
-
-
-%2$s
diff --git a/templates/PAGE_LOG.summary.tpl b/templates/PAGE_LOG.summary.tpl
deleted file mode 100644
index 05a61c5..0000000
--- a/templates/PAGE_LOG.summary.tpl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-This is the template for the edit summary of a daily log page.
-
-Placeholders:
- %1$d: year
- %2$d: month 1-12
- %2$02d: month 01-12
- %3$s: month name
- %4$d: day 1-31
- %4$02d: day 01-31
-
-
-Bot: aggiornamento pagina di servizio giornaliera per il log del 19 aprile 2018
-
-
-Bot: aggiornamento pagina di servizio giornaliera per il log del %4$d %3$s %1$d
diff --git a/templates/PAGE_LOG.title.tpl b/templates/PAGE_LOG.title.tpl
deleted file mode 100644
index 06d2d49..0000000
--- a/templates/PAGE_LOG.title.tpl
+++ /dev/null
@@ -1,16 +0,0 @@
-
-This is the template for the title of a daily log page.
-
-Placeholders:
- %1$d: year
- %2$d: month 1-12
- %2$02d: month 01-12
- %3$s: month name
- %4$d: day 1-31
- %4$02d: day 01-31
-
-
-Wikipedia:Pagine da cancellare/Log/2018 aprile 20
-
-
-Wikipedia:Pagine da cancellare/Log/%1$d %3$s %4$d