MediaWiki master
wikiBirthday.php
Go to the documentation of this file.
1<?php
15
16// @codeCoverageIgnoreStart
17require_once __DIR__ . '/Maintenance.php';
18// @codeCoverageIgnoreEnd
19
24 public function __construct() {
25 parent::__construct();
26 $this->addDescription( "Print this wiki's birthday and age" );
27 }
28
34 private function computeAge( string $wikiCreatedAt ) {
35 return date_diff(
36 date_create( MWTimestamp::now() ),
37 date_create( $wikiCreatedAt )
38 );
39 }
40
41 public function execute() {
42 $dbr = $this->getReplicaDB();
43
44 $revId = $dbr->newSelectQueryBuilder()
45 ->table( 'revision' )
46 ->field( 'MIN(rev_id)' )
47 ->caller( __METHOD__ )
48 ->fetchField();
49
50 $archiveRevId = $dbr->newSelectQueryBuilder()
51 ->table( 'archive' )
52 ->field( 'MIN(ar_rev_id)' )
53 ->caller( __METHOD__ )
54 ->fetchField();
55
56 if ( $archiveRevId && ( $archiveRevId < $revId || !$revId ) ) {
57 $timestamp = $dbr->newSelectQueryBuilder()
58 ->table( 'archive' )
59 ->field( 'ar_timestamp' )
60 ->where( [ 'ar_rev_id' => (int)$archiveRevId ] )
61 ->caller( __METHOD__ )
62 ->fetchField();
63 } else {
64 $timestamp = $dbr->newSelectQueryBuilder()
65 ->table( 'revision' )
66 ->field( 'rev_timestamp' )
67 ->where( [ 'rev_id' => (int)$revId ] )
68 ->caller( __METHOD__ )
69 ->fetchField();
70 }
71
72 $birthDay = $this->getServiceContainer()->getContentLanguage()
73 ->getHumanTimestamp( MWTimestamp::getInstance( $timestamp ) );
74
75 $text = "Wiki was created on: " . $birthDay . " <age: " .
76 $this->computeAge( $timestamp )->format(
77 "%y yr(s), %m month(s), %d day(s)"
78 ) . " old>.";
79
80 $this->output( $text . "\n" );
81 }
82}
83
84// @codeCoverageIgnoreStart
85$maintClass = WikiBirthday::class;
86require_once RUN_MAINTENANCE_IF_MAIN;
87// @codeCoverageIgnoreEnd
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getReplicaDB(string|false $virtualDomain=false)
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Library for creating and parsing MW-style timestamps.
execute()
Do the actual work.
__construct()
Default constructor.
$maintClass