Check for validation mode and load validation code if necessary before trying to...
[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 $val = wfMsg ( 'val_user_validations', $val ) ;
157 $wgOut->addHTML( $val );
158 }
159 }
160
161
162 /*
163
164 Generates each row in the contributions list.
165
166 Contributions which are marked "top" are currently on top of the history.
167 For these contributions, a [rollback] link is shown for users with sysop
168 privileges. The rollback link restores the most recent version that was not
169 written by the target user.
170
171 If the contributions page is called with the parameter &bot=1, all rollback
172 links also get that parameter. It causes the edit itself and the rollback
173 to be marked as "bot" edits. Bot edits are hidden by default from recent
174 changes, so this allows sysops to combat a busy vandal without bothering
175 other users.
176
177 TODO: This would probably look a lot nicer in a table.
178
179 */
180 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target )
181 {
182 global $wgLang, $wgOut, $wgUser, $wgRequest;
183 $page = Title::makeName( $ns, $t );
184 $link = $sk->makeKnownLink( $page, "" );
185 $topmarktext="";
186 if($topmark) {
187 if(!$isnew) {
188 $topmarktext .= $sk->makeKnownLink( $page, wfMsg("uctop"), "diff=0" );
189 } else {
190 $topmarktext .= wfMsg("newarticle");
191 }
192 $sysop = $wgUser->isSysop();
193 if($sysop ) {
194 $extraRollback = $wgRequest->getBool( "bot" ) ? '&bot=1' : '';
195 # $target = $wgRequest->getText( 'target' );
196 $topmarktext .= " [". $sk->makeKnownLink( $page,
197 wfMsg( "rollbacklink" ),
198 "action=rollback&from=" . urlencode( $target ) . $extraRollback ) ."]";
199 }
200
201 }
202 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
203
204 if($comment) {
205
206 $comment="<em>(". $sk->formatComment($comment, Title::newFromText($t) ) .")</em> ";
207
208 }
209 $d = $wgLang->timeanddate( $ts, true );
210
211 if ($isminor) {
212 $mflag = '<span class="minor">'.wfMsg( "minoreditletter" ).'</span> ';
213 } else {
214 $mflag = "";
215 }
216
217 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
218 }
219
220 function ucCountLink( $lim, $d )
221 {
222 global $wgUser, $wgLang, $wgRequest;
223
224 $target = $wgRequest->getText( 'target' );
225 $sk = $wgUser->getSkin();
226 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
227 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
228 return $s;
229 }
230
231 function ucDaysLink( $lim, $d )
232 {
233 global $wgUser, $wgLang, $wgRequest;
234
235 $target = $wgRequest->getText( 'target' );
236 $sk = $wgUser->getSkin();
237 $s = $sk->makeKnownLink( $wgLang->specialPage( "Contributions" ),
238 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
239 return $s;
240 }
241 ?>