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>" )
|
|
|
|
|
{
|
2003-05-16 11:19:06 +00:00
|
|
|
$sql = "SELECT cur_id,cur_text,cur_timestamp FROM cur " .
|
2003-04-14 23:10:40 +00:00
|
|
|
"WHERE cur_namespace=" . Namespace::getWikipedia() . " AND " .
|
|
|
|
|
"cur_title='" . wfStrencode($this->mTitle ) . "'";
|
2003-09-20 01:34:06 +00:00
|
|
|
$res = wfQuery( $sql, DB_READ, "LogPage::getContent" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if( wfNumRows( $res ) > 0 ) {
|
|
|
|
|
$s = wfFetchObject( $res );
|
|
|
|
|
$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";
|
|
|
|
|
$uid = $wgUser->getID();
|
|
|
|
|
$ut = wfStrencode( $wgUser->getName() );
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
$sql = "INSERT INTO cur (cur_timestamp,cur_user,cur_user_text,
|
2003-08-30 06:11:18 +00:00
|
|
|
cur_namespace,cur_title,cur_text,cur_comment,cur_restrictions,
|
|
|
|
|
inverse_timestamp,cur_touched)
|
2003-04-14 23:10:40 +00:00
|
|
|
VALUES ('{$now}', {$uid}, '{$ut}', " .
|
|
|
|
|
Namespace::getWikipedia() . ", '" .
|
|
|
|
|
wfStrencode( $this->mTitle ) . "', '" .
|
|
|
|
|
wfStrencode( $this->mContent ) . "', '" .
|
2003-08-30 06:11:18 +00:00
|
|
|
wfStrencode( $this->mComment ) . "', 'sysop', '{$won}','{$now}')";
|
2003-09-20 01:34:06 +00:00
|
|
|
wfQuery( $sql, DB_WRITE, $fname );
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mId = wfInsertId();
|
|
|
|
|
} else {
|
|
|
|
|
$sql = "UPDATE cur SET cur_timestamp='{$now}', " .
|
|
|
|
|
"cur_user={$uid}, cur_user_text='{$ut}', " .
|
|
|
|
|
"cur_text='" . wfStrencode( $this->mContent ) . "', " .
|
|
|
|
|
"cur_comment='" . wfStrencode( $this->mComment ) . "', " .
|
2003-08-30 06:11:18 +00:00
|
|
|
"cur_restrictions='sysop', inverse_timestamp='{$won}', cur_touched='{$now}' " .
|
2003-04-14 23:10:40 +00:00
|
|
|
"WHERE cur_id={$this->mId}";
|
2003-09-20 01:34:06 +00:00
|
|
|
wfQuery( $sql, DB_WRITE, $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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|