MediaWiki REL1_39
wikiBirthday.php
Go to the documentation of this file.
1<?php
28
29require_once __DIR__ . '/Maintenance.php';
30
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription( "Print this wiki's birthday and age" );
38 }
39
45 private function computeAge( string $wikiCreatedAt ) {
46 return date_diff(
47 date_create(),
48 date_create( $wikiCreatedAt )
49 );
50 }
51
52 public function execute() {
53 $dbr = $this->getDB( DB_REPLICA );
54
55 $revId = $dbr->newSelectQueryBuilder()
56 ->table( 'revision' )
57 ->field( 'MIN(rev_id)' )
58 ->caller( __METHOD__ )
59 ->fetchField();
60
61 $archiveRevId = $dbr->newSelectQueryBuilder()
62 ->table( 'archive' )
63 ->field( 'MIN(ar_rev_id)' )
64 ->caller( __METHOD__ )
65 ->fetchField();
66
67 if ( $archiveRevId && $archiveRevId < $revId ) {
68 $timestamp = $dbr->newSelectQueryBuilder()
69 ->table( 'archive' )
70 ->field( 'ar_timestamp' )
71 ->where( [ 'ar_rev_id' => (int)$archiveRevId ] )
72 ->caller( __METHOD__ )
73 ->fetchField();
74 } else {
75 $timestamp = $dbr->newSelectQueryBuilder()
76 ->table( 'revision' )
77 ->field( 'rev_timestamp' )
78 ->where( [ 'rev_id' => (int)$revId ] )
79 ->caller( __METHOD__ )
80 ->fetchField();
81 }
82
83 $birthDay = MediaWikiServices::getInstance()->getContentLanguage()
84 ->getHumanTimestamp( MWTimestamp::getInstance( $timestamp ) );
85
86 $text = "Wiki was created on: " . $birthDay . " <age: " .
87 $this->computeAge( $timestamp )->format(
88 "%y yr(s), %m month(s), %d day(s)"
89 ) . " old>.";
90
91 $this->output( $text . "\n" );
92 }
93}
94
95$maintClass = WikiBirthday::class;
96require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
Service locator for MediaWiki core services.
execute()
Do the actual work.
__construct()
Default constructor.
const DB_REPLICA
Definition defines.php:26
$maintClass