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