remove old_namespace and old_title from old table.
[lhc/web/wiklou.git] / includes / SpecialContributions.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Special page "user contributions".
10 * Shows a list of the contributions of a user.
11 *
12 * @return none
13 * @param string $par (optional) user name of the user for which to show the contributions
14 */
15 function wfSpecialContributions( $par = '' ) {
16 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
17 $fname = "wfSpecialContributions";
18
19 if( $par )
20 $target = $par;
21 else
22 $target = $wgRequest->getVal( 'target' );
23
24 if ( "" == $target ) {
25 $wgOut->errorpage( "notargettitle", "notargettext" );
26 return;
27 }
28
29 # FIXME: Change from numeric offsets to date offsets
30 list( $limit, $offset ) = wfCheckLimits( 50, "" );
31 $offlimit = $limit + $offset;
32 $querylimit = $offlimit + 1;
33 $hideminor = ($wgRequest->getVal( 'hideminor' ) ? 1 : 0);
34 $sk = $wgUser->getSkin();
35 $dbr =& wfGetDB( DB_SLAVE );
36 $userCond = "";
37
38 $nt = Title::newFromURL( $target );
39 if ( !$nt ) {
40 $wgOut->errorpage( "notargettitle", "notargettext" );
41 return;
42 }
43 $nt->setNamespace( Namespace::getUser() );
44
45 $id = User::idFromName( $nt->getText() );
46
47 if ( 0 == $id ) {
48 $ul = $nt->getText();
49 } else {
50 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
51 $userCond = "=" . $id;
52 }
53 $talk = $nt->getTalkPage();
54 if( $talk ) {
55 $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
56 }
57
58
59 if ( $target == 'newbies' ) {
60 # View the contributions of all recently created accounts
61 $max = $dbr->selectField( 'user', 'max(user_id)', false, $fname );
62 $userCond = ">" . ($max - $max / 100);
63 $ul = wfMsg ( 'newbies' );
64 $id = 0;
65 }
66
67 $wgOut->setSubtitle( wfMsg( "contribsub", $ul ) );
68
69 if ( $hideminor ) {
70 $cmq = "AND cur_minor_edit=0";
71 $omq = "AND old_minor_edit=0";
72 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
73 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
74 "&offset={$offset}&limit={$limit}&hideminor=0" );
75 } else {
76 $cmq = $omq = "";
77 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
78 WfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
79 "&offset={$offset}&limit={$limit}&hideminor=1" );
80 }
81
82 extract( $dbr->tableNames( 'old', 'cur' ) );
83 if ( $userCond == "" ) {
84 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
85 "WHERE cur_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$cmq} " .
86 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
87 $res1 = $dbr->query( $sql, $fname );
88
89 $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
90 "WHERE old_user_text='" . $dbr->strencode( $nt->getText() ) . "' {$omq} " .
91 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
92 $res2 = $dbr->query( $sql, $fname );
93 } else {
94 $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment,cur_minor_edit,cur_is_new,cur_user_text FROM $cur " .
95 "WHERE cur_user {$userCond} {$cmq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
96 $res1 = $dbr->query( $sql, $fname );
97
98 $sql = "SELECT old_articleid,old_timestamp,old_comment,old_minor_edit,old_user_text,old_id FROM $old " .
99 "WHERE old_user {$userCond} {$omq} ORDER BY inverse_timestamp LIMIT {$querylimit}";
100 $res2 = $dbr->query( $sql, $fname );
101 }
102 $nCur = $dbr->numRows( $res1 );
103 $nOld = $dbr->numRows( $res2 );
104
105 $top = wfShowingResults( $offset, $limit );
106 $wgOut->addHTML( "<p>{$top}\n" );
107
108 $sl = wfViewPrevNext( $offset, $limit,
109 $wgContLang->specialpage( "Contributions" ),
110 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
111 ($nCur + $nOld) <= $offlimit);
112
113 $shm = wfMsg( "showhideminor", $mlink );
114 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
115
116
117 if ( 0 == $nCur && 0 == $nOld ) {
118 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
119 return;
120 }
121 if ( 0 != $nCur ) { $obj1 = $dbr->fetchObject( $res1 ); }
122 if ( 0 != $nOld ) { $obj2 = $dbr->fetchObject( $res2 ); }
123
124 $wgOut->addHTML( "<ul>\n" );
125 for( $n = 0; $n < $offlimit; $n++ ) {
126 if ( 0 == $nCur && 0 == $nOld ) { break; }
127
128 if ( ( 0 == $nOld ) ||
129 ( ( 0 != $nCur ) &&
130 ( $obj1->cur_timestamp >= $obj2->old_timestamp ) ) ) {
131 $ns = $obj1->cur_namespace;
132 $t = $obj1->cur_title;
133 $ts = $obj1->cur_timestamp;
134 $comment =$obj1->cur_comment;
135 $me = $obj1->cur_minor_edit;
136 $isnew = $obj1->cur_is_new;
137 $usertext = $obj1->cur_user_text;
138
139 $obj1 = $dbr->fetchObject( $res1 );
140 $topmark = true;
141 $oldid = false;
142 --$nCur;
143 } else {
144 $tt = Title::newFromID($obj2->old_articleid);
145 $ns = $tt->getNamespace();
146 $t = $tt->getDBkey();
147 $ts = $obj2->old_timestamp;
148 $comment =$obj2->old_comment;
149 $me = $obj2->old_minor_edit;
150 $usertext = $obj2->old_user_text;
151 $oldid = $obj2->old_id;
152
153 $obj2 = $dbr->fetchObject( $res2 );
154 $topmark = false;
155 $isnew = false;
156 --$nOld;
157 }
158 if( $n >= $offset )
159 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
160 }
161 $wgOut->addHTML( "</ul>\n" );
162
163 # Validations
164 global $wgUseValidation;
165 if( $wgUseValidation ) {
166 require_once( 'SpecialValidate.php' );
167 $val = new Validation ;
168 $val = $val->countUserValidations ( $id ) ;
169 $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
170 }
171 }
172
173
174 /**
175 * Generates each row in the contributions list.
176 *
177 * Contributions which are marked "top" are currently on top of the history.
178 * For these contributions, a [rollback] link is shown for users with sysop
179 * privileges. The rollback link restores the most recent version that was not
180 * written by the target user.
181 *
182 * If the contributions page is called with the parameter &bot=1, all rollback
183 * links also get that parameter. It causes the edit itself and the rollback
184 * to be marked as "bot" edits. Bot edits are hidden by default from recent
185 * changes, so this allows sysops to combat a busy vandal without bothering
186 * other users.
187 *
188 * @todo This would probably look a lot nicer in a table.
189 */
190 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
191 global $wgLang, $wgOut, $wgUser, $wgRequest;
192 $page = Title::makeName( $ns, $t );
193 $link = $sk->makeKnownLink( $page, '' );
194 $difftext = $topmarktext = '';
195 if($topmark) {
196 $topmarktext .= '<strong>' . wfMsg('uctop') . '</strong>';
197 if(!$isnew) {
198 $difftext .= $sk->makeKnownLink( $page, '(' . wfMsg('diff') . ')', 'diff=0' );
199 } else {
200 $difftext .= wfMsg('newarticle');
201 }
202 $sysop = $wgUser->isSysop();
203 if($sysop ) {
204 $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
205 # $target = $wgRequest->getText( 'target' );
206 $topmarktext .= ' ['. $sk->makeKnownLink( $page,
207 wfMsg( 'rollbacklink' ),
208 'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
209 }
210
211 }
212 if ( $oldid ) {
213 $difftext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
214 }
215 $histlink='('.$sk->makeKnownLink($page,wfMsg('hist'),'action=history').')';
216
217 if($comment) {
218
219 $comment='<em>('. $sk->formatComment($comment, Title::newFromText($t) ) .')</em> ';
220
221 }
222 $d = $wgLang->timeanddate( $ts, true );
223
224 if ($isminor) {
225 $mflag = '<span class="minor">'.wfMsg( 'minoreditletter' ).'</span> ';
226 } else {
227 $mflag = '';
228 }
229
230 $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
231 }
232
233 /**
234 *
235 */
236 function ucCountLink( $lim, $d ) {
237 global $wgUser, $wgContLang, $wgRequest;
238
239 $target = $wgRequest->getText( 'target' );
240 $sk = $wgUser->getSkin();
241 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
242 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
243 return $s;
244 }
245
246 /**
247 *
248 */
249 function ucDaysLink( $lim, $d ) {
250 global $wgUser, $wgContLang, $wgRequest;
251
252 $target = $wgRequest->getText( 'target' );
253 $sk = $wgUser->getSkin();
254 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
255 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
256 return $s;
257 }
258 ?>