798ab3c5db3243a8f184b4ca28d5747f8d3d88d1
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 (!isset($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, ' | ');
154 $numbar = "$firstlast " . wfMsg("viewprevnext",
155 "<a href=\"$prevurl\">".wfMsg("prevn", $limit)."</a>",
156 "<a href=\"$nexturl\">".wfMsg("nextn", $limit)."</a>",
160 $s .= $this->beginHistoryList();
162 foreach($pages as $i => $line) {
163 $first = ($counter == 1 && $offset == 0);
164 $next = isset( $pages[$i +
1] ) ?
$pages[$i +
1 ] : null;
165 $s .= $this->historyLine( $line, $next, $counter, $notificationtimestamp, $first );
168 $s .= $this->endHistoryList( !$atend );
172 if ( isset ( $wgUseValidation ) && $wgUseValidation ) {
173 $s .= "<p>" . Validation
::link2statistics ( $this->mArticle
) . "</p>" ;
176 $wgOut->addHTML( $s );
177 wfProfileOut( $fname );
180 function beginHistoryList() {
182 $this->lastdate
= '';
183 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
184 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
185 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
186 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
187 $s .= $this->submitButton();
188 $s .= '<ul id="pagehistory">';
192 function endHistoryList() {
193 $last = wfMsg( 'last' );
196 $s .= $this->submitButton( array( 'id' => 'historysubmit' ) );
201 function submitButton( $bits = array() ) {
202 return ( $this->linesonpage
> 0 )
203 ?
wfElement( 'input', array_merge( $bits,
205 'class' => 'historysubmit',
207 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
208 'title' => wfMsg( 'tooltip-compareselectedversions' ),
209 'value' => wfMsg( 'compareselectedversions' ),
214 function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false ) {
215 global $wgLang, $wgContLang;
218 if( !isset( $message ) ) {
219 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
220 $message[$msg] = wfMsg( $msg );
224 $link = $this->revLink( $row );
226 if ( 0 == $row->rev_user
) {
227 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
228 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
229 htmlspecialchars( $row->rev_user_text
),
230 'target=' . urlencode( $row->rev_user_text
) );
232 $userPage =& Title
::makeTitle( NS_USER
, $row->rev_user_text
);
233 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $row->rev_user_text
) );
237 if( $row->rev_deleted
) {
238 $s .= '<span class="deleted">';
240 $curlink = $this->curLink( $row, $latest );
241 $lastlink = $this->lastLink( $row, $next, $counter );
242 $arbitrary = $this->diffButtons( $row, $latest, $counter );
243 $s .= "({$curlink}) ({$lastlink}) $arbitrary {$link} <span class='user'>{$ul}</span>";
245 if( $row->rev_minor_edit
) {
246 $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), $message['minoreditletter'] );
250 $s .= $this->mSkin
->commentBlock( $row->rev_comment
, $this->mTitle
);
251 if ($notificationtimestamp && ($row->rev_timestamp
>= $notificationtimestamp)) {
252 $s .= wfMsg( 'updatedmarker' );
254 if( $row->rev_deleted
) {
255 $s .= "</span> " . htmlspecialchars( wfMsg( 'deletedrev' ) );
262 function revLink( $row ) {
263 global $wgUser, $wgLang;
264 $date = $wgLang->timeanddate( $row->rev_timestamp
, true );
265 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
268 return $this->mSkin
->makeKnownLinkObj(
271 'oldid='.$row->rev_id
);
275 function curLink( $row, $latest ) {
277 $cur = htmlspecialchars( wfMsg( 'cur' ) );
279 ||
( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) ) {
282 return $this->mSkin
->makeKnownLinkObj(
285 'diff=0&oldid=' . $row->rev_id
);
289 function lastLink( $row, $next, $counter ) {
291 $last = htmlspecialchars( wfMsg( 'last' ) );
293 ||
( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) ) {
296 return $this->mSkin
->makeKnownLinkObj(
299 "diff={$row->rev_id}&oldid={$next->rev_id}",
302 ' tabindex="'.$counter.'"' );
306 function diffButtons( $row, $latest, $counter ) {
308 if( $this->linesonpage
> 1) {
311 'value' => $row->rev_id
,
312 'title' => wfMsg( 'selectolderversionfordiff' )
314 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
315 $radio['disabled'] = 'disabled';
318 # XXX: move title texts to javascript
320 $first = wfElement( 'input', array_merge(
323 'style' => 'visibility:hidden',
324 'name' => 'oldid' ) ) );
325 $checkmark = array( 'checked' => 'checked' );
327 if( $counter == 2 ) {
328 $checkmark = array( 'checked' => 'checked' );
330 $checkmark = array();
332 $first = wfElement( 'input', array_merge(
335 array( 'name' => 'oldid' ) ) );
336 $checkmark = array();
338 $second = wfElement( 'input', array_merge(
341 array( 'name' => 'diff' ) ) );
342 return $first . $second;
348 function getLastOffset($id, $step = 50) {
349 $db =& wfGetDB(DB_SLAVE
);
350 $sql = "SELECT rev_timestamp FROM revision WHERE rev_page = $id ORDER BY rev_timestamp ASC LIMIT $step";
351 $res = $db->query($sql, "getLastOffset");
352 $n = $db->numRows($res);
358 $obj = $db->fetchObject($res);
359 return $obj->rev_timestamp
;