moved script outside the ul
[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
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 );
91 }
92 while ( $line = wfFetchObject( $res ) ) {
93 $s .= $this->historyLine( $line->old_timestamp, $line->old_user,
94 $line->old_user_text, $namespace,
95 $title, $line->old_id,
96 $line->old_comment, ( $line->old_minor_edit > 0 ) );
97 }
98 $s .= $this->endHistoryList( !$atend );
99 $s .= $numbar;
100 $wgOut->addHTML( $s );
101 wfProfileOut( $fname );
102 }
103
104 function beginHistoryList()
105 {
106 global $wgTitle;
107 $this->lastdate = $this->lastline = "";
108 $s = "\n<script type='text/javascript'>
109 /*<![CDATA[*/
110 var sel = -1;
111 function anysel(oid){
112 row = document.getElementById(\"ver\" + oid);
113 if( row.selected ){
114 row.style.backgroundColor=row.oldbg;
115 row.selected = 0;
116 sel = -1;
117 } else {
118 row.oldbg = row.style.backgroundColor;
119 row.style.backgroundColor=\"lightgrey\";
120 row.selected = 1;
121 if( sel == -1){
122 sel = oid;
123 } else {
124 dodiff(sel, oid);
125 }
126 }
127 return false;
128 }
129 function dodiff(oldid, diff){
130 if( (diff < oldid && diff != 0) || oldid == 0 ){
131 tmp = oldid; oldid = diff; diff = tmp;
132 }
133 u = \"{$url}diff=\" + diff + \"&oldid=\" + oldid;
134 location.href=u;
135 }
136 /*]]>*/
137 </script>";
138 $s .= "\n<p>" . wfMsg( "histlegend" ) . "</p>\n<ul class='special'>";
139 $url = $wgTitle->getFullURL("-");
140 return $s;
141 }
142
143 function endHistoryList( $skip = false )
144 {
145 $last = wfMsg( "last" );
146
147 $s = $skip ? "" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
148 $s .= "</ul>\n";
149 return $s;
150 }
151
152 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor )
153 {
154 global $wgLang;
155
156 $artname = Title::makeName( $ns, $ttl );
157 $last = wfMsg( "last" );
158 $cur = wfMsg( "cur" );
159 $cr = wfMsg( "currentrev" );
160
161 if ( $oid && $this->lastline ) {
162 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLink(
163 $artname, $last, "diff=\\1&oldid={$oid}" ), $this->lastline );
164 } else {
165 $ret = "";
166 }
167 $dt = $wgLang->timeanddate( $ts, true );
168
169 if ( $oid ) {
170 $q = "oldid={$oid}";
171 } else {
172 $q = "";
173 }
174 $link = $this->mSkin->makeKnownLink( $artname, $dt, $q );
175
176 if ( 0 == $u ) {
177 $ul = $this->mSkin->makeKnownLink( $wgLang->specialPage( "Contributions" ),
178 $ut, "target=" . $ut );
179 } else {
180 $ul = $this->mSkin->makeLink( $wgLang->getNsText(
181 Namespace::getUser() ) . ":{$ut}", $ut );
182 }
183
184 $s = "<li>";
185 if ( $oid ) {
186 $curlink = $this->mSkin->makeKnownLink( $artname, $cur,
187 "diff=0&oldid={$oid}" );
188 } else {
189 $curlink = $cur;
190 }
191 $arbitrary = "";
192 if( $this->linesonpage > 1)
193 $arbitrary = "<input type='checkbox' onclick='anysel($oid)' title='Select any two versions to diff them' />";
194 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary . .";
195 $M = wfMsg( "minoreditletter" );
196 if ( $isminor ) {
197 $s .= " <strong>{$M}</strong>";
198 }
199 $s .= " <span id='ver$oid'>{$link} . . {$ul}</span>";
200
201 if ( "" != $c && "*" != $c ) {
202
203 $c = $this->mSkin->formatcomment($c);
204 $s .= " <em>(" . $c . ")</em>";
205 }
206 $s .= "</li>\n";
207
208 $this->lastline = $s;
209 return $ret;
210 }
211
212 }
213
214 ?>