Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
37 / 37 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
WikiBirthday | |
100.00% |
37 / 37 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
computeAge | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | /** |
3 | * Prints the birthdate and age of a wiki install. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup Maintenance |
22 | * @author Derick Alangi |
23 | * @author Daniel Kinzler |
24 | * @since 1.39 |
25 | */ |
26 | |
27 | use MediaWiki\Maintenance\Maintenance; |
28 | use MediaWiki\Utils\MWTimestamp; |
29 | |
30 | // @codeCoverageIgnoreStart |
31 | require_once __DIR__ . '/Maintenance.php'; |
32 | // @codeCoverageIgnoreEnd |
33 | |
34 | /** |
35 | * @ingroup Maintenance |
36 | */ |
37 | class WikiBirthday extends Maintenance { |
38 | public function __construct() { |
39 | parent::__construct(); |
40 | $this->addDescription( "Print this wiki's birthday and age" ); |
41 | } |
42 | |
43 | /** |
44 | * @param string $wikiCreatedAt The date the wiki was created |
45 | * |
46 | * @return DateInterval|false The wiki age |
47 | */ |
48 | private function computeAge( string $wikiCreatedAt ) { |
49 | return date_diff( |
50 | date_create( MWTimestamp::now() ), |
51 | date_create( $wikiCreatedAt ) |
52 | ); |
53 | } |
54 | |
55 | public function execute() { |
56 | $dbr = $this->getReplicaDB(); |
57 | |
58 | $revId = $dbr->newSelectQueryBuilder() |
59 | ->table( 'revision' ) |
60 | ->field( 'MIN(rev_id)' ) |
61 | ->caller( __METHOD__ ) |
62 | ->fetchField(); |
63 | |
64 | $archiveRevId = $dbr->newSelectQueryBuilder() |
65 | ->table( 'archive' ) |
66 | ->field( 'MIN(ar_rev_id)' ) |
67 | ->caller( __METHOD__ ) |
68 | ->fetchField(); |
69 | |
70 | if ( $archiveRevId && ( $archiveRevId < $revId || !$revId ) ) { |
71 | $timestamp = $dbr->newSelectQueryBuilder() |
72 | ->table( 'archive' ) |
73 | ->field( 'ar_timestamp' ) |
74 | ->where( [ 'ar_rev_id' => (int)$archiveRevId ] ) |
75 | ->caller( __METHOD__ ) |
76 | ->fetchField(); |
77 | } else { |
78 | $timestamp = $dbr->newSelectQueryBuilder() |
79 | ->table( 'revision' ) |
80 | ->field( 'rev_timestamp' ) |
81 | ->where( [ 'rev_id' => (int)$revId ] ) |
82 | ->caller( __METHOD__ ) |
83 | ->fetchField(); |
84 | } |
85 | |
86 | $birthDay = $this->getServiceContainer()->getContentLanguage() |
87 | ->getHumanTimestamp( MWTimestamp::getInstance( $timestamp ) ); |
88 | |
89 | $text = "Wiki was created on: " . $birthDay . " <age: " . |
90 | $this->computeAge( $timestamp )->format( |
91 | "%y yr(s), %m month(s), %d day(s)" |
92 | ) . " old>."; |
93 | |
94 | $this->output( $text . "\n" ); |
95 | } |
96 | } |
97 | |
98 | // @codeCoverageIgnoreStart |
99 | $maintClass = WikiBirthday::class; |
100 | require_once RUN_MAINTENANCE_IF_MAIN; |
101 | // @codeCoverageIgnoreEnd |