Split off page history code to PageHistory.php out of Article.php and Skin.php.
No substantive changes yet.
This commit is contained in:
parent
1baf68953a
commit
0020aa84d1
4 changed files with 168 additions and 138 deletions
|
|
@ -597,79 +597,6 @@ class Article {
|
|||
$this->watch( false );
|
||||
}
|
||||
|
||||
# This shares a lot of issues (and code) with Recent Changes
|
||||
|
||||
function history()
|
||||
{
|
||||
global $wgUser, $wgOut, $wgLang, $offset, $limit;
|
||||
|
||||
# If page hasn't changed, client can cache this
|
||||
|
||||
if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
|
||||
# Client cache fresh and headers sent, nothing more to do.
|
||||
return;
|
||||
}
|
||||
$fname = "Article::history";
|
||||
wfProfileIn( $fname );
|
||||
|
||||
$wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
|
||||
$wgOut->setSubtitle( wfMsg( "revhistory" ) );
|
||||
$wgOut->setArticleFlag( false );
|
||||
$wgOut->setRobotpolicy( "noindex,nofollow" );
|
||||
|
||||
if( $this->mTitle->getArticleID() == 0 ) {
|
||||
$wgOut->addHTML( wfMsg( "nohistory" ) );
|
||||
wfProfileOut( $fname );
|
||||
return;
|
||||
}
|
||||
|
||||
$offset = (int)$offset;
|
||||
$limit = (int)$limit;
|
||||
if( $limit == 0 ) $limit = 50;
|
||||
$namespace = $this->mTitle->getNamespace();
|
||||
$title = $this->mTitle->getText();
|
||||
$sql = "SELECT old_id,old_user," .
|
||||
"old_comment,old_user_text,old_timestamp,old_minor_edit ".
|
||||
"FROM old USE INDEX (name_title_timestamp) " .
|
||||
"WHERE old_namespace={$namespace} AND " .
|
||||
"old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
|
||||
"ORDER BY inverse_timestamp LIMIT $offset, $limit";
|
||||
$res = wfQuery( $sql, DB_READ, "Article::history" );
|
||||
|
||||
$revs = wfNumRows( $res );
|
||||
if( $this->mTitle->getArticleID() == 0 ) {
|
||||
$wgOut->addHTML( wfMsg( "nohistory" ) );
|
||||
wfProfileOut( $fname );
|
||||
return;
|
||||
}
|
||||
|
||||
$sk = $wgUser->getSkin();
|
||||
$numbar = wfViewPrevNext(
|
||||
$offset, $limit,
|
||||
$this->mTitle->getPrefixedText(),
|
||||
"action=history" );
|
||||
$s = $numbar;
|
||||
$s .= $sk->beginHistoryList();
|
||||
|
||||
if($offset == 0 )
|
||||
$s .= $sk->historyLine( $this->getTimestamp(), $this->getUser(),
|
||||
$this->getUserText(), $namespace,
|
||||
$title, 0, $this->getComment(),
|
||||
( $this->getMinorEdit() > 0 ) );
|
||||
|
||||
$revs = wfNumRows( $res );
|
||||
while ( $line = wfFetchObject( $res ) ) {
|
||||
$s .= $sk->historyLine( $line->old_timestamp, $line->old_user,
|
||||
$line->old_user_text, $namespace,
|
||||
$title, $line->old_id,
|
||||
$line->old_comment, ( $line->old_minor_edit > 0 ) );
|
||||
}
|
||||
$s .= $sk->endHistoryList();
|
||||
$s .= $numbar;
|
||||
$wgOut->addHTML( $s );
|
||||
wfProfileOut( $fname );
|
||||
}
|
||||
|
||||
function protect( $limit = "sysop" )
|
||||
{
|
||||
global $wgUser, $wgOut;
|
||||
|
|
|
|||
163
includes/PageHistory.php
Normal file
163
includes/PageHistory.php
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
/* Page history
|
||||
Split off from Article.php and Skin.php, 2003-12-22
|
||||
*/
|
||||
|
||||
class PageHistory {
|
||||
var $mArticle, $mTitle, $mSkin;
|
||||
var $lastline, $lastdate;
|
||||
|
||||
function PageHistory( $article ) {
|
||||
$this->mArticle =& $article;
|
||||
$this->mTitle =& $article->mTitle;
|
||||
}
|
||||
|
||||
# This shares a lot of issues (and code) with Recent Changes
|
||||
|
||||
function history()
|
||||
{
|
||||
global $wgUser, $wgOut, $wgLang, $offset, $limit;
|
||||
|
||||
# If page hasn't changed, client can cache this
|
||||
|
||||
if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
|
||||
# Client cache fresh and headers sent, nothing more to do.
|
||||
return;
|
||||
}
|
||||
$fname = "PageHistory::history";
|
||||
wfProfileIn( $fname );
|
||||
|
||||
$wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
|
||||
$wgOut->setSubtitle( wfMsg( "revhistory" ) );
|
||||
$wgOut->setArticleFlag( false );
|
||||
$wgOut->setRobotpolicy( "noindex,nofollow" );
|
||||
|
||||
if( $this->mTitle->getArticleID() == 0 ) {
|
||||
$wgOut->addHTML( wfMsg( "nohistory" ) );
|
||||
wfProfileOut( $fname );
|
||||
return;
|
||||
}
|
||||
|
||||
$offset = (int)$offset;
|
||||
$limit = (int)$limit;
|
||||
if( $limit == 0 ) $limit = 50;
|
||||
$namespace = $this->mTitle->getNamespace();
|
||||
$title = $this->mTitle->getText();
|
||||
$sql = "SELECT old_id,old_user," .
|
||||
"old_comment,old_user_text,old_timestamp,old_minor_edit ".
|
||||
"FROM old USE INDEX (name_title_timestamp) " .
|
||||
"WHERE old_namespace={$namespace} AND " .
|
||||
"old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
|
||||
"ORDER BY inverse_timestamp LIMIT $offset, $limit";
|
||||
$res = wfQuery( $sql, DB_READ, $fname );
|
||||
|
||||
$revs = wfNumRows( $res );
|
||||
if( $this->mTitle->getArticleID() == 0 ) {
|
||||
$wgOut->addHTML( wfMsg( "nohistory" ) );
|
||||
wfProfileOut( $fname );
|
||||
return;
|
||||
}
|
||||
|
||||
$this->mSkin = $wgUser->getSkin();
|
||||
$numbar = wfViewPrevNext(
|
||||
$offset, $limit,
|
||||
$this->mTitle->getPrefixedText(),
|
||||
"action=history" );
|
||||
$s = $numbar;
|
||||
$s .= $this->beginHistoryList();
|
||||
|
||||
if($offset == 0 )
|
||||
$s .= $this->historyLine( $this->mArticle->getTimestamp(), $this->mArticle->getUser(),
|
||||
$this->mArticle->getUserText(), $namespace,
|
||||
$title, 0, $this->mArticle->getComment(),
|
||||
( $this->mArticle->getMinorEdit() > 0 ) );
|
||||
|
||||
$revs = wfNumRows( $res );
|
||||
while ( $line = wfFetchObject( $res ) ) {
|
||||
$s .= $this->historyLine( $line->old_timestamp, $line->old_user,
|
||||
$line->old_user_text, $namespace,
|
||||
$title, $line->old_id,
|
||||
$line->old_comment, ( $line->old_minor_edit > 0 ) );
|
||||
}
|
||||
$s .= $this->endHistoryList();
|
||||
$s .= $numbar;
|
||||
$wgOut->addHTML( $s );
|
||||
wfProfileOut( $fname );
|
||||
}
|
||||
|
||||
function beginHistoryList()
|
||||
{
|
||||
$this->lastdate = $this->lastline = "";
|
||||
$s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
|
||||
return $s;
|
||||
}
|
||||
|
||||
function endHistoryList()
|
||||
{
|
||||
$last = wfMsg( "last" );
|
||||
|
||||
$s = preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
|
||||
$s .= "</ul>\n";
|
||||
return $s;
|
||||
}
|
||||
|
||||
function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
|
||||
{
|
||||
global $wgLang;
|
||||
|
||||
$artname = Title::makeName( $ns, $ttl );
|
||||
$last = wfMsg( "last" );
|
||||
$cur = wfMsg( "cur" );
|
||||
$cr = wfMsg( "currentrev" );
|
||||
|
||||
if ( $oid && $this->lastline ) {
|
||||
$ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
|
||||
$artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline );
|
||||
} else {
|
||||
$ret = "";
|
||||
}
|
||||
$dt = $wgLang->timeanddate( $ts, true );
|
||||
|
||||
if ( $oid ) {
|
||||
$q = "oldid={$oid}";
|
||||
} else {
|
||||
$q = "";
|
||||
}
|
||||
$link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
|
||||
|
||||
if ( 0 == $u ) {
|
||||
$ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
|
||||
$ut, "target=" . $ut );
|
||||
} else {
|
||||
$ul = $this->mSkin->makeLink( $wgLang->getNsText(
|
||||
Namespace::getUser() ) . ":{$ut}", $ut );
|
||||
}
|
||||
|
||||
$s = "<li>";
|
||||
if ( $oid ) {
|
||||
$curlink = $this->mSkin->makeKnownLink( $artname, $cur,
|
||||
"diff=0&oldid={$oid}" );
|
||||
} else {
|
||||
$curlink = $cur;
|
||||
}
|
||||
$s .= "({$curlink}) (!OLDID!{$oid}!) . .";
|
||||
|
||||
$M = wfMsg( "minoreditletter" );
|
||||
if ( $isminor ) {
|
||||
$s .= " <strong>{$M}</strong>";
|
||||
}
|
||||
$s .= " {$link} . . {$ul}";
|
||||
|
||||
if ( "" != $c && "*" != $c ) {
|
||||
$s .= " <em>(" . wfEscapeHTML($c) . ")</em>";
|
||||
}
|
||||
$s .= "</li>\n";
|
||||
|
||||
$this->lastline = $s;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1455,13 +1455,6 @@ class Skin {
|
|||
return "";
|
||||
}
|
||||
|
||||
function beginHistoryList()
|
||||
{
|
||||
$this->lastdate = $this->lastline = "";
|
||||
$s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
|
||||
return $s;
|
||||
}
|
||||
|
||||
function beginImageHistoryList()
|
||||
{
|
||||
$s = "\n<h2>" . wfMsg( "imghistory" ) . "</h2>\n" .
|
||||
|
|
@ -1476,69 +1469,12 @@ class Skin {
|
|||
return $s;
|
||||
}
|
||||
|
||||
function endHistoryList()
|
||||
{
|
||||
$last = wfMsg( "last" );
|
||||
|
||||
$s = preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
|
||||
$s .= "</ul>\n";
|
||||
return $s;
|
||||
}
|
||||
|
||||
function endImageHistoryList()
|
||||
{
|
||||
$s = "</ul>\n";
|
||||
return $s;
|
||||
}
|
||||
|
||||
function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
|
||||
{
|
||||
global $wgLang;
|
||||
|
||||
$artname = Title::makeName( $ns, $ttl );
|
||||
$last = wfMsg( "last" );
|
||||
$cur = wfMsg( "cur" );
|
||||
$cr = wfMsg( "currentrev" );
|
||||
|
||||
if ( $oid && $this->lastline ) {
|
||||
$ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->makeKnownLink(
|
||||
$artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline );
|
||||
} else {
|
||||
$ret = "";
|
||||
}
|
||||
$dt = $wgLang->timeanddate( $ts, true );
|
||||
|
||||
if ( $oid ) { $q = "oldid={$oid}"; }
|
||||
else { $q = ""; }
|
||||
$link = $this->makeKnownLink( $artname, $dt, $q );
|
||||
|
||||
if ( 0 == $u ) {
|
||||
$ul = $this->makeKnownLink( $wgLang->specialPage( "Contributions" ),
|
||||
$ut, "target=" . $ut );
|
||||
} else {
|
||||
$ul = $this->makeLink( $wgLang->getNsText(
|
||||
Namespace::getUser() ) . ":{$ut}", $ut ); }
|
||||
|
||||
$s = "<li>";
|
||||
if ( $oid ) {
|
||||
$curlink = $this->makeKnownLink( $artname, $cur,
|
||||
"diff=0&oldid={$oid}" );
|
||||
} else {
|
||||
$curlink = $cur;
|
||||
}
|
||||
$s .= "({$curlink}) (!OLDID!{$oid}!) . .";
|
||||
|
||||
$M = wfMsg( "minoreditletter" );
|
||||
if ( $isminor ) { $s .= " <strong>{$M}</strong>"; }
|
||||
$s .= " {$link} . . {$ul}";
|
||||
|
||||
if ( "" != $c && "*" != $c ) { $s .= " <em>(" . wfEscapeHTML($c) . ")</em>"; }
|
||||
$s .= "</li>\n";
|
||||
|
||||
$this->lastline = $s;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function recentChangesBlockLine ( $y ) {
|
||||
global $wgUploadPath ;
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
|
|||
case "view":
|
||||
case "watch":
|
||||
case "unwatch":
|
||||
case "history":
|
||||
case "delete":
|
||||
case "revert":
|
||||
case "rollback":
|
||||
|
|
@ -91,6 +90,11 @@ if ( Namespace::getSpecial() == $wgTitle->getNamespace() ) {
|
|||
$editor = new EditPage( $wgArticle );
|
||||
$editor->$action();
|
||||
break;
|
||||
case "history":
|
||||
include_once( "PageHistory.php" );
|
||||
$history = new PageHistory( $wgArticle );
|
||||
$history->history();
|
||||
break;
|
||||
default:
|
||||
$wgOut->errorpage( "nosuchaction", "nosuchactiontext" );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue