diff --git a/bot.php b/bot.php index e688924..e7d3a98 100755 --- a/bot.php +++ b/bot.php @@ -1,31 +1,38 @@ #!/usr/bin/php . namespace itwikidelbot; // autoload classes require __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'autoload.php'; // load credentials require __DIR__ . DIRECTORY_SEPARATOR . 'config.php'; -// create the category year +// create the yearly category $year = date( 'Y' ); -( new CategoryYear( $year ) )->saveIfNotExists(); +( new CategoryYear( $year ) ) + ->saveIfNotExists(); -// create the month category +// create the monthly category $month = date( 'n' ); // 1-12 -( new CategoryYearMonth( $year, $month ) )->saveIfNotExists(); +( new CategoryYearMonth( $year, $month ) ) + ->saveIfNotExists(); + +// create the daily category +$day = date( 'j' ); +( new CategoryYearMonthDay( $year, $month, $day ) ) + ->saveIfNotExists(); diff --git a/includes/class-CategoryYearMonthDay.php b/includes/class-CategoryYearMonthDay.php new file mode 100644 index 0000000..ff4c2c7 --- /dev/null +++ b/includes/class-CategoryYearMonthDay.php @@ -0,0 +1,110 @@ +. + +namespace itwikidelbot; + +/** + * Handle a daily category + * + * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_del_19_febbraio_2018 + */ +class CategoryYearMonthDay extends CategoryTemplated { + + /** + * Year + * + * @var int + */ + private $year; + + /** + * Month + * + * @var int 1-12 + */ + private $month; + + /** + * Day + * + * @var int 1-31 + */ + private $day; + + /** + * The template name for a daily category + * + * @override CategoryTemplated::TEMPLATE_NAME + */ + const TEMPLATE_NAME = 'CATEGORY_DAY'; + + /** + * Format of the generic title of a daily category + * + * e.g. 'Categoria:Cancellazioni del 19 aprile 2018' + */ + const GENERIC_TITLE = 'Categoria:Cancellazioni del %3$s %2$s %1$d'; + + /** + * Constructor + * + * @param $year int + * @param $month int 1-12 + * @param $day int 1-31 + */ + public function __construct( $year, $month, $day ) { + parent::__construct( self::title( $year, $month, $day ) ); + $this->year = $year; + $this->month = $month; + $this->day = $day; + } + + /** + * Get the template arguments + * + * @override CategoryTemplated::getTemplateArguments() + * @return array + */ + protected function getTemplateArguments() { + return [ + CategoryYearMonth::title( $this->year, $this->month ), + $this->year, + $this->month, + Months::number2name( $this->month - 1 ), + $this->day, + ]; + } + + /** + * Title of a daily category + * + * @param $year int + * @param $month int 1-12 + * @param $day int 1-31 + * @return string Category name e.g. 'Categoria:Cancellazioni del 19 febbraio 2018' + */ + public static function title( $year, $month, $day ) { + $human_month = Months::number2name( $month - 1 ); + return sprintf( self::GENERIC_TITLE, $year, $human_month, $day ); + } +} diff --git a/templates/CATEGORY_DAY_CONTENT.template b/templates/CATEGORY_DAY_CONTENT.template new file mode 100644 index 0000000..c73885f --- /dev/null +++ b/templates/CATEGORY_DAY_CONTENT.template @@ -0,0 +1,21 @@ + +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.template b/templates/CATEGORY_DAY_SUMMARY.template new file mode 100644 index 0000000..ffb7fbc --- /dev/null +++ b/templates/CATEGORY_DAY_SUMMARY.template @@ -0,0 +1,17 @@ + +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