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