In QueryPage: fixing a misleading comment. value needn't be numeric.
[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 if ( !$nt ) {
30 $wgOut->errorpage( "notargettitle", "notargettext" );
31 return;
32 }
33 $nt->setNamespace( Namespace::getUser() );
34
35 $id = User::idFromName( $nt->getText() );
36
37 if ( 0 == $id ) {
38 $ul = $nt->getText();
39 } else {
40 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
41 $userCond = "=" . $id;
42 }
43 $talk = $nt->getTalkPage();
44 if( $talk )
45 $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
46 else
47 $ul .= "brrrp";
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 = "";
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=" . wfEscapeHTML( $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=" . wfEscapeHTML( $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 $val = new Validation ;
152 $val = $val->countUserValidations ( $id ) ;
153 $val = wfMsg ( 'val_user_validations', $val ) ;
154 $wgOut->addHTML( $val );
155 }
156
157
158 /*
159
160 Generates each row in the contributions list.
161
162 Contributions which are marked "top" are currently on top of the history.
163 For these contributions, a [rollback] link is shown for users with sysop
164 privileges. The rollback link restores the most recent version that was not
165 written by the target user.
166
167 If the contributions page is called with the parameter &bot=1, all rollback
168 links also get that parameter. It causes the edit itself and the rollback
169 to be marked as "bot" edits. Bot edits are hidden by default from recent
170 changes, so this allows sysops to combat a busy vandal without bothering
171 other users.
172
173 TODO: This would probably look a lot nicer in a table.
174
175 */
176 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target )
177 {
178 global $wgLang, $wgOut, $wgUser, $wgRequest;
179 $page = Title::makeName( $ns, $t );
180 $link = $sk->makeKnownLink( $page, "" );
181 $topmarktext="";
182 if($topmark) {
183 if(!$isnew) {
184 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
185 } else {
186 $topmarktext .= wfMsg("newarticle");
187 }
188 $sysop = $wgUser->isSysop();
189 if($sysop ) {
190 $extraRollback = $wgRequest->getBool( "bot" ) ? '&bot=1' : '';
191 # $target = $wgRequest->getText( 'target' );
192 $topmarktext .= " [". $sk->makeKnownLink( $page,
193 wfMsg( "rollbacklink" ),
194 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
195 }
196
197 }
198 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
199
200 if($comment) {
201
202 $comment="<em>(". $sk->formatComment($comment ) .")</em> ";
203
204 }
205 $d = $wgLang->timeanddate( $ts, true );
206
207 if ($isminor) {
208 $mflag = "<strong>" . wfMsg( "minoreditletter" ) . "</strong> ";
209 } else {
210 $mflag = "";
211 }
212
213 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
214 }
215
216 function ucCountLink( $lim, $d )
217 {
218 global $wgUser, $wgLang, $wgRequest;
219
220 $target = $wgRequest->getText( 'target' );
221 $sk = $wgUser->getSkin();
222 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
223 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
224 return $s;
225 }
226
227 function ucDaysLink( $lim, $d )
228 {
229 global $wgUser, $wgLang, $wgRequest;
230
231 $target = $wgRequest->getText( 'target' );
232 $sk = $wgUser->getSkin();
233 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
234 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
235 return $s;
236 }
237 ?>