5 * Split off from Article.php and Skin.php, 2003-12-22
12 var $mArticle, $mTitle, $mSkin;
13 var $lastline, $lastdate;
15 function PageHistory( $article ) {
16 $this->mArticle
=& $article;
17 $this->mTitle
=& $article->mTitle
;
20 # This shares a lot of issues (and code) with Recent Changes
23 global $wgUser, $wgOut, $wgLang;
25 # If page hasn't changed, client can cache this
27 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
28 # Client cache fresh and headers sent, nothing more to do.
31 $fname = 'PageHistory::history';
32 wfProfileIn( $fname );
34 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
35 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
36 $wgOut->setArticleFlag( false );
37 $wgOut->setArticleRelated( true );
38 $wgOut->setRobotpolicy( 'noindex,nofollow' );
40 if( $this->mTitle
->getArticleID() == 0 ) {
41 $wgOut->addHTML( wfMsg( 'nohistory' ) );
42 wfProfileOut( $fname );
46 list( $limit, $offset ) = wfCheckLimits();
48 /* We have to draw the latest revision from 'cur' */
50 $rawoffset = $offset - 1;
55 /* Check one extra row to see whether we need to show 'next' and diff links */
56 $limitplus = $rawlimit +
1;
58 $namespace = $this->mTitle
->getNamespace();
59 $title = $this->mTitle
->getText();
61 $db =& wfGetDB( DB_SLAVE
);
62 $use_index = $db->useIndexClause( 'name_title_timestamp' );
63 $oldtable = $db->tableName( 'old' );
65 $sql = "SELECT old_id,old_user," .
66 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
67 "FROM $oldtable $use_index " .
68 "WHERE old_namespace={$namespace} AND " .
69 "old_title='" . $db->strencode( $this->mTitle
->getDBkey() ) . "' " .
70 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
71 $res = $db->query( $sql, $fname );
73 $revs = $db->numRows( $res );
75 if( $revs < $limitplus ) // the sql above tries to fetch one extra
76 $this->linesonpage
= $revs;
78 $this->linesonpage
= $revs - 1;
80 $atend = ($revs < $limitplus);
82 $this->mSkin
= $wgUser->getSkin();
83 $numbar = wfViewPrevNext(
85 $this->mTitle
->getPrefixedText(),
86 'action=history', $atend );
88 if($this->linesonpage
> 0) {
89 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
90 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
91 $this->submitbuttonhtml1
= $submitpart1 . ' />';
92 $this->submitbuttonhtml2
= $submitpart1 . ' id="historysubmit" />';
94 $s .= $this->beginHistoryList();
98 $s .= $this->historyLine(
99 $this->mArticle
->getTimestamp(),
100 $this->mArticle
->getUser(),
101 $this->mArticle
->getUserText(), $namespace,
102 $title, 0, $this->mArticle
->getComment(),
103 ( $this->mArticle
->getMinorEdit() > 0 ),
107 while ( $line = $db->fetchObject( $res ) ) {
108 $s .= $this->historyLine(
109 $line->old_timestamp
, $line->old_user
,
110 $line->old_user_text
, $namespace,
111 $title, $line->old_id
,
112 $line->old_comment
, ( $line->old_minor_edit
> 0 ),
116 $s .= $this->endHistoryList( !$atend );
118 $wgOut->addHTML( $s );
119 wfProfileOut( $fname );
122 function beginHistoryList() {
124 $this->lastdate
= $this->lastline
= '';
125 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
126 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
127 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
128 $s .= "<input type='hidden' name='title' value='{$prefixedkey}' />\n";
129 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
130 $s .= '<ul id="pagehistory">';
134 function endHistoryList( $skip = false ) {
135 $last = wfMsg( 'last' );
137 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
139 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
144 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' ) {
147 $artname = Title
::makeName( $ns, $ttl );
148 $last = wfMsg( 'last' );
149 $cur = wfMsg( 'cur' );
150 $cr = wfMsg( 'currentrev' );
152 if ( $oid && $this->lastline
) {
153 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLink(
154 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
158 $dt = $wgLang->timeanddate( $ts, true );
165 $link = $this->mSkin
->makeKnownLink( $artname, $dt, $q );
168 $ul = $this->mSkin
->makeKnownLink( $wgLang->specialPage( 'Contributions' ),
169 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
171 $ul = $this->mSkin
->makeLink( $wgLang->getNsText(
172 Namespace::getUser() ) . ':'.$ut , htmlspecialchars( $ut ) );
177 $curlink = $this->mSkin
->makeKnownLink( $artname, $cur,
178 'diff=0&oldid='.$oid );
183 if( $this->linesonpage
> 1) {
184 # XXX: move title texts to javascript
187 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
188 $checkmark = ' checked="checked"';
190 if( $counter == 2 ) $checkmark = ' checked="checked"';
191 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
194 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
196 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
197 $s .= $isminor ?
' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
200 if ( '' != $c && '*' != $c ) {
201 $c = $this->mSkin
->formatcomment($c,$this->mTitle
);
202 $s .= " <em>($c)</em>";
206 $this->lastline
= $s;