MediaWiki
REL1_39
wikiBirthday.php
Go to the documentation of this file.
1
<?php
27
use
MediaWiki\MediaWikiServices
;
28
29
require_once __DIR__ .
'/Maintenance.php'
;
30
34
class
WikiBirthday
extends
Maintenance
{
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;
96
require_once RUN_MAINTENANCE_IF_MAIN;
getDB
getDB()
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:66
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:443
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:319
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:212
WikiBirthday
Definition
wikiBirthday.php:34
WikiBirthday\execute
execute()
Do the actual work.
Definition
wikiBirthday.php:52
WikiBirthday\__construct
__construct()
Default constructor.
Definition
wikiBirthday.php:35
DB_REPLICA
const DB_REPLICA
Definition
defines.php:26
$dbr
$dbr
Definition
testCompression.php:54
$maintClass
$maintClass
Definition
wikiBirthday.php:95
maintenance
wikiBirthday.php
Generated on Thu Nov 21 2024 05:25:09 for MediaWiki by
1.10.0