2 # Class to simplify the use of log pages
5 /* private */ var $mTitle, $mContent, $mContentLoaded, $mId, $mComment;
6 var $mUpdateRecentChanges ;
8 function LogPage( $title, $defaulttext = "<ul>\n</ul>" )
10 # For now, assume title is correct dbkey
11 # and log pages always go in Wikipedia namespace
12 $this->mTitle
= $title;
14 $this->mUpdateRecentChanges
= true ;
15 $this->mContentLoaded
= false;
16 $this->getContent( $defaulttext );
19 function getContent( $defaulttext = "<ul>\n</ul>" )
21 $sql = "SELECT cur_id,cur_text FROM cur " .
22 "WHERE cur_namespace=" . Namespace::getWikipedia() . " AND " .
23 "cur_title='" . wfStrencode($this->mTitle
) . "'";
24 $res = wfQuery( $sql, "LogPage::getContent" );
26 if( wfNumRows( $res ) > 0 ) {
27 $s = wfFetchObject( $res );
28 $this->mId
= $s->cur_id
;
29 $this->mContent
= $s->cur_text
;
32 $this->mContent
= $defaulttext;
34 $this->mContentLoaded
= true; # Well, sort of
36 return $this->mContent
;
39 function saveContent()
42 $fname = "LogPage::saveContent";
43 $uid = $wgUser->getID();
44 $ut = wfStrencode( $wgUser->getName() );
46 if( !$this->mContentLoaded
) return false;
47 $now = date( "YmdHis" );
48 $won = wfInvertTimestamp( $now );
50 $sql = "INSERT INTO cur (cur_timestamp,cur_user,cur_user_text,
51 cur_namespace,cur_title,cur_text,cur_comment,cur_restrictions,inverse_timestamp)
52 VALUES ('{$now}', {$uid}, '{$ut}', " .
53 Namespace::getWikipedia() . ", '" .
54 wfStrencode( $this->mTitle
) . "', '" .
55 wfStrencode( $this->mContent
) . "', '" .
56 wfStrencode( $this->mComment
) . "', 'sysop', '{$won}')";
57 wfQuery( $sql, $fname );
58 $this->mId
= wfInsertId();
60 $sql = "UPDATE cur SET cur_timestamp='{$now}', " .
61 "cur_user={$uid}, cur_user_text='{$ut}', " .
62 "cur_text='" . wfStrencode( $this->mContent
) . "', " .
63 "cur_comment='" . wfStrencode( $this->mComment
) . "', " .
64 "cur_restrictions='sysop', inverse_timestamp='{$won}' " .
65 "WHERE cur_id={$this->mId}";
66 wfQuery( $sql, $fname );
69 # And update recentchanges
70 if ( $this->mUpdateRecentChanges
) {
71 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,
72 rc_user,rc_user_text,rc_namespace,rc_title,rc_comment,
73 rc_cur_id) VALUES ('{$now}','{$now}',{$uid},'{$ut}',4,'" .
74 wfStrencode( $this->mTitle
) . "','" .
75 wfStrencode( $this->mComment
) . "',{$this->mId})";
76 wfQuery( $sql, $fname );
81 function addEntry( $action, $comment, $textaction = "" )
83 global $wgLang, $wgUser;
86 $ut = $wgUser->getName();
87 $uid = $wgUser->getID();
90 $wgLang->getNsText( Namespace::getUser() ) .
95 $d = $wgLang->timeanddate( date( "YmdHis" ), false );
97 preg_match( "/^(.*?)<ul>(.*)$/sD", $this->mContent
, $m );
100 $this->mComment
= $textaction;
102 $this->mComment
= $action;
104 if ( "" == $comment ) {
107 $inline = " <em>({$comment})</em>";
108 $this->mComment
.= ": {$comment}";
110 $this->mContent
= "{$m[1]}<ul><li>{$d} {$ul} {$action}{$inline}</li>\n{$m[2]}";
112 # TODO: automatic log rotation...
114 return $this->saveContent();