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, $wgIsMySQL, $wgIsPg;
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 $use_index=$wgIsMySQL?
"USE INDEX (name_title_timestamp)":"";
58 $oldtable=$wgIsPg?
'"old"':'old';
59 $sql = "SELECT old_id,old_user," .
60 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
61 "FROM $oldtable $use_index " .
62 "WHERE old_namespace={$namespace} AND " .
63 "old_title='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
64 "ORDER BY inverse_timestamp".wfLimitResult($limitplus,$rawoffset);
65 $res = wfQuery( $sql, DB_READ
, $fname );
67 $revs = wfNumRows( $res );
69 if( $revs < $limitplus ) // the sql above tries to fetch one extra
70 $this->linesonpage
= $revs;
72 $this->linesonpage
= $revs - 1;
74 $atend = ($revs < $limitplus);
76 $this->mSkin
= $wgUser->getSkin();
77 $numbar = wfViewPrevNext(
79 $this->mTitle
->getPrefixedText(),
80 "action=history", $atend );
82 if($this->linesonpage
> 0) {
83 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
84 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
85 $this->submitbuttonhtml1
= $submitpart1 . ' />';
86 $this->submitbuttonhtml2
= $submitpart1 . ' id="historysubmit" />';
88 $s .= $this->beginHistoryList();
92 $s .= $this->historyLine(
93 $this->mArticle
->getTimestamp(),
94 $this->mArticle
->getUser(),
95 $this->mArticle
->getUserText(), $namespace,
96 $title, 0, $this->mArticle
->getComment(),
97 ( $this->mArticle
->getMinorEdit() > 0 ),
101 while ( $line = wfFetchObject( $res ) ) {
102 $s .= $this->historyLine(
103 $line->old_timestamp
, $line->old_user
,
104 $line->old_user_text
, $namespace,
105 $title, $line->old_id
,
106 $line->old_comment
, ( $line->old_minor_edit
> 0 ),
110 $s .= $this->endHistoryList( !$atend );
112 $wgOut->addHTML( $s );
113 wfProfileOut( $fname );
116 function beginHistoryList()
119 $this->lastdate
= $this->lastline
= "";
120 $s = "\n<p>" . wfMsg( "histlegend" ).'</p>';
121 $s .="\n<form action=\"" . $wgTitle->escapeLocalURL( '-' ) . "\" method=\"get\">";
122 $s .= "<input type=\"hidden\" name=\"title\" value=\"".wfEscapeHTML($wgTitle->getPrefixedDbKey())."\"/>\n";
123 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
124 $s .= "" . "\n<ul id=\"pagehistory\" >";
128 function endHistoryList( $skip = false )
130 $last = wfMsg( "last" );
132 $s = $skip ?
"" : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
134 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
."\n":'';
139 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' )
143 $artname = Title
::makeName( $ns, $ttl );
144 $last = wfMsg( "last" );
145 $cur = wfMsg( "cur" );
146 $cr = wfMsg( "currentrev" );
148 if ( $oid && $this->lastline
) {
149 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLink(
150 $artname, $last, "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
154 $dt = $wgLang->timeanddate( $ts, true );
161 $link = $this->mSkin
->makeKnownLink( $artname, $dt, $q );
164 $ul = $this->mSkin
->makeKnownLink( $wgLang->specialPage( "Contributions" ),
165 htmlspecialchars( $ut ), "target=" . urlencode( $ut ) );
167 $ul = $this->mSkin
->makeLink( $wgLang->getNsText(
168 Namespace::getUser() ) . ":{$ut}", htmlspecialchars( $ut ) );
173 $curlink = $this->mSkin
->makeKnownLink( $artname, $cur,
174 "diff=0&oldid={$oid}" );
179 if( $this->linesonpage
> 1) {
180 # XXX: move title texts to javascript
183 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'" />';
184 $checkmark = ' checked="checked"';
186 if( $counter == 2 ) $checkmark = ' checked="checked"';
187 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.wfMsg('selectolderversionfordiff').'"'.$checkmark.' />';
190 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.wfMsg('selectnewerversionfordiff').'"'.$checkmark.' />';
192 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
193 $s .= $isminor ?
' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>': '' ;
196 if ( "" != $c && "*" != $c ) {
198 $c = $this->mSkin
->formatcomment($c);
199 $s .= " <em>(" . $c . ")</em>";
203 $this->lastline
= $s;