Show "block" link in Special:Recentchanges for logged in users, too, if
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2 /**
3 * Page history
4 *
5 * Split off from Article.php and Skin.php, 2003-12-22
6 * @package MediaWiki
7 */
8
9 /**
10 * @todo document
11 * @package MediaWiki
12 */
13 class PageHistory {
14 var $mArticle, $mTitle, $mSkin;
15 var $lastline, $lastdate;
16 var $linesonpage;
17 function PageHistory( $article ) {
18 $this->mArticle =& $article;
19 $this->mTitle =& $article->mTitle;
20 }
21
22 # This shares a lot of issues (and code) with Recent Changes
23
24 function history() {
25 global $wgUser, $wgOut, $wgLang, $wgShowUpdatedMarker;
26
27 # If page hasn't changed, client can cache this
28
29 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
30 # Client cache fresh and headers sent, nothing more to do.
31 return;
32 }
33 $fname = 'PageHistory::history';
34 wfProfileIn( $fname );
35
36 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
37 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
38 $wgOut->setArticleFlag( false );
39 $wgOut->setArticleRelated( true );
40 $wgOut->setRobotpolicy( 'noindex,nofollow' );
41
42 $id = $this->mTitle->getArticleID();
43 if( $id == 0 ) {
44 $wgOut->addHTML( wfMsg( 'nohistory' ) );
45 wfProfileOut( $fname );
46 return;
47 }
48
49 list( $limit, $offset ) = wfCheckLimits();
50
51 /* Check one extra row to see whether we need to show 'next' and diff links */
52 $limitplus = $limit + 1;
53
54 $namespace = $this->mTitle->getNamespace();
55 $title = $this->mTitle->getText();
56 $uid = $wgUser->getID();
57 $db =& wfGetDB( DB_SLAVE );
58 if ($wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' )) {
59 $dbr =& wfGetDB( DB_MASTER );
60 $row = $dbr->selectRow( 'watchlist',
61 array( 'wl_notificationtimestamp' ),
62 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle->getDBkey(), 'wl_user' => $wgUser->getID() ),
63 $fname );
64 $notificationtimestamp = $row->wl_notificationtimestamp;
65 } else $notificationtimestamp = false ;
66
67 $db =& wfGetDB( DB_SLAVE );
68 $use_index = $db->useIndexClause( 'page_timestamp' );
69 $revision = $db->tableName( 'revision' );
70
71 $sql = "SELECT rev_id,rev_user," .
72 "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit ".
73 "FROM $revision $use_index " .
74 "WHERE rev_page=$id " .
75 "ORDER BY inverse_timestamp ".$db->limitResult($limitplus,$offset);
76 $res = $db->query( $sql, $fname );
77
78 $revs = $db->numRows( $res );
79
80 if( $revs < $limitplus ) // the sql above tries to fetch one extra
81 $this->linesonpage = $revs;
82 else
83 $this->linesonpage = $revs - 1;
84
85 $atend = ($revs < $limitplus);
86
87 $this->mSkin = $wgUser->getSkin();
88 $numbar = wfViewPrevNext(
89 $offset, $limit,
90 $this->mTitle->getPrefixedText(),
91 'action=history', $atend );
92 $s = $numbar;
93 if($this->linesonpage > 0) {
94 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
95 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
96 $this->submitbuttonhtml1 = $submitpart1 . ' />';
97 $this->submitbuttonhtml2 = $submitpart1 . ' id="historysubmit" />';
98 }
99 $s .= $this->beginHistoryList();
100 $counter = 1;
101 while ( $line = $db->fetchObject( $res ) ) {
102 $s .= $this->historyLine(
103 $line->rev_timestamp, $line->rev_user,
104 $line->rev_user_text, $namespace,
105 $title, $line->rev_id,
106 $line->rev_comment, ( $line->rev_minor_edit > 0 ),
107 $counter,
108 $notificationtimestamp,
109 ($counter == 1 && $offset == 0)
110 );
111 $counter++;
112 }
113 $s .= $this->endHistoryList( !$atend );
114 $s .= $numbar;
115 $wgOut->addHTML( $s );
116 wfProfileOut( $fname );
117 }
118
119 function beginHistoryList() {
120 global $wgTitle;
121 $this->lastdate = $this->lastline = '';
122 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
123 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
124 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
125 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
126 $s .= !empty($this->submitbuttonhtml1) ? $this->submitbuttonhtml1."\n":'';
127 $s .= '<ul id="pagehistory">';
128 return $s;
129 }
130
131 function endHistoryList( $skip = false ) {
132 $last = wfMsg( 'last' );
133
134 $s = $skip ? '' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
135 $s .= '</ul>';
136 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2 : '';
137 $s .= '</form>';
138 return $s;
139 }
140
141 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false, $latest = false ) {
142 global $wgLang, $wgContLang;
143
144 static $message;
145 if( !isset( $message ) ) {
146 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
147 $message[$msg] = wfMsg( $msg );
148 }
149 }
150
151 if ( $oid && $this->lastline ) {
152 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLinkObj(
153 $this->mTitle, $message['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->makeKnownLinkObj( $this->mTitle, $dt, $q );
165
166 if ( 0 == $u ) {
167 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
168 $ul = $this->mSkin->makeKnownLinkObj( $contribsPage,
169 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
170 } else {
171 $userPage =& Title::makeTitle( NS_USER, $ut );
172 $ul = $this->mSkin->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
173 }
174
175 $s = '<li>';
176 if ( $oid && !$latest ) {
177 $curlink = $this->mSkin->makeKnownLinkObj( $this->mTitle, $message['cur'],
178 'diff=0&oldid='.$oid );
179 } else {
180 $curlink = $message['cur'];
181 }
182 $arbitrary = '';
183 if( $this->linesonpage > 1) {
184 # XXX: move title texts to javascript
185 $checkmark = '';
186 if ( !$oid || $latest ) {
187 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
188 $checkmark = ' checked="checked"';
189 } else {
190 if( $counter == 2 ) $checkmark = ' checked="checked"';
191 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
192 $checkmark = '';
193 }
194 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
195 }
196 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
197 $s .= $isminor ? ' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
198
199
200 if ( '' != $c && '*' != $c ) {
201 $c = $this->mSkin->formatcomment( $c, $this->mTitle );
202 $s .= " <em>($c)</em>";
203 }
204 if ($notificationtimestamp && ($ts >= $notificationtimestamp)) {
205 $s .= wfMsg( 'updatedmarker' );
206 }
207 $s .= '</li>';
208
209 $this->lastline = $s;
210 return $ret;
211 }
212
213 }
214
215 ?>