c2f0d6ad5560b7c58d3890483ff9d64a8cc4ad92
[lhc/web/wiklou.git] / includes / LogPage.php
1 <?php
2 #$Id$
3 #
4 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
6 #
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.
11 #
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.
16 #
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
21
22 /**
23 * Contain log classes
24 */
25
26 /**
27 * Class to simplify the use of log pages.
28 * The logs are now kept in a table which is easier to manage and trim
29 * than ever-growing wiki pages.
30 */
31 class LogPage {
32 /* private */ var $type, $action, $comment;
33 var $updateRecentChanges = true;
34
35 function LogPage( $type ) {
36 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
37 $this->type = $type;
38 }
39
40 function saveContent() {
41 if( wfReadOnly() ) return;
42
43 global $wgUser;
44 $fname = 'LogPage::saveContent';
45
46 $dbw =& wfGetDB( DB_MASTER );
47 $uid = $wgUser->getID();
48
49 $this->timestamp = $now = wfTimestampNow();
50 $dbw->insertArray( 'logging',
51 array(
52 'log_type' => $this->type,
53 'log_action' => $this->action,
54 'log_timestamp' => $dbw->timestamp( $now ),
55 'log_user' => $uid,
56 'log_namespace' => $this->target->getNamespace(),
57 'log_title' => $this->target->getDBkey(),
58 'log_comment' => $this->comment
59 ), $fname
60 );
61
62 # And update recentchanges
63 if ( $this->updateRecentChanges ) {
64 $rcComment = $this->actionText;
65 if( '' != $this->comment ) {
66 $rcComment .= ': ' . $this->comment;
67 }
68 $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
69 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
70 }
71 return true;
72 }
73
74 /**
75 * @static
76 */
77 function validTypes() {
78 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
79 return $types;
80 }
81
82 /**
83 * @static
84 */
85 function validActions( $type ) {
86 static $actions = array(
87 '' => NULL,
88 'block' => array( 'block', 'unblock' ),
89 'protect' => array( 'protect', 'unprotect' ),
90 'rights' => array( 'rights' ),
91 'delete' => array( 'delete', 'restore' ),
92 'upload' => array( 'upload' )
93 );
94 return $actions[$type];
95 }
96
97 /**
98 * @static
99 */
100 function isLogType( $type ) {
101 return in_array( $type, LogPage::validTypes() );
102 }
103
104 /**
105 * @static
106 */
107 function logName( $type ) {
108 static $typeText = array(
109 '' => 'log',
110 'block' => 'blocklogpage',
111 'protect' => 'protectlogpage',
112 'rights' => 'bureaucratlog',
113 'delete' => 'dellogpage',
114 'upload' => 'uploadlogpage',
115 );
116 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
117 }
118
119 /**
120 * @static
121 */
122 function logHeader( $type ) {
123 static $headerText = array(
124 '' => 'alllogstext',
125 'block' => 'blocklogtext',
126 'protect' => 'protectlogtext',
127 'rights' => '',
128 'delete' => 'dellogpagetext',
129 'upload' => 'uploadlogpagetext'
130 );
131 return wfMsg( $headerText[$type] );
132 }
133
134 /**
135 * @static
136 */
137 function actionText( $type, $action, $titleLink = NULL ) {
138 static $actions = array(
139 'block/block' => 'blocklogentry',
140 'block/unblock' => 'blocklogentry',
141 'protect/protect' => 'protectedarticle',
142 'protect/unprotect' => 'unprotectedarticle',
143 'rights/rights' => 'bureaucratlogentry',
144 'delete/delete' => 'deletedarticle',
145 'delete/restore' => 'undeletedarticle',
146 'upload/upload' => 'uploadedimage',
147 'upload/revert' => 'uploadedimage',
148 );
149 $key = "$type/$action";
150 if( isset( $actions[$key] ) ) {
151 if( is_null( $titleLink ) ) {
152 return wfMsg( $actions[$key] );
153 } else {
154 return wfMsg( $actions[$key], $titleLink );
155 }
156 } else {
157 wfDebug( "LogPage::actionText - unknown action $key\n" );
158 return "$action $titleLink";
159 }
160 }
161
162 function addEntry( $action, &$target, $comment ) {
163 global $wgLang, $wgUser;
164
165 $this->action = $action;
166 $this->target =& $target;
167 $this->comment = $comment;
168 $this->actionText = LogPage::actionText( $this->type, $action,
169 $target->getPrefixedText() );
170
171 return $this->saveContent();
172 }
173 }
174
175 ?>