diff --git a/includes/class-CategoryTemplated.php b/includes/class-CategoryTemplated.php index a462cd6..74eda8e 100644 --- a/includes/class-CategoryTemplated.php +++ b/includes/class-CategoryTemplated.php @@ -1,76 +1,140 @@ . namespace itwikidelbot; /** * Handle a generic category associated to a template */ -abstract class CategoryTemplated extends Category { +class CategoryTemplated extends Category { /** * Template name of this category + * + * @param $name */ - const TEMPLATE_NAME = 'TEMPLATE_NAME'; + private $name; /** - * Get the template arguments + * Arguments to be passed to the template + * + * @var array + */ + private $args; + + /** + * Constructor + * + * @param $name Template name + * @param $args Template arguments + */ + public function __construct( $name, $args ) { + $this->name = $name; + $this->args = $args; + parent::__construct( $this->getTemplatedTitle() ); + } + + /** + * Get the name of the template + * + * @return string + */ + public function getTemplateName() { + return $this->name; + } + + /** + * Get the name of the template for the page title + * + * @return string + */ + public function getTemplateTitleName() { + return $this->getTemplateName() . '_TITLE'; + } + + /** + * Get the name of the template for the summary * - * To be overrided + * @return string + */ + public function getTemplateSummaryName() { + return $this->getTemplateName() . '_SUMMARY'; + } + + /** + * Get the name of the template for the content + */ + public function getTemplateContentName() { + return $this->getTemplateName() . '_CONTENT'; + } + + /** + * Get the template arguments * * @return array */ - abstract protected function getTemplateArguments(); + public function getTemplateArguments() { + return $this->args; + } /** * Get the edit summary for this category from its template * * @return string */ public function getTemplatedSummary() { - return Template::get( static::TEMPLATE_NAME . '_SUMMARY', $this->getTemplateArguments() ); + return Template::get( $this->getTemplateSummaryName(), $this->getTemplateArguments() ); + } + + /** + * Get the page title from its template + * + * @return string + */ + public function getTemplatedTitle() { + return Template::get( $this->getTemplateTitleName(), $this->getTemplateArguments() ); } /** * Get the page content for this category from its template * * @return string */ public function getTemplatedContent() { - return Template::get( static::TEMPLATE_NAME . '_CONTENT', $this->getTemplateArguments() ); + return Template::get( $this->getTemplateContentName(), $this->getTemplateArguments() ); } /** * Save this category from the content of its template * * @return mixed */ public function save() { return $this->saveByContentSummary( $this->getTemplatedContent(), $this->getTemplatedSummary() ); } /** - * Save this category from the content of its template if not exists + * Save this category from the content of its template if it does not exist * * @return bool|mixed */ public function saveIfNotExists() { if( ! $this->exists() ) { return $this->save(); } return false; } } diff --git a/includes/class-CategoryYear.php b/includes/class-CategoryYear.php index 69fe6f0..e96e422 100644 --- a/includes/class-CategoryYear.php +++ b/includes/class-CategoryYear.php @@ -1,91 +1,54 @@ . namespace itwikidelbot; /** * Handle a yearly category * * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_-_2017 */ class CategoryYear extends CategoryTemplated { /** * Year * * @var int */ private $year; - /** - * The template name for a yearly category - * - * @override CategoryTemplated::TEMPLATE_NAME - */ - const TEMPLATE_NAME = 'CATEGORY_YEAR'; - - /** - * Format of the generic title of a yearly category - * - * e.g. 'Categoria:Cancellazioni - 2018' - */ - const GENERIC_TITLE = 'Categoria:Cancellazioni - %d'; - - /** - * Parent category title - */ - const PARENT_CATEGORY_TITLE = 'Categoria:Pagine in cancellazione per anno'; - /** * Constructor * * @param $year int + * @see CategoryTemplated::__construct() */ public function __construct( $year ) { - parent::__construct( self::title( $year ) ) ; - $this->year = $year; - } - /** - * Get the template arguments - * - * @override CategoryTemplated::getTemplateArguments() - * @return array - */ - protected function getTemplateArguments() { - return [ - self::PARENT_CATEGORY_TITLE, - $this->year, - ]; - } + parent::__construct( 'CATEGORY_YEAR', [ + $year + ] ); - /** - * Title of the category in the specified year - * - * @param $year int e.g. 2018 - * @return string Category name e.g. 'Categoria:Cancellazioni - 2018' - */ - public static function title( $year ) { - return sprintf( self::GENERIC_TITLE, $year ); + $this->year = $year; } } diff --git a/includes/class-CategoryYearMonth.php b/includes/class-CategoryYearMonth.php index 3a1cc5c..e39cfc1 100644 --- a/includes/class-CategoryYearMonth.php +++ b/includes/class-CategoryYearMonth.php @@ -1,99 +1,67 @@ . namespace itwikidelbot; /** * Handle a monthly category * * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_-_aprile_2018 */ class CategoryYearMonth extends CategoryTemplated { /** * Year * * @var int */ private $year; /** * Month * * @var int 1-12 */ private $month; - /** - * The template name for a monthly category - * - * @override CategoryTemplated::TEMPLATE_NAME - */ - const TEMPLATE_NAME = 'CATEGORY_MONTH'; - - /** - * Format of the generic title of a monthly category - * - * e.g. 'Categoria:Cancellazioni - aprile 2018' - */ - const GENERIC_TITLE = 'Categoria:Cancellazioni - %2$s %1$d'; - /** * Constructor * * @param $year int * @param $month int 1-12 + * @see CategoryTemplated::__construct() */ public function __construct( $year, $month ) { - parent::__construct( self::title( $year, $month ) ); - $this->year = $year; - $this->month = $month; - } - /** - * Get the template arguments - * - * @override CategoryTemplated::getTemplateArguments() - * @return array - */ - protected function getTemplateArguments() { - return [ - CategoryYear::title( $this->year ), - $this->year, - $this->month, - Months::number2name( $this->month - 1 ), - ]; - } + parent::__construct( 'CATEGORY_MONTH', [ + $parent_title = ( new CategoryYear( $year ) ) + ->getTemplatedTitle(), + $year, + $month, + Months::number2name( $month - 1 ), + ] ); - /** - * Title of a monthly category - * - * @param $year int e.g. 2018 - * @param $month int e.g. 4 - * @return string Category name e.g. 'Categoria:Cancellazioni - aprile 2018' - */ - public static function title( $year, $month ) { - $human_month = Months::number2name( $month - 1 ); - return sprintf( self::GENERIC_TITLE, $year, $human_month ); + $this->year = $year; + $this->month = $month; } } diff --git a/includes/class-CategoryYearMonthDay.php b/includes/class-CategoryYearMonthDay.php index ff4c2c7..e09b5dc 100644 --- a/includes/class-CategoryYearMonthDay.php +++ b/includes/class-CategoryYearMonthDay.php @@ -1,110 +1,77 @@ . 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 + * @see CategoryTemplated::__construct() */ public function __construct( $year, $month, $day ) { - parent::__construct( self::title( $year, $month, $day ) ); + + parent::__construct( 'CATEGORY_DAY', [ + ( new CategoryYearMonth( $year, $month ) ) + ->getTemplatedTitle(), + $year, + $month, + Months::number2name( $month - 1 ), + $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_TITLE.template b/templates/CATEGORY_DAY_TITLE.template new file mode 100644 index 0000000..6d6e59a --- /dev/null +++ b/templates/CATEGORY_DAY_TITLE.template @@ -0,0 +1,17 @@ + +This is the template for the title 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 + + +Categoria:Cancellazioni del 19 aprile 2018 + + +Categoria:Cancellazioni del %5$d %4$s %2$d diff --git a/templates/CATEGORY_MONTH_TITLE.template b/templates/CATEGORY_MONTH_TITLE.template new file mode 100644 index 0000000..5a5e2de --- /dev/null +++ b/templates/CATEGORY_MONTH_TITLE.template @@ -0,0 +1,15 @@ + +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.template b/templates/CATEGORY_YEAR_CONTENT.template index 7bcc7c6..d41a1a9 100644 --- a/templates/CATEGORY_YEAR_CONTENT.template +++ b/templates/CATEGORY_YEAR_CONTENT.template @@ -1,12 +1,11 @@ This is the template for the content of a yearly category. Placeholders: - %1$s: category title - %2$d: year + %1$d: year -[[Categoria:Cancellazioni - 2018| 2018]] +[[Categoria:Pagine in cancellazione per anno| 2018]] -[[%1$s| %2$d]] +[[Categoria:Pagine in cancellazione per anno| %1$d]] diff --git a/templates/CATEGORY_YEAR_SUMMARY.template b/templates/CATEGORY_YEAR_SUMMARY.template index 6e82703..7d9922c 100644 --- a/templates/CATEGORY_YEAR_SUMMARY.template +++ b/templates/CATEGORY_YEAR_SUMMARY.template @@ -1,12 +1,11 @@ This is the template for the summary of a yearly category. Placeholders: - %1$s: category title - %2$d: year + %1$d: year Bot: creazione categoria annuale di servizio per il 2018 -Bot: creazione categoria annuale di servizio per il %2$d +Bot: creazione categoria annuale di servizio per il %1$d diff --git a/templates/CATEGORY_YEAR_TITLE.template b/templates/CATEGORY_YEAR_TITLE.template new file mode 100644 index 0000000..7d33317 --- /dev/null +++ b/templates/CATEGORY_YEAR_TITLE.template @@ -0,0 +1,11 @@ + +This is the template for the title of a yearly category. + +Placeholders: + %1$d: year + + +Categoria:Cancellazioni - 2018 + + +Categoria:Cancellazioni - %1$d