4 # Class to simplify the use of log pages
7 /* private */ var $mTitle, $mContent, $mContentLoaded, $mId, $mComment;
8 var $mUpdateRecentChanges ;
10 function LogPage( $title, $defaulttext = "<ul>\n</ul>" )
12 # For now, assume title is correct dbkey
13 # and log pages always go in Wikipedia namespace
14 $this->mTitle
= str_replace( " ", "_", $title );
16 $this->mUpdateRecentChanges
= true ;
17 $this->mContentLoaded
= false;
18 $this->getContent( $defaulttext );
21 function getContent( $defaulttext = "<ul>\n</ul>" )
23 $fname = 'LogPage::getContent';
25 $dbw =& wfGetDB( DB_MASTER
);
26 $s = $dbw->getArray( 'cur',
27 array( 'cur_id','cur_text','cur_timestamp' ),
28 array( 'cur_namespace' => Namespace::getWikipedia(), 'cur_title' => $this->mTitle
),
33 $this->mId
= $s->cur_id
;
34 $this->mContent
= $s->cur_text
;
35 $this->mTimestamp
= wfTimestamp(TS_MW
,$s->cur_timestamp
);
38 $this->mContent
= $defaulttext;
39 $this->mTimestamp
= wfTimestamp(TS_MW
);
41 $this->mContentLoaded
= true; # Well, sort of
43 return $this->mContent
;
46 function getTimestamp()
48 if( !$this->mContentLoaded
) {
51 return $this->mTimestamp
;
54 function saveContent()
56 if( wfReadOnly() ) return;
59 $fname = "LogPage::saveContent";
61 $dbw =& wfGetDB( DB_MASTER
);
62 $uid = $wgUser->getID();
64 if( !$this->mContentLoaded
) return false;
65 $this->mTimestamp
= $now = wfTimestampNow();
66 $won = wfInvertTimestamp( $now );
68 $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
70 # Note: this query will deadlock if another thread has called getContent(),
71 # at least in MySQL 4.0.17 InnoDB
72 $dbw->insertArray( 'cur',
75 'cur_timestamp' => $dbw->timestamp($now),
77 'cur_user_text' => $wgUser->getName(),
78 'cur_namespace' => NS_WIKIPEDIA
,
79 'cur_title' => $this->mTitle
,
80 'cur_text' => $this->mContent
,
81 'cur_comment' => $this->mComment
,
82 'cur_restrictions' => 'sysop',
83 'inverse_timestamp' => $won,
84 'cur_touched' => $dbw->timestamp($now),
87 $this->mId
= $dbw->insertId();
89 $dbw->updateArray( 'cur',
91 'cur_timestamp' => $dbw->timestamp($now),
93 'cur_user_text' => $wgUser->getName(),
94 'cur_text' => $this->mContent
,
95 'cur_comment' => $this->mComment
,
96 'cur_restrictions' => 'sysop',
97 'inverse_timestamp' => $won,
98 'cur_touched' => $dbw->timestamp($now),
100 'cur_id' => $this->mId
105 # And update recentchanges
106 if ( $this->mUpdateRecentChanges
) {
107 $titleObj = Title
::makeTitle( Namespace::getWikipedia(), $this->mTitle
);
108 RecentChange
::notifyLog( $now, $titleObj, $wgUser, $this->mComment
);
113 function addEntry( $action, $comment, $textaction = "" )
115 global $wgLang, $wgUser;
117 $comment_esc = wfEscapeWikiText( $comment );
121 $ut = $wgUser->getName();
122 $uid = $wgUser->getID();
125 $wgLang->getNsText( Namespace::getUser() ) .
131 # Use the wiki-wide default date format instead of the user's setting
132 $d = $wgLang->timeanddate( wfTimestampNow(), false, MW_DATE_DEFAULT
);
134 if( preg_match( "/^(.*?)<ul>(.*)$/sD", $this->mContent
, $m ) ) {
143 $this->mComment
= $textaction;
145 $this->mComment
= $action;
147 if ( "" == $comment ) {
150 $inline = " <em>({$comment_esc})</em>";
151 # comment gets escaped again, so we use the unescaped version
152 $this->mComment
.= ": {$comment}";
154 $this->mContent
= "{$before}<ul><li>{$d} {$ul} {$action}{$inline}</li>\n{$after}";
156 # TODO: automatic log rotation...
158 return $this->saveContent();
161 function replaceContent( $text, $comment = "" )
163 $this->mContent
= $text;
164 $this->mComment
= $comment;
165 $this->mTimestamp
= wfTimestampNow();
166 return $this->saveContent();
169 function showAsDisabledPage( $rawhtml = true )
171 global $wgLang, $wgOut;
172 if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
173 # Client cache fresh and headers sent, nothing more to do.
176 $func = ( $rawhtml ?
"addHTML" : "addWikiText" );
178 "<p>" . wfMsg( "perfdisabled" ) . "</p>\n\n" .
179 "<p>" . wfMsg( "perfdisabledsub", $wgLang->timeanddate( $this->getTimestamp() ) ) . "</p>\n\n" .