5 * Split off from Article.php and Skin.php, 2003-12-22
14 var $mArticle, $mTitle, $mSkin;
15 var $lastline, $lastdate;
17 function PageHistory( $article ) {
18 $this->mArticle
=& $article;
19 $this->mTitle
=& $article->mTitle
;
22 # This shares a lot of issues (and code) with Recent Changes
25 global $wgUser, $wgOut, $wgLang, $wgShowUpdatedMarker, $wgRequest,
28 # If page hasn't changed, client can cache this
30 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
31 # Client cache fresh and headers sent, nothing more to do.
34 $fname = 'PageHistory::history';
35 wfProfileIn( $fname );
37 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
38 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
39 $wgOut->setArticleFlag( false );
40 $wgOut->setArticleRelated( true );
41 $wgOut->setRobotpolicy( 'noindex,nofollow' );
43 $id = $this->mTitle
->getArticleID();
45 $wgOut->addHTML( wfMsg( 'nohistory' ) );
46 wfProfileOut( $fname );
50 $limit = $wgRequest->getInt('limit');
51 if (!$limit) $limit = 50;
52 $offset = $wgRequest->getText('offset');
53 if (!isset($offset) ||
!preg_match("/^[0-9]+$/", $offset)) $offset = 0;
55 /* Check one extra row to see whether we need to show 'next' and diff links */
56 $limitplus = $limit +
1;
58 $namespace = $this->mTitle
->getNamespace();
59 $title = $this->mTitle
->getText();
60 $uid = $wgUser->getID();
61 $db =& wfGetDB( DB_SLAVE
);
62 if ($uid && $wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' ))
63 $notificationtimestamp = $db->selectField( 'watchlist',
64 'wl_notificationtimestamp',
65 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle
->getDBkey(), 'wl_user' => $uid ),
67 else $notificationtimestamp = false;
69 $use_index = $db->useIndexClause( 'page_timestamp' );
70 $revision = $db->tableName( 'revision' );
72 $limits = $offsets = "";
74 if ($wgRequest->getText("dir") == "prev")
77 list($dirs, $oper) = array("DESC", "<");
79 list($dirs, $oper) = array("ASC", ">");
83 $offsets .= " AND rev_timestamp $oper '$offset' ";
85 $limits .= " LIMIT $limitplus ";
87 $sql = "SELECT rev_id,rev_user," .
88 "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit ".
89 "FROM $revision $use_index " .
90 "WHERE rev_page=$id " .
92 "ORDER BY rev_timestamp $dirs " .
94 $res = $db->query( $sql, $fname );
96 $revs = $db->numRows( $res );
98 if( $revs < $limitplus ) // the sql above tries to fetch one extra
99 $this->linesonpage
= $revs;
101 $this->linesonpage
= $revs - 1;
103 $atend = ($revs < $limitplus);
105 $this->mSkin
= $wgUser->getSkin();
109 while ($line = $db->fetchObject($res)) {
112 if ($dir) $pages = array_reverse($pages);
113 if (count($pages) > 1)
114 $lowts = $pages[count($pages) - 2]->rev_timestamp
;
116 $lowts = $pages[count($pages) - 1]->rev_timestamp
;
119 $prevurl = $wgTitle->escapeLocalURL("action=history&dir=prev&offset={$offset}&limit={$limit}");
120 $nexturl = $wgTitle->escapeLocalURL("action=history&offset={$lowts}&limit={$limit}");
122 foreach (array(20, 50, 100, 250, 500) as $num) {
123 $urls[] = "<a href=\"".$wgTitle->escapeLocalURL(
124 "action=history&offset={$offset}&limit={$num}")."\">".$wgLang->formatNum($num)."</a>";
126 $bits = implode($urls, ' | ');
127 $numbar = wfMsg("viewprevnext",
128 "<a href=\"$prevurl\">".wfMsg("prevn", $limit)."</a>",
129 "<a href=\"$nexturl\">".wfMsg("nextn", $limit)."</a>",
133 if($this->linesonpage
> 0) {
134 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
135 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
136 $this->submitbuttonhtml1
= $submitpart1 . ' />';
137 $this->submitbuttonhtml2
= $submitpart1 . ' id="historysubmit" />';
139 $s .= $this->beginHistoryList();
141 foreach($pages as $line) {
142 $s .= $this->historyLine(
143 $line->rev_timestamp
, $line->rev_user
,
144 $line->rev_user_text
, $namespace,
145 $title, $line->rev_id
,
146 $line->rev_comment
, ( $line->rev_minor_edit
> 0 ),
148 $notificationtimestamp,
149 ($counter == 1 && $offset == 0)
153 $s .= $this->endHistoryList( !$atend );
155 $wgOut->addHTML( $s );
156 wfProfileOut( $fname );
159 function beginHistoryList() {
161 $this->lastdate
= $this->lastline
= '';
162 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
163 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
164 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
165 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
166 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
167 $s .= '<ul id="pagehistory">';
171 function endHistoryList( $skip = false ) {
172 $last = wfMsg( 'last' );
174 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
176 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
181 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false, $latest = false ) {
182 global $wgLang, $wgContLang;
185 if( !isset( $message ) ) {
186 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
187 $message[$msg] = wfMsg( $msg );
191 if ( $oid && $this->lastline
) {
192 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLinkObj(
193 $this->mTitle
, $message['last'], "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
197 $dt = $wgLang->timeanddate( $ts, true );
204 $link = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $dt, $q );
207 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
208 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
209 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
211 $userPage =& Title
::makeTitle( NS_USER
, $ut );
212 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
216 if ( $oid && !$latest ) {
217 $curlink = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $message['cur'],
218 'diff=0&oldid='.$oid );
220 $curlink = $message['cur'];
223 if( $this->linesonpage
> 1) {
224 # XXX: move title texts to javascript
226 if ( !$oid ||
$latest ) {
227 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
228 $checkmark = ' checked="checked"';
230 if( $counter == 2 ) $checkmark = ' checked="checked"';
231 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
234 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
236 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
237 $s .= $isminor ?
' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
240 $s .= $this->mSkin
->commentBlock( $c, $this->mTitle
);
241 if ($notificationtimestamp && ($ts >= $notificationtimestamp)) {
242 $s .= wfMsg( 'updatedmarker' );
246 $this->lastline
= $s;