From 0020aa84d1209b14e85026cadd262e63faeb417e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 21 Dec 2003 12:01:29 +0000 Subject: [PATCH] Split off page history code to PageHistory.php out of Article.php and Skin.php. No substantive changes yet. --- includes/Article.php | 73 ------------------ includes/PageHistory.php | 163 +++++++++++++++++++++++++++++++++++++++ includes/Skin.php | 64 --------------- wiki.phtml | 6 +- 4 files changed, 168 insertions(+), 138 deletions(-) create mode 100644 includes/PageHistory.php diff --git a/includes/Article.php b/includes/Article.php index 56ec140c8a..470fffdf2b 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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; diff --git a/includes/PageHistory.php b/includes/PageHistory.php new file mode 100644 index 0000000000..d3fbff6dc2 --- /dev/null +++ b/includes/PageHistory.php @@ -0,0 +1,163 @@ +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

" . wfMsg( "histlegend" ) . "\n

\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 = "
  • "; + 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 .= " {$M}"; + } + $s .= " {$link} . . {$ul}"; + + if ( "" != $c && "*" != $c ) { + $s .= " (" . wfEscapeHTML($c) . ")"; + } + $s .= "
  • \n"; + + $this->lastline = $s; + return $ret; + } + +} + +?> diff --git a/includes/Skin.php b/includes/Skin.php index a26ebd7422..16c400ed63 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1455,13 +1455,6 @@ class Skin { return ""; } - function beginHistoryList() - { - $this->lastdate = $this->lastline = ""; - $s = "\n

    " . wfMsg( "histlegend" ) . "\n

    \n"; - return $s; - } - function endImageHistoryList() { $s = "\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 = "
  • "; - if ( $oid ) { - $curlink = $this->makeKnownLink( $artname, $cur, - "diff=0&oldid={$oid}" ); - } else { - $curlink = $cur; - } - $s .= "({$curlink}) (!OLDID!{$oid}!) . ."; - - $M = wfMsg( "minoreditletter" ); - if ( $isminor ) { $s .= " {$M}"; } - $s .= " {$link} . . {$ul}"; - - if ( "" != $c && "*" != $c ) { $s .= " (" . wfEscapeHTML($c) . ")"; } - $s .= "
  • \n"; - - $this->lastline = $s; - return $ret; - } - function recentChangesBlockLine ( $y ) { global $wgUploadPath ; diff --git a/wiki.phtml b/wiki.phtml index 5141de3adf..962a97efb5 100644 --- a/wiki.phtml +++ b/wiki.phtml @@ -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" ); } -- 2.20.1