5 * Split off from Article.php and Skin.php, 2003-12-22
9 include_once ( "SpecialValidate.php" );
17 var $mArticle, $mTitle, $mSkin;
20 function PageHistory( $article ) {
21 $this->mArticle
=& $article;
22 $this->mTitle
=& $article->mTitle
;
25 # This shares a lot of issues (and code) with Recent Changes
28 global $wgUser, $wgOut, $wgLang, $wgShowUpdatedMarker, $wgRequest,
29 $wgTitle, $wgUseValidation ;
31 # If page hasn't changed, client can cache this
33 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
34 # Client cache fresh and headers sent, nothing more to do.
37 $fname = 'PageHistory::history';
38 wfProfileIn( $fname );
40 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
41 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
42 $wgOut->setArticleFlag( false );
43 $wgOut->setArticleRelated( true );
44 $wgOut->setRobotpolicy( 'noindex,nofollow' );
46 $id = $this->mTitle
->getArticleID();
48 $wgOut->addHTML( wfMsg( 'nohistory' ) );
49 wfProfileOut( $fname );
53 $limit = $wgRequest->getInt('limit');
54 if (!$limit) $limit = 50;
55 $offset = $wgRequest->getText('offset');
56 if (!strlen($offset) ||
!preg_match("/^[0-9]+$/", $offset)) $offset = 0;
58 if (($gowhere = $wgRequest->getText("go")) !== NULL) {
61 if (($lastid = $this->getLastOffset($id, $limit)) === NULL)
63 $gourl = $wgTitle->getLocalURL("action=history&limit={$limit}&offset={$lastid}");
69 if (!is_null($gourl)) {
70 $wgOut->redirect($gourl);
75 $firsturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}&go=first");
76 $lasturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}");
77 $firsttext = wfMsg("histfirst");
78 $lasttext = wfMsg("histlast");
80 $firstlast = "(<a href=\"$firsturl\">$firsttext</a> | <a href=\"$lasturl\">$lasttext</a>)";
82 /* Check one extra row to see whether we need to show 'next' and diff links */
83 $limitplus = $limit +
1;
85 $namespace = $this->mTitle
->getNamespace();
86 $title = $this->mTitle
->getText();
87 $uid = $wgUser->getID();
88 $db =& wfGetDB( DB_SLAVE
);
89 if ($uid && $wgShowUpdatedMarker )
90 $notificationtimestamp = $db->selectField( 'watchlist',
91 'wl_notificationtimestamp',
92 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle
->getDBkey(), 'wl_user' => $uid ),
94 else $notificationtimestamp = false;
96 $use_index = $db->useIndexClause( 'page_timestamp' );
97 $revision = $db->tableName( 'revision' );
99 $limits = $offsets = "";
101 if ($wgRequest->getText("dir") == "prev")
104 list($dirs, $oper) = array("DESC", "<");
106 list($dirs, $oper) = array("ASC", ">");
110 $offsets .= " AND rev_timestamp $oper '$offset' ";
112 $limits .= " LIMIT $limitplus ";
114 $sql = "SELECT rev_id,rev_user," .
115 "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,rev_deleted ".
116 "FROM $revision $use_index " .
117 "WHERE rev_page=$id " .
119 "ORDER BY rev_timestamp $dirs " .
121 $res = $db->query( $sql, $fname );
123 $revs = $db->numRows( $res );
125 if( $revs < $limitplus ) // the sql above tries to fetch one extra
126 $this->linesonpage
= $revs;
128 $this->linesonpage
= $revs - 1;
130 $atend = ($revs < $limitplus);
132 $this->mSkin
= $wgUser->getSkin();
136 while ($line = $db->fetchObject($res)) {
139 if ($dir) $pages = array_reverse($pages);
140 if (count($pages) > 1)
141 $lowts = $pages[count($pages) - 2]->rev_timestamp
;
143 $lowts = $pages[count($pages) - 1]->rev_timestamp
;
146 $prevurl = $wgTitle->escapeLocalURL("action=history&dir=prev&offset={$offset}&limit={$limit}");
147 $nexturl = $wgTitle->escapeLocalURL("action=history&offset={$lowts}&limit={$limit}");
149 foreach (array(20, 50, 100, 250, 500) as $num) {
150 $urls[] = "<a href=\"".$wgTitle->escapeLocalURL(
151 "action=history&offset={$offset}&limit={$num}")."\">".$wgLang->formatNum($num)."</a>";
153 $bits = implode($urls, ' | ');
155 $prevtext = "<a href=\"$prevurl\">".wfMsg("prevn", $limit)."</a>";
156 else $prevtext = wfMsg("prevn", $limit);
157 if ($revs >= $limitplus)
158 $nexttext = "<a href=\"$nexturl\">".wfMsg("nextn", $limit)."</a>";
159 else $nexttext = wfMsg("nextn", $limit);
161 $numbar = "$firstlast " . wfMsg("viewprevnext", $prevtext, $nexttext, $bits);
164 $s .= $this->beginHistoryList();
166 foreach($pages as $i => $line) {
167 $first = ($counter == 1 && $offset == 0);
168 $next = isset( $pages[$i +
1] ) ?
$pages[$i +
1 ] : null;
169 $s .= $this->historyLine( $line, $next, $counter, $notificationtimestamp, $first );
172 $s .= $this->endHistoryList( !$atend );
176 if ( isset ( $wgUseValidation ) && $wgUseValidation ) {
177 $s .= "<p>" . Validation
::link2statistics ( $this->mArticle
) . "</p>" ;
180 $wgOut->addHTML( $s );
181 wfProfileOut( $fname );
184 function beginHistoryList() {
186 $this->lastdate
= '';
187 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
188 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
189 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
190 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
191 $s .= $this->submitButton();
192 $s .= '<ul id="pagehistory">';
196 function endHistoryList() {
197 $last = wfMsg( 'last' );
200 $s .= $this->submitButton( array( 'id' => 'historysubmit' ) );
205 function submitButton( $bits = array() ) {
206 return ( $this->linesonpage
> 0 )
207 ?
wfElement( 'input', array_merge( $bits,
209 'class' => 'historysubmit',
211 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
212 'title' => wfMsg( 'tooltip-compareselectedversions' ),
213 'value' => wfMsg( 'compareselectedversions' ),
218 function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false ) {
219 global $wgLang, $wgContLang;
222 if( !isset( $message ) ) {
223 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
224 $message[$msg] = wfMsg( $msg );
228 $link = $this->revLink( $row );
230 if ( 0 == $row->rev_user
) {
231 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
232 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
233 htmlspecialchars( $row->rev_user_text
),
234 'target=' . urlencode( $row->rev_user_text
) );
236 $userPage =& Title
::makeTitle( NS_USER
, $row->rev_user_text
);
237 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $row->rev_user_text
) );
241 if( $row->rev_deleted
) {
242 $s .= '<span class="deleted">';
244 $curlink = $this->curLink( $row, $latest );
245 $lastlink = $this->lastLink( $row, $next, $counter );
246 $arbitrary = $this->diffButtons( $row, $latest, $counter );
247 $s .= "({$curlink}) ({$lastlink}) $arbitrary {$link} <span class='user'>{$ul}</span>";
249 if( $row->rev_minor_edit
) {
250 $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), $message['minoreditletter'] );
254 $s .= $this->mSkin
->commentBlock( $row->rev_comment
, $this->mTitle
);
255 if ($notificationtimestamp && ($row->rev_timestamp
>= $notificationtimestamp)) {
256 $s .= wfMsg( 'updatedmarker' );
258 if( $row->rev_deleted
) {
259 $s .= "</span> " . htmlspecialchars( wfMsg( 'deletedrev' ) );
266 function revLink( $row ) {
267 global $wgUser, $wgLang;
268 $date = $wgLang->timeanddate( $row->rev_timestamp
, true );
269 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
272 return $this->mSkin
->makeKnownLinkObj(
275 'oldid='.$row->rev_id
);
279 function curLink( $row, $latest ) {
281 $cur = htmlspecialchars( wfMsg( 'cur' ) );
283 ||
( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) ) {
286 return $this->mSkin
->makeKnownLinkObj(
289 'diff=0&oldid=' . $row->rev_id
);
293 function lastLink( $row, $next, $counter ) {
295 $last = htmlspecialchars( wfMsg( 'last' ) );
297 ||
( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) ) {
300 return $this->mSkin
->makeKnownLinkObj(
303 "diff={$row->rev_id}&oldid={$next->rev_id}",
306 ' tabindex="'.$counter.'"' );
310 function diffButtons( $row, $latest, $counter ) {
312 if( $this->linesonpage
> 1) {
315 'value' => $row->rev_id
,
316 'title' => wfMsg( 'selectolderversionfordiff' )
318 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
319 $radio['disabled'] = 'disabled';
322 # XXX: move title texts to javascript
324 $first = wfElement( 'input', array_merge(
327 'style' => 'visibility:hidden',
328 'name' => 'oldid' ) ) );
329 $checkmark = array( 'checked' => 'checked' );
331 if( $counter == 2 ) {
332 $checkmark = array( 'checked' => 'checked' );
334 $checkmark = array();
336 $first = wfElement( 'input', array_merge(
339 array( 'name' => 'oldid' ) ) );
340 $checkmark = array();
342 $second = wfElement( 'input', array_merge(
345 array( 'name' => 'diff' ) ) );
346 return $first . $second;
352 function getLastOffset($id, $step = 50) {
353 $db =& wfGetDB(DB_SLAVE
);
354 $sql = "SELECT rev_timestamp FROM revision WHERE rev_page = $id ORDER BY rev_timestamp ASC LIMIT $step";
355 $res = $db->query($sql, "getLastOffset");
356 $n = $db->numRows($res);
362 $obj = $db->fetchObject($res);
363 return $obj->rev_timestamp
;