same minor typo as in LocalSettings (in example config url)
[mediawiki.git] / includes / PageHistory.php
blobdf5a580eb8771db850f560d04bf2c9d1786c3a2a
1 <?php
3 /* Page history
4 Split off from Article.php and Skin.php, 2003-12-22
5 */
7 class PageHistory {
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
18 function history()
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.
26 return;
28 $fname = "PageHistory::history";
29 wfProfileIn( $fname );
31 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
32 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setArticleRelated( true );
35 $wgOut->setRobotpolicy( "noindex,nofollow" );
37 if( $this->mTitle->getArticleID() == 0 ) {
38 $wgOut->addHTML( wfMsg( "nohistory" ) );
39 wfProfileOut( $fname );
40 return;
43 list( $limit, $offset ) = wfCheckLimits();
45 /* We have to draw the latest revision from 'cur' */
46 $rawlimit = $limit;
47 $rawoffset = $offset - 1;
48 if( 0 == $offset ) {
49 $rawlimit--;
50 $rawoffset = 0;
52 /* Check one extra row to see whether we need to show 'next' and diff links */
53 $limitplus = $rawlimit + 1;
55 $namespace = $this->mTitle->getNamespace();
56 $title = $this->mTitle->getText();
57 $sql = "SELECT old_id,old_user," .
58 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
59 "FROM old USE INDEX (name_title_timestamp) " .
60 "WHERE old_namespace={$namespace} AND " .
61 "old_title='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
62 "ORDER BY inverse_timestamp LIMIT $rawoffset, $limitplus";
63 $res = wfQuery( $sql, DB_READ, $fname );
65 $revs = wfNumRows( $res );
66 $atend = ($revs < $limitplus);
68 $this->mSkin = $wgUser->getSkin();
69 $numbar = wfViewPrevNext(
70 $offset, $limit,
71 $this->mTitle->getPrefixedText(),
72 "action=history", $atend );
73 $s = $numbar;
74 $s .= $this->beginHistoryList();
76 if( $offset == 0 )
77 $s .= $this->historyLine( $this->mArticle->getTimestamp(), $this->mArticle->getUser(),
78 $this->mArticle->getUserText(), $namespace,
79 $title, 0, $this->mArticle->getComment(),
80 ( $this->mArticle->getMinorEdit() > 0 ) );
82 while ( $line = wfFetchObject( $res ) ) {
83 $s .= $this->historyLine( $line->old_timestamp, $line->old_user,
84 $line->old_user_text, $namespace,
85 $title, $line->old_id,
86 $line->old_comment, ( $line->old_minor_edit > 0 ) );
88 $s .= $this->endHistoryList( !$atend );
89 $s .= $numbar;
90 $wgOut->addHTML( $s );
91 wfProfileOut( $fname );
94 function beginHistoryList()
96 $this->lastdate = $this->lastline = "";
97 $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
98 return $s;
101 function endHistoryList( $skip = false )
103 $last = wfMsg( "last" );
105 $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
106 $s .= "</ul>\n";
107 return $s;
110 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
112 global $wgLang;
114 $artname = Title::makeName( $ns, $ttl );
115 $last = wfMsg( "last" );
116 $cur = wfMsg( "cur" );
117 $cr = wfMsg( "currentrev" );
119 if ( $oid && $this->lastline ) {
120 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
121 $artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline );
122 } else {
123 $ret = "";
125 $dt = $wgLang->timeanddate( $ts, true );
127 if ( $oid ) {
128 $q = "oldid={$oid}";
129 } else {
130 $q = "";
132 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
134 if ( 0 == $u ) {
135 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
136 $ut, "target=" . $ut );
137 } else {
138 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
139 Namespace::getUser() ) . ":{$ut}", $ut );
142 $s = "<li>";
143 if ( $oid ) {
144 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
145 "diff=0&oldid={$oid}" );
146 } else {
147 $curlink = $cur;
149 $s .= "({$curlink}) (!OLDID!{$oid}!) . .";
151 $M = wfMsg( "minoreditletter" );
152 if ( $isminor ) {
153 $s .= " <strong>{$M}</strong>";
155 $s .= " {$link} . . {$ul}";
157 if ( "" != $c && "*" != $c ) {
158 $s .= " <em>(" . wfEscapeHTML($c) . ")</em>";
160 $s .= "</li>\n";
162 $this->lastline = $s;
163 return $ret;