Implement http://bugzilla.wikipedia.org/show_bug.cgi?id=802
[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_namespace,old_title,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_namespace,old_title,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 $ns = $obj2->old_namespace;
145 $t = $obj2->old_title;
146 $ts = $obj2->old_timestamp;
147 $comment =$obj2->old_comment;
148 $me = $obj2->old_minor_edit;
149 $usertext = $obj2->old_user_text;
150 $oldid = $obj2->old_id;
151
152 $obj2 = $dbr->fetchObject( $res2 );
153 $topmark = false;
154 $isnew = false;
155 --$nOld;
156 }
157 if( $n >= $offset )
158 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext, $oldid );
159 }
160 $wgOut->addHTML( "</ul>\n" );
161
162 # Validations
163 global $wgUseValidation;
164 if( $wgUseValidation ) {
165 require_once( 'SpecialValidate.php' );
166 $val = new Validation ;
167 $val = $val->countUserValidations ( $id ) ;
168 $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
169 }
170
171 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
172 }
173
174
175 /**
176 * Generates each row in the contributions list.
177 *
178 * Contributions which are marked "top" are currently on top of the history.
179 * For these contributions, a [rollback] link is shown for users with sysop
180 * privileges. The rollback link restores the most recent version that was not
181 * written by the target user.
182 *
183 * If the contributions page is called with the parameter &bot=1, all rollback
184 * links also get that parameter. It causes the edit itself and the rollback
185 * to be marked as "bot" edits. Bot edits are hidden by default from recent
186 * changes, so this allows sysops to combat a busy vandal without bothering
187 * other users.
188 *
189 * @todo This would probably look a lot nicer in a table.
190 */
191 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
192 global $wgLang, $wgOut, $wgUser, $wgRequest;
193 $page = Title::makeName( $ns, $t );
194 $link = $sk->makeKnownLink( $page, '' );
195 $difftext = $topmarktext = '';
196 if($topmark) {
197 $topmarktext .= '<strong>' . wfMsg('uctop') . '</strong>';
198 if(!$isnew) {
199 $difftext .= $sk->makeKnownLink( $page, '(' . wfMsg('diff') . ')', 'diff=0' );
200 } else {
201 $difftext .= wfMsg('newarticle');
202 }
203
204 if( $wgUser->isAllowed('rollback') ) {
205 $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
206 # $target = $wgRequest->getText( 'target' );
207 $topmarktext .= ' ['. $sk->makeKnownLink( $page,
208 wfMsg( 'rollbacklink' ),
209 'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
210 }
211
212 }
213 if ( $oldid ) {
214 $difftext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
215 }
216 $histlink='('.$sk->makeKnownLink($page,wfMsg('hist'),'action=history').')';
217
218 if($comment) {
219
220 $comment='<em>('. $sk->formatComment($comment, Title::newFromText($t) ) .')</em> ';
221
222 }
223 $d = $wgLang->timeanddate( $ts, true );
224
225 if ($isminor) {
226 $mflag = '<span class="minor">'.wfMsg( 'minoreditletter' ).'</span> ';
227 } else {
228 $mflag = '';
229 }
230
231 $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
232 }
233
234 /**
235 *
236 */
237 function ucCountLink( $lim, $d ) {
238 global $wgUser, $wgContLang, $wgRequest;
239
240 $target = $wgRequest->getText( 'target' );
241 $sk = $wgUser->getSkin();
242 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
243 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
244 return $s;
245 }
246
247 /**
248 *
249 */
250 function ucDaysLink( $lim, $d ) {
251 global $wgUser, $wgContLang, $wgRequest;
252
253 $target = $wgRequest->getText( 'target' );
254 $sk = $wgUser->getSkin();
255 $s = $sk->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
256 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
257 return $s;
258 }
259 ?>