Work through the NFC substeps with the actual data to make the substep times more...
[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
172
173 /**
174 * Generates each row in the contributions list.
175 *
176 * Contributions which are marked "top" are currently on top of the history.
177 * For these contributions, a [rollback] link is shown for users with sysop
178 * privileges. The rollback link restores the most recent version that was not
179 * written by the target user.
180 *
181 * If the contributions page is called with the parameter &bot=1, all rollback
182 * links also get that parameter. It causes the edit itself and the rollback
183 * to be marked as "bot" edits. Bot edits are hidden by default from recent
184 * changes, so this allows sysops to combat a busy vandal without bothering
185 * other users.
186 *
187 * @todo This would probably look a lot nicer in a table.
188 */
189 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
190 global $wgLang, $wgOut, $wgUser, $wgRequest;
191 $page = Title::makeName( $ns, $t );
192 $link = $sk->makeKnownLink( $page, '' );
193 $difftext = $topmarktext = '';
194 if($topmark) {
195 $topmarktext .= '<strong>' . wfMsg('uctop') . '</strong>';
196 if(!$isnew) {
197 $difftext .= $sk->makeKnownLink( $page, '(' . wfMsg('diff') . ')', 'diff=0' );
198 } else {
199 $difftext .= wfMsg('newarticle');
200 }
201
202 if( $wgUser->isAllowed('rollback') ) {
203 $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
204 # $target = $wgRequest->getText( 'target' );
205 $topmarktext .= ' ['. $sk->makeKnownLink( $page,
206 wfMsg( 'rollbacklink' ),
207 'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
208 }
209
210 }
211 if ( $oldid ) {
212 $difftext= $sk->makeKnownLink( $page, '('.wfMsg('diff').')', 'diff=prev&oldid='.$oldid );
213 }
214 $histlink='('.$sk->makeKnownLink($page,wfMsg('hist'),'action=history').')';
215
216 if($comment) {
217
218 $comment='<em>('. $sk->formatComment($comment, Title::newFromText($t) ) .')</em> ';
219
220 }
221 $d = $wgLang->timeanddate( $ts, true );
222
223 if ($isminor) {
224 $mflag = '<span class="minor">'.wfMsg( 'minoreditletter' ).'</span> ';
225 } else {
226 $mflag = '';
227 }
228
229 $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
230 }
231
232 /**
233 *
234 */
235 function ucCountLink( $lim, $d ) {
236 global $wgUser, $wgContLang, $wgRequest;
237
238 $target = $wgRequest->getText( 'target' );
239 $sk = $wgUser->getSkin();
240 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
241 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
242 return $s;
243 }
244
245 /**
246 *
247 */
248 function ucDaysLink( $lim, $d ) {
249 global $wgUser, $wgContLang, $wgRequest;
250
251 $target = $wgRequest->getText( 'target' );
252 $sk = $wgUser->getSkin();
253 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
254 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
255 return $s;
256 }
257 ?>