\n" )
{
# For now, assume title is correct dbkey
# and log pages always go in Wikipedia namespace
$this->mTitle = str_replace( " ", "_", $title );
$this->mId = 0;
$this->mUpdateRecentChanges = true ;
$this->mContentLoaded = false;
$this->getContent( $defaulttext );
}
function getContent( $defaulttext = "
" )
{
$fname = 'LogPage::getContent';
$dbw =& wfGetDB( DB_WRITE );
$s = $dbw->getArray( 'cur',
array( 'cur_id','cur_text','cur_timestamp' ),
array( 'cur_namespace' => Namespace::getWikipedia(), 'cur_title' => $this->mTitle ),
$fname, 'FOR UPDATE'
);
if( $s !== false ) {
$this->mId = $s->cur_id;
$this->mContent = $s->cur_text;
$this->mTimestamp = $s->cur_timestamp;
} else {
$this->mId = 0;
$this->mContent = $defaulttext;
$this->mTimestamp = wfTimestampNow();
}
$this->mContentLoaded = true; # Well, sort of
return $this->mContent;
}
function getTimestamp()
{
if( !$this->mContentLoaded ) {
$this->getContent();
}
return $this->mTimestamp;
}
function saveContent()
{
if( wfReadOnly() ) return;
global $wgUser;
$fname = "LogPage::saveContent";
$dbw =& wfGetDB( DB_WRITE );
$uid = $wgUser->getID();
if( !$this->mContentLoaded ) return false;
$this->mTimestamp = $now = wfTimestampNow();
$won = wfInvertTimestamp( $now );
if($this->mId == 0) {
$seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
# Note: this query will deadlock if another thread has called getContent(),
# at least in MySQL 4.0.17 InnoDB
$dbw->insertArray( 'cur',
array(
'cur_id' => $seqVal,
'cur_timestamp' => $now,
'cur_user' => $uid,
'cur_user_text' => $wgUser->getName(),
'cur_namespace' => NS_WIKIPEDIA,
'cur_title' => $this->mTitle,
'cur_text' => $this->mContent,
'cur_comment' => $this->mComment,
'cur_restrictions' => 'sysop',
'inverse_timestamp' => $won,
'cur_touched' => $now,
), $fname
);
$this->mId = $dbw->insertId();
} else {
$dbw->updateArray( 'cur',
array( /* SET */
'cur_timestamp' => $now,
'cur_user' => $uid,
'cur_user_text' => $wgUser->getName(),
'cur_text' => $this->mContent,
'cur_comment' => $this->mComment,
'cur_restrictions' => 'sysop',
'inverse_timestamp' => $won,
'cur_touched' => $now,
), array( /* WHERE */
'cur_id' => $this->mId
), $fname
);
}
# And update recentchanges
if ( $this->mUpdateRecentChanges ) {
$titleObj = Title::makeTitle( Namespace::getWikipedia(), $this->mTitle );
RecentChange::notifyLog( $now, $titleObj, $wgUser, $this->mComment );
}
return true;
}
function addEntry( $action, $comment, $textaction = "" )
{
global $wgLang, $wgUser;
$comment_esc = wfEscapeWikiText( $comment );
$this->getContent();
$ut = $wgUser->getName();
$uid = $wgUser->getID();
if( $uid ) {
$ul = "[[" .
$wgLang->getNsText( Namespace::getUser() ) .
":{$ut}|{$ut}]]";
} else {
$ul = $ut;
}
$d = $wgLang->timeanddate( wfTimestampNow(), false );
if( preg_match( "/^(.*?)(.*)$/sD", $this->mContent, $m ) ) {
$before = $m[1];
$after = $m[2];
} else {
$before = "";
$after = "";
}
if($textaction)
$this->mComment = $textaction;
else
$this->mComment = $action;
if ( "" == $comment ) {
$inline = "";
} else {
$inline = " ({$comment_esc})";
# comment gets escaped again, so we use the unescaped version
$this->mComment .= ": {$comment}";
}
$this->mContent = "{$before}- {$d} {$ul} {$action}{$inline}
\n{$after}";
# TODO: automatic log rotation...
return $this->saveContent();
}
function replaceContent( $text, $comment = "" )
{
$this->mContent = $text;
$this->mComment = $comment;
$this->mTimestamp = wfTimestampNow();
return $this->saveContent();
}
function showAsDisabledPage( $rawhtml = true )
{
global $wgLang, $wgOut;
if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
# Client cache fresh and headers sent, nothing more to do.
return;
}
$func = ( $rawhtml ? "addHTML" : "addWikiText" );
$wgOut->$func(
"" . wfMsg( "perfdisabled" ) . "
\n\n" .
"" . wfMsg( "perfdisabledsub", $wgLang->timeanddate( $this->getTimestamp() ) ) . "
\n\n" .
"
\n\n" .
$this->getContent()
);
return;
}
}
?>