4 Split off from Article.php and Skin.php, 2003-12-22
8 var $mArticle, $mTitle, $mSkin;
9 var $lastline, $lastdate;
11 function PageHistory( $article ) {
12 $this->mArticle
=& $article;
13 $this->mTitle
=& $article->mTitle
;
16 # This shares a lot of issues (and code) with Recent Changes
20 global $wgUser, $wgOut, $wgLang;
22 # If page hasn't changed, client can cache this
24 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
25 # Client cache fresh and headers sent, nothing more to do.
28 $fname = "PageHistory::history";
29 wfProfileIn( $fname );
31 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
32 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setRobotpolicy( "noindex,nofollow" );
36 if( $this->mTitle
->getArticleID() == 0 ) {
37 $wgOut->addHTML( wfMsg( "nohistory" ) );
38 wfProfileOut( $fname );
42 list( $limit, $offset ) = wfCheckLimits();
44 /* We have to draw the latest revision from 'cur' */
46 $rawoffset = $offset - 1;
51 /* Check one extra row to see whether we need to show 'next' and diff links */
52 $limitplus = $rawlimit +
1;
54 $namespace = $this->mTitle
->getNamespace();
55 $title = $this->mTitle
->getText();
56 $sql = "SELECT old_id,old_user," .
57 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
58 "FROM old USE INDEX (name_title_timestamp) " .
59 "WHERE old_namespace={$namespace} AND " .
60 "old_title='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
61 "ORDER BY inverse_timestamp LIMIT $rawoffset, $limitplus";
62 $res = wfQuery( $sql, DB_READ
, $fname );
64 $revs = wfNumRows( $res );
65 $atend = ($revs < $limitplus);
67 $this->mSkin
= $wgUser->getSkin();
68 $numbar = wfViewPrevNext(
70 $this->mTitle
->getPrefixedText(),
73 $s .= $this->beginHistoryList();
76 $s .= $this->historyLine( $this->mArticle
->getTimestamp(), $this->mArticle
->getUser(),
77 $this->mArticle
->getUserText(), $namespace,
78 $title, 0, $this->mArticle
->getComment(),
79 ( $this->mArticle
->getMinorEdit() > 0 ) );
81 while ( $line = wfFetchObject( $res ) ) {
82 $s .= $this->historyLine( $line->old_timestamp
, $line->old_user
,
83 $line->old_user_text
, $namespace,
84 $title, $line->old_id
,
85 $line->old_comment
, ( $line->old_minor_edit
> 0 ) );
87 $s .= $this->endHistoryList( !$atend );
89 $wgOut->addHTML( $s );
90 wfProfileOut( $fname );
93 function beginHistoryList()
95 $this->lastdate
= $this->lastline
= "";
96 $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
100 function endHistoryList( $skip = false )
102 $last = wfMsg( "last" );
104 $s = $skip ?
"" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
109 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
113 $artname = Title
::makeName( $ns, $ttl );
114 $last = wfMsg( "last" );
115 $cur = wfMsg( "cur" );
116 $cr = wfMsg( "currentrev" );
118 if ( $oid && $this->lastline
) {
119 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLink(
120 $artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline
);
124 $dt = $wgLang->timeanddate( $ts, true );
131 $link = $this->mSkin
->makeKnownLink( $artname, $dt, $q );
134 $ul = $this->mSkin
->makeKnownLink( $wgLang->specialPage( "Contributions" ),
135 $ut, "target=" . $ut );
137 $ul = $this->mSkin
->makeLink( $wgLang->getNsText(
138 Namespace::getUser() ) . ":{$ut}", $ut );
143 $curlink = $this->mSkin
->makeKnownLink( $artname, $cur,
144 "diff=0&oldid={$oid}" );
148 $s .= "({$curlink}) (!OLDID!{$oid}!) . .";
150 $M = wfMsg( "minoreditletter" );
152 $s .= " <strong>{$M}</strong>";
154 $s .= " {$link} . . {$ul}";
156 if ( "" != $c && "*" != $c ) {
157 $s .= " <em>(" . wfEscapeHTML($c) . ")</em>";
161 $this->lastline
= $s;