Whoops
[lhc/web/wiklou.git] / includes / PageHistory.php
1 <?php
2 /**
3 * Page history
4 *
5 * Split off from Article.php and Skin.php, 2003-12-22
6 * @package MediaWiki
7 */
8
9 /**
10 * @todo document
11 * @package MediaWiki
12 */
13 class PageHistory {
14 var $mArticle, $mTitle, $mSkin;
15 var $lastline, $lastdate;
16 var $linesonpage;
17 function PageHistory( $article ) {
18 $this->mArticle =& $article;
19 $this->mTitle =& $article->mTitle;
20 }
21
22 # This shares a lot of issues (and code) with Recent Changes
23
24 function history() {
25 global $wgUser, $wgOut, $wgLang;
26
27 # If page hasn't changed, client can cache this
28
29 if( $wgOut->checkLastModified( $this->mArticle->getTimestamp() ) ){
30 # Client cache fresh and headers sent, nothing more to do.
31 return;
32 }
33 $fname = 'PageHistory::history';
34 wfProfileIn( $fname );
35
36 $wgOut->setPageTitle( $this->mTitle->getPRefixedText() );
37 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
38 $wgOut->setArticleFlag( false );
39 $wgOut->setArticleRelated( true );
40 $wgOut->setRobotpolicy( 'noindex,nofollow' );
41
42 if( $this->mTitle->getArticleID() == 0 ) {
43 $wgOut->addHTML( wfMsg( 'nohistory' ) );
44 wfProfileOut( $fname );
45 return;
46 }
47
48 list( $limit, $offset ) = wfCheckLimits();
49
50 /* We have to draw the latest revision from 'cur' */
51 $rawlimit = $limit;
52 $rawoffset = $offset - 1;
53 if( 0 == $offset ) {
54 $rawlimit--;
55 $rawoffset = 0;
56 }
57 /* Check one extra row to see whether we need to show 'next' and diff links */
58 $limitplus = $rawlimit + 1;
59
60 $namespace = $this->mTitle->getNamespace();
61 $title = $this->mTitle->getText();
62
63 $db =& wfGetDB( DB_SLAVE );
64 $use_index = $db->useIndexClause( 'name_title_timestamp' );
65 $oldtable = $db->tableName( 'old' );
66
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 );
74
75 $revs = $db->numRows( $res );
76
77 if( $revs < $limitplus ) // the sql above tries to fetch one extra
78 $this->linesonpage = $revs;
79 else
80 $this->linesonpage = $revs - 1;
81
82 $atend = ($revs < $limitplus);
83
84 $this->mSkin = $wgUser->getSkin();
85 $numbar = wfViewPrevNext(
86 $offset, $limit,
87 $this->mTitle->getPrefixedText(),
88 'action=history', $atend );
89 $s = $numbar;
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" />';
95 }
96 $s .= $this->beginHistoryList();
97 $counter = 1;
98 if( $offset == 0 ){
99 $this->linesonpage++;
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 ),
106 $counter++
107 );
108 }
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 ),
115 $counter++
116 );
117 }
118 $s .= $this->endHistoryList( !$atend );
119 $s .= $numbar;
120 $wgOut->addHTML( $s );
121 wfProfileOut( $fname );
122 }
123
124 function beginHistoryList() {
125 global $wgTitle;
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">';
133 return $s;
134 }
135
136 function endHistoryList( $skip = false ) {
137 $last = wfMsg( 'last' );
138
139 $s = $skip ? '' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
140 $s .= '</ul>';
141 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2 : '';
142 $s .= '</form>';
143 return $s;
144 }
145
146 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '' ) {
147 global $wgLang, $wgContLang;
148
149 static $message;
150 if( !isset( $message ) ) {
151 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
152 $message[$msg] = wfMsg( $msg );
153 }
154 }
155
156 if ( $oid && $this->lastline ) {
157 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLinkObj(
158 $this->mTitle, $message['last'], "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
159 } else {
160 $ret = '';
161 }
162 $dt = $wgLang->timeanddate( $ts, true );
163
164 if ( $oid ) {
165 $q = 'oldid='.$oid;
166 } else {
167 $q = '';
168 }
169 $link = $this->mSkin->makeKnownLinkObj( $this->mTitle, $dt, $q );
170
171 if ( 0 == $u ) {
172 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
173 $ul = $this->mSkin->makeKnownLinkObj( $contribsPage,
174 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
175 } else {
176 $userPage =& Title::makeTitle( NS_USER, $ut );
177 $ul = $this->mSkin->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
178 }
179
180 $s = '<li>';
181 if ( $oid ) {
182 $curlink = $this->mSkin->makeKnownLinkObj( $this->mTitle, $message['cur'],
183 'diff=0&oldid='.$oid );
184 } else {
185 $curlink = $message['cur'];
186 }
187 $arbitrary = '';
188 if( $this->linesonpage > 1) {
189 # XXX: move title texts to javascript
190 $checkmark = '';
191 if ( !$oid ) {
192 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
193 $checkmark = ' checked="checked"';
194 } else {
195 if( $counter == 2 ) $checkmark = ' checked="checked"';
196 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
197 $checkmark = '';
198 }
199 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
200 }
201 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
202 $s .= $isminor ? ' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
203
204
205 if ( '' != $c && '*' != $c ) {
206 $c = $this->mSkin->formatcomment( $c, $this->mTitle );
207 $s .= " <em>($c)</em>";
208 }
209 $s .= '</li>';
210
211 $this->lastline = $s;
212 return $ret;
213 }
214
215 }
216
217 ?>