590daa04f8f3af56c182792f8b45656d7e44c8f4
4 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
22 # Class to simplify the use of log pages.
23 # The logs are now kept in a table which is easier to manage and trim
24 # than ever-growing wiki pages.
27 /* private */ var $type, $action, $comment;
28 var $updateRecentChanges = true;
30 function LogPage( $type ) {
31 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
35 function saveContent() {
36 if( wfReadOnly() ) return;
39 $fname = 'LogPage::saveContent';
41 $dbw =& wfGetDB( DB_MASTER
);
42 $uid = $wgUser->getID();
44 $this->timestamp
= $now = wfTimestampNow();
45 $dbw->insertArray( 'logging',
47 'log_type' => $this->type
,
48 'log_action' => $this->action
,
49 'log_timestamp' => $dbw->timestamp( $now ),
51 'log_namespace' => $this->target
->getNamespace(),
52 'log_title' => $this->target
->getDBkey(),
53 'log_comment' => $this->comment
57 # And update recentchanges
58 if ( $this->updateRecentChanges
) {
59 $rcComment = $this->actionText
;
60 if( '' != $this->comment
) {
61 $rcComment .= ': ' . $this->comment
;
63 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Log/' . $this->type
);
64 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $rcComment );
69 /* static */ function validTypes() {
70 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
74 /* static */ function validActions( $type ) {
75 static $actions = array(
77 'block' => array( 'block', 'unblock' ),
78 'protect' => array( 'protect', 'unprotect' ),
79 'rights' => array( 'rights' ),
80 'delete' => array( 'delete', 'restore' ),
81 'upload' => array( 'upload' )
83 return $actions[$type];
86 /* static */ function isLogType( $type ) {
87 return in_array( $type, LogPage
::validTypes() );
90 /* static */ function logName( $type ) {
91 static $typeText = array(
93 'block' => 'blocklogpage',
94 'protect' => 'protectlogpage',
95 'rights' => 'bureaucratlog',
96 'delete' => 'dellogpage',
97 'upload' => 'uploadlogpage',
99 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
102 /* static */ function logHeader( $type ) {
103 static $headerText = array(
105 'block' => 'blocklogtext',
106 'protect' => 'protectlogtext',
108 'delete' => 'dellogpagetext',
109 'upload' => 'uploadlogpagetext'
111 return wfMsg( $headerText[$type] );
114 /* static */ function actionText( $type, $action, $titleLink = NULL ) {
115 static $actions = array(
116 'block/block' => 'blocklogentry',
117 'block/unblock' => 'blocklogentry',
118 'protect/protect' => 'protectedarticle',
119 'protect/unprotect' => 'unprotectedarticle',
120 'rights/rights' => 'bureaucratlogentry',
121 'delete/delete' => 'deletedarticle',
122 'delete/restore' => 'undeletedarticle',
123 'upload/upload' => 'uploadedimage',
124 'upload/revert' => 'uploadedimage',
126 $key = "$type/$action";
127 if( isset( $actions[$key] ) ) {
128 if( is_null( $titleLink ) ) {
129 return wfMsg( $actions[$key] );
131 return wfMsg( $actions[$key], $titleLink );
134 wfDebug( "LogPage::actionText - unknown action $key\n" );
135 return "$action $titleLink";
139 function addEntry( $action, &$target, $comment ) {
140 global $wgLang, $wgUser;
142 $this->action
= $action;
143 $this->target
=& $target;
144 $this->comment
= $comment;
145 $this->actionText
= LogPage
::actionText( $this->type
, $action,
146 $target->getPrefixedText() );
148 return $this->saveContent();