diff --git a/includes/class-CategoryYearMonthDay.php b/includes/class-CategoryYearMonthDay.php index ba8756a..b14b686 100644 --- a/includes/class-CategoryYearMonthDay.php +++ b/includes/class-CategoryYearMonthDay.php @@ -1,178 +1,179 @@ . namespace itwikidelbot; /** - * Handle a daily category that contains semplified PDC pages + * 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'; /** * Template arguments * * @override CategoryYearMonth::getTemplateArguments() */ public function getTemplateArguments() { return array_merge( [ ( new CategoryYearMonth( $this->getYear(), $this->getMonth() ) ) ->getTemplatedTitle() ], parent::getTemplateArguments() ); } /** * Operate on every children page */ public function operateEveryChildrenPage() { // Categories for PDCs in order of importance (I think) $Categories = [ CategoryYearMonthDayTypeVoting::class, CategoryYearMonthDayTypeProlonged::class, CategoryYearMonthDayTypeConsensual::class, CategoryYearMonthDayTypeOrdinary::class, - self::class, // semplified + CategoryYearMonthDayTypeSimple::class, ]; $pages_by_type = []; foreach( $Categories as $Category ) { $category = new $Category( $this->getYear(), $this->getMonth(), $this->getDay() ); // fetch the pages in this category $pages = $category->fetchChildrenPages(); if( count( $pages ) ) { $category->saveIfNotExists(); } // sort by last update usort( $pages, function ( $a, $b ) { return $a->getDate() > $b->getDate(); } ); $pages_by_type[ $Category ] = $pages; } // PageYearMonthDayPDCsCount::createFromPagePDCs( $this, $pages_by_type ) // ->save(); PageYearMonthDayPDCsLog::createFromPagePDCs( $this, $pages_by_type ) ->save(); } /** * Fetch children PDC pages from this category * * @return array */ protected function fetchChildrenPages() { $api = self::api()->setApiData( [ '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 (completly unuseful) // 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(), 'gcmnamespace' => 4, // Wikipedia namespace (not category) // 'gcmtype' => 'page', // Note: Ignored when cmsort=timestamp is set. // '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 // TODO: probably the revisions parameter is unuseful. Info already provides "touched" (sometimes ._.) '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 // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Binfo 'clprop' => 'sortkey', // timestamp of the latest revision // https://it.wikipedia.org/w/api.php?action=help&modules=query%2Brevisions // 'rvprop' => 'timestamp', ] ); $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 // Note: pages are not directly saved with their pageid to preserve their order $pageid = $page->pageid; if( isset( $all[ $pageid ] ) ) { foreach( $page as $property => $value ) { $all[ $pageid ]->{$property} = $value; } } else { $all[ $pageid ] = $page; } } } } $all_pdc = []; foreach( $all as $page ) { $pdc = $this->createPDCFromRaw( $page ); if( $pdc && $pdc->isValid() ) { $all_pdc[] = $pdc; } } return $all_pdc; } /** * Create a PDF from raw (of this type) * * @param $pdc mixed */ public function createPDCFromRaw( $pdc ) { return PDC::createFromRaw( static::class, $pdc ); } } diff --git a/includes/class-CategoryYearMonthDayType.php b/includes/class-CategoryYearMonthDayType.php index f391125..f9de63c 100644 --- a/includes/class-CategoryYearMonthDayType.php +++ b/includes/class-CategoryYearMonthDayType.php @@ -1,66 +1,64 @@ . namespace itwikidelbot; /** - * Handle a daily category with a specified PDC type - * - * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_consensuali_del_13_aprile_2018 + * 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'; /** * PDC type e.g. 'consensuale' * * To be overrided */ const PDC_TYPE = 'EXAMPLE'; /** * Get the PDC type * * @return string e.g. 'consensuale' */ public function getPDCType() { return static::PDC_TYPE; } /** * Get template arguments * * @override CategoryTemplated::getTemplateArguments() */ public function getTemplateArguments() { $parent_arguments = parent::getTemplateArguments(); $parent_arguments[] = $this->getPDCType(); return $parent_arguments; } } diff --git a/includes/class-CategoryYearMonthDayType.php b/includes/class-CategoryYearMonthDayTypeSimple.php similarity index 63% copy from includes/class-CategoryYearMonthDayType.php copy to includes/class-CategoryYearMonthDayTypeSimple.php index f391125..d8677d6 100644 --- a/includes/class-CategoryYearMonthDayType.php +++ b/includes/class-CategoryYearMonthDayTypeSimple.php @@ -1,66 +1,62 @@ . namespace itwikidelbot; /** - * Handle a daily category with a specified PDC type + * Handle a daily category of semplified PDCs * - * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_consensuali_del_13_aprile_2018 + * Pratically, a semplified PDC category is the daily PDC category. + * So the template of this class cames from CategoryYearMonthDay. + * + * e.g. https://it.wikipedia.org/wiki/Categoria:Cancellazioni_del_1_aprile_2017 */ -abstract class CategoryYearMonthDayType extends CategoryYearMonthDay { - - /** - * Template name of this category - * - * @override CategoryTemplated::TEMPLATE_NAME - */ - const TEMPLATE_NAME = 'CATEGORY_DAY_PDCTYPE'; +class CategoryYearMonthDayTypeSimple extends CategoryYearMonthDayType { /** - * PDC type e.g. 'consensuale' + * PDC type * - * To be overrided + * @override CategoryYearMonthDayType::PDC_TYPE */ - const PDC_TYPE = 'EXAMPLE'; + const PDC_TYPE = 'semplificate'; /** - * Get the PDC type + * Template name of this category * - * @return string e.g. 'consensuale' + * @override CategoryTemplated::getTemplateName() + * @see CategoryYearMonthDay::TEMPLATE_NAME */ - public function getPDCType() { - return static::PDC_TYPE; + public function getTemplateName() { + return CategoryYearMonthDay::TEMPLATE_NAME; } /** - * Get template arguments + * Template arguments * - * @override CategoryTemplated::getTemplateArguments() + * @override CategoryYearMonth::getTemplateArguments() */ public function getTemplateArguments() { - $parent_arguments = parent::getTemplateArguments(); - $parent_arguments[] = $this->getPDCType(); - return $parent_arguments; + return CategoryYearMonthDay::getTemplateArguments(); } + }