3
# SpecialLastUserLogin Mediawiki extension
5
# Original by Justin G. Cramer and Danila Ulyanov 22.11.2005
7
# Extended by Thomas Klein
9
# http://www.mediawiki.org/
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation; either version 2 of the License, or
14
# (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License along
22
# with this program; if not, write to the Free Software Foundation, Inc.,
23
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
# http://www.gnu.org/copyleft/gpl.html
30
* - Fixed problems with MediaWiki 1.6
33
* - Fixed problems with varibale $_COOKIE and $PHPSELF
34
* - Translation to german
35
* - Insert style cellpadding in table
38
* - The code checked the user authorizes
41
* - Make a link to the user page
44
* - Release of the first version
47
if( !defined( 'MEDIAWIKI' ) ) {
51
require_once "$IP/includes/SpecialPage.php";
53
$wgExtensionFunctions[] = "wfLastUserLogin";
54
$wgExtensionFunctions[] = "wfUpdateUserTouched";
56
$wgExtensionCredits['specialpage'][] = array(
57
'name' => 'LastUserLogin',
58
'description' => 'Displays the last time a user logged in',
59
'url' => 'http://meta.wikimedia.org/wiki/SpecialLastUserLoginEx',
60
'author' => 'Justin G. Cramer, Danila Ulyanov, Thomas Klein',
63
function wfUpdateUserTouched() {
64
global $wgDBprefix, $wgOut, $wgDBname;
65
if (isset($_COOKIE) && isset($_COOKIE["{$wgDBname}_{$wgDBprefix}UserID"])) {
66
$db = &wfGetDB(DB_SLAVE);
67
$query = "UPDATE {$wgDBprefix}user SET user_touched = '".wfTimestamp(TS_MW)."' WHERE user_id = ".intval($_COOKIE["{$wgDBname}_{$wgDBprefix}UserID"]);
72
function wfLastUserLogin() {
74
class SpecialLastUserLogin extends SpecialPage {
75
function SpecialLastUserLogin() {
76
SpecialPage::SpecialPage('LastUserLogin', 'block');
80
global $wgDBprefix, $wgOut, $wgLang, $PHPSELF;
83
if ( ! $wgUser->isAllowed('block') ) {
84
$wgOut->permissionRequired('block');
89
$skin = $wgUser->getSkin( );
91
$wgOut->setPagetitle( wfMsg( 'lastuserlogin' ) );
93
$db = &wfGetDB(DB_SLAVE);
94
$style = 'style="border:1px solid #000;text-align:left;"';
95
$fields = array('user_name'=>'lastuserlogin_userid',
96
'user_real_name'=>'lastuserlogin_username',
97
'user_email'=>'lastuserlogin_useremail',
98
'user_touched'=>'lastuserlogin_lastlogin'
100
//get order by and check it
101
if(isset($_REQUEST['order_by'])){
102
if(isset($fields[$_REQUEST['order_by']])){
103
$orderby = $_REQUEST['order_by'];
105
$orderby = 'user_name';
108
$orderby = 'user_name';
111
//get order type and check it
112
if(isset($_REQUEST['order_type'])){
113
if($_REQUEST['order_type']=='DESC'){
114
$ordertype = $_REQUEST['order_type'];
122
$query = "SELECT user_name, user_real_name, user_email, user_touched FROM ".$wgDBprefix."user ORDER BY ".$orderby." ".$ordertype;
123
$ordertype = $ordertype=='ASC'?'DESC':'ASC';
125
if ($result = $db->doQuery($query)) {
126
$out = '<table width="100%" cellpadding="3" '.$style.'><tr>';
128
foreach($fields as $key=>$value){
129
$out .= '<th '.$style.'><a href="?order_by='.$key.'&order_type='.$ordertype.'">'.wfMsg( $value ).'</a></th>';
132
$out .= "<th $style>".wfMsg( 'lastuserlogin_daysago' )."</th>";
135
while ($row = $db->fetchRow($result)) {
137
foreach($fields as $key=>$value){
139
if ($key == "user_touched") {
140
$style = 'style="border:1px solid #000"';
141
$out .= "<td $style>".$wgLang->timeanddate( wfTimestamp(TS_MW, $row[$key]), true).
142
'</td><td style="border: 1px solid #000; text-align:right;">'.
143
$wgLang->formatNum(round((mktime() - wfTimestamp(TS_UNIX, $row[$key]))/3600/24, 2), 2)."</td>";
145
if ($key == "user_name") {
146
$userPage = Title::makeTitle( NS_USER, htmlspecialchars($row[$key]));
147
$name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
149
$out .= '<td '.$style.'>'.$name.'</a></td>';
151
$out .= '<td '.$style.'>'.htmlspecialchars($row[$key]).' </td>';
160
$wgOut->addHTML( $out );
165
SpecialPage::addPage( new SpecialLastUserLogin );
167
global $wgMessageCache, $wgLanguageCode;
169
if ($wgLanguageCode == 'de') {
170
$wgMessageCache->addMessage('lastuserlogin' ,'Letzte Anmeldungen');
171
$wgMessageCache->addMessage('lastuserlogin_userid', 'Anmeldename');
172
$wgMessageCache->addMessage('lastuserlogin_username', 'Benutzername');
173
$wgMessageCache->addMessage('lastuserlogin_useremail', 'E-Mail-Adresse');
174
$wgMessageCache->addMessage('lastuserlogin_lastlogin', 'Letzte Anmeldung');
175
$wgMessageCache->addMessage('lastuserlogin_daysago', 'Tage');
178
$wgMessageCache->addMessage('lastuserlogin' ,'Last User Login');
179
$wgMessageCache->addMessage('lastuserlogin_userid', 'User ID');
180
$wgMessageCache->addMessage('lastuserlogin_username', 'User Name');
181
$wgMessageCache->addMessage('lastuserlogin_useremail', 'User Email');
182
$wgMessageCache->addMessage('lastuserlogin_lastlogin', 'Last Login');
183
$wgMessageCache->addMessage('lastuserlogin_daysago', 'Days Ago');