(bug 454) Merge e-notif 2.00
[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, $wgShowUpdatedMarker;
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 $uid = $wgUser->getID();
63 $db =& wfGetDB( DB_SLAVE );
64 if ($wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' )) {
65 $dbr =& wfGetDB( DB_MASTER );
66 $row = $dbr->selectRow( 'watchlist',
67 array( 'wl_notificationtimestamp' ),
68 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle->getDBkey(), 'wl_user' => $wgUser->getID() ),
69 $fname );
70 $notificationtimestamp = $row->wl_notificationtimestamp;
71 } else $notificationtimestamp = false ;
72
73 $use_index = $db->useIndexClause( 'name_title_timestamp' );
74 $oldtable = $db->tableName( 'old' );
75
76 $sql = "SELECT old_id,old_user," .
77 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
78 "FROM $oldtable $use_index " .
79 "WHERE old_namespace={$namespace} AND " .
80 "old_title='" . $db->strencode( $this->mTitle->getDBkey() ) . "' " .
81 "ORDER BY inverse_timestamp".$db->limitResult($limitplus,$rawoffset);
82 $res = $db->query( $sql, $fname );
83
84 $revs = $db->numRows( $res );
85
86 if( $revs < $limitplus ) // the sql above tries to fetch one extra
87 $this->linesonpage = $revs;
88 else
89 $this->linesonpage = $revs - 1;
90
91 $atend = ($revs < $limitplus);
92
93 $this->mSkin = $wgUser->getSkin();
94 $numbar = wfViewPrevNext(
95 $offset, $limit,
96 $this->mTitle->getPrefixedText(),
97 'action=history', $atend );
98 $s = $numbar;
99 if($this->linesonpage > 0) {
100 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
101 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
102 $this->submitbuttonhtml1 = $submitpart1 . ' />';
103 $this->submitbuttonhtml2 = $submitpart1 . ' id="historysubmit" />';
104 }
105 $s .= $this->beginHistoryList();
106 $counter = 1;
107 if( $offset == 0 ){
108 $this->linesonpage++;
109 $s .= $this->historyLine(
110 $this->mArticle->getTimestamp(),
111 $this->mArticle->getUser(),
112 $this->mArticle->getUserText(), $namespace,
113 $title, 0, $this->mArticle->getComment(),
114 ( $this->mArticle->getMinorEdit() > 0 ),
115 $counter++,
116 $notificationtimestamp
117 );
118 }
119 while ( $line = $db->fetchObject( $res ) ) {
120 $s .= $this->historyLine(
121 $line->old_timestamp, $line->old_user,
122 $line->old_user_text, $namespace,
123 $title, $line->old_id,
124 $line->old_comment, ( $line->old_minor_edit > 0 ),
125 $counter++,
126 $notificationtimestamp
127 );
128 }
129 $s .= $this->endHistoryList( !$atend );
130 $s .= $numbar;
131 $wgOut->addHTML( $s );
132 wfProfileOut( $fname );
133 }
134
135 function beginHistoryList() {
136 global $wgTitle;
137 $this->lastdate = $this->lastline = '';
138 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
139 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
140 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
141 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
142 $s .= !empty($this->submitbuttonhtml1) ? $this->submitbuttonhtml1."\n":'';
143 $s .= '<ul id="pagehistory">';
144 return $s;
145 }
146
147 function endHistoryList( $skip = false ) {
148 $last = wfMsg( 'last' );
149
150 $s = $skip ? '' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline );
151 $s .= '</ul>';
152 $s .= !empty($this->submitbuttonhtml2) ? $this->submitbuttonhtml2 : '';
153 $s .= '</form>';
154 return $s;
155 }
156
157 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false ) {
158 global $wgLang, $wgContLang;
159
160 static $message;
161 if( !isset( $message ) ) {
162 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
163 $message[$msg] = wfMsg( $msg );
164 }
165 }
166
167 if ( $oid && $this->lastline ) {
168 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin->makeKnownLinkObj(
169 $this->mTitle, $message['last'], "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline );
170 } else {
171 $ret = '';
172 }
173 $dt = $wgLang->timeanddate( $ts, true );
174
175 if ( $oid ) {
176 $q = 'oldid='.$oid;
177 } else {
178 $q = '';
179 }
180 $link = $this->mSkin->makeKnownLinkObj( $this->mTitle, $dt, $q );
181
182 if ( 0 == $u ) {
183 $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
184 $ul = $this->mSkin->makeKnownLinkObj( $contribsPage,
185 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
186 } else {
187 $userPage =& Title::makeTitle( NS_USER, $ut );
188 $ul = $this->mSkin->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
189 }
190
191 $s = '<li>';
192 if ( $oid ) {
193 $curlink = $this->mSkin->makeKnownLinkObj( $this->mTitle, $message['cur'],
194 'diff=0&oldid='.$oid );
195 } else {
196 $curlink = $message['cur'];
197 }
198 $arbitrary = '';
199 if( $this->linesonpage > 1) {
200 # XXX: move title texts to javascript
201 $checkmark = '';
202 if ( !$oid ) {
203 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
204 $checkmark = ' checked="checked"';
205 } else {
206 if( $counter == 2 ) $checkmark = ' checked="checked"';
207 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
208 $checkmark = '';
209 }
210 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
211 }
212 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
213 $s .= $isminor ? ' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
214
215
216 if ( '' != $c && '*' != $c ) {
217 $c = $this->mSkin->formatcomment( $c, $this->mTitle );
218 $s .= " <em>($c)</em>";
219 }
220 if ($notificationtimestamp && ($ts >= $notificationtimestamp)) {
221 $s .= wfMsg( 'updatedmarker' );
222 }
223 $s .= '</li>';
224
225 $this->lastline = $s;
226 return $ret;
227 }
228
229 }
230
231 ?>