Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F15179894
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Unknown
Size
17 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/includes/class-PDC.php b/includes/class-PDC.php
index 7318613..70ec1f2 100644
--- a/includes/class-PDC.php
+++ b/includes/class-PDC.php
@@ -1,440 +1,422 @@
<?php
# it.wiki deletion bot in PHP
# Copyright (C) 2013 Mauro742, MauroBot
# https://it.wikipedia.org/wiki/Utente:Mauro742
# https://it.wikipedia.org/wiki/Utente:MauroBot
# Originally under Creative Commons BY SA 3.0 International
# https://it.wikipedia.org/wiki/Utente:MauroBot/BotCancellazioni/core.js
# https://creativecommons.org/licenses/by-sa/3.0/
# https://wikimediafoundation.org/wiki/Special:MyLanguage/Terms_of_Use/it
# Copyright (C) 2018 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 <https://www.gnu.org/licenses/>.
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 = self::PREFIX . 'multiple/';
/**
* PDC category type
*
* @var CategoryYearMonthDayType
*/
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;
/**
* Page length in bytes
*
* @var int
*/
private $length;
/**
* When the PDC was added to the PDC type category
*
* @var date
*/
private $startDate;
/**
* Last update
*
* @var date
*/
private $lasteditDate;
/**
* Is Protected?
*
* @var bool
*/
private $isProtected;
/**
* Properties that the raw object must have
*
* @var array
*/
private static $RAW_PROPERTIES = [
'pageid',
'title',
'length',
'touched',
'protection',
'categories'
];
/**
* Constructor
*
* @param $category_type CategoryYearMonthDayType 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 $start DateTime When the PDC was added to the PDC type category
* @param $lastedit DateTime PDC lastedit date
* @param $is_protected bool Is the PDC protected?
* @see Page::__construct()
* @throws PDCException
*/
public function __construct( $category_type, $id, $title, $title_subject, $length, DateTime $start, DateTime $lastedit, $is_protected ) {
$this->categoryType = $category_type;
$this->id = $id;
$this->titleSubject = $title_subject;
$this->length = $length;
$this->startDate = $start;
$this->lasteditDate = $lastedit;
$this->isProtected = $is_protected;
parent::__construct( $title );
// consistence checks
if( ! $this->isTitlePrefixValid() ) {
throw new PDCException( 'not a PDC' );
}
if( $this->getDurationDays() > 7 ) {
throw new PDCExceptionExpired( 'not anymore a PDC of type ' . $this->getType() );
}
$this->checkTitleSubjectConsistence();
}
/**
* 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 page length
*
* @return int
*/
public function getLength() {
return $this->length;
}
/**
* Get the start date of this PDC (of this type)
*
* @return DateTime
*/
public function getStartDate() {
return $this->startDate;
}
/**
* Get the latest update date
*
* @return DateTime
*/
public function getLasteditDate() {
return $this->lasteditDate;
}
/**
* Get the PDC type class
*
* @return class
*/
public function getTypeClass() {
return $this->categoryType;
}
/**
* Get the PDC type name
*
* @return string e.g. 'consensuale'
*/
public function getType() {
return $this->getTypeClass()::getPDCType();
}
- /**
- * Get the PDC color
- *
- * @return string
- */
- public function getColor() {
- return Template::get( 'PDC.' . $this->getType() . '.color' );
- }
-
- /**
- * Get the PDC go to action label
- *
- * @return string
- */
- public function getGotoActionLabel() {
- return Template::get( 'PDC.' . $this->getType() . '.goto' );
- }
-
/**
* Check if this page is protected
*
* @return bool
*/
public function isProtected() {
return $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
*/
private 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 );
}
/**
* Verify if the title of the subject is consistent with the PDC title
*
* @return bool
*/
private function checkTitleSubjectConsistence() {
// 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 ];
}
}
if( $subject !== $subject_gen ) {
throw new PDCException( sprintf(
'the sortkey is "%s" and it is inconsistent with the PDC suffix "%s"',
$subject_gen,
$subject
) );
}
}
/**
* Static constructor
*
* @param $type CategoryYearMonthDayType Specified PDC type
* @param $page mixed
* @return self
* @throws PDCException
*/
public static function createFromRaw( $type, $page ) {
// verify consistence
foreach( self::$RAW_PROPERTIES as $property ) {
if( ! isset( $page->$property ) ) {
throw new PDCException( "PDC has not property $property" );
}
}
// read the title of the subject from the {{DEFAULTSORT}} category sortkey prefix
// get the start date of this PDC from the timestamp
$title_subject = null;;
$date_added_in_category = null;
foreach( $page->categories as $category ) {
if( ! isset( $category->title ) ) {
throw new PDCException( 'missing category title' );
}
if( $category->title === $type->getTitle() ) {
$title_subject = $category->sortkeyprefix;
$date_added_in_category = $category->timestamp;
}
break;
}
if( ! isset( $title_subject ) ) {
throw new PDCException( 'missing category sortkey prefix that contains title subject' );
}
if( ! isset( $date_added_in_category ) ) {
throw new PDCException( 'missing timestamp that contains the PDC start date' );
}
// 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(
$type,
(int) $page->pageid,
$page->title,
$title_subject,
(int) $page->length,
DateTime::createFromFormat( DateTime::ISO8601, $date_added_in_category ),
DateTime::createFromFormat( DateTime::ISO8601, $page->touched ),
$is_protected
);
}
/**
* 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 CategoryYearMonthDayTypeSimple::getPDCType():
$slope = 0.0365;
$offset = -24.0;
break;
case CategoryYearMonthDayTypeConsensual::getPDCType():
$slope = 0.0075;
$offset = -12.81;
break;
case CategoryYearMonthDayTypeProlonged::getPDCType():
$slope = 0.0035;
$offset = -9.76;
break;
case CategoryYearMonthDayTypeOrdinary::getPDCType():
case CategoryYearMonthDayTypeVoting ::getPDCType():
$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 number of days of duration of this PDC
*
* @return int
*/
public function getDurationDays() {
return (int) $this->getStartDate()->diff( $this->getLasteditDate() )->format('%a');
}
/**
* 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 ] );
}
}
diff --git a/includes/class-PageYearMonthDayPDCsCount.php b/includes/class-PageYearMonthDayPDCsCount.php
index 56e5eee..c61c17e 100644
--- a/includes/class-PageYearMonthDayPDCsCount.php
+++ b/includes/class-PageYearMonthDayPDCsCount.php
@@ -1,118 +1,117 @@
<?php
# it.wiki deletion bot in PHP
# Copyright (C) 2018 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 <https://www.gnu.org/licenses/>.
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: goto action label e.g. 'pagina di discussione'
*
* @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 )
] );
}
$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->isProtected()
? '.ENDED.entry'
: '.RUNNING.entry';
return Template::get( $template_name, [
$pdc->getTitleSubject(),
$pdc->getTemperature(),
$pdc->isMultiple(),
- $pdc->getColor(),
+ '', // TODO: Ex color. Now unuseful.
$i,
$pdc->getType(),
$pdc->getHumanDuration(),
- $this->getTitle(),
- $pdc->getGotoActionLabel()
+ $this->getTitle()
] );
}
}
diff --git a/templates/PDC.con_votazione.color.tpl b/templates/PDC.con_votazione.color.tpl
deleted file mode 100644
index 0c0dba0..0000000
--- a/templates/PDC.con_votazione.color.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the color of a PDC 'con votazione'.
-
-<!-- START TEMPLATE -->
-#ffe2df
diff --git a/templates/PDC.con_votazione.goto.tpl b/templates/PDC.con_votazione.goto.tpl
deleted file mode 100644
index c794b60..0000000
--- a/templates/PDC.con_votazione.goto.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the "vai alla [qualcosa]" action.
-
-This is for a voting PDC.
-
-<!-- START TEMPLATE -->
-votazione
diff --git a/templates/PDC.consensuale.color.tpl b/templates/PDC.consensuale.color.tpl
deleted file mode 100644
index e68c130..0000000
--- a/templates/PDC.consensuale.color.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the color of a PDC 'consensuale'.
-
-<!-- START TEMPLATE -->
-#ffc
diff --git a/templates/PDC.consensuale.goto.tpl b/templates/PDC.consensuale.goto.tpl
deleted file mode 100644
index ecab17d..0000000
--- a/templates/PDC.consensuale.goto.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the "vai alla [qualcosa]" action.
-
-This is for a consensual PDC.
-
-<!-- START TEMPLATE -->
-discussione
diff --git a/templates/PDC.ordinarie.color.tpl b/templates/PDC.ordinarie.color.tpl
deleted file mode 100644
index b075dff..0000000
--- a/templates/PDC.ordinarie.color.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the color of a PDC 'ordinaria'.
-
-<!-- START TEMPLATE -->
-#ffe2df
diff --git a/templates/PDC.ordinarie.goto.tpl b/templates/PDC.ordinarie.goto.tpl
deleted file mode 100644
index 2343833..0000000
--- a/templates/PDC.ordinarie.goto.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the "vai alla [qualcosa]" action.
-
-This is for an ordinary PDC.
-
-<!-- START TEMPLATE -->
-votazione
diff --git a/templates/PDC.prorogate.color.tpl b/templates/PDC.prorogate.color.tpl
deleted file mode 100644
index 5983e9e..0000000
--- a/templates/PDC.prorogate.color.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the color of a PDC 'consensuale prorogata'.
-
-<!-- START TEMPLATE -->
-#ffc
diff --git a/templates/PDC.prorogate.goto.tpl b/templates/PDC.prorogate.goto.tpl
deleted file mode 100644
index b5d8f9a..0000000
--- a/templates/PDC.prorogate.goto.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the "vai alla [qualcosa]" action.
-
-This is for a prorogated PDC.
-
-<!-- START TEMPLATE -->
-discussione
diff --git a/templates/PDC.semplificate.color.tpl b/templates/PDC.semplificate.color.tpl
deleted file mode 100644
index 6872e2e..0000000
--- a/templates/PDC.semplificate.color.tpl
+++ /dev/null
@@ -1,5 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the color of a PDC 'semplificata'.
-
-<!-- START TEMPLATE -->
-#e5ffe5
diff --git a/templates/PDC.semplificate.goto.tpl b/templates/PDC.semplificate.goto.tpl
deleted file mode 100644
index 15396ca..0000000
--- a/templates/PDC.semplificate.goto.tpl
+++ /dev/null
@@ -1,7 +0,0 @@
-<!-- START DOCUMENTATION -->
-This is the template for the "vai alla [qualcosa]" action.
-
-This is for a semplified PDC.
-
-<!-- START TEMPLATE -->
-proposta di cancellazione
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 05:19 (14 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264907
Default Alt Text
(17 KB)
Attached To
Mode
R32 Italian Wikipedia Deletion Bot
Attached
Detach File
Event Timeline