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 if( $this->mTitle
->getArticleID() == 0 ) {
43 $wgOut->addHTML( wfMsg( 'nohistory' ) );
44 wfProfileOut( $fname );
48 list( $limit, $offset ) = wfCheckLimits();
50 /* We have to draw the latest revision from 'cur' */
52 $rawoffset = $offset - 1;
57 /* Check one extra row to see whether we need to show 'next' and diff links */
58 $limitplus = $rawlimit +
1;
60 $namespace = $this->mTitle
->getNamespace();
61 $title = $this->mTitle
->getText();
62 $uid = $wgUser->getID();
63 $db =& wfGetDB( DB_SLAVE
);
64 if ($wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' )) {
65 $dbr =& wfGetDB( DB_MASTER
);
66 $row = $dbr->selectRow( 'watchlist',
67 array( 'wl_notificationtimestamp' ),
68 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle
->getDBkey(), 'wl_user' => $wgUser->getID() ),
70 $notificationtimestamp = $row->wl_notificationtimestamp
;
71 } else $notificationtimestamp = false ;
73 $use_index = $db->useIndexClause( 'name_title_timestamp' );
74 $oldtable = $db->tableName( 'old' );
76 $sql = "SELECT old_id,old_user," .
77 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
78 "FROM $oldtable $use_index " .
79 "WHERE old_namespace={$namespace} AND " .
80 "old_title='" . $db->strencode( $this->mTitle
->getDBkey() ) . "' " .
81 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
82 $res = $db->query( $sql, $fname );
84 $revs = $db->numRows( $res );
86 if( $revs < $limitplus ) // the sql above tries to fetch one extra
87 $this->linesonpage
= $revs;
89 $this->linesonpage
= $revs - 1;
91 $atend = ($revs < $limitplus);
93 $this->mSkin
= $wgUser->getSkin();
94 $numbar = wfViewPrevNext(
96 $this->mTitle
->getPrefixedText(),
97 'action=history', $atend );
99 if($this->linesonpage
> 0) {
100 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
101 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
102 $this->submitbuttonhtml1
= $submitpart1 . ' />';
103 $this->submitbuttonhtml2
= $submitpart1 . ' id="historysubmit" />';
105 $s .= $this->beginHistoryList();
108 $this->linesonpage++
;
109 $s .= $this->historyLine(
110 $this->mArticle
->getTimestamp(),
111 $this->mArticle
->getUser(),
112 $this->mArticle
->getUserText(), $namespace,
113 $title, 0, $this->mArticle
->getComment(),
114 ( $this->mArticle
->getMinorEdit() > 0 ),
116 $notificationtimestamp
119 while ( $line = $db->fetchObject( $res ) ) {
120 $s .= $this->historyLine(
121 $line->old_timestamp
, $line->old_user
,
122 $line->old_user_text
, $namespace,
123 $title, $line->old_id
,
124 $line->old_comment
, ( $line->old_minor_edit
> 0 ),
126 $notificationtimestamp
129 $s .= $this->endHistoryList( !$atend );
131 $wgOut->addHTML( $s );
132 wfProfileOut( $fname );
135 function beginHistoryList() {
137 $this->lastdate
= $this->lastline
= '';
138 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
139 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
140 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
141 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
142 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
143 $s .= '<ul id="pagehistory">';
147 function endHistoryList( $skip = false ) {
148 $last = wfMsg( 'last' );
150 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
152 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
157 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false ) {
158 global $wgLang, $wgContLang;
161 if( !isset( $message ) ) {
162 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
163 $message[$msg] = wfMsg( $msg );
167 if ( $oid && $this->lastline
) {
168 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLinkObj(
169 $this->mTitle
, $message['last'], "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
173 $dt = $wgLang->timeanddate( $ts, true );
180 $link = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $dt, $q );
183 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
184 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
185 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
187 $userPage =& Title
::makeTitle( NS_USER
, $ut );
188 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
193 $curlink = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $message['cur'],
194 'diff=0&oldid='.$oid );
196 $curlink = $message['cur'];
199 if( $this->linesonpage
> 1) {
200 # XXX: move title texts to javascript
203 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
204 $checkmark = ' checked="checked"';
206 if( $counter == 2 ) $checkmark = ' checked="checked"';
207 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
210 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
212 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
213 $s .= $isminor ?
' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
216 if ( '' != $c && '*' != $c ) {
217 $c = $this->mSkin
->formatcomment( $c, $this->mTitle
);
218 $s .= " <em>($c)</em>";
220 if ($notificationtimestamp && ($ts >= $notificationtimestamp)) {
221 $s .= wfMsg( 'updatedmarker' );
225 $this->lastline
= $s;