Merge "MultiUsernameFilter: Don't try to split ids if they're not a string"
[mediawiki.git] / maintenance / wikiBirthday.php
blob7726e7da56fa9bbd4b006c05656a914534e5c05b
1 <?php
2 /**
3 * Prints the birthdate and age of a wiki install.
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.
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.
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
20 * @file
21 * @ingroup Maintenance
22 * @author Derick Alangi
23 * @author Daniel Kinzler
24 * @since 1.39
27 use MediaWiki\Maintenance\Maintenance;
28 use MediaWiki\Utils\MWTimestamp;
30 // @codeCoverageIgnoreStart
31 require_once __DIR__ . '/Maintenance.php';
32 // @codeCoverageIgnoreEnd
34 /**
35 * @ingroup Maintenance
37 class WikiBirthday extends Maintenance {
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( "Print this wiki's birthday and age" );
43 /**
44 * @param string $wikiCreatedAt The date the wiki was created
46 * @return DateInterval|false The wiki age
48 private function computeAge( string $wikiCreatedAt ) {
49 return date_diff(
50 date_create( MWTimestamp::now() ),
51 date_create( $wikiCreatedAt )
55 public function execute() {
56 $dbr = $this->getReplicaDB();
58 $revId = $dbr->newSelectQueryBuilder()
59 ->table( 'revision' )
60 ->field( 'MIN(rev_id)' )
61 ->caller( __METHOD__ )
62 ->fetchField();
64 $archiveRevId = $dbr->newSelectQueryBuilder()
65 ->table( 'archive' )
66 ->field( 'MIN(ar_rev_id)' )
67 ->caller( __METHOD__ )
68 ->fetchField();
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();
86 $birthDay = $this->getServiceContainer()->getContentLanguage()
87 ->getHumanTimestamp( MWTimestamp::getInstance( $timestamp ) );
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>.";
94 $this->output( $text . "\n" );
98 // @codeCoverageIgnoreStart
99 $maintClass = WikiBirthday::class;
100 require_once RUN_MAINTENANCE_IF_MAIN;
101 // @codeCoverageIgnoreEnd