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 ($uid && $wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' ))
59 $notificationtimestamp = $db->selectField( 'watchlist',
60 'wl_notificationtimestamp',
61 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle
->getDBkey(), 'wl_user' => $uid ),
63 else $notificationtimestamp = false;
65 $use_index = $db->useIndexClause( 'page_timestamp' );
66 $revision = $db->tableName( 'revision' );
68 $sql = "SELECT rev_id,rev_user," .
69 "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit ".
70 "FROM $revision $use_index " .
71 "WHERE rev_page=$id " .
72 "ORDER BY rev_timestamp DESC ".$db->limitResult($limitplus,$offset);
73 $res = $db->query( $sql, $fname );
75 $revs = $db->numRows( $res );
77 if( $revs < $limitplus ) // the sql above tries to fetch one extra
78 $this->linesonpage
= $revs;
80 $this->linesonpage
= $revs - 1;
82 $atend = ($revs < $limitplus);
84 $this->mSkin
= $wgUser->getSkin();
85 $numbar = wfViewPrevNext(
87 $this->mTitle
->getPrefixedText(),
88 'action=history', $atend );
90 if($this->linesonpage
> 0) {
91 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
92 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
93 $this->submitbuttonhtml1
= $submitpart1 . ' />';
94 $this->submitbuttonhtml2
= $submitpart1 . ' id="historysubmit" />';
96 $s .= $this->beginHistoryList();
98 while ( $line = $db->fetchObject( $res ) ) {
99 $s .= $this->historyLine(
100 $line->rev_timestamp
, $line->rev_user
,
101 $line->rev_user_text
, $namespace,
102 $title, $line->rev_id
,
103 $line->rev_comment
, ( $line->rev_minor_edit
> 0 ),
105 $notificationtimestamp,
106 ($counter == 1 && $offset == 0)
110 $s .= $this->endHistoryList( !$atend );
112 $wgOut->addHTML( $s );
113 wfProfileOut( $fname );
116 function beginHistoryList() {
118 $this->lastdate
= $this->lastline
= '';
119 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
120 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
121 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
122 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
123 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
124 $s .= '<ul id="pagehistory">';
128 function endHistoryList( $skip = false ) {
129 $last = wfMsg( 'last' );
131 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
133 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
138 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false, $latest = false ) {
139 global $wgLang, $wgContLang;
142 if( !isset( $message ) ) {
143 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
144 $message[$msg] = wfMsg( $msg );
148 if ( $oid && $this->lastline
) {
149 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLinkObj(
150 $this->mTitle
, $message['last'], "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
154 $dt = $wgLang->timeanddate( $ts, true );
161 $link = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $dt, $q );
164 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
165 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
166 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
168 $userPage =& Title
::makeTitle( NS_USER
, $ut );
169 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
173 if ( $oid && !$latest ) {
174 $curlink = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $message['cur'],
175 'diff=0&oldid='.$oid );
177 $curlink = $message['cur'];
180 if( $this->linesonpage
> 1) {
181 # XXX: move title texts to javascript
183 if ( !$oid ||
$latest ) {
184 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
185 $checkmark = ' checked="checked"';
187 if( $counter == 2 ) $checkmark = ' checked="checked"';
188 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
191 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
193 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
194 $s .= $isminor ?
' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
197 $s .= $this->mSkin
->commentBlock( $c, $this->mTitle
);
198 if ($notificationtimestamp && ($ts >= $notificationtimestamp)) {
199 $s .= wfMsg( 'updatedmarker' );
203 $this->lastline
= $s;