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