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
21 * @ingroup Maintenance
22 * @author Derick Alangi
23 * @author Daniel Kinzler
27 use MediaWiki\Maintenance\Maintenance
;
28 use MediaWiki\Utils\MWTimestamp
;
30 // @codeCoverageIgnoreStart
31 require_once __DIR__
. '/Maintenance.php';
32 // @codeCoverageIgnoreEnd
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" );
44 * @param string $wikiCreatedAt The date the wiki was created
46 * @return DateInterval|false The wiki age
48 private function computeAge( string $wikiCreatedAt ) {
50 date_create( MWTimestamp
::now() ),
51 date_create( $wikiCreatedAt )
55 public function execute() {
56 $dbr = $this->getReplicaDB();
58 $revId = $dbr->newSelectQueryBuilder()
60 ->field( 'MIN(rev_id)' )
61 ->caller( __METHOD__
)
64 $archiveRevId = $dbr->newSelectQueryBuilder()
66 ->field( 'MIN(ar_rev_id)' )
67 ->caller( __METHOD__
)
70 if ( $archiveRevId && ( $archiveRevId < $revId ||
!$revId ) ) {
71 $timestamp = $dbr->newSelectQueryBuilder()
73 ->field( 'ar_timestamp' )
74 ->where( [ 'ar_rev_id' => (int)$archiveRevId ] )
75 ->caller( __METHOD__
)
78 $timestamp = $dbr->newSelectQueryBuilder()
80 ->field( 'rev_timestamp' )
81 ->where( [ 'rev_id' => (int)$revId ] )
82 ->caller( __METHOD__
)
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)"
94 $this->output( $text . "\n" );
98 // @codeCoverageIgnoreStart
99 $maintClass = WikiBirthday
::class;
100 require_once RUN_MAINTENANCE_IF_MAIN
;
101 // @codeCoverageIgnoreEnd