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