* (bug 829) Fix URL-escaping on block success
[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( 'old', 'cur' ) );
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 $page = $dbr->tableName( 'page' );
100 $revision = $dbr->tableName( 'revision' );
101 $sql = "SELECT
102 page_namespace,page_title,page_is_new,page_latest,
103 rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text
104 FROM $page,$revision USE INDEX($index)
105 WHERE page_id=rev_page AND $condition $minorQuery " .
106 "ORDER BY inverse_timestamp LIMIT {$querylimit}";
107 $res = $dbr->query( $sql, $fname );
108 $numRows = $dbr->numRows( $res );
109
110 $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace ) );
111
112 $top = wfShowingResults( $offset, $limit );
113 $wgOut->addHTML( "<p>{$top}\n" );
114
115 $sl = wfViewPrevNext( $offset, $limit,
116 $wgContLang->specialpage( "Contributions" ),
117 "hideminor={$hideminor}&namespace={$namespace}&target=" . wfUrlEncode( $target ),
118 ($numRows) <= $offlimit);
119
120 $shm = wfMsg( "showhideminor", $mlink );
121 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
122
123
124 if ( 0 == $numRows ) {
125 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
126 return;
127 }
128
129 $wgOut->addHTML( "<ul>\n" );
130 while( $obj = $dbr->fetchObject( $res ) ) {
131 ucListEdit( $sk,
132 $obj->page_namespace,
133 $obj->page_title,
134 $obj->rev_timestamp,
135 ($obj->rev_id == $obj->page_latest),
136 $obj->rev_comment,
137 ($obj->rev_minor_edit),
138 $obj->page_is_new,
139 $obj->rev_user_text,
140 $obj->rev_id );
141 }
142 $wgOut->addHTML( "</ul>\n" );
143
144 # Validations
145 global $wgUseValidation;
146 if( $wgUseValidation ) {
147 require_once( 'SpecialValidate.php' );
148 $val = new Validation ;
149 $val = $val->countUserValidations ( $id ) ;
150 $wgOut->addHTML( wfMsg ( 'val_user_validations', $val ) );
151 }
152
153 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
154 }
155
156
157 /**
158 * Generates each row in the contributions list.
159 *
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.
164 *
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.
170 *
171 * @todo This would probably look a lot nicer in a table.
172 */
173 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
174 $fname = 'ucListEdit';
175 wfProfileIn( $fname );
176
177 global $wgLang, $wgOut, $wgUser, $wgRequest;
178 static $messages;
179 if( !isset( $messages ) ) {
180 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
181 $messages[$msg] = wfMsg( $msg );
182 }
183 }
184
185 $page =& Title::makeTitle( $ns, $t );
186 $link = $sk->makeKnownLinkObj( $page, '' );
187 $difftext = $topmarktext = '';
188 if($topmark) {
189 $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
190 if(!$isnew) {
191 $difftext .= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'] . ')', 'diff=0' );
192 } else {
193 $difftext .= $messages['newarticle'];
194 }
195
196 if( $wgUser->isAllowed('rollback') ) {
197 $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
198 # $target = $wgRequest->getText( 'target' );
199 $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
200 $messages['rollbacklink'],
201 'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
202 }
203
204 }
205 if ( $oldid ) {
206 $difftext= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$oldid );
207 }
208 $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
209
210 if( $comment ) {
211 $comment = '<em>(' . $sk->formatComment( $comment, $page ) . ')</em> ';
212 }
213 $d = $wgLang->timeanddate( $ts, true );
214
215 if ($isminor) {
216 $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
217 } else {
218 $mflag = '';
219 }
220
221 $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
222 wfProfileOut( $fname );
223 }
224
225 /**
226 *
227 */
228 function ucCountLink( $lim, $d ) {
229 global $wgUser, $wgContLang, $wgRequest;
230
231 $target = $wgRequest->getText( 'target' );
232 $sk = $wgUser->getSkin();
233 $s = $sk->makeKnownLink( $wgContLang->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, $wgContLang, $wgRequest;
243
244 $target = $wgRequest->getText( 'target' );
245 $sk = $wgUser->getSkin();
246 $s = $sk->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
247 "{$d}", "target={$target}&days={$d}&limit={$lim}" );
248 return $s;
249 }
250
251 /**
252 * Generates a form used to restrict display of contributions
253 * to a specific namespace
254 *
255 * @return none
256 * @param string $target target user to show contributions for
257 * @param string $hideminor whether minor contributions are hidden
258 * @param string $namespace currently selected namespace, NULL for show all
259 */
260 function namespaceForm ( $target, $hideminor, $namespace ) {
261 global $wgContLang, $wgScript;
262
263 $namespaceselect = '<form><select name="namespace">';
264 $namespaceselect .= '<option value="" '.(is_null($namespace) ? ' selected="selected"' : '').'>'.wfMsg( 'all' ).'</option>';
265 $arr = $wgContLang->getNamespaces();
266 foreach( array_keys( $arr ) as $i ) {
267 if( $i < 0 ) {
268 continue;
269 }
270 $namespacename = str_replace ( "_", " ", $arr[$i] );
271 $n = ($i == 0) ? wfMsg ( 'articlenamespace' ) : $namespacename;
272 $sel = ($i === $namespace) ? ' selected="selected"' : '';
273 $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>";
274 }
275 $namespaceselect .= '</select>';
276
277 $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
278
279 $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
280 $out .= '<input type="hidden" name="title" value="'.$wgContLang->specialpage( 'Contributions' ).'" />';
281 $out .= '<input type="hidden" name="target" value="'.htmlspecialchars( $target ).'" />';
282 $out .= '<input type="hidden" name="hideminor" value="'.$hideminor.'" />';
283 $out .= wfMsg ( 'allpagesformtext2', $namespaceselect, $submitbutton );
284 $out .= '</form></div>';
285 return $out;
286 }
287 ?>