@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -18,20 +18,20 @@ discard block |
||
| 18 | 18 | * @return array[] |
| 19 | 19 | */ |
| 20 | 20 | public function getUsersToProcess() : array { |
| 21 | - if ( $this->users === null ) { |
|
| 22 | - $this->getLogger()->debug( 'Retrieving users list' ); |
|
| 23 | - $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
|
| 24 | - $listUsers = json_decode( $content, true ); |
|
| 21 | + if ($this->users === null) { |
|
| 22 | + $this->getLogger()->debug('Retrieving users list'); |
|
| 23 | + $content = $this->getController()->getPageContent($this->getConfig()->get('list-title')); |
|
| 24 | + $listUsers = json_decode($content, true); |
|
| 25 | 25 | |
| 26 | 26 | $this->users = []; |
| 27 | - foreach ( $listUsers as $user => $groups ) { |
|
| 28 | - $timestamp = $this->getValidTimestamp( $groups ); |
|
| 27 | + foreach ($listUsers as $user => $groups) { |
|
| 28 | + $timestamp = $this->getValidTimestamp($groups); |
|
| 29 | 29 | |
| 30 | - if ( date( 'd/m', $timestamp ) === date( 'd/m' ) && |
|
| 30 | + if (date('d/m', $timestamp) === date('d/m') && |
|
| 31 | 31 | // Don't trigger if the date is actually today |
| 32 | - date( 'd/m/Y', $timestamp ) !== date( 'd/m/Y' ) |
|
| 32 | + date('d/m/Y', $timestamp) !== date('d/m/Y') |
|
| 33 | 33 | ) { |
| 34 | - $this->users[ $user ] = $groups; |
|
| 34 | + $this->users[$user] = $groups; |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -45,17 +45,15 @@ discard block |
||
| 45 | 45 | * @param array $groups |
| 46 | 46 | * @return int |
| 47 | 47 | */ |
| 48 | - private function getValidTimestamp( array $groups ) : int { |
|
| 49 | - $checkuser = isset( $groups[ 'checkuser' ] ) ? |
|
| 50 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'checkuser' ] )->getTimestamp() : |
|
| 51 | - 0; |
|
| 52 | - $bureaucrat = isset( $groups[ 'bureaucrat' ] ) ? |
|
| 53 | - \DateTime::createFromFormat( 'd/m/Y', $groups[ 'bureaucrat' ] )->getTimestamp() : |
|
| 54 | - 0; |
|
| 48 | + private function getValidTimestamp(array $groups) : int { |
|
| 49 | + $checkuser = isset($groups['checkuser']) ? |
|
| 50 | + \DateTime::createFromFormat('d/m/Y', $groups['checkuser'])->getTimestamp() : 0; |
|
| 51 | + $bureaucrat = isset($groups['bureaucrat']) ? |
|
| 52 | + \DateTime::createFromFormat('d/m/Y', $groups['bureaucrat'])->getTimestamp() : 0; |
|
| 55 | 53 | |
| 56 | - $timestamp = max( $bureaucrat, $checkuser ); |
|
| 57 | - if ( $timestamp === 0 ) { |
|
| 58 | - $timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups[ 'sysop' ] )->getTimestamp(); |
|
| 54 | + $timestamp = max($bureaucrat, $checkuser); |
|
| 55 | + if ($timestamp === 0) { |
|
| 56 | + $timestamp = \DateTime::createFromFormat('d/m/Y', $groups['sysop'])->getTimestamp(); |
|
| 59 | 57 | } |
| 60 | 58 | return $timestamp; |
| 61 | 59 | } |
@@ -65,8 +63,8 @@ discard block |
||
| 65 | 63 | * |
| 66 | 64 | * @param string $name |
| 67 | 65 | */ |
| 68 | - public function removeUser( string $name ) { |
|
| 69 | - unset( $this->users[ $name ] ); |
|
| 66 | + public function removeUser(string $name) { |
|
| 67 | + unset($this->users[$name]); |
|
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | /** |
@@ -79,7 +77,7 @@ discard block |
||
| 79 | 77 | /** |
| 80 | 78 | * @param string $title |
| 81 | 79 | */ |
| 82 | - public function addCreatedPages( string $title ) { |
|
| 80 | + public function addCreatedPages(string $title) { |
|
| 83 | 81 | $this->createdPages[] = $title; |
| 84 | 82 | } |
| 85 | 83 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Request; |
| 4 | 4 | |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * @param array $params |
| 38 | 38 | * @param bool $isPOST |
| 39 | 39 | */ |
| 40 | - protected function __construct( array $params, bool $isPOST = false ) { |
|
| 41 | - $this->params = [ 'format' => 'json' ] + $params; |
|
| 40 | + protected function __construct(array $params, bool $isPOST = false) { |
|
| 41 | + $this->params = ['format' => 'json'] + $params; |
|
| 42 | 42 | $this->method = $isPOST ? 'POST' : 'GET'; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -49,11 +49,11 @@ discard block |
||
| 49 | 49 | * @param bool $isPOST |
| 50 | 50 | * @return self |
| 51 | 51 | */ |
| 52 | - public static function newFromParams( array $params, bool $isPOST = false ) : self { |
|
| 53 | - if ( extension_loaded( 'curl' ) ) { |
|
| 54 | - $ret = new CurlRequest( $params, $isPOST ); |
|
| 52 | + public static function newFromParams(array $params, bool $isPOST = false) : self { |
|
| 53 | + if (extension_loaded('curl')) { |
|
| 54 | + $ret = new CurlRequest($params, $isPOST); |
|
| 55 | 55 | } else { |
| 56 | - $ret = new NativeRequest( $params, $isPOST ); |
|
| 56 | + $ret = new NativeRequest($params, $isPOST); |
|
| 57 | 57 | } |
| 58 | 58 | return $ret; |
| 59 | 59 | } |
@@ -67,19 +67,19 @@ discard block |
||
| 67 | 67 | $curParams = $this->params; |
| 68 | 68 | $sets = []; |
| 69 | 69 | do { |
| 70 | - $res = $this->makeRequestInternal( $curParams ); |
|
| 70 | + $res = $this->makeRequestInternal($curParams); |
|
| 71 | 71 | |
| 72 | - $this->handleErrorAndWarnings( $res ); |
|
| 72 | + $this->handleErrorAndWarnings($res); |
|
| 73 | 73 | $sets[] = $res; |
| 74 | 74 | |
| 75 | 75 | $finished = true; |
| 76 | - if ( isset( $res->continue ) ) { |
|
| 77 | - $curParams = array_merge( $curParams, get_object_vars( $res->continue ) ); |
|
| 76 | + if (isset($res->continue)) { |
|
| 77 | + $curParams = array_merge($curParams, get_object_vars($res->continue)); |
|
| 78 | 78 | $finished = false; |
| 79 | 79 | } |
| 80 | - } while ( !$finished ); |
|
| 80 | + } while (!$finished); |
|
| 81 | 81 | |
| 82 | - return $this->mergeSets( $sets ); |
|
| 82 | + return $this->mergeSets($sets); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | * @param array $params |
| 89 | 89 | * @return \stdClass |
| 90 | 90 | */ |
| 91 | - private function makeRequestInternal( array $params ) : \stdClass { |
|
| 92 | - if ( $this->method === 'POST' ) { |
|
| 91 | + private function makeRequestInternal(array $params) : \stdClass { |
|
| 92 | + if ($this->method === 'POST') { |
|
| 93 | 93 | $params['maxlag'] = self::MAXLAG; |
| 94 | 94 | } |
| 95 | - $params = http_build_query( $params ); |
|
| 95 | + $params = http_build_query($params); |
|
| 96 | 96 | |
| 97 | - $body = $this->reallyMakeRequest( $params ); |
|
| 97 | + $body = $this->reallyMakeRequest($params); |
|
| 98 | 98 | |
| 99 | - $this->setCookies( $this->newCookies ); |
|
| 100 | - return json_decode( $body ); |
|
| 99 | + $this->setCookies($this->newCookies); |
|
| 100 | + return json_decode($body); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -106,18 +106,18 @@ discard block |
||
| 106 | 106 | * @param string $params |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - abstract protected function reallyMakeRequest( string $params ) : string; |
|
| 109 | + abstract protected function reallyMakeRequest(string $params) : string; |
|
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | 112 | * After a request, set cookies for the next ones |
| 113 | 113 | * |
| 114 | 114 | * @param array $cookies |
| 115 | 115 | */ |
| 116 | - protected function setCookies( array $cookies ) { |
|
| 117 | - foreach ( $cookies as $cookie ) { |
|
| 118 | - $bits = explode( ';', $cookie ); |
|
| 119 | - list( $name, $value ) = explode( '=', $bits[0] ); |
|
| 120 | - self::$cookiesToSet[ $name ] = $value; |
|
| 116 | + protected function setCookies(array $cookies) { |
|
| 117 | + foreach ($cookies as $cookie) { |
|
| 118 | + $bits = explode(';', $cookie); |
|
| 119 | + list($name, $value) = explode('=', $bits[0]); |
|
| 120 | + self::$cookiesToSet[$name] = $value; |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * @param \stdClass $res |
| 128 | 128 | * @throws APIRequestException |
| 129 | 129 | */ |
| 130 | - protected function handleErrorAndWarnings( $res ) { |
|
| 131 | - if ( isset( $res->error ) ) { |
|
| 132 | - switch ( $res->error->code ) { |
|
| 130 | + protected function handleErrorAndWarnings($res) { |
|
| 131 | + if (isset($res->error)) { |
|
| 132 | + switch ($res->error->code) { |
|
| 133 | 133 | case 'missingtitle': |
| 134 | 134 | $ex = new MissingPageException; |
| 135 | 135 | break; |
@@ -137,13 +137,13 @@ discard block |
||
| 137 | 137 | $ex = new ProtectedPageException; |
| 138 | 138 | break; |
| 139 | 139 | default: |
| 140 | - $ex = new APIRequestException( $res->error->code . ' - ' . $res->error->info ); |
|
| 140 | + $ex = new APIRequestException($res->error->code . ' - ' . $res->error->info); |
|
| 141 | 141 | } |
| 142 | 142 | throw $ex; |
| 143 | - } elseif ( isset( $res->warnings ) ) { |
|
| 144 | - $act = $this->params[ 'action' ]; |
|
| 143 | + } elseif (isset($res->warnings)) { |
|
| 144 | + $act = $this->params['action']; |
|
| 145 | 145 | $warning = $res->warnings->$act; |
| 146 | - throw new APIRequestException( reset( $warning ) ); |
|
| 146 | + throw new APIRequestException(reset($warning)); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -153,16 +153,16 @@ discard block |
||
| 153 | 153 | * @param \stdClass[] $sets |
| 154 | 154 | * @return array |
| 155 | 155 | */ |
| 156 | - private function mergeSets( array $sets ) : array { |
|
| 157 | - $sets = $this->objectToArray( $sets ); |
|
| 156 | + private function mergeSets(array $sets) : array { |
|
| 157 | + $sets = $this->objectToArray($sets); |
|
| 158 | 158 | // Use the first set as template |
| 159 | - $ret = array_shift( $sets ); |
|
| 159 | + $ret = array_shift($sets); |
|
| 160 | 160 | $act = $this->params['action']; |
| 161 | 161 | |
| 162 | - foreach ( $sets as $set ) { |
|
| 162 | + foreach ($sets as $set) { |
|
| 163 | 163 | $ret[$act] = array_merge_recursive( |
| 164 | - $this->objectToArray( $ret[$act] ), |
|
| 165 | - $this->objectToArray( $set[$act] ) |
|
| 164 | + $this->objectToArray($ret[$act]), |
|
| 165 | + $this->objectToArray($set[$act]) |
|
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | return $ret; |
@@ -175,14 +175,14 @@ discard block |
||
| 175 | 175 | * @param \stdClass|array $objOrArray |
| 176 | 176 | * @return array |
| 177 | 177 | */ |
| 178 | - private function objectToArray( $objOrArray ) : array { |
|
| 178 | + private function objectToArray($objOrArray) : array { |
|
| 179 | 179 | $array = []; |
| 180 | - if ( is_object( $objOrArray ) ) { |
|
| 181 | - $objOrArray = get_object_vars( $objOrArray ); |
|
| 180 | + if (is_object($objOrArray)) { |
|
| 181 | + $objOrArray = get_object_vars($objOrArray); |
|
| 182 | 182 | } |
| 183 | - foreach ( $objOrArray as $key => $value ) { |
|
| 184 | - if ( is_object( $value ) || is_array( $value ) ) { |
|
| 185 | - $value = $this->objectToArray( $value ); |
|
| 183 | + foreach ($objOrArray as $key => $value) { |
|
| 184 | + if (is_object($value) || is_array($value)) { |
|
| 185 | + $value = $this->objectToArray($value); |
|
| 186 | 186 | } |
| 187 | 187 | $array[$key] = $value; |
| 188 | 188 | } |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | protected function getHeaders() :array { |
| 198 | 198 | $ret = self::HEADERS; |
| 199 | - if ( self::$cookiesToSet ) { |
|
| 199 | + if (self::$cookiesToSet) { |
|
| 200 | 200 | $cookies = []; |
| 201 | - foreach ( self::$cookiesToSet as $cname => $cval ) { |
|
| 202 | - $cookies[] = trim( "$cname=$cval" ); |
|
| 201 | + foreach (self::$cookiesToSet as $cname => $cval) { |
|
| 202 | + $cookies[] = trim("$cname=$cval"); |
|
| 203 | 203 | } |
| 204 | - $ret[] = 'Cookie: ' . implode( '; ', $cookies ); |
|
| 204 | + $ret[] = 'Cookie: ' . implode('; ', $cookies); |
|
| 205 | 205 | } |
| 206 | 206 | return $ret; |
| 207 | 207 | } |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * @param array $headers |
| 213 | 213 | * @return string |
| 214 | 214 | */ |
| 215 | - protected function buildHeadersString( array $headers ) : string { |
|
| 215 | + protected function buildHeadersString(array $headers) : string { |
|
| 216 | 216 | $ret = ''; |
| 217 | - foreach ( $headers as $header ) { |
|
| 217 | + foreach ($headers as $header) { |
|
| 218 | 218 | $ret .= "$header\r\n"; |
| 219 | 219 | } |
| 220 | 220 | return $ret; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Exception; |
| 4 | 4 | |
@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @param string|null $title If available |
| 11 | 11 | */ |
| 12 | - public function __construct( string $title = null ) { |
|
| 13 | - if ( $title ) { |
|
| 14 | - parent::__construct( "The specified page doesn't exist: $title" ); |
|
| 12 | + public function __construct(string $title = null) { |
|
| 13 | + if ($title) { |
|
| 14 | + parent::__construct("The specified page doesn't exist: $title"); |
|
| 15 | 15 | } else { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Exception; |
| 4 | 4 | |
@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @param string|null $title If available |
| 11 | 11 | */ |
| 12 | - public function __construct( string $title = null ) { |
|
| 13 | - if ( $title ) { |
|
| 14 | - parent::__construct( "The specified page is protected: $title" ); |
|
| 12 | + public function __construct(string $title = null) { |
|
| 13 | + if ($title) { |
|
| 14 | + parent::__construct("The specified page is protected: $title"); |
|
| 15 | 15 | } else { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -13,19 +13,19 @@ discard block |
||
| 13 | 13 | * @inheritDoc |
| 14 | 14 | */ |
| 15 | 15 | public function run() : TaskResult { |
| 16 | - $this->getLogger()->info( 'Starting task UpdatesAround' ); |
|
| 16 | + $this->getLogger()->info('Starting task UpdatesAround'); |
|
| 17 | 17 | |
| 18 | - foreach ( $this->getDataProvider()->getCreatedPages() as $page ) { |
|
| 18 | + foreach ($this->getDataProvider()->getCreatedPages() as $page) { |
|
| 19 | 19 | // Wikipedia:Amministratori/Riconferma annuale |
| 20 | - $this->addToMainPage( $page ); |
|
| 20 | + $this->addToMainPage($page); |
|
| 21 | 21 | // WP:Wikipediano/Votazioni |
| 22 | - $this->addVote( $page ); |
|
| 22 | + $this->addVote($page); |
|
| 23 | 23 | // Template:VotazioniRCnews |
| 24 | - $this->addNews( $page ); |
|
| 24 | + $this->addNews($page); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - $this->getLogger()->info( 'Task UpdatesAround completed successfully' ); |
|
| 28 | - return new TaskResult( self::STATUS_OK ); |
|
| 27 | + $this->getLogger()->info('Task UpdatesAround completed successfully'); |
|
| 28 | + return new TaskResult(self::STATUS_OK); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @param string $page |
| 35 | 35 | */ |
| 36 | - protected function addToMainPage( string $page ) { |
|
| 37 | - $this->getLogger()->info( "Adding $page to main" ); |
|
| 36 | + protected function addToMainPage(string $page) { |
|
| 37 | + $this->getLogger()->info("Adding $page to main"); |
|
| 38 | 38 | |
| 39 | 39 | $params = [ |
| 40 | - 'title' => $this->getConfig()->get( 'ric-main-page' ), |
|
| 40 | + 'title' => $this->getConfig()->get('ric-main-page'), |
|
| 41 | 41 | 'appendtext' => '{{' . $page . '}}', |
| 42 | - 'summary' => $this->getConfig()->get( 'ric-main-page-summary' ) |
|
| 42 | + 'summary' => $this->getConfig()->get('ric-main-page-summary') |
|
| 43 | 43 | ]; |
| 44 | 44 | |
| 45 | - $this->getController()->editPage( $params ); |
|
| 45 | + $this->getController()->editPage($params); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -50,37 +50,37 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @param string $page |
| 52 | 52 | */ |
| 53 | - protected function addVote( string $page ) { |
|
| 54 | - $this->getLogger()->info( "Adding $page to votes" ); |
|
| 55 | - $votePage = $this->getConfig()->get( 'ric-vote-page' ); |
|
| 53 | + protected function addVote(string $page) { |
|
| 54 | + $this->getLogger()->info("Adding $page to votes"); |
|
| 55 | + $votePage = $this->getConfig()->get('ric-vote-page'); |
|
| 56 | 56 | |
| 57 | - $content = $this->getController()->getPageContent( $votePage ); |
|
| 57 | + $content = $this->getController()->getPageContent($votePage); |
|
| 58 | 58 | // Remove comments etc. |
| 59 | - $visibleContent = strip_tags( $content ); |
|
| 60 | - $user = explode( '/', $page )[2]; |
|
| 59 | + $visibleContent = strip_tags($content); |
|
| 60 | + $user = explode('/', $page)[2]; |
|
| 61 | 61 | $time = $this->getTimeWithArticle(); |
| 62 | 62 | |
| 63 | 63 | $newLine = "*[[Utente:$user|]]. La [[$page|procedura]] termina $time"; |
| 64 | 64 | |
| 65 | 65 | $introReg = '!^;È in corso la .*riconferma tacita.* degli .*amministratori.+!m'; |
| 66 | - if ( preg_match( $introReg, $visibleContent ) ) { |
|
| 67 | - $newContent = preg_replace( $introReg, '$0' . "\n$newLine;", $content, 1 ); |
|
| 66 | + if (preg_match($introReg, $visibleContent)) { |
|
| 67 | + $newContent = preg_replace($introReg, '$0' . "\n$newLine;", $content, 1); |
|
| 68 | 68 | } else { |
| 69 | 69 | $matches = []; |
| 70 | - if ( preg_match( $introReg, $content, $matches ) === false ) { |
|
| 71 | - throw new TaskException( 'Intro not found in vote page' ); |
|
| 70 | + if (preg_match($introReg, $content, $matches) === false) { |
|
| 71 | + throw new TaskException('Intro not found in vote page'); |
|
| 72 | 72 | } |
| 73 | 73 | $beforeReg = '!INSERIRE LA NOTIZIA PIÙ NUOVA IN CIMA.+!m'; |
| 74 | - $newContent = preg_replace( $beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1 ); |
|
| 74 | + $newContent = preg_replace($beforeReg, "$0\n{$matches[0]}\n$newLine.", $content, 1); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $params = [ |
| 78 | 78 | 'title' => $votePage, |
| 79 | 79 | 'text' => $newContent, |
| 80 | - 'summary' => $this->getConfig()->get( 'ric-vote-page-summary' ) |
|
| 80 | + 'summary' => $this->getConfig()->get('ric-vote-page-summary') |
|
| 81 | 81 | ]; |
| 82 | 82 | |
| 83 | - $this->getController()->editPage( $params ); |
|
| 83 | + $this->getController()->editPage($params); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | 91 | private function getTimeWithArticle() : string { |
| 92 | - $oldLoc = setlocale( LC_TIME, 'it_IT', 'Italian_Italy', 'Italian' ); |
|
| 93 | - $endTS = time() + ( 60 * 60 * 24 * 7 ); |
|
| 94 | - $endTime = strftime( '%e %B alle %R', $endTS ); |
|
| 92 | + $oldLoc = setlocale(LC_TIME, 'it_IT', 'Italian_Italy', 'Italian'); |
|
| 93 | + $endTS = time() + (60 * 60 * 24 * 7); |
|
| 94 | + $endTime = strftime('%e %B alle %R', $endTS); |
|
| 95 | 95 | // Remove the left space if day has a single digit |
| 96 | - $endTime = ltrim( $endTime ); |
|
| 97 | - $artic = in_array( date( 'j', $endTS ), [ 8, 11 ] ) ? "l'" : "il "; |
|
| 98 | - setlocale( LC_TIME, $oldLoc ); |
|
| 96 | + $endTime = ltrim($endTime); |
|
| 97 | + $artic = in_array(date('j', $endTS), [8, 11]) ? "l'" : "il "; |
|
| 98 | + setlocale(LC_TIME, $oldLoc); |
|
| 99 | 99 | |
| 100 | 100 | return $artic . $endTime; |
| 101 | 101 | } |
@@ -105,27 +105,27 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @param string $page |
| 107 | 107 | */ |
| 108 | - protected function addNews( string $page ) { |
|
| 109 | - $this->getLogger()->info( "Adding $page to news" ); |
|
| 110 | - $newsPage = $this->getConfig()->get( 'ric-news-page' ); |
|
| 108 | + protected function addNews(string $page) { |
|
| 109 | + $this->getLogger()->info("Adding $page to news"); |
|
| 110 | + $newsPage = $this->getConfig()->get('ric-news-page'); |
|
| 111 | 111 | |
| 112 | - $content = $this->getController()->getPageContent( $newsPage ); |
|
| 112 | + $content = $this->getController()->getPageContent($newsPage); |
|
| 113 | 113 | $reg = '!(\| *riconferme[ _]tacite[ _]amministratori *= *)(\d+)!'; |
| 114 | 114 | |
| 115 | 115 | $matches = []; |
| 116 | - if ( preg_match( $reg, $content, $matches ) === false ) { |
|
| 117 | - throw new TaskException( 'Param not found in news page' ); |
|
| 116 | + if (preg_match($reg, $content, $matches) === false) { |
|
| 117 | + throw new TaskException('Param not found in news page'); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $newNum = (int)$matches[2] + 1; |
| 121 | - $newContent = preg_replace( $reg, '${1}' . $newNum, $content ); |
|
| 121 | + $newContent = preg_replace($reg, '${1}' . $newNum, $content); |
|
| 122 | 122 | |
| 123 | 123 | $params = [ |
| 124 | 124 | 'title' => $newsPage, |
| 125 | 125 | 'text' => $newContent, |
| 126 | - 'summary' => $this->getConfig()->get( 'ric-news-page-summary' ) |
|
| 126 | + 'summary' => $this->getConfig()->get('ric-news-page-summary') |
|
| 127 | 127 | ]; |
| 128 | 128 | |
| 129 | - $this->getController()->editPage( $params ); |
|
| 129 | + $this->getController()->editPage($params); |
|
| 130 | 130 | } |
| 131 | 131 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -19,18 +19,18 @@ discard block |
||
| 19 | 19 | * @inheritDoc |
| 20 | 20 | */ |
| 21 | 21 | public function run() : TaskResult { |
| 22 | - $this->getLogger()->info( 'Starting task UpdateList' ); |
|
| 22 | + $this->getLogger()->info('Starting task UpdateList'); |
|
| 23 | 23 | $this->actualList = $this->getActualAdmins(); |
| 24 | 24 | $this->botList = $this->getList(); |
| 25 | 25 | |
| 26 | 26 | $missing = $this->getMissingGroups(); |
| 27 | 27 | $extra = $this->getExtraGroups(); |
| 28 | 28 | |
| 29 | - if ( $missing || $extra ) { |
|
| 30 | - $this->doUpdateList( $this->getNewContent( $missing, $extra ) ); |
|
| 29 | + if ($missing || $extra) { |
|
| 30 | + $this->doUpdateList($this->getNewContent($missing, $extra)); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( $this->errors ) { |
|
| 33 | + if ($this->errors) { |
|
| 34 | 34 | // We're fine with it, but don't run other tasks |
| 35 | 35 | $msg = 'Task UpdateList completed with warnings.'; |
| 36 | 36 | $status = self::STATUS_ERROR; |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | $status = self::STATUS_OK; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $this->getLogger()->info( $msg ); |
|
| 43 | - return new TaskResult( $status, $this->errors ); |
|
| 42 | + $this->getLogger()->info($msg); |
|
| 43 | + return new TaskResult($status, $this->errors); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * @return array |
| 48 | 48 | */ |
| 49 | 49 | protected function getActualAdmins() : array { |
| 50 | - $this->getLogger()->debug( 'Retrieving admins - API' ); |
|
| 50 | + $this->getLogger()->debug('Retrieving admins - API'); |
|
| 51 | 51 | $params = [ |
| 52 | 52 | 'action' => 'query', |
| 53 | 53 | 'list' => 'allusers', |
@@ -56,23 +56,23 @@ discard block |
||
| 56 | 56 | 'aulimit' => 'max', |
| 57 | 57 | ]; |
| 58 | 58 | |
| 59 | - $req = RequestBase::newFromParams( $params ); |
|
| 60 | - return $this->extractAdmins( $req->execute() ); |
|
| 59 | + $req = RequestBase::newFromParams($params); |
|
| 60 | + return $this->extractAdmins($req->execute()); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @param array $data |
| 65 | 65 | * @return array |
| 66 | 66 | */ |
| 67 | - protected function extractAdmins( array $data ) : array { |
|
| 67 | + protected function extractAdmins(array $data) : array { |
|
| 68 | 68 | $ret = []; |
| 69 | - $blacklist = $this->getConfig()->get( 'exclude-admins' ); |
|
| 70 | - foreach ( $data['query']['allusers'] as $u ) { |
|
| 71 | - if ( in_array( $u['name'], $blacklist ) ) { |
|
| 69 | + $blacklist = $this->getConfig()->get('exclude-admins'); |
|
| 70 | + foreach ($data['query']['allusers'] as $u) { |
|
| 71 | + if (in_array($u['name'], $blacklist)) { |
|
| 72 | 72 | continue; |
| 73 | 73 | } |
| 74 | - $interestingGroups = array_intersect( $u['groups'], [ 'sysop', 'bureaucrat', 'checkuser' ] ); |
|
| 75 | - $ret[ $u['name'] ] = $interestingGroups; |
|
| 74 | + $interestingGroups = array_intersect($u['groups'], ['sysop', 'bureaucrat', 'checkuser']); |
|
| 75 | + $ret[$u['name']] = $interestingGroups; |
|
| 76 | 76 | } |
| 77 | 77 | return $ret; |
| 78 | 78 | } |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | 83 | protected function getList() : array { |
| 84 | - $this->getLogger()->debug( 'Retrieving admins - JSON list' ); |
|
| 85 | - $content = $this->getController()->getPageContent( $this->getConfig()->get( 'list-title' ) ); |
|
| 84 | + $this->getLogger()->debug('Retrieving admins - JSON list'); |
|
| 85 | + $content = $this->getController()->getPageContent($this->getConfig()->get('list-title')); |
|
| 86 | 86 | |
| 87 | - return json_decode( $content, true ); |
|
| 87 | + return json_decode($content, true); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -94,20 +94,20 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | protected function getMissingGroups() : array { |
| 96 | 96 | $missing = []; |
| 97 | - foreach ( $this->actualList as $adm => $groups ) { |
|
| 98 | - if ( !isset( $this->botList[ $adm ] ) ) { |
|
| 97 | + foreach ($this->actualList as $adm => $groups) { |
|
| 98 | + if (!isset($this->botList[$adm])) { |
|
| 99 | 99 | $groupsList = $groups; |
| 100 | - } elseif ( count( $groups ) > count( $this->botList[$adm] ) ) { |
|
| 100 | + } elseif (count($groups) > count($this->botList[$adm])) { |
|
| 101 | 101 | // Only some groups are missing |
| 102 | - $groupsList = array_diff_key( $groups, $this->botList[$adm] ); |
|
| 102 | + $groupsList = array_diff_key($groups, $this->botList[$adm]); |
|
| 103 | 103 | } else { |
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - foreach ( $groupsList as $group ) { |
|
| 107 | + foreach ($groupsList as $group) { |
|
| 108 | 108 | try { |
| 109 | - $missing[ $adm ][ $group ] = $this->getFlagDate( $adm, $group ); |
|
| 110 | - } catch ( TaskException $e ) { |
|
| 109 | + $missing[$adm][$group] = $this->getFlagDate($adm, $group); |
|
| 110 | + } catch (TaskException $e) { |
|
| 111 | 111 | $this->errors[] = $e->getMessage(); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * @return string |
| 124 | 124 | * @throws TaskException |
| 125 | 125 | */ |
| 126 | - protected function getFlagDate( string $admin, string $group ) : string { |
|
| 127 | - $this->getLogger()->info( "Retrieving $group flag date for $admin" ); |
|
| 126 | + protected function getFlagDate(string $admin, string $group) : string { |
|
| 127 | + $this->getLogger()->info("Retrieving $group flag date for $admin"); |
|
| 128 | 128 | |
| 129 | - if ( $group === 'checkuser' ) { |
|
| 129 | + if ($group === 'checkuser') { |
|
| 130 | 130 | // Little hack |
| 131 | 131 | $oldUrl = RequestBase::$url; |
| 132 | 132 | RequestBase::$url = 'https://meta.wikimedia.org/w/api.php'; |
@@ -142,19 +142,19 @@ discard block |
||
| 142 | 142 | 'lelimit' => 'max' |
| 143 | 143 | ]; |
| 144 | 144 | |
| 145 | - $req = RequestBase::newFromParams( $params ); |
|
| 145 | + $req = RequestBase::newFromParams($params); |
|
| 146 | 146 | $data = $req->execute(); |
| 147 | - $ts = $this->extractTimestamp( $data, $group ); |
|
| 147 | + $ts = $this->extractTimestamp($data, $group); |
|
| 148 | 148 | |
| 149 | - if ( isset( $oldUrl ) ) { |
|
| 149 | + if (isset($oldUrl)) { |
|
| 150 | 150 | RequestBase::$url = $oldUrl; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ( $ts === null ) { |
|
| 154 | - throw new TaskException( "$group flag date unavailable for $admin" ); |
|
| 153 | + if ($ts === null) { |
|
| 154 | + throw new TaskException("$group flag date unavailable for $admin"); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - return date( "d/m/Y", strtotime( $ts ) ); |
|
| 157 | + return date("d/m/Y", strtotime($ts)); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -164,15 +164,15 @@ discard block |
||
| 164 | 164 | * @param string $group |
| 165 | 165 | * @return string|null |
| 166 | 166 | */ |
| 167 | - private function extractTimestamp( array $data, string $group ) : ?string { |
|
| 167 | + private function extractTimestamp(array $data, string $group) : ?string { |
|
| 168 | 168 | $ts = null; |
| 169 | - foreach ( $data['query']['logevents'] as $entry ) { |
|
| 170 | - if ( !isset( $entry['params'] ) ) { |
|
| 169 | + foreach ($data['query']['logevents'] as $entry) { |
|
| 170 | + if (!isset($entry['params'])) { |
|
| 171 | 171 | // Old entries |
| 172 | 172 | continue; |
| 173 | 173 | } |
| 174 | - if ( in_array( $group, $entry['params']['newgroups'] ) && |
|
| 175 | - !in_array( $group, $entry['params']['oldgroups'] ) |
|
| 174 | + if (in_array($group, $entry['params']['newgroups']) && |
|
| 175 | + !in_array($group, $entry['params']['oldgroups']) |
|
| 176 | 176 | ) { |
| 177 | 177 | $ts = $entry['timestamp']; |
| 178 | 178 | break; |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | protected function getExtraGroups() : array { |
| 190 | 190 | $extra = []; |
| 191 | - foreach ( $this->botList as $name => $groups ) { |
|
| 192 | - if ( !isset( $this->actualList[ $name ] ) ) { |
|
| 193 | - $extra[ $name ] = $groups; |
|
| 194 | - } elseif ( count( $groups ) > count( $this->actualList[ $name ] ) ) { |
|
| 195 | - $extra[ $name ] = array_diff_key( $groups, $this->actualList[ $name ] ); |
|
| 191 | + foreach ($this->botList as $name => $groups) { |
|
| 192 | + if (!isset($this->actualList[$name])) { |
|
| 193 | + $extra[$name] = $groups; |
|
| 194 | + } elseif (count($groups) > count($this->actualList[$name])) { |
|
| 195 | + $extra[$name] = array_diff_key($groups, $this->actualList[$name]); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | return $extra; |
@@ -203,25 +203,25 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param array $newContent |
| 205 | 205 | */ |
| 206 | - protected function doUpdateList( array $newContent ) { |
|
| 207 | - ksort( $newContent ); |
|
| 206 | + protected function doUpdateList(array $newContent) { |
|
| 207 | + ksort($newContent); |
|
| 208 | 208 | |
| 209 | - if ( $newContent !== $this->botList ) { |
|
| 210 | - $this->getLogger()->info( 'Updating admin list' ); |
|
| 209 | + if ($newContent !== $this->botList) { |
|
| 210 | + $this->getLogger()->info('Updating admin list'); |
|
| 211 | 211 | } else { |
| 212 | - $this->getLogger()->info( 'Admin list already up-to-date' ); |
|
| 212 | + $this->getLogger()->info('Admin list already up-to-date'); |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $stringified = json_encode( $newContent ); |
|
| 216 | + $stringified = json_encode($newContent); |
|
| 217 | 217 | |
| 218 | 218 | $params = [ |
| 219 | - 'title' => $this->getConfig()->get( 'list-title' ), |
|
| 219 | + 'title' => $this->getConfig()->get('list-title'), |
|
| 220 | 220 | 'text' => $stringified, |
| 221 | - 'summary' => $this->getConfig()->get( 'list-update-summary' ) |
|
| 221 | + 'summary' => $this->getConfig()->get('list-update-summary') |
|
| 222 | 222 | ]; |
| 223 | 223 | |
| 224 | - $this->getController()->editPage( $params ); |
|
| 224 | + $this->getController()->editPage($params); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -231,19 +231,19 @@ discard block |
||
| 231 | 231 | * @param array[] $extra |
| 232 | 232 | * @return array[] |
| 233 | 233 | */ |
| 234 | - protected function getNewContent( array $missing, array $extra ) : array { |
|
| 234 | + protected function getNewContent(array $missing, array $extra) : array { |
|
| 235 | 235 | $newContent = $this->botList; |
| 236 | - foreach ( $newContent as $user => $groups ) { |
|
| 237 | - if ( isset( $missing[ $user ] ) ) { |
|
| 238 | - $newContent[ $user ] = array_merge( $groups, $missing[ $user ] ); |
|
| 239 | - unset( $missing[ $user ] ); |
|
| 240 | - } elseif ( isset( $extra[ $user ] ) ) { |
|
| 241 | - $newContent[ $user ] = array_diff_key( $groups, $extra[ $user ] ); |
|
| 236 | + foreach ($newContent as $user => $groups) { |
|
| 237 | + if (isset($missing[$user])) { |
|
| 238 | + $newContent[$user] = array_merge($groups, $missing[$user]); |
|
| 239 | + unset($missing[$user]); |
|
| 240 | + } elseif (isset($extra[$user])) { |
|
| 241 | + $newContent[$user] = array_diff_key($groups, $extra[$user]); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | // Add users which don't have an entry at all |
| 245 | - $newContent = array_merge( $newContent, $missing ); |
|
| 245 | + $newContent = array_merge($newContent, $missing); |
|
| 246 | 246 | // And remove empty users |
| 247 | - return array_filter( $newContent ); |
|
| 247 | + return array_filter($newContent); |
|
| 248 | 248 | } |
| 249 | 249 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param TaskDataProvider $dataProvider |
| 25 | 25 | */ |
| 26 | - final public function __construct( TaskDataProvider $dataProvider ) { |
|
| 27 | - set_exception_handler( [ $this, 'handleException' ] ); |
|
| 28 | - set_error_handler( [ $this, 'handleError' ] ); |
|
| 26 | + final public function __construct(TaskDataProvider $dataProvider) { |
|
| 27 | + set_exception_handler([$this, 'handleException']); |
|
| 28 | + set_error_handler([$this, 'handleError']); |
|
| 29 | 29 | parent::__construct(); |
| 30 | 30 | $this->dataProvider = $dataProvider; |
| 31 | 31 | } |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | * @param \Throwable $ex |
| 49 | 49 | * @protected |
| 50 | 50 | */ |
| 51 | - public function handleException( \Throwable $ex ) { |
|
| 51 | + public function handleException(\Throwable $ex) { |
|
| 52 | 52 | $this->getLogger()->error( |
| 53 | - get_class( $ex ) . ': ' . |
|
| 53 | + get_class($ex) . ': ' . |
|
| 54 | 54 | $ex->getMessage() . "\nTrace:\n" . |
| 55 | 55 | $ex->getTraceAsString() |
| 56 | 56 | ); |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param int $errline |
| 66 | 66 | * @protected |
| 67 | 67 | */ |
| 68 | - public function handleError( $errno, $errstr, $errfile, $errline ) { |
|
| 69 | - throw new \ErrorException( $errstr, 0, $errno, $errfile, $errline ); |
|
| 68 | + public function handleError($errno, $errstr, $errfile, $errline) { |
|
| 69 | + throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | * @inheritDoc |
| 15 | 15 | */ |
| 16 | 16 | public function run() : TaskResult { |
| 17 | - $this->getLogger()->info( 'Starting task CreatePage' ); |
|
| 17 | + $this->getLogger()->info('Starting task CreatePage'); |
|
| 18 | 18 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 19 | 19 | |
| 20 | - foreach ( $users as $user => $groups ) { |
|
| 21 | - $this->processUser( $user, $groups ); |
|
| 20 | + foreach ($users as $user => $groups) { |
|
| 21 | + $this->processUser($user, $groups); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - $this->getLogger()->info( 'Task CreatePage completed successfully' ); |
|
| 25 | - return new TaskResult( self::STATUS_OK ); |
|
| 24 | + $this->getLogger()->info('Task CreatePage completed successfully'); |
|
| 25 | + return new TaskResult(self::STATUS_OK); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -31,27 +31,27 @@ discard block |
||
| 31 | 31 | * @param string $user |
| 32 | 32 | * @param array $groups |
| 33 | 33 | */ |
| 34 | - protected function processUser( string $user, array $groups ) { |
|
| 34 | + protected function processUser(string $user, array $groups) { |
|
| 35 | 35 | try { |
| 36 | - $num = $this->getLastPageNum( $user ) + 1; |
|
| 37 | - } catch ( TaskException $e ) { |
|
| 36 | + $num = $this->getLastPageNum($user) + 1; |
|
| 37 | + } catch (TaskException $e) { |
|
| 38 | 38 | // The page was already created today. PLZ let this poor bot work! |
| 39 | - $this->getDataProvider()->removeUser( $user ); |
|
| 40 | - $this->getLogger()->warning( $e->getMessage() . "\nRemoving $user." ); |
|
| 39 | + $this->getDataProvider()->removeUser($user); |
|
| 40 | + $this->getLogger()->warning($e->getMessage() . "\nRemoving $user."); |
|
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $baseTitle = $this->getConfig()->get( 'ric-main-page' ) . "/$user"; |
|
| 44 | + $baseTitle = $this->getConfig()->get('ric-main-page') . "/$user"; |
|
| 45 | 45 | $pageTitle = "$baseTitle/$num"; |
| 46 | - $this->doCreatePage( $pageTitle, $user, $groups ); |
|
| 46 | + $this->doCreatePage($pageTitle, $user, $groups); |
|
| 47 | 47 | |
| 48 | - $newText = str_replace( '$title', $pageTitle, $this->getConfig()->get( 'ric-base-page-text' ) ); |
|
| 49 | - if ( $num === 1 ) { |
|
| 50 | - $this->createBasePage( $baseTitle, $newText ); |
|
| 48 | + $newText = str_replace('$title', $pageTitle, $this->getConfig()->get('ric-base-page-text')); |
|
| 49 | + if ($num === 1) { |
|
| 50 | + $this->createBasePage($baseTitle, $newText); |
|
| 51 | 51 | } else { |
| 52 | - $this->updateBasePage( $baseTitle, $newText ); |
|
| 52 | + $this->updateBasePage($baseTitle, $newText); |
|
| 53 | 53 | } |
| 54 | - $this->getDataProvider()->addCreatedPages( $pageTitle ); |
|
| 54 | + $this->getDataProvider()->addCreatedPages($pageTitle); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | * @return int |
| 62 | 62 | * @throws TaskException |
| 63 | 63 | */ |
| 64 | - protected function getLastPageNum( string $user ) : int { |
|
| 65 | - $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
|
| 66 | - $unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[1]; |
|
| 64 | + protected function getLastPageNum(string $user) : int { |
|
| 65 | + $this->getLogger()->debug("Retrieving previous pages for $user"); |
|
| 66 | + $unprefixedTitle = explode(':', $this->getConfig()->get('ric-main-page'), 2)[1]; |
|
| 67 | 67 | $params = [ |
| 68 | 68 | 'action' => 'query', |
| 69 | 69 | 'list' => 'allpages', |
@@ -72,16 +72,16 @@ discard block |
||
| 72 | 72 | 'aplimit' => 'max' |
| 73 | 73 | ]; |
| 74 | 74 | |
| 75 | - $res = ( RequestBase::newFromParams( $params ) )->execute(); |
|
| 75 | + $res = (RequestBase::newFromParams($params))->execute(); |
|
| 76 | 76 | |
| 77 | 77 | $last = 0; |
| 78 | - foreach ( $res['query']['allpages'] as $page ) { |
|
| 79 | - if ( $this->pageWasCreatedToday( $page['title'] ) ) { |
|
| 80 | - throw new TaskException( 'Page ' . $page['title'] . ' was already created.' ); |
|
| 78 | + foreach ($res['query']['allpages'] as $page) { |
|
| 79 | + if ($this->pageWasCreatedToday($page['title'])) { |
|
| 80 | + throw new TaskException('Page ' . $page['title'] . ' was already created.'); |
|
| 81 | 81 | } |
| 82 | - $bits = explode( '/', $page['title'] ); |
|
| 83 | - $cur = intval( end( $bits ) ); |
|
| 84 | - if ( is_numeric( $cur ) && $cur > $last ) { |
|
| 82 | + $bits = explode('/', $page['title']); |
|
| 83 | + $cur = intval(end($bits)); |
|
| 84 | + if (is_numeric($cur) && $cur > $last) { |
|
| 85 | 85 | $last = $cur; |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @param string $title |
| 93 | 93 | * @return bool |
| 94 | 94 | */ |
| 95 | - private function pageWasCreatedToday( string $title ) : bool { |
|
| 95 | + private function pageWasCreatedToday(string $title) : bool { |
|
| 96 | 96 | $params = [ |
| 97 | 97 | 'action' => 'query', |
| 98 | 98 | 'prop' => 'revisions', |
@@ -103,10 +103,10 @@ discard block |
||
| 103 | 103 | 'rvdir' => 'newer' |
| 104 | 104 | ]; |
| 105 | 105 | |
| 106 | - $res = ( RequestBase::newFromParams( $params ) )->execute(); |
|
| 106 | + $res = (RequestBase::newFromParams($params))->execute(); |
|
| 107 | 107 | $data = $res['query']['pages']; |
| 108 | - $time = strtotime( reset( $data )['revisions'][0]['timestamp'] ); |
|
| 109 | - return date( 'z/Y' ) === date( 'z/Y', $time ); |
|
| 108 | + $time = strtotime(reset($data)['revisions'][0]['timestamp']); |
|
| 109 | + return date('z/Y') === date('z/Y', $time); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -116,24 +116,24 @@ discard block |
||
| 116 | 116 | * @param string $user |
| 117 | 117 | * @param array $groups |
| 118 | 118 | */ |
| 119 | - protected function doCreatePage( string $title, string $user, array $groups ) { |
|
| 120 | - $this->getLogger()->info( "Creating page $title" ); |
|
| 121 | - $text = $this->getConfig()->get( 'ric-page-text' ); |
|
| 119 | + protected function doCreatePage(string $title, string $user, array $groups) { |
|
| 120 | + $this->getLogger()->info("Creating page $title"); |
|
| 121 | + $text = $this->getConfig()->get('ric-page-text'); |
|
| 122 | 122 | $textParams = [ |
| 123 | 123 | '$user' => $user, |
| 124 | 124 | '$date' => $groups['sysop'], |
| 125 | 125 | '$burocrate' => $groups['bureaucrat'] ?? '', |
| 126 | 126 | '$checkuser' => $groups['checkuser'] ?? '' |
| 127 | 127 | ]; |
| 128 | - $text = strtr( $text, $textParams ); |
|
| 128 | + $text = strtr($text, $textParams); |
|
| 129 | 129 | |
| 130 | 130 | $params = [ |
| 131 | 131 | 'title' => $title, |
| 132 | 132 | 'text' => $text, |
| 133 | - 'summary' => $this->getConfig()->get( 'ric-page-summary' ) |
|
| 133 | + 'summary' => $this->getConfig()->get('ric-page-summary') |
|
| 134 | 134 | ]; |
| 135 | 135 | |
| 136 | - $this->getController()->editPage( $params ); |
|
| 136 | + $this->getController()->editPage($params); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -142,16 +142,16 @@ discard block |
||
| 142 | 142 | * @param string $title |
| 143 | 143 | * @param string $newText |
| 144 | 144 | */ |
| 145 | - protected function createBasePage( string $title, string $newText ) { |
|
| 146 | - $this->getLogger()->info( "Creating base page $title" ); |
|
| 145 | + protected function createBasePage(string $title, string $newText) { |
|
| 146 | + $this->getLogger()->info("Creating base page $title"); |
|
| 147 | 147 | |
| 148 | 148 | $params = [ |
| 149 | 149 | 'title' => $title, |
| 150 | 150 | 'text' => $newText, |
| 151 | - 'summary' => $this->getConfig()->get( 'ric-base-page-summary' ) |
|
| 151 | + 'summary' => $this->getConfig()->get('ric-base-page-summary') |
|
| 152 | 152 | ]; |
| 153 | 153 | |
| 154 | - $this->getController()->editPage( $params ); |
|
| 154 | + $this->getController()->editPage($params); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -159,15 +159,15 @@ discard block |
||
| 159 | 159 | * @param string $title |
| 160 | 160 | * @param string $newText |
| 161 | 161 | */ |
| 162 | - protected function updateBasePage( string $title, string $newText ) { |
|
| 163 | - $this->getLogger()->info( "Updating base page $title" ); |
|
| 162 | + protected function updateBasePage(string $title, string $newText) { |
|
| 163 | + $this->getLogger()->info("Updating base page $title"); |
|
| 164 | 164 | |
| 165 | 165 | $params = [ |
| 166 | 166 | 'title' => $title, |
| 167 | 167 | 'appendtext' => $newText, |
| 168 | - 'summary' => $this->getConfig()->get( 'ric-base-page-summary-update' ) |
|
| 168 | + 'summary' => $this->getConfig()->get('ric-base-page-summary-update') |
|
| 169 | 169 | ]; |
| 170 | 170 | |
| 171 | - $this->getController()->editPage( $params ); |
|
| 171 | + $this->getController()->editPage($params); |
|
| 172 | 172 | } |
| 173 | 173 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme; |
| 4 | 4 | |
@@ -26,26 +26,26 @@ discard block |
||
| 26 | 26 | * @param array $defaults |
| 27 | 27 | * @throws ConfigException |
| 28 | 28 | */ |
| 29 | - public static function init( array $defaults ) { |
|
| 30 | - if ( self::$instance ) { |
|
| 31 | - throw new ConfigException( 'Config was already initialized' ); |
|
| 29 | + public static function init(array $defaults) { |
|
| 30 | + if (self::$instance) { |
|
| 31 | + throw new ConfigException('Config was already initialized'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $inst = new self; |
| 35 | - $inst->set( 'list-title', $defaults['list-title'] ); |
|
| 36 | - $inst->set( 'username', $defaults['username'] ); |
|
| 37 | - $inst->set( 'password', $defaults['password'] ); |
|
| 35 | + $inst->set('list-title', $defaults['list-title']); |
|
| 36 | + $inst->set('username', $defaults['username']); |
|
| 37 | + $inst->set('password', $defaults['password']); |
|
| 38 | 38 | self::$instance = $inst; |
| 39 | 39 | |
| 40 | 40 | // On-wiki values |
| 41 | 41 | try { |
| 42 | - $conf = ( new WikiController )->getPageContent( $defaults[ 'config-title' ] ); |
|
| 43 | - } catch ( MissingPageException $e ) { |
|
| 44 | - throw new ConfigException( 'Please create a config page.' ); |
|
| 42 | + $conf = (new WikiController)->getPageContent($defaults['config-title']); |
|
| 43 | + } catch (MissingPageException $e) { |
|
| 44 | + throw new ConfigException('Please create a config page.'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - foreach ( json_decode( $conf, true ) as $key => $val ) { |
|
| 48 | - self::$instance->set( $key, $val ); |
|
| 47 | + foreach (json_decode($conf, true) as $key => $val) { |
|
| 48 | + self::$instance->set($key, $val); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * @param string $key |
| 56 | 56 | * @param mixed $value |
| 57 | 57 | */ |
| 58 | - protected function set( string $key, $value ) { |
|
| 59 | - $this->opts[ $key ] = $value; |
|
| 58 | + protected function set(string $key, $value) { |
|
| 59 | + $this->opts[$key] = $value; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * @throws ConfigException |
| 67 | 67 | */ |
| 68 | 68 | public static function getInstance() : self { |
| 69 | - if ( !self::$instance ) { |
|
| 70 | - throw new ConfigException( 'Config not yet initialized' ); |
|
| 69 | + if (!self::$instance) { |
|
| 70 | + throw new ConfigException('Config not yet initialized'); |
|
| 71 | 71 | } |
| 72 | 72 | return self::$instance; |
| 73 | 73 | } |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | * @return mixed |
| 80 | 80 | * @throws ConfigException |
| 81 | 81 | */ |
| 82 | - public function get( string $opt ) { |
|
| 83 | - if ( !isset( $this->opts[ $opt ] ) ) { |
|
| 84 | - throw new ConfigException( "Config option '$opt' not set." ); |
|
| 82 | + public function get(string $opt) { |
|
| 83 | + if (!isset($this->opts[$opt])) { |
|
| 84 | + throw new ConfigException("Config option '$opt' not set."); |
|
| 85 | 85 | } |
| 86 | - return $this->opts[ $opt ]; |
|
| 86 | + return $this->opts[$opt]; |
|
| 87 | 87 | } |
| 88 | 88 | } |