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