2 # Copyright (C) 2008 Aaron Schulz
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
22 * @addtogroup SpecialPage
28 function wfSpecialLog( $par = '' ) {
29 global $wgRequest, $wgOut, $wgUser;
31 $type = $wgRequest->getVal( 'type', $par );
32 $user = $wgRequest->getText( 'user' );
33 $title = $wgRequest->getText( 'page' );
34 $pattern = $wgRequest->getBool( 'pattern' );
35 # Create a LogPager item to get the results and a LogEventList
36 # item to format them...
37 $loglist = new LogEventList( $wgUser->getSkin() );
38 $pager = new LogPager( $loglist, $type, $user, $title, $pattern );
39 # Set title and add header
40 $loglist->showHeader( $wgOut, $pager->getType() );
42 $loglist->showOptions( $wgOut, $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern() );
45 $pager->getNavigationBar() .
46 '<ul id="logevents">' . "\n" .
49 $pager->getNavigationBar()
56 class LogPager
extends ReverseChronologicalPager
{
57 var $type = '', $user = '', $title = '', $pattern = '';
60 * @param LogEventList $loglist,
61 * @param string $type,
62 * @param string $user,
63 * @param string $page,
64 * @param string $pattern
67 function __construct( $loglist, $type, $user, $title, $pattern, $conds = array() ) {
68 parent
::__construct();
69 $this->mConds
= $conds;
71 $this->mLogList
= $loglist;
73 $this->limitType( $type );
74 $this->limitUser( $user );
75 $this->limitTitle( $title, $pattern );
79 * Set the log reader to return only entries of the given type.
80 * Type restrictions enforced here
81 * @param string $type A log type ('upload', 'delete', etc)
84 private function limitType( $type ) {
85 global $wgLogRestrictions, $wgUser;
86 // Reset the array, clears extra "where" clauses when $par is used
87 $hiddenLogs = array();
88 // Nothing to show the user requested a log they can't see
89 if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
90 $this->mConds
[] = "NULL";
93 // Don't show private logs to unpriviledged users
94 foreach( $wgLogRestrictions as $logtype => $right ) {
95 if( !$wgUser->isAllowed($right) ||
empty($type) ) {
96 $safetype = $this->mDb
->strencode( $logtype );
97 $hiddenLogs[] = "'$safetype'";
100 if( !empty($hiddenLogs) ) {
101 $this->mConds
[] = 'log_type NOT IN('.implode(',',$hiddenLogs).')';
108 $this->mConds
['log_type'] = $type;
112 * Set the log reader to return only entries by the given user.
113 * @param string $name (In)valid user name
116 function limitUser( $name ) {
120 $usertitle = Title
::makeTitleSafe( NS_USER
, $name );
121 if( is_null($usertitle) ) {
124 $this->user
= $usertitle->getText();
125 /* Fetch userid at first, if known, provides awesome query plan afterwards */
126 $userid = User
::idFromName( $this->user
);
128 /* It should be nicer to abort query at all,
129 but for now it won't pass anywhere behind the optimizer */
130 $this->mConds
[] = "NULL";
132 $this->mConds
['log_user'] = $userid;
137 * Set the log reader to return only entries affecting the given page.
138 * (For the block and rights logs, this is a user page.)
139 * @param string $page Title name as text
142 function limitTitle( $page, $pattern ) {
145 $title = Title
::newFromText( $page );
146 if( strlen($page) == 0 ||
!$title instanceof Title
)
149 $this->title
= $title->getPrefixedText();
150 $this->pattern
= $pattern;
151 $ns = $title->getNamespace();
152 if( $pattern && !$wgMiserMode ) {
153 # use escapeLike to avoid expensive search patterns like 't%st%'
154 $safetitle = $this->mDb
->escapeLike( $title->getDBkey() );
155 $this->mConds
['log_namespace'] = $ns;
156 $this->mConds
[] = "log_title LIKE '$safetitle%'";
158 $this->mConds
['log_namespace'] = $ns;
159 $this->mConds
['log_title'] = $title->getDBkey();
163 function getQueryInfo() {
164 $this->mConds
[] = 'user_id = log_user';
165 # Hack this until live
166 global $wgAllowLogDeletion;
167 $log_id = $wgAllowLogDeletion ?
'log_id' : '0 AS log_id';
169 'tables' => array( 'logging', 'user' ),
170 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title',
171 'log_params', 'log_comment', $log_id, 'log_deleted', 'log_timestamp', 'user_name' ),
172 'conds' => $this->mConds
,
177 function getIndexField() {
178 return 'log_timestamp';
181 function formatRow( $row ) {
182 return $this->mLogList
->logLine( $row );
185 public function getType() {
189 public function getUser() {
193 public function getPage() {
197 public function getPattern() {
198 return $this->pattern
;