d78192bf30b1ccca1665757b356c20b0f2d709b7
[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
58 $db =& wfGetDB( DB_SLAVE );
59 $use_index = $db->useIndexClause( 'name_title_timestamp' );
60 $oldtable = $db->tableName( 'old' );
61
62 $sql = "SELECT old_id,old_user," .
63 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
64 "FROM $oldtable $use_index " .
65 "WHERE old_namespace={$namespace} AND " .
66 "old_title='" . $db->strencode( $this->mTitle->getDBkey() ) . "' " .
67 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
68 $res = $db->query( $sql, $fname );
69
70 $revs = $db->numRows( $res );
71
72 if( $revs < $limitplus ) // the sql above tries to fetch one extra
73 $this->linesonpage = $revs;
74 else
75 $this->linesonpage = $revs - 1;
76
77 $atend = ($revs < $limitplus);
78
79 $this->mSkin = $wgUser->getSkin();
80 $numbar = wfViewPrevNext(
81 $offset, $limit,
82 $this->mTitle->getPrefixedText(),
83 'action=history', $atend );
84 $s = $numbar;
85 if($this->linesonpage > 0) {
86 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
87 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
88 $this->submitbuttonhtml1 = $submitpart1 . ' />';
89 $this->submitbuttonhtml2 = $submitpart1 . ' id="historysubmit" />';
90 }
91 $s .= $this->beginHistoryList();
92 $counter = 1;
93 if( $offset == 0 ){
94 $this->linesonpage++;
95 $s .= $this->historyLine(
96 $this->mArticle->getTimestamp(),
97 $this->mArticle->getUser(),
98 $this->mArticle->getUserText(), $namespace,
99 $title, 0, $this->mArticle->getComment(),
100 ( $this->mArticle->getMinorEdit() > 0 ),
101 $counter++
102 );
103 }
104 while ( $line = $db->fetchObject( $res ) ) {
105 $s .= $this->historyLine(
106 $line->old_timestamp, $line->old_user,
107 $line->old_user_text, $namespace,
108 $title, $line->old_id,
109 $line->old_comment, ( $line->old_minor_edit > 0 ),
110 $counter++
111 );
112 }
113 $s .= $this->endHistoryList( !$atend );
114 $s .= $numbar;
115 $wgOut->addHTML( $s );
116 wfProfileOut( $fname );
117 }
118
119 function beginHistoryList()
120 {
121 global $wgTitle;
122 $this->lastdate = $this->lastline = '';
123 $s = "\n<p>" . wfMsg( 'histlegend' ).'</p>';
124 $s .="\n<form action=\"" . $wgTitle->escapeLocalURL( '-' ) . "\" method=\"get\">";
125 $s .= "<input type=\"hidden\" name=\"title\" value=\"".htmlspecialchars($wgTitle->getPrefixedDbKey())."\"/>\n";
126 $s .= !empty($this->submitbuttonhtml1) ? $this->submitbuttonhtml1."\n":'';
127 $s .= "" . "\n<ul id=\"pagehistory\" >";
128 return $s;
129 }
130
131 function endHistoryList( $skip = false )
132 {
133 $last = wfMsg( 'last' );
134
135 $s = $skip ? '' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
136 $s .= "</ul>";
137 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2."\n":'';
138 $s .= "</form>\n";
139 return $s;
140 }
141
142 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' )
143 {
144 global $wgLang;
145
146 $artname = Title::makeName( $ns, $ttl );
147 $last = wfMsg( 'last' );
148 $cur = wfMsg( 'cur' );
149 $cr = wfMsg( 'currentrev' );
150
151 if ( $oid && $this->lastline ) {
152 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
153 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
154 } else {
155 $ret = '';
156 }
157 $dt = $wgLang->timeanddate( $ts, true );
158
159 if ( $oid ) {
160 $q = 'oldid='.$oid;
161 } else {
162 $q = '';
163 }
164 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
165
166 if ( 0 == $u ) {
167 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( 'Contributions' ),
168 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
169 } else {
170 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
171 Namespace::getUser() ) . ':'.$ut , htmlspecialchars( $ut ) );
172 }
173
174 $s = '<li>';
175 if ( $oid ) {
176 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
177 'diff=0&oldid='.$oid );
178 } else {
179 $curlink = $cur;
180 }
181 $arbitrary = '';
182 if( $this->linesonpage > 1) {
183 # XXX: move title texts to javascript
184 $checkmark = '';
185 if ( !$oid ) {
186 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
187 $checkmark = ' checked="checked"';
188 } else {
189 if( $counter == 2 ) $checkmark = ' checked="checked"';
190 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
191 $checkmark = '';
192 }
193 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
194 }
195 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
196 $s .= $isminor ? ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
197
198
199 if ( '' != $c && '*' != $c ) {
200 $c = $this->mSkin->formatcomment($c,$this->mTitle);
201 $s .= " <em>(" . $c . ")</em>";
202 }
203 $s .= "</li>\n";
204
205 $this->lastline = $s;
206 return $ret;
207 }
208
209 }
210
211 ?>