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