didn't mean to commit that comment
[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( NS_TALK ) ) . ')';
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
101 $use_index = $dbr->useIndexClause( $index );
102 $sql = "SELECT
103 page_namespace,page_title,page_is_new,page_latest,
104 rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text
105 FROM $page,$revision $use_index
106 WHERE page_id=rev_page AND $condition $minorQuery " .
107 "ORDER BY rev_timestamp DESC LIMIT {$querylimit}";
108 $res = $dbr->query( $sql, $fname );
109 $numRows = $dbr->numRows( $res );
110
111 $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace ) );
112
113 $top = wfShowingResults( $offset, $limit );
114 $wgOut->addHTML( "<p>{$top}\n" );
115
116 $sl = wfViewPrevNext( $offset, $limit,
117 $wgContLang->specialpage( "Contributions" ),
118 "hideminor={$hideminor}&namespace={$namespace}&target=" . wfUrlEncode( $target ),
119 ($numRows) <= $offlimit);
120
121 $shm = wfMsg( "showhideminor", $mlink );
122 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
123
124
125 if ( 0 == $numRows ) {
126 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
127 return;
128 }
129
130 $wgOut->addHTML( "<ul>\n" );
131 while( $obj = $dbr->fetchObject( $res ) ) {
132 ucListEdit( $sk,
133 $obj->page_namespace,
134 $obj->page_title,
135 $obj->rev_timestamp,
136 ($obj->rev_id == $obj->page_latest),
137 $obj->rev_comment,
138 ($obj->rev_minor_edit),
139 $obj->page_is_new,
140 $obj->rev_user_text,
141 $obj->rev_id );
142 }
143 $wgOut->addHTML( "</ul>\n" );
144
145 $wgOut->addHTML( "<br />{$sl} ($shm)\n");
146 }
147
148
149 /**
150 * Generates each row in the contributions list.
151 *
152 * Contributions which are marked "top" are currently on top of the history.
153 * For these contributions, a [rollback] link is shown for users with sysop
154 * privileges. The rollback link restores the most recent version that was not
155 * written by the target user.
156 *
157 * If the contributions page is called with the parameter &bot=1, all rollback
158 * links also get that parameter. It causes the edit itself and the rollback
159 * to be marked as "bot" edits. Bot edits are hidden by default from recent
160 * changes, so this allows sysops to combat a busy vandal without bothering
161 * other users.
162 *
163 * @todo This would probably look a lot nicer in a table.
164 */
165 function ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment, $isminor, $isnew, $target, $oldid ) {
166 $fname = 'ucListEdit';
167 wfProfileIn( $fname );
168
169 global $wgLang, $wgOut, $wgUser, $wgRequest;
170 static $messages;
171 if( !isset( $messages ) ) {
172 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
173 $messages[$msg] = wfMsg( $msg );
174 }
175 }
176
177 $page =& Title::makeTitle( $ns, $t );
178 $link = $sk->makeKnownLinkObj( $page, '' );
179 $difftext = $topmarktext = '';
180 if($topmark) {
181 $topmarktext .= '<strong>' . $messages['uctop'] . '</strong>';
182 if(!$isnew) {
183 $difftext .= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'] . ')', 'diff=0' );
184 } else {
185 $difftext .= $messages['newarticle'];
186 }
187
188 if( $wgUser->isAllowed('rollback') ) {
189 $extraRollback = $wgRequest->getBool( 'bot' ) ? '&bot=1' : '';
190 $extraRollback .= '&token=' . urlencode(
191 $wgUser->editToken( array( $page->getPrefixedText(), $target ) ) );
192 # $target = $wgRequest->getText( 'target' );
193 $topmarktext .= ' ['. $sk->makeKnownLinkObj( $page,
194 $messages['rollbacklink'],
195 'action=rollback&from=' . urlencode( $target ) . $extraRollback ) .']';
196 }
197
198 }
199 if ( $oldid ) {
200 $difftext= $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$oldid );
201 }
202 $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
203
204 $comment = $sk->commentBlock( $comment, $page );
205 $d = $wgLang->timeanddate( $ts, true );
206
207 if ($isminor) {
208 $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
209 } else {
210 $mflag = '';
211 }
212
213 $wgOut->addHTML( "<li>{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}</li>\n" );
214 wfProfileOut( $fname );
215 }
216
217 /**
218 * Generates a form used to restrict display of contributions
219 * to a specific namespace
220 *
221 * @return none
222 * @param string $target target user to show contributions for
223 * @param string $hideminor whether minor contributions are hidden
224 * @param string $namespace currently selected namespace, NULL for show all
225 */
226 function namespaceForm ( $target, $hideminor, $namespace ) {
227 global $wgContLang, $wgScript;
228
229 $namespaceselect = '<select name="namespace">';
230 $namespaceselect .= '<option value="" '.(is_null($namespace) ? ' selected="selected"' : '').'>'.wfMsg( 'all' ).'</option>';
231 $arr = $wgContLang->getNamespaces();
232 foreach( array_keys( $arr ) as $i ) {
233 if( $i < 0 ) {
234 continue;
235 }
236 $namespacename = str_replace ( "_", " ", $arr[$i] );
237 $n = ($i == 0) ? wfMsg ( 'articlenamespace' ) : $namespacename;
238 $sel = ($i === $namespace) ? ' selected="selected"' : '';
239 $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>";
240 }
241 $namespaceselect .= '</select>';
242
243 $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
244
245 $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>";
246 $out .= '<input type="hidden" name="title" value="'.$wgContLang->specialpage( 'Contributions' ).'" />';
247 $out .= '<input type="hidden" name="target" value="'.htmlspecialchars( $target ).'" />';
248 $out .= '<input type="hidden" name="hideminor" value="'.$hideminor.'" />';
249 $out .= wfMsg ( 'allpagesformtext2', $namespaceselect, $submitbutton );
250 $out .= '</form></div>';
251 return $out;
252 }
253 ?>