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