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;
27 # If page hasn't changed, client can cache this
29 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
30 # Client cache fresh and headers sent, nothing more to do.
33 $fname = 'PageHistory::history';
34 wfProfileIn( $fname );
36 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
37 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
38 $wgOut->setArticleFlag( false );
39 $wgOut->setArticleRelated( true );
40 $wgOut->setRobotpolicy( 'noindex,nofollow' );
42 $id = $this->mTitle
->getArticleID();
44 $wgOut->addHTML( wfMsg( 'nohistory' ) );
45 wfProfileOut( $fname );
49 list( $limit, $offset ) = wfCheckLimits();
51 /* Check one extra row to see whether we need to show 'next' and diff links */
52 $limitplus = $limit +
1;
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() ),
64 $notificationtimestamp = $row->wl_notificationtimestamp
;
65 } else $notificationtimestamp = false ;
67 $db =& wfGetDB( DB_SLAVE
);
68 $use_index = $db->useIndexClause( 'page_timestamp' );
69 $revision = $db->tableName( 'revision' );
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 );
78 $revs = $db->numRows( $res );
80 if( $revs < $limitplus ) // the sql above tries to fetch one extra
81 $this->linesonpage
= $revs;
83 $this->linesonpage
= $revs - 1;
85 $atend = ($revs < $limitplus);
87 $this->mSkin
= $wgUser->getSkin();
88 $numbar = wfViewPrevNext(
90 $this->mTitle
->getPrefixedText(),
91 'action=history', $atend );
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" />';
99 $s .= $this->beginHistoryList();
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 ),
108 $notificationtimestamp,
109 ($counter == 1 && $offset == 0)
113 $s .= $this->endHistoryList( !$atend );
115 $wgOut->addHTML( $s );
116 wfProfileOut( $fname );
119 function beginHistoryList() {
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">';
131 function endHistoryList( $skip = false ) {
132 $last = wfMsg( 'last' );
134 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
136 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
141 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false, $latest = false ) {
142 global $wgLang, $wgContLang;
145 if( !isset( $message ) ) {
146 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
147 $message[$msg] = wfMsg( $msg );
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
);
157 $dt = $wgLang->timeanddate( $ts, true );
164 $link = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $dt, $q );
167 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
168 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
169 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
171 $userPage =& Title
::makeTitle( NS_USER
, $ut );
172 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
176 if ( $oid && !$latest ) {
177 $curlink = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $message['cur'],
178 'diff=0&oldid='.$oid );
180 $curlink = $message['cur'];
183 if( $this->linesonpage
> 1) {
184 # XXX: move title texts to javascript
186 if ( !$oid ||
$latest ) {
187 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
188 $checkmark = ' checked="checked"';
190 if( $counter == 2 ) $checkmark = ' checked="checked"';
191 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
194 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
196 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
197 $s .= $isminor ?
' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
200 if ( '' != $c && '*' != $c ) {
201 $c = $this->mSkin
->formatcomment( $c, $this->mTitle
);
202 $s .= " <em>($c)</em>";
204 if ($notificationtimestamp && ($ts >= $notificationtimestamp)) {
205 $s .= wfMsg( 'updatedmarker' );
209 $this->lastline
= $s;