diff --git a/config-example.php b/config-example.php index 742d86a..4f9eb9e 100644 --- a/config-example.php +++ b/config-example.php @@ -1,5 +1,10 @@ . namespace itwikidelbot; use \wm\WikipediaIt; use \mw\Tokens; /** * Handle a category */ class Category { + /** + * Do nothing + * + * @var bool + */ + public static $PORCELAIN = false; + + /** + * Debug mode + * + * @var bool + */ + public static $INSPECT = false; + /** * @var string Category title with prefix */ private $title; /** * Construct a Category * * @param $title Category title with its prefix */ public function __construct( $title ) { $this->title = $title; } /** * Get the category title with its prefix * * @return string */ public function getTitle() { return $this->title; } /** * Save this category * * @param $content string Category content * @param $summary string Edit summary * @return bool|mixed False if not created */ public function saveByContentSummary( $content, $summary ) { return static::saveByTitleContentSummary( $this->getTitle(), $content, $summary ); } /** * Save this category if it does not exist * * @param $content string Category content * @param $summary string Edit summary * @return bool|mixed False if not created */ public function saveByContentSummaryIfNotExists( $content, $summary ) { return self::saveByTitleContentSummaryIfNotExists( $this->getTitle(), $content, $summary ); } /** * Check if this category exists * * @return bool */ public function exists() { return static::existsByTitle( $this->getTitle() ); } /** * Save a category * * @param $title string Category name with prefix * @param $content string Category content * @param $summary string Edit summary * @return mixed Response */ public static function saveByTitleContentSummary( $title, $content, $summary ) { $wit = WikipediaIt::getInstance(); $args = [ 'action' => 'edit', 'title' => $title, 'text' => $content, 'summary' => $summary, 'token' => $wit->login()->getToken( Tokens::CSRF ), 'bot' => 1, ]; - var_dump( $args );exit; - return $wit->post( $args ); + if( self::$INSPECT ) { + print_r( $args ); + } + if( ! self::$PORCELAIN ) { + return $wit->post( $args ); + } } /** * Save a category if it does not exist * * @param $title string Category name with prefix * @param $content string Category content * @param $summary string Edit summary * @return bool|mixed False if not created */ public static function saveByTitleContentSummaryIfNotExists( $title, $content, $summary ) { if( ! static::existsByTitle( $title ) ) { return static::saveByTitleContentSummary( $title, $content, $summary ); } return false; } /** * Check if a category title exists * * @param $title string Category name with prefix * @return bool */ public static function existsByTitle( $title ) { $categoryinfo = WikipediaIt::getInstance()->fetch( [ 'action' => 'query', 'prop' => 'categoryinfo', 'titles' => $title, ] ); foreach( $categoryinfo->query->pages as $pageid => $page ) { return $pageid < 0 && isset( $page->missing ); } return false; } }