246715829614050e6238738aef836fffbe2a90e8
[lhc/web/wiklou.git] / includes / SpecialContributions.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Special page "user contributions".
10 * Shows a list of the contributions of a user.
11 *
12 * @return none
13 * @param string $par (optional) user name of the user for which to show the contributions
14 */
15 function wfSpecialContributions( $par = '' ) {
16 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
17 $fname = 'wfSpecialContributions';
18
19 if( $par )
20 $target = $par;
21 else
22 $target = $wgRequest->getVal( 'target' );
23
24 if ( '' == $target ) {
25 $wgOut->errorpage( 'notargettitle', 'notargettext' );
26 return;
27 }
28
29 # FIXME: Change from numeric offsets to date offsets
30 list( $limit, $offset ) = wfCheckLimits( 50, '' );
31 $offlimit = $limit + $offset;
32 $querylimit = $offlimit + 1;
33 $hideminor = ($wgRequest->getVal( 'hideminor' ) ? 1 : 0);
34 $sk = $wgUser->getSkin();
35 $dbr =& wfGetDB( DB_SLAVE );
36 $userCond = "";
37 $namespace = $wgRequest->getVal( 'namespace', '' );
38 if( $namespace != '' ) {
39 $namespace = IntVal( $namespace );
40 } else {
41 $namespace = NULL;
42 }
43
44 $nt = Title::newFromURL( $target );
45 if ( !$nt ) {
46 $wgOut->errorpage( 'notargettitle', 'notargettext' );
47 return;
48 }
49 $nt =& Title::makeTitle( NS_USER, $nt->getDBkey() );
50
51 $id = User::idFromName( $nt->getText() );
52
53 if ( 0 == $id ) {
54 $ul = $nt->getText();
55 } else {
56 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
57 $userCond = '=' . $id;
58 }
59 $talk = $nt->getTalkPage();
60 if( $talk ) {
61 $ul .= ' (' . $sk->makeLinkObj( $talk, $wgLang->getNsText(Namespace::getTalk(0)) ) . ')';
62 }
63
64
65 if ( $target == 'newbies' ) {
66 # View the contributions of all recently created accounts
67 $max = $dbr->selectField( 'user', 'max(user_id)', false, $fname );
68 $userCond = '>' . ($max - $max / 100);
69 $ul = wfMsg ( 'newbies' );
70 $id = 0;
71 }
72
73 $wgOut->setSubtitle( wfMsg( 'contribsub', $ul ) );
74
75 if ( $hideminor ) {
76 $minorQuery = "AND rev_minor_edit=0";
77 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
78 WfMsg( "show" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
79 "&offset={$offset}&limit={$limit}&hideminor=0&namespace={$namespace}" );
80 } else {
81 $minorQuery = "";
82 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
83 WfMsg( 'hide' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
84 "&offset={$offset}&limit={$limit}&hideminor=1&namespace={$namespace}" );
85 }
86
87 if( !is_null($namespace) ) {
88 $minorQuery .= " AND page_namespace = {$namespace}";
89 }
90
91 extract( $dbr->tableNames( 'page', 'revision' ) );
92 if ( $userCond == "" ) {
93 $condition = "rev_user_text=" . $dbr->addQuotes( $nt->getText() );
94 $index = 'usertext_timestamp';
95 } else {
96 $condition = "rev_user {$userCond}";
97 $index = 'user_timestamp';
98 }
99
100 $sql = "SELECT
101 page_namespace,page_title,page_is_new,page_latest,
102 rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text
103 FROM $page,$revision USE INDEX($index)
104 WHERE page_id=rev_page AND $condition $minorQuery " .
105 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
106 $res = $dbr->query( $sql, $fname );
107 $numRows = $dbr->numRows( $res );
108
109 $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace ) );
110
111 $top = wfShowingResults( $offset, $limit );
112 $wgOut->addHTML( "<p>{$top}\n" );
113
114 $sl = wfViewPrevNext( $offset, $limit,
115 $wgContLang->specialpage( "Contributions" ),
116 "hideminor={$hideminor}&namespace={$namespace}&target=" . wfUrlEncode( $target ),
117 ($numRows) <= $offlimit);
118
119 $shm = wfMsg( "showhideminor", $mlink );
120 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
121
122
123 if ( 0 == $numRows ) {
124 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
125 return;
126 }
127
128 $wgOut->addHTML( "<ul>\n" );
129 while( $obj = $dbr->fetchObject( $res ) ) {
130 ucListEdit( $sk,
131 $obj->page_namespace,
132 $obj->page_title,
133 $obj->rev_timestamp,
134 ($obj->rev_id == $obj->page_latest),
135 $obj->rev_comment,
136 ($obj->rev_minor_edit),
137 $obj->page_is_new,
138 $obj->rev_user_text,
139 $obj->rev_id );
140 }
141 $wgOut->addHTML( "</ul>\n" );
142
143 # Validations
144 global $wgUseValidation;
145 if( $wgUseValidation ) {
146 require_once( 'SpecialValidate.php' );
147 $val = new Validation ;
148 $val = $val->countUserValidations ( $id ) ;
149 $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
150 }
151
152 $wgOut->addHTML( "<br />{$sl} ($shm)\n");
153 }
154
155
156 /**
157 * Generates each row in the contributions list.
158 *
159 * Contributions which are marked "top" are currently on top of the history.
160 * For these contributions, a [rollback] link is shown for users with sysop
161 * privileges. The rollback link restores the most recent version that was not
162 * written by the target user.
163 *
164 * If the contributions page is called with the parameter &bot=1, all rollback
165 * links also get that parameter. It causes the edit itself and the rollback
166 * to be marked as "bot" edits. Bot edits are hidden by default from recent
167 * changes, so this allows sysops to combat a busy vandal without bothering
168 * other users.
169 *
170 * @todo This would probably look a lot nicer in a table.
171 */
172 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
173 $fname = 'ucListEdit';
174 wfProfileIn( $fname );
175
176 global $wgLang, $wgOut, $wgUser, $wgRequest;
177 static $messages;
178 if( !isset( $messages ) ) {
179 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
180 $messages[$msg] = wfMsg( $msg );
181 }
182 }
183
184 $page =& Title::makeTitle( $ns, $t );
185 $link = $sk->makeKnownLinkObj( $page, '' );
186 $difftext = $topmarktext = '';
187 if($topmark) {
188 $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
189 if(!$isnew) {
190 $difftext .= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'] . ')', 'diff=0' );
191 } else {
192 $difftext .= $messages['newarticle'];
193 }
194
195 if( $wgUser->isAllowed('rollback') ) {
196 $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
197 # $target = $wgRequest->getText( 'target' );
198 $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
199 $messages['rollbacklink'],
200 'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
201 }
202
203 }
204 if ( $oldid ) {
205 $difftext= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$oldid );
206 }
207 $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
208
209 if( $comment ) {
210 $comment = '<em>(' . $sk->formatComment( $comment, $page ) . ')</em> ';
211 }
212 $d = $wgLang->timeanddate( $ts, true );
213
214 if ($isminor) {
215 $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
216 } else {
217 $mflag = '';
218 }
219
220 $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
221 wfProfileOut( $fname );
222 }
223
224 /**
225 *
226 */
227 function ucCountLink( $lim, $d ) {
228 global $wgUser, $wgContLang, $wgRequest;
229
230 $target = $wgRequest->getText( 'target' );
231 $sk = $wgUser->getSkin();
232 $s = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
233 "{$lim}", "target={$target}&days={$d}&limit={$lim}" );
234 return $s;
235 }
236
237 /**
238 *
239 */
240 function ucDaysLink( $lim, $d ) {
241 global $wgUser, $wgContLang, $wgRequest;
242
243 $target = $wgRequest->getText( 'target' );
244 $sk = $wgUser->getSkin();
245 $s = $sk->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
246 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
247 return $s;
248 }
249
250 /**
251 * Generates a form used to restrict display of contributions
252 * to a specific namespace
253 *
254 * @return none
255 * @param string $target target user to show contributions for
256 * @param string $hideminor whether minor contributions are hidden
257 * @param string $namespace currently selected namespace, NULL for show all
258 */
259 function namespaceForm ( $target, $hideminor, $namespace ) {
260 global $wgContLang, $wgScript;
261
262 $namespaceselect = '<select name="namespace">';
263 $namespaceselect .= '<option value="" '.(is_null($namespace) ? ' selected="selected"' : '').'>'.wfMsg( 'all' ).'</option>';
264 $arr = $wgContLang->getNamespaces();
265 foreach( array_keys( $arr ) as $i ) {
266 if( $i < 0 ) {
267 continue;
268 }
269 $namespacename = str_replace ( "_", " ", $arr[$i] );
270 $n = ($i == 0) ? wfMsg ( 'articlenamespace' ) : $namespacename;
271 $sel = ($i === $namespace) ? ' selected="selected"' : '';
272 $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>";
273 }
274 $namespaceselect .= '</select>';
275
276 $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
277
278 $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
279 $out .= '<input type="hidden" name="title" value="'.$wgContLang->specialpage( 'Contributions' ).'" />';
280 $out .= '<input type="hidden" name="target" value="'.htmlspecialchars( $target ).'" />';
281 $out .= '<input type="hidden" name="hideminor" value="'.$hideminor.'" />';
282 $out .= wfMsg ( 'allpagesformtext2', $namespaceselect, $submitbutton );
283 $out .= '</form></div>';
284 return $out;
285 }
286 ?>