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