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
= str_replace( " ", "_", $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,cur_timestamp 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
;
30 $this->mTimestamp
= $s->cur_timestamp
;
33 $this->mContent
= $defaulttext;
34 $this->mTimestamp
= wfTimestampNow();
36 $this->mContentLoaded
= true; # Well, sort of
38 return $this->mContent
;
41 function getTimestamp()
43 if( !$this->mContentLoaded
) {
46 return $this->mTimestamp
;
49 function saveContent()
51 if( wfReadOnly() ) return;
54 $fname = "LogPage::saveContent";
55 $uid = $wgUser->getID();
56 $ut = wfStrencode( $wgUser->getName() );
58 if( !$this->mContentLoaded
) return false;
59 $this->mTimestamp
= $now = wfTimestampNow();
60 $won = wfInvertTimestamp( $now );
62 $sql = "INSERT INTO cur (cur_timestamp,cur_user,cur_user_text,
63 cur_namespace,cur_title,cur_text,cur_comment,cur_restrictions,inverse_timestamp)
64 VALUES ('{$now}', {$uid}, '{$ut}', " .
65 Namespace::getWikipedia() . ", '" .
66 wfStrencode( $this->mTitle
) . "', '" .
67 wfStrencode( $this->mContent
) . "', '" .
68 wfStrencode( $this->mComment
) . "', 'sysop', '{$won}')";
69 wfQuery( $sql, $fname );
70 $this->mId
= wfInsertId();
72 $sql = "UPDATE cur SET cur_timestamp='{$now}', " .
73 "cur_user={$uid}, cur_user_text='{$ut}', " .
74 "cur_text='" . wfStrencode( $this->mContent
) . "', " .
75 "cur_comment='" . wfStrencode( $this->mComment
) . "', " .
76 "cur_restrictions='sysop', inverse_timestamp='{$won}' " .
77 "WHERE cur_id={$this->mId}";
78 wfQuery( $sql, $fname );
81 # And update recentchanges
82 if ( $this->mUpdateRecentChanges
) {
83 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,
84 rc_user,rc_user_text,rc_namespace,rc_title,rc_comment,
85 rc_cur_id) VALUES ('{$now}','{$now}',{$uid},'{$ut}',4,'" .
86 wfStrencode( $this->mTitle
) . "','" .
87 wfStrencode( $this->mComment
) . "',{$this->mId})";
88 wfQuery( $sql, $fname );
93 function addEntry( $action, $comment, $textaction = "" )
95 global $wgLang, $wgUser;
98 $ut = $wgUser->getName();
99 $uid = $wgUser->getID();
102 $wgLang->getNsText( Namespace::getUser() ) .
107 $d = $wgLang->timeanddate( wfTimestampNow(), false );
109 preg_match( "/^(.*?)<ul>(.*)$/sD", $this->mContent
, $m );
112 $this->mComment
= $textaction;
114 $this->mComment
= $action;
116 if ( "" == $comment ) {
119 $inline = " <em>({$comment})</em>";
120 $this->mComment
.= ": {$comment}";
122 $this->mContent
= "{$m[1]}<ul><li>{$d} {$ul} {$action}{$inline}</li>\n{$m[2]}";
124 # TODO: automatic log rotation...
126 return $this->saveContent();
129 function replaceContent( $text, $comment = "" )
131 $this->mContent
= $text;
132 $this->mComment
= $comment;
133 $this->mTimestamp
= wfTimestampNow();
134 return $this->saveContent();
137 function showAsDisabledPage( $rawhtml = true )
139 global $wgLang, $wgOut;
140 $wgOut->checkLastModified( $this->getTimestamp() );
141 $func = ( $rawhtml ?
"addHTML" : "addWikiText" );
143 "<p>" . wfMsg( "perfdisabled" ) . "</p>\n\n" .
144 "<p>" . wfMsg( "perfdisabledsub", $wgLang->timeanddate( $this->getTimestamp() ) ) . "</p>\n\n" .