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