fixed subtle bug -- missing comma in SQL causing watchlist to display user page link...
[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
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 $atend = ($revs < $limitplus);
67
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();
75
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 ) );
81
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 ) );
87 }
88 $s .= $this->endHistoryList( !$atend );
89 $s .= $numbar;
90 $wgOut->addHTML( $s );
91 wfProfileOut( $fname );
92 }
93
94 function beginHistoryList()
95 {
96 global $wgTitle;
97 $this->lastdate = $this->lastline = "";
98 $s = "\n<p>" . wfMsg( "histlegend" ) . "\n<ul>";
99 $url = wfLocalUrl( $wgTitle->getPrefixedText(), "dummy=1");
100 $s .= "<SCRIPT>
101 var sel = -1;
102 function anysel(oid){
103 row = document.getElementById(\"ver\" + oid);
104 if( row.selected ){
105 row.style.backgroundColor=row.oldbg;
106 row.selected = 0;
107 sel = -1;
108 } else {
109 row.oldbg = row.style.backgroundColor;
110 row.style.backgroundColor=\"lightgrey\";
111 row.selected = 1;
112 if( sel == -1){
113 sel = oid;
114 } else {
115 dodiff(sel, oid);
116 }
117 }
118 return false;
119 }
120 function dodiff(v1, v2){
121 if(v2 > v1){ tmp = v1; v1 = v2; v2 = tmp; }
122 u = \"{$url}&diff=\" + v1 + \"&oldid=\" + v2;
123 location.href=u;
124 }
125 </SCRIPT>";
126 return $s;
127 }
128
129 function endHistoryList( $skip = false )
130 {
131 $last = wfMsg( "last" );
132
133 $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
134 $s .= "</ul>\n";
135 return $s;
136 }
137
138 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
139 {
140 global $wgLang;
141
142 $artname = Title::makeName( $ns, $ttl );
143 $last = wfMsg( "last" );
144 $cur = wfMsg( "cur" );
145 $cr = wfMsg( "currentrev" );
146
147 if ( $oid && $this->lastline ) {
148 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
149 $artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline );
150 } else {
151 $ret = "";
152 }
153 $dt = $wgLang->timeanddate( $ts, true );
154
155 if ( $oid ) {
156 $q = "oldid={$oid}";
157 } else {
158 $q = "";
159 }
160 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
161
162 if ( 0 == $u ) {
163 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
164 $ut, "target=" . $ut );
165 } else {
166 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
167 Namespace::getUser() ) . ":{$ut}", $ut );
168 }
169
170 $s = "<li>";
171 if ( $oid ) {
172 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
173 "diff=0&oldid={$oid}" );
174 } else {
175 $curlink = $cur;
176 }
177 $any .= "<INPUT TYPE=CHECKBOX onClick='anysel($oid)' TITLE='Select any two versions to diff them'>";
178 $s .= "({$curlink}) (!OLDID!{$oid}!) $any. .";
179 $M = wfMsg( "minoreditletter" );
180 if ( $isminor ) {
181 $s .= " <strong>{$M}</strong>";
182 }
183 $s .= " <span ID='ver$oid'>{$link} . . {$ul}</span>";
184
185 if ( "" != $c && "*" != $c ) {
186 $s .= " <em>(" . wfEscapeHTML($c) . ")</em>";
187 }
188 $s .= "</li>\n";
189
190 $this->lastline = $s;
191 return $ret;
192 }
193
194 }
195
196 ?>