File: SpecialLastUserLogin.php

package info (click to toggle)
mediawiki-extensions 0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 132 kB
  • ctags: 209
  • sloc: php: 892; makefile: 6
file content (187 lines) | stat: -rw-r--r-- 6,460 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
#
# SpecialLastUserLogin Mediawiki extension
# 
# Original by Justin G. Cramer and Danila Ulyanov 22.11.2005
# 
# Extended by Thomas Klein
#
# http://www.mediawiki.org/
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or 
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html

/**
* ChangeLog
*
* 04.04.2006 1.0.4
*  - Fixed problems with MediaWiki 1.6
*
* 29.03.2006 1.0.3
*  - Fixed problems with varibale $_COOKIE and $PHPSELF
*  - Translation to german
*  - Insert style cellpadding in table
*
* 20.12.2005 1.0.2
*  - The code checked the user authorizes
*
* 09.12.2005 1.0.1
*  - Make a link to the user page
*
* 30.11.2005 1.0.0
*  - Release of the first version
*/

if( !defined( 'MEDIAWIKI' ) ) {
  die();
}

require_once "$IP/includes/SpecialPage.php";

$wgExtensionFunctions[] = "wfLastUserLogin";
$wgExtensionFunctions[] = "wfUpdateUserTouched";

$wgExtensionCredits['specialpage'][] = array(
                                            'name' => 'LastUserLogin',
                                            'description' => 'Displays the last time a user logged in',
                                            'url' => 'http://meta.wikimedia.org/wiki/SpecialLastUserLoginEx',
                                            'author' => 'Justin G. Cramer, Danila Ulyanov, Thomas Klein',
                                            'version'=>'1.0.4');

function wfUpdateUserTouched() {
  global $wgDBprefix, $wgOut, $wgDBname;
  if (isset($_COOKIE) && isset($_COOKIE["{$wgDBname}_{$wgDBprefix}UserID"])) {
      $db = &wfGetDB(DB_SLAVE);
      $query = "UPDATE {$wgDBprefix}user SET user_touched = '".wfTimestamp(TS_MW)."' WHERE user_id = ".intval($_COOKIE["{$wgDBname}_{$wgDBprefix}UserID"]);
      $db->doQuery($query);
  }
}

function wfLastUserLogin() {

  class SpecialLastUserLogin extends SpecialPage {
  function SpecialLastUserLogin() {
    SpecialPage::SpecialPage('LastUserLogin', 'block');
  }

  function execute() {
    global $wgDBprefix, $wgOut, $wgLang, $PHPSELF;
    global $wgUser;
    
    if ( ! $wgUser->isAllowed('block') ) {
      $wgOut->permissionRequired('block');
      return;
    }
    
    $this->setHeaders();
    $skin = $wgUser->getSkin( );

    $wgOut->setPagetitle( wfMsg( 'lastuserlogin' ) );
    
    $db = &wfGetDB(DB_SLAVE);
    $style = 'style="border:1px solid #000;text-align:left;"';
    $fields = array('user_name'=>'lastuserlogin_userid',
                    'user_real_name'=>'lastuserlogin_username',
                    'user_email'=>'lastuserlogin_useremail',
                    'user_touched'=>'lastuserlogin_lastlogin'
                    );
    //get order by and check it
    if(isset($_REQUEST['order_by'])){
        if(isset($fields[$_REQUEST['order_by']])){
          $orderby = $_REQUEST['order_by'];
        }else{
          $orderby = 'user_name';
        }               
    }else{
       $orderby = 'user_name';
    }       
    
    //get order type and check it
    if(isset($_REQUEST['order_type'])){
      if($_REQUEST['order_type']=='DESC'){
        $ordertype = $_REQUEST['order_type'];
      }else{
        $ordertype = 'ASC';
      }               
    }else{
      $ordertype = 'ASC';
    }       
  
    $query = "SELECT user_name, user_real_name, user_email, user_touched FROM ".$wgDBprefix."user ORDER BY ".$orderby." ".$ordertype;
    $ordertype = $ordertype=='ASC'?'DESC':'ASC';
   
    if ($result = $db->doQuery($query)) {
      $out = '<table width="100%" cellpadding="3" '.$style.'><tr>';
    
      foreach($fields as $key=>$value){
        $out .= '<th '.$style.'><a href="?order_by='.$key.'&order_type='.$ordertype.'">'.wfMsg( $value ).'</a></th>';
      }
    
      $out .= "<th $style>".wfMsg( 'lastuserlogin_daysago' )."</th>";
      $out .= '</tr>';
    
      while ($row = $db->fetchRow($result)) {
        $out .= '<tr>';
        foreach($fields as $key=>$value){
    
        if ($key == "user_touched") {
          $style = 'style="border:1px solid #000"';
          $out .= "<td $style>".$wgLang->timeanddate( wfTimestamp(TS_MW, $row[$key]), true).
                  '</td><td style="border: 1px solid #000; text-align:right;">'.
                  $wgLang->formatNum(round((mktime() - wfTimestamp(TS_UNIX, $row[$key]))/3600/24, 2), 2)."</td>";
        } else {
          if ($key == "user_name") {
            $userPage = Title::makeTitle( NS_USER, htmlspecialchars($row[$key]));
            $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );

            $out .= '<td '.$style.'>'.$name.'</a></td>';          
          } else { 
            $out .= '<td '.$style.'>'.htmlspecialchars($row[$key]).' </td>';
          }
        }
      }
    
      $out .= '</tr>';
    }
        }
    $out .= '</table>';
    $wgOut->addHTML( $out );
    
    }
  }
  
  SpecialPage::addPage( new SpecialLastUserLogin );
  
  global $wgMessageCache, $wgLanguageCode;
  
  if ($wgLanguageCode == 'de') {
    $wgMessageCache->addMessage('lastuserlogin' ,'Letzte Anmeldungen');
    $wgMessageCache->addMessage('lastuserlogin_userid', 'Anmeldename');
    $wgMessageCache->addMessage('lastuserlogin_username', 'Benutzername');
    $wgMessageCache->addMessage('lastuserlogin_useremail', 'E-Mail-Adresse');
    $wgMessageCache->addMessage('lastuserlogin_lastlogin', 'Letzte Anmeldung');
    $wgMessageCache->addMessage('lastuserlogin_daysago', 'Tage');
  }
  else {
    $wgMessageCache->addMessage('lastuserlogin' ,'Last User Login');
    $wgMessageCache->addMessage('lastuserlogin_userid', 'User ID');
    $wgMessageCache->addMessage('lastuserlogin_username', 'User Name');
    $wgMessageCache->addMessage('lastuserlogin_useremail', 'User Email');
    $wgMessageCache->addMessage('lastuserlogin_lastlogin', 'Last Login');
    $wgMessageCache->addMessage('lastuserlogin_daysago', 'Days Ago');
  }
}

?>