4 Split off from Article.php and Skin.php, 2003-12-22
8 var $mArticle, $mTitle, $mSkin;
9 var $lastline, $lastdate;
11 function PageHistory( $article ) {
12 $this->mArticle
=& $article;
13 $this->mTitle
=& $article->mTitle
;
16 # This shares a lot of issues (and code) with Recent Changes
20 global $wgUser, $wgOut, $wgLang;
22 # If page hasn't changed, client can cache this
24 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
25 # Client cache fresh and headers sent, nothing more to do.
28 $fname = "PageHistory::history";
29 wfProfileIn( $fname );
31 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
32 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setArticleRelated( true );
35 $wgOut->setRobotpolicy( "noindex,nofollow" );
37 if( $this->mTitle
->getArticleID() == 0 ) {
38 $wgOut->addHTML( wfMsg( "nohistory" ) );
39 wfProfileOut( $fname );
43 list( $limit, $offset ) = wfCheckLimits();
45 /* We have to draw the latest revision from 'cur' */
47 $rawoffset = $offset - 1;
52 /* Check one extra row to see whether we need to show 'next' and diff links */
53 $limitplus = $rawlimit +
1;
55 $namespace = $this->mTitle
->getNamespace();
56 $title = $this->mTitle
->getText();
57 $sql = "SELECT old_id,old_user," .
58 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
59 "FROM old USE INDEX (name_title_timestamp) " .
60 "WHERE old_namespace={$namespace} AND " .
61 "old_title='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
62 "ORDER BY inverse_timestamp LIMIT $rawoffset, $limitplus";
63 $res = wfQuery( $sql, DB_READ
, $fname );
65 $revs = wfNumRows( $res );
67 if( $revs < $limitplus ) // the sql above tries to fetch one extra
68 $this->linesonpage
= $revs;
70 $this->linesonpage
= $revs - 1;
72 $atend = ($revs < $limitplus);
74 $this->mSkin
= $wgUser->getSkin();
75 $numbar = wfViewPrevNext(
77 $this->mTitle
->getPrefixedText(),
78 "action=history", $atend );
80 $s .= $this->beginHistoryList();
84 $s .= $this->historyLine(
85 $this->mArticle
->getTimestamp(),
86 $this->mArticle
->getUser(),
87 $this->mArticle
->getUserText(), $namespace,
88 $title, 0, $this->mArticle
->getComment(),
89 ( $this->mArticle
->getMinorEdit() > 0 ),
93 while ( $line = wfFetchObject( $res ) ) {
94 $s .= $this->historyLine(
95 $line->old_timestamp
, $line->old_user
,
96 $line->old_user_text
, $namespace,
97 $title, $line->old_id
,
98 $line->old_comment
, ( $line->old_minor_edit
> 0 ),
102 $s .= $this->endHistoryList( !$atend );
104 $wgOut->addHTML( $s );
105 wfProfileOut( $fname );
108 function beginHistoryList()
111 $this->lastdate
= $this->lastline
= "";
112 $s = "\n<p>" . wfMsg( "histlegend" ).'</p>';
113 $s .="\n<form id=\"pagehistory\" name=\"pagehistory\" action=\"" . $wgTitle->getFullURL("-") . "\" method=\"get\">";
114 $s .= "<input type=\"hidden\" name=\"title\" value=\"".urlencode($wgTitle->getPrefixedDbKey())."\"/>\n";
119 function endHistoryList( $skip = false )
121 $last = wfMsg( "last" );
123 $s = $skip ?
"" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
125 if( $this->linesonpage
> 1) {
126 $s .= '<button type="submit">'.wfMsg('compareselectedversions')."</button><br/><br/>\n";
132 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' )
136 $artname = Title
::makeName( $ns, $ttl );
137 $last = wfMsg( "last" );
138 $cur = wfMsg( "cur" );
139 $cr = wfMsg( "currentrev" );
141 if ( $oid && $this->lastline
) {
142 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLink(
143 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
147 $dt = $wgLang->timeanddate( $ts, true );
154 $link = $this->mSkin
->makeKnownLink( $artname, $dt, $q );
157 $ul = $this->mSkin
->makeKnownLink( $wgLang->specialPage( "Contributions" ),
158 $ut, "target=" . $ut );
160 $ul = $this->mSkin
->makeLink( $wgLang->getNsText(
161 Namespace::getUser() ) . ":{$ut}", $ut );
166 $curlink = $this->mSkin
->makeKnownLink( $artname, $cur,
167 "diff=0&oldid={$oid}" );
172 if( $this->linesonpage
> 1) {
173 # XXX: move title texts to javascript
176 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
177 $checkmark = ' checked="checked"';
179 if( $counter == 2 ) $checkmark = ' checked="checked"';
180 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
183 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
185 $M = wfMsg( "minoreditletter" );
187 $s .= "<span class='hflag'>{$M}</span>";
189 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='hlinedesc'>{$ul}</span>";
191 if ( "" != $c && "*" != $c ) {
193 $c = $this->mSkin
->formatcomment($c);
194 $s .= " <em>(" . $c . ")</em>";
198 $this->lastline
= $s;