~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to extensions/SpecialLastUserLogin.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
#
3
 
# SpecialLastUserLogin Mediawiki extension
4
 
5
 
# Original by Justin G. Cramer and Danila Ulyanov 22.11.2005
6
 
7
 
# Extended by Thomas Klein
8
 
#
9
 
# http://www.mediawiki.org/
10
 
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.
15
 
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.
20
 
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
25
 
 
26
 
/**
27
 
* ChangeLog
28
 
*
29
 
* 04.04.2006 1.0.4
30
 
*  - Fixed problems with MediaWiki 1.6
31
 
*
32
 
* 29.03.2006 1.0.3
33
 
*  - Fixed problems with varibale $_COOKIE and $PHPSELF
34
 
*  - Translation to german
35
 
*  - Insert style cellpadding in table
36
 
*
37
 
* 20.12.2005 1.0.2
38
 
*  - The code checked the user authorizes
39
 
*
40
 
* 09.12.2005 1.0.1
41
 
*  - Make a link to the user page
42
 
*
43
 
* 30.11.2005 1.0.0
44
 
*  - Release of the first version
45
 
*/
46
 
 
47
 
if( !defined( 'MEDIAWIKI' ) ) {
48
 
  die();
49
 
}
50
 
 
51
 
require_once "$IP/includes/SpecialPage.php";
52
 
 
53
 
$wgExtensionFunctions[] = "wfLastUserLogin";
54
 
$wgExtensionFunctions[] = "wfUpdateUserTouched";
55
 
 
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',
61
 
                                            'version'=>'1.0.4');
62
 
 
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"]);
68
 
      $db->doQuery($query);
69
 
  }
70
 
}
71
 
 
72
 
function wfLastUserLogin() {
73
 
 
74
 
  class SpecialLastUserLogin extends SpecialPage {
75
 
  function SpecialLastUserLogin() {
76
 
    SpecialPage::SpecialPage('LastUserLogin', 'block');
77
 
  }
78
 
 
79
 
  function execute() {
80
 
    global $wgDBprefix, $wgOut, $wgLang, $PHPSELF;
81
 
    global $wgUser;
82
 
    
83
 
    if ( ! $wgUser->isAllowed('block') ) {
84
 
      $wgOut->permissionRequired('block');
85
 
      return;
86
 
    }
87
 
    
88
 
    $this->setHeaders();
89
 
    $skin = $wgUser->getSkin( );
90
 
 
91
 
    $wgOut->setPagetitle( wfMsg( 'lastuserlogin' ) );
92
 
    
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'
99
 
                    );
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'];
104
 
        }else{
105
 
          $orderby = 'user_name';
106
 
        }               
107
 
    }else{
108
 
       $orderby = 'user_name';
109
 
    }       
110
 
    
111
 
    //get order type and check it
112
 
    if(isset($_REQUEST['order_type'])){
113
 
      if($_REQUEST['order_type']=='DESC'){
114
 
        $ordertype = $_REQUEST['order_type'];
115
 
      }else{
116
 
        $ordertype = 'ASC';
117
 
      }               
118
 
    }else{
119
 
      $ordertype = 'ASC';
120
 
    }       
121
 
  
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';
124
 
   
125
 
    if ($result = $db->doQuery($query)) {
126
 
      $out = '<table width="100%" cellpadding="3" '.$style.'><tr>';
127
 
    
128
 
      foreach($fields as $key=>$value){
129
 
        $out .= '<th '.$style.'><a href="?order_by='.$key.'&order_type='.$ordertype.'">'.wfMsg( $value ).'</a></th>';
130
 
      }
131
 
    
132
 
      $out .= "<th $style>".wfMsg( 'lastuserlogin_daysago' )."</th>";
133
 
      $out .= '</tr>';
134
 
    
135
 
      while ($row = $db->fetchRow($result)) {
136
 
        $out .= '<tr>';
137
 
        foreach($fields as $key=>$value){
138
 
    
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>";
144
 
        } else {
145
 
          if ($key == "user_name") {
146
 
            $userPage = Title::makeTitle( NS_USER, htmlspecialchars($row[$key]));
147
 
            $name = $skin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText() ) );
148
 
 
149
 
            $out .= '<td '.$style.'>'.$name.'</a></td>';          
150
 
          } else { 
151
 
            $out .= '<td '.$style.'>'.htmlspecialchars($row[$key]).' </td>';
152
 
          }
153
 
        }
154
 
      }
155
 
    
156
 
      $out .= '</tr>';
157
 
    }
158
 
        }
159
 
    $out .= '</table>';
160
 
    $wgOut->addHTML( $out );
161
 
    
162
 
    }
163
 
  }
164
 
  
165
 
  SpecialPage::addPage( new SpecialLastUserLogin );
166
 
  
167
 
  global $wgMessageCache, $wgLanguageCode;
168
 
  
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');
176
 
  }
177
 
  else {
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');
184
 
  }
185
 
}
186
 
 
187
 
?>