2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2003-04-14 23:10:40 +00:00
|
|
|
# Class to simplify the use of log pages
|
|
|
|
|
|
|
|
|
|
class LogPage {
|
|
|
|
|
/* private */ var $mTitle, $mContent, $mContentLoaded, $mId, $mComment;
|
|
|
|
|
var $mUpdateRecentChanges ;
|
|
|
|
|
|
|
|
|
|
function LogPage( $title, $defaulttext = "<ul>\n</ul>" )
|
|
|
|
|
{
|
|
|
|
|
# For now, assume title is correct dbkey
|
|
|
|
|
# and log pages always go in Wikipedia namespace
|
2003-05-16 11:19:06 +00:00
|
|
|
$this->mTitle = str_replace( " ", "_", $title );
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mId = 0;
|
|
|
|
|
$this->mUpdateRecentChanges = true ;
|
|
|
|
|
$this->mContentLoaded = false;
|
|
|
|
|
$this->getContent( $defaulttext );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getContent( $defaulttext = "<ul>\n</ul>" )
|
|
|
|
|
{
|
2004-07-10 03:09:26 +00:00
|
|
|
$fname = 'LogPage::getContent';
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$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 ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mId = $s->cur_id;
|
|
|
|
|
$this->mContent = $s->cur_text;
|
2003-05-16 11:19:06 +00:00
|
|
|
$this->mTimestamp = $s->cur_timestamp;
|
2003-04-14 23:10:40 +00:00
|
|
|
} else {
|
|
|
|
|
$this->mId = 0;
|
|
|
|
|
$this->mContent = $defaulttext;
|
2003-05-16 11:19:06 +00:00
|
|
|
$this->mTimestamp = wfTimestampNow();
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
$this->mContentLoaded = true; # Well, sort of
|
|
|
|
|
|
|
|
|
|
return $this->mContent;
|
|
|
|
|
}
|
2003-05-16 11:19:06 +00:00
|
|
|
|
|
|
|
|
function getTimestamp()
|
|
|
|
|
{
|
|
|
|
|
if( !$this->mContentLoaded ) {
|
|
|
|
|
$this->getContent();
|
|
|
|
|
}
|
|
|
|
|
return $this->mTimestamp;
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
function saveContent()
|
|
|
|
|
{
|
2003-05-16 11:19:06 +00:00
|
|
|
if( wfReadOnly() ) return;
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$fname = "LogPage::saveContent";
|
2004-07-10 03:09:26 +00:00
|
|
|
|
|
|
|
|
$dbw =& wfGetDB( DB_WRITE );
|
2003-04-14 23:10:40 +00:00
|
|
|
$uid = $wgUser->getID();
|
|
|
|
|
|
|
|
|
|
if( !$this->mContentLoaded ) return false;
|
2003-05-16 11:19:06 +00:00
|
|
|
$this->mTimestamp = $now = wfTimestampNow();
|
2003-04-14 23:10:40 +00:00
|
|
|
$won = wfInvertTimestamp( $now );
|
|
|
|
|
if($this->mId == 0) {
|
2004-07-10 03:09:26 +00:00
|
|
|
$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();
|
2003-04-14 23:10:40 +00:00
|
|
|
} else {
|
2004-07-10 03:09:26 +00:00
|
|
|
$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
|
|
|
|
|
);
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# And update recentchanges
|
|
|
|
|
if ( $this->mUpdateRecentChanges ) {
|
2004-01-17 05:49:39 +00:00
|
|
|
$titleObj = Title::makeTitle( Namespace::getWikipedia(), $this->mTitle );
|
|
|
|
|
RecentChange::notifyLog( $now, $titleObj, $wgUser, $this->mComment );
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addEntry( $action, $comment, $textaction = "" )
|
|
|
|
|
{
|
|
|
|
|
global $wgLang, $wgUser;
|
2003-11-28 07:44:49 +00:00
|
|
|
|
|
|
|
|
$comment_esc = wfEscapeWikiText( $comment );
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->getContent();
|
|
|
|
|
|
|
|
|
|
$ut = $wgUser->getName();
|
|
|
|
|
$uid = $wgUser->getID();
|
|
|
|
|
if( $uid ) {
|
|
|
|
|
$ul = "[[" .
|
|
|
|
|
$wgLang->getNsText( Namespace::getUser() ) .
|
|
|
|
|
":{$ut}|{$ut}]]";
|
|
|
|
|
} else {
|
|
|
|
|
$ul = $ut;
|
|
|
|
|
}
|
2003-06-30 01:33:16 +00:00
|
|
|
$d = $wgLang->timeanddate( wfTimestampNow(), false );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
if( preg_match( "/^(.*?)<ul>(.*)$/sD", $this->mContent, $m ) ) {
|
|
|
|
|
$before = $m[1];
|
|
|
|
|
$after = $m[2];
|
|
|
|
|
} else {
|
|
|
|
|
$before = "";
|
|
|
|
|
$after = "";
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
if($textaction)
|
|
|
|
|
$this->mComment = $textaction;
|
|
|
|
|
else
|
|
|
|
|
$this->mComment = $action;
|
|
|
|
|
|
|
|
|
|
if ( "" == $comment ) {
|
|
|
|
|
$inline = "";
|
|
|
|
|
} else {
|
2003-11-28 07:44:49 +00:00
|
|
|
$inline = " <em>({$comment_esc})</em>";
|
|
|
|
|
# comment gets escaped again, so we use the unescaped version
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mComment .= ": {$comment}";
|
|
|
|
|
}
|
2004-03-08 09:09:35 +00:00
|
|
|
$this->mContent = "{$before}<ul><li>{$d} {$ul} {$action}{$inline}</li>\n{$after}";
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# TODO: automatic log rotation...
|
|
|
|
|
|
|
|
|
|
return $this->saveContent();
|
|
|
|
|
}
|
2003-05-16 11:19:06 +00:00
|
|
|
|
|
|
|
|
function replaceContent( $text, $comment = "" )
|
|
|
|
|
{
|
|
|
|
|
$this->mContent = $text;
|
|
|
|
|
$this->mComment = $comment;
|
|
|
|
|
$this->mTimestamp = wfTimestampNow();
|
|
|
|
|
return $this->saveContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showAsDisabledPage( $rawhtml = true )
|
|
|
|
|
{
|
|
|
|
|
global $wgLang, $wgOut;
|
2003-12-11 20:16:34 +00:00
|
|
|
if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
|
|
|
|
|
# Client cache fresh and headers sent, nothing more to do.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-05-16 11:19:06 +00:00
|
|
|
$func = ( $rawhtml ? "addHTML" : "addWikiText" );
|
|
|
|
|
$wgOut->$func(
|
|
|
|
|
"<p>" . wfMsg( "perfdisabled" ) . "</p>\n\n" .
|
|
|
|
|
"<p>" . wfMsg( "perfdisabledsub", $wgLang->timeanddate( $this->getTimestamp() ) ) . "</p>\n\n" .
|
|
|
|
|
"<hr />\n\n" .
|
|
|
|
|
$this->getContent()
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|