<?php
/**
* Author: Raze Soldier (razesoldier@outlook.com)
* License: GPL 3.0
*/
/**
* 获取一个用户成为自动确认用户的时间
* 仅用于中文维基百科
* @param string $username 需要检查的用户名
* @return 当指定的用户还不是自动确认用户时返回false,其它情况返回用户成为自动确认用户的时间(格式:ISO 8601)
*/
function getUserAutoconfirmTime($username) {
$arrContextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
# 检查用户是否是自动确认用户
$usersApi = "https://zh.wikipedia.org/w/api.php?action=query&list=users&ususers={$username}&usprop=registration|groups&format=json";
$userData = file_get_contents( $usersApi, false, stream_context_create( $arrContextOptions ) );
$userDataArray = json_decode( $userData, true );
if ( !in_array( 'autoconfirmed', $userDataArray['query']['users'][0]['groups'] ) ) {
return false;
}
$registerTime = strtotime( $userDataArray['query']['users'][0]['registration'] );
$limitTime = $registerTime + 604800;
$usercontribsApi = "https://zh.wikipedia.org/w/api.php?action=query&list=usercontribs&ucuser={$username}&ucstart={$registerTime}&ucend={$limitTime}&format=json";
$usercontribsData = file_get_contents( $usercontribsApi, false, stream_context_create( $arrContextOptions ) );
$usercontribsArray = json_decode( $usercontribsData, true );
// 如果在7天内编辑数等于大于50,返回注册时间+7天的时间
if ( count( $usercontribsArray['query']['usercontribs'] ) >= 50 ) {
return date( 'c', $limitTime );
}
// 返回第50次编辑的时间
$editApi = "https://zh.wikipedia.org/w/api.php?action=query&list=usercontribs&ucuser={$username}&ucdir=newer&uclimit=50&format=json";
$editData = file_get_contents( $editApi, false, stream_context_create( $arrContextOptions ) );
return json_decode( $editData, true )['query']['usercontribs'][49]['timestamp'];
}