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 $fname = 'LogPage::getContent';
23 $dbw =& wfGetDB( DB_WRITE
);
24 $s = $dbw->getArray( 'cur',
25 array( 'cur_id','cur_text','cur_timestamp' ),
26 array( 'cur_namespace' => Namespace::getWikipedia(), 'cur_title' => $this->mTitle
),
31 $this->mId
= $s->cur_id
;
32 $this->mContent
= $s->cur_text
;
33 $this->mTimestamp
= $s->cur_timestamp
;
36 $this->mContent
= $defaulttext;
37 $this->mTimestamp
= wfTimestampNow();
39 $this->mContentLoaded
= true; # Well, sort of
41 return $this->mContent
;
44 function getTimestamp()
46 if( !$this->mContentLoaded
) {
49 return $this->mTimestamp
;
52 function saveContent()
54 if( wfReadOnly() ) return;
57 $fname = "LogPage::saveContent";
59 $dbw =& wfGetDB( DB_WRITE
);
60 $uid = $wgUser->getID();
62 if( !$this->mContentLoaded
) return false;
63 $this->mTimestamp
= $now = wfTimestampNow();
64 $won = wfInvertTimestamp( $now );
66 $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
68 # Note: this query will deadlock if another thread has called getContent(),
69 # at least in MySQL 4.0.17 InnoDB
70 $dbw->insertArray( 'cur',
73 'cur_timestamp' => $now,
75 'cur_user_text' => $wgUser->getName(),
76 'cur_namespace' => NS_WIKIPEDIA
,
77 'cur_title' => $this->mTitle
,
78 'cur_text' => $this->mContent
,
79 'cur_comment' => $this->mComment
,
80 'cur_restrictions' => 'sysop',
81 'inverse_timestamp' => $won,
82 'cur_touched' => $now,
85 $this->mId
= $dbw->insertId();
87 $dbw->updateArray( 'cur',
89 'cur_timestamp' => $now,
91 'cur_user_text' => $wgUser->getName(),
92 'cur_text' => $this->mContent
,
93 'cur_comment' => $this->mComment
,
94 'cur_restrictions' => 'sysop',
95 'inverse_timestamp' => $won,
96 'cur_touched' => $now,
98 'cur_id' => $this->mId
103 # And update recentchanges
104 if ( $this->mUpdateRecentChanges
) {
105 $titleObj = Title
::makeTitle( Namespace::getWikipedia(), $this->mTitle
);
106 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $this->mComment
);
111 function addEntry( $action, $comment, $textaction = "" )
113 global $wgLang, $wgUser;
115 $comment_esc = wfEscapeWikiText( $comment );
119 $ut = $wgUser->getName();
120 $uid = $wgUser->getID();
123 $wgLang->getNsText( Namespace::getUser() ) .
128 $d = $wgLang->timeanddate( wfTimestampNow(), false );
130 if( preg_match( "/^(.*?)<ul>(.*)$/sD", $this->mContent
, $m ) ) {
139 $this->mComment
= $textaction;
141 $this->mComment
= $action;
143 if ( "" == $comment ) {
146 $inline = " <em>({$comment_esc})</em>";
147 # comment gets escaped again, so we use the unescaped version
148 $this->mComment
.= ": {$comment}";
150 $this->mContent
= "{$before}<ul><li>{$d} {$ul} {$action}{$inline}</li>\n{$after}";
152 # TODO: automatic log rotation...
154 return $this->saveContent();
157 function replaceContent( $text, $comment = "" )
159 $this->mContent
= $text;
160 $this->mComment
= $comment;
161 $this->mTimestamp
= wfTimestampNow();
162 return $this->saveContent();
165 function showAsDisabledPage( $rawhtml = true )
167 global $wgLang, $wgOut;
168 if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
169 # Client cache fresh and headers sent, nothing more to do.
172 $func = ( $rawhtml ?
"addHTML" : "addWikiText" );
174 "<p>" . wfMsg( "perfdisabled" ) . "</p>\n\n" .
175 "<p>" . wfMsg( "perfdisabledsub", $wgLang->timeanddate( $this->getTimestamp() ) ) . "</p>\n\n" .