Last User Login 은 사용자들이 마지막으로 로그인 한 시간을 테이블로 나타낸다.
소스 코드 생성
- SpecialLastUserLogin.php
- SpecialLastUserLogin_body.php
- SpecialLastUserLogin.i18n.php
# vi extensions/SpecialLastUserLogin.php
<?php
/**
* SpecialLastUserLogin MediaWiki extension
*
* @file
* @ingroup Extensions
* @version 1.2.0
* @author Justin G. Cramer
* @author Danila Ulyanov
* @author Thomas Klein
* @link http://www.mediawiki.org/wiki/Extension:SpecialLastUserLoginEx Documentation
*
* 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
*/
if( !defined( 'MEDIAWIKI' ) ) {
die();
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits['specialpage'][] = array(
'name' => 'LastUserLogin',
'version' => '1.2.0',
'author' => array('Justin G. Cramer', 'Danila Ulyanov', 'Thomas Klein'),
'description' => 'Displays the last time a user logged in',
'url' => 'http://www.mediawiki.org/wiki/Extension:SpecialLastUserLoginEx',
);
// New user right
$wgAvailableRights[] = 'lastlogin';
// Set up the new special page
$dir = dirname(__FILE__) . '/';
$wgAutoloadClasses['LastUserLogin'] = $dir . 'SpecialLastUserLogin_body.php';
$wgExtensionMessagesFiles['LastUserLogin'] = $dir . 'SpecialLastUserLogin.i18n.php';
$wgSpecialPages['LastUserLogin'] = 'LastUserLogin';
// Function that updates the database when a user logs in
$wgExtensionFunctions[] = 'wfUpdateUserTouched';
function wfUpdateUserTouched() {
global $wgOut, $wgCookiePrefix;
if( isset( $_COOKIE ) && isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
$dbw = wfGetDB( DB_MASTER );
$query = "UPDATE ".$dbw->tableName('user')." SET user_touched = '".$dbw->timestamp()."' WHERE user_id = ".intval($_COOKIE["{$wgCookiePrefix}UserID"]);
$dbw->doQuery($query);
}
}
<?php
/**
* SpecialLastUserLogin MediaWiki extension
*
* @file
* @ingroup Extensions
* @version 1.2.0
* @author Justin G. Cramer
* @author Danila Ulyanov
* @author Thomas Klein
* @link http://www.mediawiki.org/wiki/Extension:SpecialLastUserLoginEx Documentation
*
* 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
*/
if( !defined( 'MEDIAWIKI' ) ) {
die();
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits['specialpage'][] = array(
'name' => 'LastUserLogin',
'version' => '1.2.0',
'author' => array('Justin G. Cramer', 'Danila Ulyanov', 'Thomas Klein'),
'description' => 'Displays the last time a user logged in',
'url' => 'http://www.mediawiki.org/wiki/Extension:SpecialLastUserLoginEx',
);
// New user right
$wgAvailableRights[] = 'lastlogin';
// Set up the new special page
$dir = dirname(__FILE__) . '/';
$wgAutoloadClasses['LastUserLogin'] = $dir . 'SpecialLastUserLogin_body.php';
$wgExtensionMessagesFiles['LastUserLogin'] = $dir . 'SpecialLastUserLogin.i18n.php';
$wgSpecialPages['LastUserLogin'] = 'LastUserLogin';
// Function that updates the database when a user logs in
$wgExtensionFunctions[] = 'wfUpdateUserTouched';
function wfUpdateUserTouched() {
global $wgOut, $wgCookiePrefix;
if( isset( $_COOKIE ) && isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
$dbw = wfGetDB( DB_MASTER );
$query = "UPDATE ".$dbw->tableName('user')." SET user_touched = '".$dbw->timestamp()."' WHERE user_id = ".intval($_COOKIE["{$wgCookiePrefix}UserID"]);
$dbw->doQuery($query);
}
}
# vi extensions/SpecialLastUserLogin_body.php
<?php
class LastUserLogin extends SpecialPage {
/**
* Constructor
*/
public function __construct() {
parent::__construct( 'LastUserLogin'/*class*/, 'lastlogin'/*restriction*/ );
}
/**
* Show the special page
*
* @param $par Mixed: parameter passed to the page or null
*/
public function execute( $par ) {
global $wgUser, $wgOut, $wgLang;
wfLoadExtensionMessages( 'LastUserLogin' );
# If user is blocked, s/he doesn't need to access this page
if ( $wgUser->isBlocked() ) {
$wgOut->blockedPage();
return;
}
# Show a message if the database is in read-only mode
if ( wfReadOnly() ) {
$wgOut->readOnlyPage();
return;
}
# If the user doesn't have the required 'lastlogin' permission, display an error
if( !$wgUser->isAllowed( 'lastlogin' ) ) {
$wgOut->permissionRequired( 'lastlogin' );
return;
}
$this->setHeaders();
$skin = $wgUser->getSkin();
$wgOut->setPageTitle( wfMsg( 'lastuserlogin' ) );
$dbr = 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 ".$dbr->tableName('user')." ORDER BY ".$orderby." ".$ordertype;
$ordertype = $ordertype == 'ASC' ? 'DESC' : 'ASC';
if( $result = $dbr->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 = $dbr->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 );
}
}
<?php
class LastUserLogin extends SpecialPage {
/**
* Constructor
*/
public function __construct() {
parent::__construct( 'LastUserLogin'/*class*/, 'lastlogin'/*restriction*/ );
}
/**
* Show the special page
*
* @param $par Mixed: parameter passed to the page or null
*/
public function execute( $par ) {
global $wgUser, $wgOut, $wgLang;
wfLoadExtensionMessages( 'LastUserLogin' );
# If user is blocked, s/he doesn't need to access this page
if ( $wgUser->isBlocked() ) {
$wgOut->blockedPage();
return;
}
# Show a message if the database is in read-only mode
if ( wfReadOnly() ) {
$wgOut->readOnlyPage();
return;
}
# If the user doesn't have the required 'lastlogin' permission, display an error
if( !$wgUser->isAllowed( 'lastlogin' ) ) {
$wgOut->permissionRequired( 'lastlogin' );
return;
}
$this->setHeaders();
$skin = $wgUser->getSkin();
$wgOut->setPageTitle( wfMsg( 'lastuserlogin' ) );
$dbr = 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 ".$dbr->tableName('user')." ORDER BY ".$orderby." ".$ordertype;
$ordertype = $ordertype == 'ASC' ? 'DESC' : 'ASC';
if( $result = $dbr->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 = $dbr->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 );
}
}
# vi extensions/SpecialLastUserLogin.i18n.php
<?php
/**
* Internationalization file for LastUserLogin extension.
*
* @file
* @ingroup Extensions
*/
$messages = array();
/** English
* @author Justin G. Cramer
* @author Danila Ulyanov
* @author Thomas Klein
*/
$messages['en'] = array(
'lastuserlogin' => 'Last user login',
'lastuserlogin_userid' => 'Username',
'lastuserlogin_username' => 'Real name',
'lastuserlogin_useremail' => 'User email',
'lastuserlogin_lastlogin' => 'Last login',
'lastuserlogin_daysago' => 'Days ago',
);
/** German (Deutsch) */
$messages['de'] = array(
'lastuserlogin' => 'Letzte Anmeldungen',
'lastuserlogin_userid' => 'Benutzername',
'lastuserlogin_username' => 'Echter Name',
'lastuserlogin_useremail' => 'E-Mail-Adresse',
'lastuserlogin_lastlogin' => 'Letzte Anmeldung',
'lastuserlogin_daysago' => 'Tage',
);
/** French (Français) */
$messages['fr'] = array(
'lastuserlogin_userid' => 'Nom d’utilisateur',
'lastuserlogin_username' => 'Nom réel',
);
/** Latin (Latina) */
$messages['la'] = array(
'lastuserlogin_userid' => 'Nomen usoris',
'lastuserlogin_username' => 'Nomen tuum verum',
);
/** Dutch (Nederlands) */
$messages['nl'] = array(
'lastuserlogin' => 'Laatste aanmeldingen van gebruikers',
'lastuserlogin_userid' => 'Gebruikersnaam',
'lastuserlogin_username' => 'Echte naam',
'lastuserlogin_useremail' => 'E-mail',
'lastuserlogin_lastlogin' => 'Laatste aanmelding',
'lastuserlogin_daysago' => 'Aantal dagen geleden',
);
/* Lithuanian (Lietuvių) */
$messages['lt'] = array(
'lastuserlogin' => 'Paskutinis naudotojo prisijungimas',
'lastuserlogin_userid' => 'Naudotojo vardas',
'lastuserlogin_username' => 'Tikras vardas',
'lastuserlogin_useremail' => 'Naudotojo el. paštas',
'lastuserlogin_lastlogin' => 'Paskutinis prisijungimas',
'lastuserlogin_daysago' => 'Dienų prieš',
);
/* Polish (Polski) */
$messages['pl'] = array(
'lastuserlogin' => 'Ostatnie zalogowania użytkownika',
'lastuserlogin_userid' => 'Login',
'lastuserlogin_username' => 'Prawdziwa nazwa',
'lastuserlogin_useremail' => 'Adres e-mail',
'lastuserlogin_lastlogin' => 'Ostatnie zalogowanie',
'lastuserlogin_daysago' => 'dni temu',
);
/* Russian (Russian) */
$messages['ru'] = array(
'lastuserlogin' => 'Недавние посещения пользователей',
'lastuserlogin_userid' => 'Имя пользователя',
'lastuserlogin_username' => 'Настоящее имя',
'lastuserlogin_useremail' => 'Электронная почта',
'lastuserlogin_lastlogin' => 'Недавнее посещение',
'lastuserlogin_daysago' => 'Дней назад',
);
/* Japanese (日本語) */
$messages['ja'] = array(
'lastuserlogin' => '利用者の最終ログイン',
'lastuserlogin_userid' => '利用者名',
'lastuserlogin_username' => '本名',
'lastuserlogin_useremail' => 'メールアドレス',
'lastuserlogin_lastlogin' => '最終ログイン',
'lastuserlogin_daysago' => '経過日数',
);
<?php
/**
* Internationalization file for LastUserLogin extension.
*
* @file
* @ingroup Extensions
*/
$messages = array();
/** English
* @author Justin G. Cramer
* @author Danila Ulyanov
* @author Thomas Klein
*/
$messages['en'] = array(
'lastuserlogin' => 'Last user login',
'lastuserlogin_userid' => 'Username',
'lastuserlogin_username' => 'Real name',
'lastuserlogin_useremail' => 'User email',
'lastuserlogin_lastlogin' => 'Last login',
'lastuserlogin_daysago' => 'Days ago',
);
/** German (Deutsch) */
$messages['de'] = array(
'lastuserlogin' => 'Letzte Anmeldungen',
'lastuserlogin_userid' => 'Benutzername',
'lastuserlogin_username' => 'Echter Name',
'lastuserlogin_useremail' => 'E-Mail-Adresse',
'lastuserlogin_lastlogin' => 'Letzte Anmeldung',
'lastuserlogin_daysago' => 'Tage',
);
/** French (Français) */
$messages['fr'] = array(
'lastuserlogin_userid' => 'Nom d’utilisateur',
'lastuserlogin_username' => 'Nom réel',
);
/** Latin (Latina) */
$messages['la'] = array(
'lastuserlogin_userid' => 'Nomen usoris',
'lastuserlogin_username' => 'Nomen tuum verum',
);
/** Dutch (Nederlands) */
$messages['nl'] = array(
'lastuserlogin' => 'Laatste aanmeldingen van gebruikers',
'lastuserlogin_userid' => 'Gebruikersnaam',
'lastuserlogin_username' => 'Echte naam',
'lastuserlogin_useremail' => 'E-mail',
'lastuserlogin_lastlogin' => 'Laatste aanmelding',
'lastuserlogin_daysago' => 'Aantal dagen geleden',
);
/* Lithuanian (Lietuvių) */
$messages['lt'] = array(
'lastuserlogin' => 'Paskutinis naudotojo prisijungimas',
'lastuserlogin_userid' => 'Naudotojo vardas',
'lastuserlogin_username' => 'Tikras vardas',
'lastuserlogin_useremail' => 'Naudotojo el. paštas',
'lastuserlogin_lastlogin' => 'Paskutinis prisijungimas',
'lastuserlogin_daysago' => 'Dienų prieš',
);
/* Polish (Polski) */
$messages['pl'] = array(
'lastuserlogin' => 'Ostatnie zalogowania użytkownika',
'lastuserlogin_userid' => 'Login',
'lastuserlogin_username' => 'Prawdziwa nazwa',
'lastuserlogin_useremail' => 'Adres e-mail',
'lastuserlogin_lastlogin' => 'Ostatnie zalogowanie',
'lastuserlogin_daysago' => 'dni temu',
);
/* Russian (Russian) */
$messages['ru'] = array(
'lastuserlogin' => 'Недавние посещения пользователей',
'lastuserlogin_userid' => 'Имя пользователя',
'lastuserlogin_username' => 'Настоящее имя',
'lastuserlogin_useremail' => 'Электронная почта',
'lastuserlogin_lastlogin' => 'Недавнее посещение',
'lastuserlogin_daysago' => 'Дней назад',
);
/* Japanese (日本語) */
$messages['ja'] = array(
'lastuserlogin' => '利用者の最終ログイン',
'lastuserlogin_userid' => '利用者名',
'lastuserlogin_username' => '本名',
'lastuserlogin_useremail' => 'メールアドレス',
'lastuserlogin_lastlogin' => '最終ログイン',
'lastuserlogin_daysago' => '経過日数',
);
설정 변경
* 기본 설정 파일에 Last User Login 파일 인크루드 행 추가
# vi LocalSettings.php
require_once( "$IP/extensions/SpecialLastUserLogin.php" );
require_once( "$IP/extensions/SpecialLastUserLogin.php" );
* 추가하고 싶은 권한 설정
# vi includes/DefaultSettings.php
$wgGroupPermissions['sysop']['lastlogin'] = true;
$wgGroupPermissions['sysop']['lastlogin'] = true;
WRITTEN BY
- 손가락귀신
정신 못차리면, 벌 받는다.
,