5 * Split off from Article.php and Skin.php, 2003-12-22
14 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 /* Check one extra row to see whether we need to show 'next' and diff links */
59 $limitplus = $limit +
1;
61 $namespace = $this->mTitle
->getNamespace();
62 $title = $this->mTitle
->getText();
63 $uid = $wgUser->getID();
64 $db =& wfGetDB( DB_SLAVE
);
65 if ($uid && $wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' ))
66 $notificationtimestamp = $db->selectField( 'watchlist',
67 'wl_notificationtimestamp',
68 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle
->getDBkey(), 'wl_user' => $uid ),
70 else $notificationtimestamp = false;
72 $use_index = $db->useIndexClause( 'page_timestamp' );
73 $revision = $db->tableName( 'revision' );
75 $limits = $offsets = "";
77 if ($wgRequest->getText("dir") == "prev")
80 list($dirs, $oper) = array("DESC", "<");
82 list($dirs, $oper) = array("ASC", ">");
86 $offsets .= " AND rev_timestamp $oper '$offset' ";
88 $limits .= " LIMIT $limitplus ";
90 $sql = "SELECT rev_id,rev_user," .
91 "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,rev_deleted ".
92 "FROM $revision $use_index " .
93 "WHERE rev_page=$id " .
95 "ORDER BY rev_timestamp $dirs " .
97 $res = $db->query( $sql, $fname );
99 $revs = $db->numRows( $res );
101 if( $revs < $limitplus ) // the sql above tries to fetch one extra
102 $this->linesonpage
= $revs;
104 $this->linesonpage
= $revs - 1;
106 $atend = ($revs < $limitplus);
108 $this->mSkin
= $wgUser->getSkin();
112 while ($line = $db->fetchObject($res)) {
115 if ($dir) $pages = array_reverse($pages);
116 if (count($pages) > 1)
117 $lowts = $pages[count($pages) - 2]->rev_timestamp
;
119 $lowts = $pages[count($pages) - 1]->rev_timestamp
;
122 $prevurl = $wgTitle->escapeLocalURL("action=history&dir=prev&offset={$offset}&limit={$limit}");
123 $nexturl = $wgTitle->escapeLocalURL("action=history&offset={$lowts}&limit={$limit}");
125 foreach (array(20, 50, 100, 250, 500) as $num) {
126 $urls[] = "<a href=\"".$wgTitle->escapeLocalURL(
127 "action=history&offset={$offset}&limit={$num}")."\">".$wgLang->formatNum($num)."</a>";
129 $bits = implode($urls, ' | ');
130 $numbar = wfMsg("viewprevnext",
131 "<a href=\"$prevurl\">".wfMsg("prevn", $limit)."</a>",
132 "<a href=\"$nexturl\">".wfMsg("nextn", $limit)."</a>",
136 $s .= $this->beginHistoryList();
138 foreach($pages as $i => $line) {
139 $first = ($counter == 1 && $offset == 0);
140 $next = isset( $pages[$i +
1] ) ?
$pages[$i +
1 ] : null;
141 $s .= $this->historyLine( $line, $next, $counter, $notificationtimestamp, $first );
144 $s .= $this->endHistoryList( !$atend );
148 if ( isset ( $wgUseValidation ) && $wgUseValidation ) {
149 $s .= "<p>" . Validation
::link2statistics ( $this->mArticle
) . "</p>" ;
152 $wgOut->addHTML( $s );
153 wfProfileOut( $fname );
156 function beginHistoryList() {
158 $this->lastdate
= '';
159 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
160 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
161 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
162 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
163 $s .= $this->submitButton();
164 $s .= '<ul id="pagehistory">';
168 function endHistoryList() {
169 $last = wfMsg( 'last' );
172 $s .= $this->submitButton( array( 'id' => 'historysubmit' ) );
177 function submitButton( $bits = array() ) {
178 return ( $this->linesonpage
> 0 )
179 ?
wfElement( 'input', array_merge( $bits,
181 'class' => 'historysubmit',
183 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
184 'title' => wfMsg( 'tooltip-compareselectedversions' ),
185 'value' => wfMsg( 'compareselectedversions' ),
190 function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, $latest = false ) {
191 global $wgLang, $wgContLang;
194 if( !isset( $message ) ) {
195 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
196 $message[$msg] = wfMsg( $msg );
200 $link = $this->revLink( $row );
202 if ( 0 == $row->rev_user
) {
203 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
204 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
205 htmlspecialchars( $row->rev_user_text
),
206 'target=' . urlencode( $row->rev_user_text
) );
208 $userPage =& Title
::makeTitle( NS_USER
, $row->rev_user_text
);
209 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $row->rev_user_text
) );
213 if( $row->rev_deleted
) {
214 $s .= '<span class="deleted">';
216 $curlink = $this->curLink( $row, $latest );
217 $lastlink = $this->lastLink( $row, $next, $counter );
218 $arbitrary = $this->diffButtons( $row, $latest, $counter );
219 $s .= "({$curlink}) ({$lastlink}) $arbitrary {$link} <span class='user'>{$ul}</span>";
221 if( $row->rev_minor_edit
) {
222 $s .= ' ' . wfElement( 'span', array( 'class' => 'minor' ), $message['minoreditletter'] );
226 $s .= $this->mSkin
->commentBlock( $row->rev_comment
, $this->mTitle
);
227 if ($notificationtimestamp && ($row->rev_timestamp
>= $notificationtimestamp)) {
228 $s .= wfMsg( 'updatedmarker' );
230 if( $row->rev_deleted
) {
231 $s .= "</span> " . htmlspecialchars( wfMsg( 'deletedrev' ) );
238 function revLink( $row ) {
239 global $wgUser, $wgLang;
240 $date = $wgLang->timeanddate( $row->rev_timestamp
, true );
241 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
244 return $this->mSkin
->makeKnownLinkObj(
247 'oldid='.$row->rev_id
);
251 function curLink( $row, $latest ) {
253 $cur = htmlspecialchars( wfMsg( 'cur' ) );
255 ||
( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) ) {
258 return $this->mSkin
->makeKnownLinkObj(
261 'diff=0&oldid=' . $row->rev_id
);
265 function lastLink( $row, $next, $counter ) {
267 $last = htmlspecialchars( wfMsg( 'last' ) );
269 ||
( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) ) {
272 return $this->mSkin
->makeKnownLinkObj(
275 "diff={$row->rev_id}&oldid={$next->rev_id}",
278 ' tabindex="'.$counter.'"' );
282 function diffButtons( $row, $latest, $counter ) {
284 if( $this->linesonpage
> 1) {
287 'value' => $row->rev_id
,
288 'title' => wfMsg( 'selectolderversionfordiff' )
290 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
291 $radio['disabled'] = 'disabled';
294 # XXX: move title texts to javascript
296 $first = wfElement( 'input', array_merge(
299 'style' => 'visibility:hidden',
300 'name' => 'oldid' ) ) );
301 $checkmark = array( 'checked' => 'checked' );
303 if( $counter == 2 ) {
304 $checkmark = array( 'checked' => 'checked' );
306 $checkmark = array();
308 $first = wfElement( 'input', array_merge(
311 array( 'name' => 'oldid' ) ) );
312 $checkmark = array();
314 $second = wfElement( 'input', array_merge(
317 array( 'name' => 'diff' ) ) );
318 return $first . $second;