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, $offset, $limit;
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 $offset = (int)$offset;
44 if( $limit == 0 ) $limit = 50;
45 $namespace = $this->mTitle
->getNamespace();
46 $title = $this->mTitle
->getText();
47 $sql = "SELECT old_id,old_user," .
48 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
49 "FROM old USE INDEX (name_title_timestamp) " .
50 "WHERE old_namespace={$namespace} AND " .
51 "old_title='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
52 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
53 $res = wfQuery( $sql, DB_READ
, $fname );
55 $revs = wfNumRows( $res );
56 if( $this->mTitle
->getArticleID() == 0 ) {
57 $wgOut->addHTML( wfMsg( "nohistory" ) );
58 wfProfileOut( $fname );
62 $this->mSkin
= $wgUser->getSkin();
63 $numbar = wfViewPrevNext(
65 $this->mTitle
->getPrefixedText(),
68 $s .= $this->beginHistoryList();
71 $s .= $this->historyLine( $this->mArticle
->getTimestamp(), $this->mArticle
->getUser(),
72 $this->mArticle
->getUserText(), $namespace,
73 $title, 0, $this->mArticle
->getComment(),
74 ( $this->mArticle
->getMinorEdit() > 0 ) );
76 $revs = wfNumRows( $res );
77 while ( $line = wfFetchObject( $res ) ) {
78 $s .= $this->historyLine( $line->old_timestamp
, $line->old_user
,
79 $line->old_user_text
, $namespace,
80 $title, $line->old_id
,
81 $line->old_comment
, ( $line->old_minor_edit
> 0 ) );
83 $s .= $this->endHistoryList();
85 $wgOut->addHTML( $s );
86 wfProfileOut( $fname );
89 function beginHistoryList()
91 $this->lastdate
= $this->lastline
= "";
92 $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
96 function endHistoryList()
98 $last = wfMsg( "last" );
100 $s = preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
105 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
109 $artname = Title
::makeName( $ns, $ttl );
110 $last = wfMsg( "last" );
111 $cur = wfMsg( "cur" );
112 $cr = wfMsg( "currentrev" );
114 if ( $oid && $this->lastline
) {
115 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLink(
116 $artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline
);
120 $dt = $wgLang->timeanddate( $ts, true );
127 $link = $this->mSkin
->makeKnownLink( $artname, $dt, $q );
130 $ul = $this->mSkin
->makeKnownLink( $wgLang->specialPage( "Contributions" ),
131 $ut, "target=" . $ut );
133 $ul = $this->mSkin
->makeLink( $wgLang->getNsText(
134 Namespace::getUser() ) . ":{$ut}", $ut );
139 $curlink = $this->mSkin
->makeKnownLink( $artname, $cur,
140 "diff=0&oldid={$oid}" );
144 $s .= "({$curlink}) (!OLDID!{$oid}!) . .";
146 $M = wfMsg( "minoreditletter" );
148 $s .= " <strong>{$M}</strong>";
150 $s .= " {$link} . . {$ul}";
152 if ( "" != $c && "*" != $c ) {
153 $s .= " <em>(" . wfEscapeHTML($c) . ")</em>";
157 $this->lastline
= $s;