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