MediaWiki master
wikiBirthday.php
Go to the documentation of this file.
1<?php
29
30// @codeCoverageIgnoreStart
31require_once __DIR__ . '/Maintenance.php';
32// @codeCoverageIgnoreEnd
33
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( "Print this wiki's birthday and age" );
41 }
42
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;
100require_once RUN_MAINTENANCE_IF_MAIN;
101// @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.
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