Removed CVS keywords from files, to make merging between branches
[lhc/web/wiklou.git] / includes / LogPage.php
1 <?php
2 #
3 # Copyright (C) 2002, 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # http://www.gnu.org/copyleft/gpl.html
20
21 /**
22 * Contain log classes
23 *
24 * @package MediaWiki
25 */
26
27 /**
28 * Class to simplify the use of log pages.
29 * The logs are now kept in a table which is easier to manage and trim
30 * than ever-growing wiki pages.
31 *
32 * @package MediaWiki
33 */
34 class LogPage {
35 /* private */ var $type, $action, $comment;
36 var $updateRecentChanges = true;
37
38 function LogPage( $type ) {
39 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
40 $this->type = $type;
41 }
42
43 function saveContent() {
44 if( wfReadOnly() ) return;
45
46 global $wgUser;
47 $fname = 'LogPage::saveContent';
48
49 $dbw =& wfGetDB( DB_MASTER );
50 $uid = $wgUser->getID();
51
52 $this->timestamp = $now = wfTimestampNow();
53 $dbw->insert( 'logging',
54 array(
55 'log_type' => $this->type,
56 'log_action' => $this->action,
57 'log_timestamp' => $dbw->timestamp( $now ),
58 'log_user' => $uid,
59 'log_namespace' => $this->target->getNamespace(),
60 'log_title' => $this->target->getDBkey(),
61 'log_comment' => $this->comment
62 ), $fname
63 );
64
65 # And update recentchanges
66 if ( $this->updateRecentChanges ) {
67 $rcComment = $this->actionText;
68 if( '' != $this->comment ) {
69 $rcComment .= ': ' . $this->comment;
70 }
71 $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
72 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
73 }
74 return true;
75 }
76
77 /**
78 * @static
79 */
80 function validTypes() {
81 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
82 return $types;
83 }
84
85 /**
86 * @static
87 */
88 function validActions( $type ) {
89 static $actions = array(
90 '' => NULL,
91 'block' => array( 'block', 'unblock' ),
92 'protect' => array( 'protect', 'unprotect' ),
93 'rights' => array( 'rights' ),
94 'delete' => array( 'delete', 'restore' ),
95 'upload' => array( 'upload' )
96 );
97 return $actions[$type];
98 }
99
100 /**
101 * @static
102 */
103 function isLogType( $type ) {
104 return in_array( $type, LogPage::validTypes() );
105 }
106
107 /**
108 * @static
109 */
110 function logName( $type ) {
111 static $typeText = array(
112 '' => 'log',
113 'block' => 'blocklogpage',
114 'protect' => 'protectlogpage',
115 'rights' => 'bureaucratlog',
116 'delete' => 'dellogpage',
117 'upload' => 'uploadlogpage',
118 );
119 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
120 }
121
122 /**
123 * @static
124 */
125 function logHeader( $type ) {
126 static $headerText = array(
127 '' => 'alllogstext',
128 'block' => 'blocklogtext',
129 'protect' => 'protectlogtext',
130 'rights' => '',
131 'delete' => 'dellogpagetext',
132 'upload' => 'uploadlogpagetext'
133 );
134 return wfMsg( $headerText[$type] );
135 }
136
137 /**
138 * @static
139 */
140 function actionText( $type, $action, $titleLink = NULL ) {
141 static $actions = array(
142 'block/block' => 'blocklogentry',
143 'block/unblock' => 'blocklogentry',
144 'protect/protect' => 'protectedarticle',
145 'protect/unprotect' => 'unprotectedarticle',
146 'rights/rights' => 'bureaucratlogentry',
147 'delete/delete' => 'deletedarticle',
148 'delete/restore' => 'undeletedarticle',
149 'upload/upload' => 'uploadedimage',
150 'upload/revert' => 'uploadedimage',
151 );
152 $key = "$type/$action";
153 if( isset( $actions[$key] ) ) {
154 if( is_null( $titleLink ) ) {
155 return wfMsg( $actions[$key] );
156 } else {
157 return wfMsg( $actions[$key], $titleLink );
158 }
159 } else {
160 wfDebug( "LogPage::actionText - unknown action $key\n" );
161 return "$action $titleLink";
162 }
163 }
164
165 /**
166 * Add a log entry
167 * @param string $action one of 'block', 'protect', 'rights', 'delete', 'upload'
168 * @param &$target
169 * @param string $comment Description associated
170 */
171 function addEntry( $action, &$target, $comment ) {
172 global $wgLang, $wgUser;
173
174 $this->action = $action;
175 $this->target =& $target;
176 $this->comment = $comment;
177 $this->actionText = LogPage::actionText( $this->type, $action,
178 $target->getPrefixedText() );
179
180 return $this->saveContent();
181 }
182 }
183
184 ?>