4 * @subpackage SpecialPage
8 * Special page "user contributions".
9 * Shows a list of the contributions of a user.
12 * @param string $par (optional) user name of the user for which to show the contributions
14 function wfSpecialContributions( $par = null ) {
15 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
16 $fname = 'wfSpecialContributions';
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);
25 if ( '' == $target ) {
26 $wgOut->errorpage( 'notargettitle', 'notargettext' );
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
);
37 $nt = Title
::newFromURL( $target );
39 $wgOut->errorpage( 'notargettitle', 'notargettext' );
42 $nt =& Title
::makeTitle( NS_USER
, $nt->getDBkey() );
44 $id = User
::idFromName( $nt->getText() );
49 $ul = $sk->makeLinkObj( $nt, htmlspecialchars( $nt->getText() ) );
50 $userCond = '=' . $id;
52 $talk = $nt->getTalkPage();
54 $ul .= ' (' . $sk->makeLinkObj( $talk, $wgLang->getNsText( NS_TALK
) ) . ')';
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' );
66 $wgOut->setSubtitle( wfMsg( 'contribsub', $ul ) );
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}" );
75 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Contributions" ),
76 WfMsg( 'hide' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
77 "&offset={$offset}&limit={$limit}&hideminor=1&namespace={$namespace}" );
80 if( !is_null($namespace) ) {
81 $minorQuery .= ' AND page_namespace ' . ($invert ?
'!' : '') . "= {$namespace}";
84 extract( $dbr->tableNames( 'page', 'revision' ) );
85 if ( $userCond == "" ) {
86 $condition = "rev_user_text=" . $dbr->addQuotes( $nt->getText() );
87 $index = 'usertext_timestamp';
89 $condition = "rev_user {$userCond}";
90 $index = 'user_timestamp';
94 $use_index = $dbr->useIndexClause( $index );
96 page_namespace,page_title,page_is_new,page_latest,
97 rev_id,rev_timestamp,rev_comment,rev_minor_edit,rev_user_text,
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 );
105 $wgOut->addHTML( ucNamespaceForm( $target, $hideminor, $namespace, $invert ) );
107 $top = wfShowingResults( $offset, $limit );
108 $wgOut->addHTML( "<p>{$top}\n" );
110 $sl = wfViewPrevNext( $offset, $limit,
111 $wgContLang->specialpage( "Contributions" ),
112 "hideminor={$hideminor}&namespace={$namespace}&target=" . wfUrlEncode( $target ),
113 ($numRows) <= $limit);
115 $shm = wfMsg( "showhideminor", $mlink );
116 $wgOut->addHTML( "<br />{$sl} ($shm)</p>\n");
119 if ( 0 == $numRows ) {
120 $wgOut->addHTML( "\n<p>" . wfMsg( "nocontribs" ) . "</p>\n" );
124 $wgOut->addHTML( "<ul>\n" );
126 while( $obj = $dbr->fetchObject( $res ) ) {
127 if( ++
$n > $limit ) {
128 // Extra row for determining 'next'ability, don't display
131 $wgOut->addHTML( ucListEdit( $sk, $obj ) );
133 $dbr->freeResult( $res );
134 $wgOut->addHTML( "</ul>\n" );
136 $wgOut->addHTML( "<br />{$sl} ($shm)\n");
141 * Generates each row in the contributions list.
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.
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
154 * @todo This would probably look a lot nicer in a table.
156 function ucListEdit( $sk, $row ) {
157 $fname = 'ucListEdit';
158 wfProfileIn( $fname );
160 global $wgLang, $wgOut, $wgUser, $wgRequest;
162 if( !isset( $messages ) ) {
163 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
164 $messages[$msg] = wfMsg( $msg );
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' );
176 $difftext .= $messages['newarticle'];
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 ) .']';
189 if( $row->rev_deleted
&& !$wgUser->isAllowed( 'undelete' ) ) {
190 $difftext = '(' . $messages['diff'] . ')';
192 $difftext = $sk->makeKnownLinkObj( $page, '(' . $messages['diff'].')', 'diff=prev&oldid='.$row->rev_id
);
194 $histlink='('.$sk->makeKnownLinkObj( $page, $messages['hist'], 'action=history' ) . ')';
196 $comment = $sk->commentBlock( $row->rev_comment
, $page );
197 $d = $wgLang->timeanddate( $row->rev_timestamp
, true );
199 if( $row->rev_minor_edit
) {
200 $mflag = '<span class="minor">' . $messages['minoreditletter'] . '</span> ';
205 $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
206 if( $row->rev_deleted
) {
207 $ret = '<span class="deleted">' . $ret . '</span> ' . htmlspecialchars( wfMsg( 'deletedrev' ) );
209 $ret = "<li>$ret</li>\n";
210 wfProfileOut( $fname );
215 * Generates a form used to restrict display of contributions
216 * to a specific namespace
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)
224 function ucNamespaceForm ( $target, $hideminor, $namespace, $invert ) {
225 global $wgContLang, $wgScript;
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 ) {
233 $n = $ns === NS_MAIN ?
wfMsg ( 'blanknamespace' ) : $name;
234 $sel = $namespace == $ns ?
' selected="selected"' : '';
235 $namespaceselect .= "<option value='$ns'$sel>$n</option>";
237 $namespaceselect .= '</select>';
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.'" />';
244 <div id='nsselect' class='contributions'>
245 <label for='nsselectbox'>" . wfMsg('namespace') . "</label>
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>
251 $out .= '</form></div>';