access key and tooltip for 'compare selected versions' button, defaults to 'v'
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2
3 /* Page history
4 Split off from Article.php and Skin.php, 2003-12-22
5 */
6
7 class PageHistory {
8 var $mArticle, $mTitle, $mSkin;
9 var $lastline, $lastdate;
10 var $linesonpage;
11 function PageHistory( $article ) {
12 $this->mArticle =& $article;
13 $this->mTitle =& $article->mTitle;
14 }
15
16 # This shares a lot of issues (and code) with Recent Changes
17
18 function history()
19 {
20 global $wgUser, $wgOut, $wgLang;
21
22 # If page hasn't changed, client can cache this
23
24 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
25 # Client cache fresh and headers sent, nothing more to do.
26 return;
27 }
28 $fname = "PageHistory::history";
29 wfProfileIn( $fname );
30
31 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
32 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setArticleRelated( true );
35 $wgOut->setRobotpolicy( "noindex,nofollow" );
36
37 if( $this->mTitle->getArticleID() == 0 ) {
38 $wgOut->addHTML( wfMsg( "nohistory" ) );
39 wfProfileOut( $fname );
40 return;
41 }
42
43 list( $limit, $offset ) = wfCheckLimits();
44
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;
51 }
52 /* Check one extra row to see whether we need to show 'next' and diff links */
53 $limitplus = $rawlimit + 1;
54
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 );
64
65 $revs = wfNumRows( $res );
66
67 if( $revs < $limitplus ) // the sql above tries to fetch one extra
68 $this->linesonpage = $revs;
69 else
70 $this->linesonpage = $revs - 1;
71
72 $atend = ($revs < $limitplus);
73
74 $this->mSkin = $wgUser->getSkin();
75 $numbar = wfViewPrevNext(
76 $offset, $limit,
77 $this->mTitle->getPrefixedText(),
78 "action=history", $atend );
79 $s = $numbar;
80 $s .= $this->beginHistoryList();
81 $counter = 1;
82 if( $offset == 0 ){
83 $this->linesonpage++;
84 $s .= $this->historyLine(
85 $this->mArticle->getTimestamp(),
86 $this->mArticle->getUser(),
87 $this->mArticle->getUserText(), $namespace,
88 $title, 0, $this->mArticle->getComment(),
89 ( $this->mArticle->getMinorEdit() > 0 ),
90 $counter++
91 );
92 }
93 while ( $line = wfFetchObject( $res ) ) {
94 $s .= $this->historyLine(
95 $line->old_timestamp, $line->old_user,
96 $line->old_user_text, $namespace,
97 $title, $line->old_id,
98 $line->old_comment, ( $line->old_minor_edit > 0 ),
99 $counter++
100 );
101 }
102 $s .= $this->endHistoryList( !$atend );
103 $s .= $numbar;
104 $wgOut->addHTML( $s );
105 wfProfileOut( $fname );
106 }
107
108 function beginHistoryList()
109 {
110 global $wgTitle;
111 $this->lastdate = $this->lastline = "";
112 $s = "\n<p>" . wfMsg( "histlegend" ).'</p>';
113 $s .="\n<form id=\"pagehistory\" name=\"pagehistory\" action=\"" . $wgTitle->getFullURL("-") . "\" method=\"get\">";
114 $s .= "<input type=\"hidden\" name=\"title\" value=\"".htmlspecialchars($wgTitle->getPrefixedDbKey())."\"/>\n";
115 $s .= "" . "\n<ul>";
116 return $s;
117 }
118
119 function endHistoryList( $skip = false )
120 {
121 $last = wfMsg( "last" );
122
123 $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
124 $s .= "</ul>\n";
125 if( $this->linesonpage > 1) {
126 $s .= '<button type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
127 '" title="'.wfMsg('tooltip-compareselectedversions').'">'.wfMsg('compareselectedversions')."</button><br/><br/>\n";
128 }
129 $s .= "</form>\n";
130 return $s;
131 }
132
133 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' )
134 {
135 global $wgLang;
136
137 $artname = Title::makeName( $ns, $ttl );
138 $last = wfMsg( "last" );
139 $cur = wfMsg( "cur" );
140 $cr = wfMsg( "currentrev" );
141
142 if ( $oid && $this->lastline ) {
143 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
144 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
145 } else {
146 $ret = "";
147 }
148 $dt = $wgLang->timeanddate( $ts, true );
149
150 if ( $oid ) {
151 $q = "oldid={$oid}";
152 } else {
153 $q = "";
154 }
155 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
156
157 if ( 0 == $u ) {
158 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
159 $ut, "target=" . $ut );
160 } else {
161 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
162 Namespace::getUser() ) . ":{$ut}", $ut );
163 }
164
165 $s = "<li>";
166 if ( $oid ) {
167 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
168 "diff=0&oldid={$oid}" );
169 } else {
170 $curlink = $cur;
171 }
172 $arbitrary = "";
173 if( $this->linesonpage > 1) {
174 # XXX: move title texts to javascript
175 $checkmark = "";
176 if ( !$oid ) {
177 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
178 $checkmark = ' checked="checked"';
179 } else {
180 if( $counter == 2 ) $checkmark = ' checked="checked"';
181 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
182 $checkmark = '';
183 }
184 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
185 }
186 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
187 $s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
188
189
190 if ( "" != $c && "*" != $c ) {
191
192 $c = $this->mSkin->formatcomment($c);
193 $s .= " <em>(" . $c . ")</em>";
194 }
195 $s .= "</li>\n";
196
197 $this->lastline = $s;
198 return $ret;
199 }
200
201 }
202
203 ?>