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;
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();
63 $db =& wfGetDB( DB_SLAVE
);
64 $use_index = $db->useIndexClause( 'name_title_timestamp' );
65 $oldtable = $db->tableName( 'old' );
67 $sql = "SELECT old_id,old_user," .
68 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
69 "FROM $oldtable $use_index " .
70 "WHERE old_namespace={$namespace} AND " .
71 "old_title='" . $db->strencode( $this->mTitle
->getDBkey() ) . "' " .
72 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
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();
100 $s .= $this->historyLine(
101 $this->mArticle
->getTimestamp(),
102 $this->mArticle
->getUser(),
103 $this->mArticle
->getUserText(), $namespace,
104 $title, 0, $this->mArticle
->getComment(),
105 ( $this->mArticle
->getMinorEdit() > 0 ),
109 while ( $line = $db->fetchObject( $res ) ) {
110 $s .= $this->historyLine(
111 $line->old_timestamp
, $line->old_user
,
112 $line->old_user_text
, $namespace,
113 $title, $line->old_id
,
114 $line->old_comment
, ( $line->old_minor_edit
> 0 ),
118 $s .= $this->endHistoryList( !$atend );
120 $wgOut->addHTML( $s );
121 wfProfileOut( $fname );
124 function beginHistoryList() {
126 $this->lastdate
= $this->lastline
= '';
127 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
128 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
129 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
130 $s .= "<input type='hidden' name='title' value='{$prefixedkey}' />\n";
131 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
132 $s .= '<ul id="pagehistory">';
136 function endHistoryList( $skip = false ) {
137 $last = wfMsg( 'last' );
139 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
141 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
146 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' ) {
147 global $wgLang, $wgContLang;
149 $artname = Title
::makeName( $ns, $ttl );
150 $last = wfMsg( 'last' );
151 $cur = wfMsg( 'cur' );
152 $cr = wfMsg( 'currentrev' );
154 if ( $oid && $this->lastline
) {
155 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLink(
156 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
160 $dt = $wgLang->timeanddate( $ts, true );
167 $link = $this->mSkin
->makeKnownLink( $artname, $dt, $q );
170 $ul = $this->mSkin
->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
171 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
173 $ul = $this->mSkin
->makeLink( $wgContLang->getNsText(
174 Namespace::getUser() ) . ':'.$ut , htmlspecialchars( $ut ) );
179 $curlink = $this->mSkin
->makeKnownLink( $artname, $cur,
180 'diff=0&oldid='.$oid );
185 if( $this->linesonpage
> 1) {
186 # XXX: move title texts to javascript
189 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
190 $checkmark = ' checked="checked"';
192 if( $counter == 2 ) $checkmark = ' checked="checked"';
193 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
196 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
198 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
199 $s .= $isminor ?
' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
202 if ( '' != $c && '*' != $c ) {
203 $c = $this->mSkin
->formatcomment($c,$this->mTitle
);
204 $s .= " <em>($c)</em>";
208 $this->lastline
= $s;