Show pretty localized log names in Recentchanges instead of Special:Log/upload etc
[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 # 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.
25
26 class LogPage {
27 /* private */ var $type, $action, $comment;
28 var $updateRecentChanges = true;
29
30 function LogPage( $type ) {
31 # Type is one of 'block', 'protect', 'rights', 'delete', 'upload'
32 $this->type = $type;
33 }
34
35 function saveContent() {
36 if( wfReadOnly() ) return;
37
38 global $wgUser;
39 $fname = 'LogPage::saveContent';
40
41 $dbw =& wfGetDB( DB_MASTER );
42 $uid = $wgUser->getID();
43
44 $this->timestamp = $now = wfTimestampNow();
45 $dbw->insertArray( 'logging',
46 array(
47 'log_type' => $this->type,
48 'log_action' => $this->action,
49 'log_timestamp' => $dbw->timestamp( $now ),
50 'log_user' => $uid,
51 'log_namespace' => $this->target->getNamespace(),
52 'log_title' => $this->target->getDBkey(),
53 'log_comment' => $this->comment
54 ), $fname
55 );
56
57 # And update recentchanges
58 if ( $this->updateRecentChanges ) {
59 $rcComment = $this->actionText;
60 if( '' != $this->comment ) {
61 $rcComment .= ': ' . $this->comment;
62 }
63 $titleObj = Title::makeTitle( NS_SPECIAL, 'Log/' . $this->type );
64 RecentChange::notifyLog( $now, $titleObj, $wgUser, $rcComment );
65 }
66 return true;
67 }
68
69 /* static */ function &validTypes() {
70 static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload' );
71 return $types;
72 }
73
74 /* static */ function isLogType( $type ) {
75 return in_array( $type, LogPage::validTypes() );
76 }
77
78 /* static */ function logName( $type ) {
79 static $typeText = array(
80 '' => 'log',
81 'block' => 'blocklogpage',
82 'protect' => 'protectlogpage',
83 'rights' => 'bureaucratlog',
84 'delete' => 'dellogpage',
85 'upload' => 'uploadlogpage',
86 );
87 return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
88 }
89
90 /* static */ function logHeader( $type ) {
91 static $headerText = array(
92 '' => 'alllogstext',
93 'block' => 'blocklogtext',
94 'protect' => 'protectlogtext',
95 'rights' => '',
96 'delete' => 'dellogpagetext',
97 'upload' => 'uploadlogpagetext'
98 );
99 return wfMsg( $headerText[$type] );
100 }
101
102 /* static */ function actionText( $type, $action, $titleLink ) {
103 static $actions = array(
104 'block/block' => 'blocklogentry',
105 'block/unblock' => 'blocklogentry',
106 'protect/protect' => 'protectedarticle',
107 'protect/unprotect' => 'unprotectedarticle',
108 'rights/rights' => 'bureaucratlogentry',
109 'delete/delete' => 'deletedarticle',
110 'delete/restore' => 'undeletedarticle',
111 'upload/upload' => 'uploadedimage',
112 'upload/revert' => 'uploadedimage',
113 );
114 $key = "$type/$action";
115 if( isset( $actions[$key] ) ) {
116 return wfMsg( $actions[$key], $titleLink );
117 } else {
118 wfDebug( "LogPage::actionText - unknown action $key\n" );
119 return "$action $titleLink";
120 }
121 }
122
123 function addEntry( $action, &$target, $comment ) {
124 global $wgLang, $wgUser;
125
126 $this->action = $action;
127 $this->target =& $target;
128 $this->comment = $comment;
129 $this->actionText = LogPage::actionText( $this->type, $action,
130 $target->getPrefixedText() );
131
132 return $this->saveContent();
133 }
134 }
135
136 ?>