MediaWiki master
wikiBirthday.php
Go to the documentation of this file.
1<?php
28
29// @codeCoverageIgnoreStart
30require_once __DIR__ . '/Maintenance.php';
31// @codeCoverageIgnoreEnd
32
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription( "Print this wiki's birthday and age" );
40 }
41
47 private function computeAge( string $wikiCreatedAt ) {
48 return date_diff(
49 date_create( MWTimestamp::now() ),
50 date_create( $wikiCreatedAt )
51 );
52 }
53
54 public function execute() {
55 $dbr = $this->getReplicaDB();
56
57 $revId = $dbr->newSelectQueryBuilder()
58 ->table( 'revision' )
59 ->field( 'MIN(rev_id)' )
60 ->caller( __METHOD__ )
61 ->fetchField();
62
63 $archiveRevId = $dbr->newSelectQueryBuilder()
64 ->table( 'archive' )
65 ->field( 'MIN(ar_rev_id)' )
66 ->caller( __METHOD__ )
67 ->fetchField();
68
69 if ( $archiveRevId && ( $archiveRevId < $revId || !$revId ) ) {
70 $timestamp = $dbr->newSelectQueryBuilder()
71 ->table( 'archive' )
72 ->field( 'ar_timestamp' )
73 ->where( [ 'ar_rev_id' => (int)$archiveRevId ] )
74 ->caller( __METHOD__ )
75 ->fetchField();
76 } else {
77 $timestamp = $dbr->newSelectQueryBuilder()
78 ->table( 'revision' )
79 ->field( 'rev_timestamp' )
80 ->where( [ 'rev_id' => (int)$revId ] )
81 ->caller( __METHOD__ )
82 ->fetchField();
83 }
84
85 $birthDay = $this->getServiceContainer()->getContentLanguage()
86 ->getHumanTimestamp( MWTimestamp::getInstance( $timestamp ) );
87
88 $text = "Wiki was created on: " . $birthDay . " <age: " .
89 $this->computeAge( $timestamp )->format(
90 "%y yr(s), %m month(s), %d day(s)"
91 ) . " old>.";
92
93 $this->output( $text . "\n" );
94 }
95}
96
97// @codeCoverageIgnoreStart
98$maintClass = WikiBirthday::class;
99require_once RUN_MAINTENANCE_IF_MAIN;
100// @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