The last checkin changed 'copyrightwarning' in a way that broke if the
[mediawiki.git] / includes / SpecialContributions.php
blob8b7688cef60356f1d6e9f006dbdab46dd1de810a
1 <?php
3 function wfSpecialContributions( $par = "" )
5 global $wgUser, $wgOut, $wgLang, $wgRequest;
6 $fname = "wfSpecialContributions";
7 $sysop = $wgUser->isSysop();
9 if( $par )
10 $target = $par;
11 else
12 $target = $wgRequest->getVal( 'target' );
14 if ( "" == $target ) {
15 $wgOut->errorpage( "notargettitle", "notargettext" );
16 return;
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 = "";
28 $nt = Title::newFromURL( $target );
29 if ( !$nt ) {
30 $wgOut->errorpage( "notargettitle", "notargettext" );
31 return;
33 $nt->setNamespace( Namespace::getUser() );
35 $id = User::idFromName( $nt->getText() );
37 if ( 0 == $id ) {
38 $ul = $nt->getText();
39 } else {
40 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
41 $userCond = "=" . $id;
43 $talk = $nt->getTalkPage();
44 if( $talk )
45 $ul .= " (" . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ")";
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;
55 $wgOut->setSubtitle( wfMsg( "contribsub", $ul ) );
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" );
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 );
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 );
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 );
90 $nCur = $dbr->numRows( $res1 );
91 $nOld = $dbr->numRows( $res2 );
93 $top = wfShowingResults( $offset, $limit );
94 $wgOut->addHTML( "<p>{$top}\n" );
96 $sl = wfViewPrevNext( $offset, $limit,
97 $wgLang->specialpage( "Contributions" ),
98 "hideminor={$hideminor}&target=" . wfUrlEncode( $target ),
99 ($nCur + $nOld) <= $offlimit);
101 $shm = wfMsg( "showhideminor", $mlink );
102 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
105 if ( 0 == $nCur && 0 == $nOld ) {
106 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
107 return;
109 if ( 0 != $nCur ) { $obj1 = $dbr->fetchObject( $res1 ); }
110 if ( 0 != $nOld ) { $obj2 = $dbr->fetchObject( $res2 ); }
112 $wgOut->addHTML( "<ul>\n" );
113 for( $n = 0; $n < $offlimit; $n++ ) {
114 if ( 0 == $nCur && 0 == $nOld ) { break; }
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;
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;
138 $obj2 = $dbr->fetchObject( $res2 );
139 $topmark = false;
140 $isnew = false;
141 --$nOld;
143 if( $n >= $offset )
144 ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, ( $me > 0), $isnew, $usertext );
146 $wgOut->addHTML( "</ul>\n" );
148 # Validations
149 $val = new Validation ;
150 $val = $val->countUserValidations ( $id ) ;
151 $val = wfMsg ( 'val_user_validations', $val ) ;
152 $wgOut->addHTML( $val );
158 Generates each row in the contributions list.
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.
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.
171 TODO: This would probably look a lot nicer in a table.
174 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target )
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");
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 ) ."]";
196 $histlink="(".$sk->makeKnownLink($page,wfMsg("hist"),"action=history").")";
198 if($comment) {
200 $comment="<em>(". $sk->formatComment($comment ) .")</em> ";
203 $d = $wgLang->timeanddate( $ts, true );
205 if ($isminor) {
206 $mflag = '<span class="minor">'.wfMsg( "minoreditletter" ).'</span> ';
207 } else {
208 $mflag = "";
211 $wgOut->addHTML( "<li>{$d} {$histlink} {$mflag} {$link} {$comment}{$topmarktext}</li>\n" );
214 function ucCountLink( $lim, $d )
216 global $wgUser, $wgLang, $wgRequest;
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;
225 function ucDaysLink( $lim, $d )
227 global $wgUser, $wgLang, $wgRequest;
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;