revert r106095, fix apparently not this simple
[lhc/web/wiklou.git] / includes / specials / SpecialContributions.php
index 307181c..aa97ad8 100644 (file)
@@ -74,24 +74,22 @@ class SpecialContributions extends SpecialPage {
                $this->opts['target'] = $target;
                $this->opts['topOnly'] = $request->getBool( 'topOnly' );
 
-               $nt = Title::makeTitleSafe( NS_USER, $target );
-               if( !$nt ) {
+               $userObj = User::newFromName( $target, false );
+               if( !$userObj ) {
                        $out->addHTML( $this->getForm() );
                        return;
                }
-               $id = User::idFromName( $nt->getText() );
+               $nt = $userObj->getUserPage();
+               $id = $userObj->getID();
 
                if( $this->opts['contribs'] != 'newbie' ) {
                        $target = $nt->getText();
-                       $out->setSubtitle( $this->contributionsSub( $nt, $id ) );
-                       $out->setHTMLTitle( wfMsg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ),$target ) ) );
-                       $userObj = User::newFromName( $target, false );
-                       if ( is_object( $userObj ) ) {
-                               $this->getSkin()->setRelevantUser( $userObj );
-                       }
+                       $out->addSubtitle( $this->contributionsSub( $userObj ) );
+                       $out->setHTMLTitle( $this->msg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ), $target ) ) );
+                       $this->getSkin()->setRelevantUser( $userObj );
                } else {
-                       $out->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') );
-                       $out->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) );
+                       $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub') );
+                       $out->setHTMLTitle( $this->msg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) );
                }
 
                if( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) {
@@ -100,7 +98,9 @@ class SpecialContributions extends SpecialPage {
                        $this->opts['namespace'] = '';
                }
 
-               $this->opts['tagFilter'] = (string) $request->getVal( 'tagFilter' );
+               $this->opts['nsInvert'] = (bool) $request->getVal( 'nsInvert' );
+
+               $this->opts['tagfilter'] = (string) $request->getVal( 'tagfilter' );
 
                // Allows reverts to have the bot flag in recent changes. It is just here to
                // be passed in the form at the top of the page
@@ -133,8 +133,8 @@ class SpecialContributions extends SpecialPage {
                        if ( $this->opts['deletedOnly'] ) {
                                $apiParams['deletedonly'] = true;
                        }
-                       if ( $this->opts['tagFilter'] !== '' ) {
-                               $apiParams['tagfilter'] = $this->opts['tagFilter'];
+                       if ( $this->opts['tagfilter'] !== '' ) {
+                               $apiParams['tagfilter'] = $this->opts['tagfilter'];
                        }
                        if ( $this->opts['namespace'] !== '' ) {
                                $apiParams['namespace'] = $this->opts['namespace'];
@@ -167,6 +167,7 @@ class SpecialContributions extends SpecialPage {
                                'month' => $this->opts['month'],
                                'deletedOnly' => $this->opts['deletedOnly'],
                                'topOnly' => $this->opts['topOnly'],
+                               'nsInvert' => $this->opts['nsInvert'],
                        ) );
                        if( !$pager->getNumRows() ) {
                                $out->addWikiMsg( 'nocontribs', $target );
@@ -190,8 +191,7 @@ class SpecialContributions extends SpecialPage {
                                if ( IP::isIPAddress( $target ) ) {
                                        $message = 'sp-contributions-footer-anon';
                                } else {
-                                       $userObj = User::newFromName( $target );
-                                       if ( !$userObj || $userObj->isAnon() ) {
+                                       if ( $userObj->isAnon() ) {
                                                // No message for non-existing users
                                                return;
                                        }
@@ -208,22 +208,21 @@ class SpecialContributions extends SpecialPage {
 
        /**
         * Generates the subheading with links
-        * @param $nt Title object for the target
-        * @param $id Integer: User ID for the target
+        * @param $userObj User object for the target
         * @return String: appropriately-escaped HTML to be output literally
         * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined.
         */
-       protected function contributionsSub( $nt, $id ) {
-               if ( $id === null ) {
-                       $user = htmlspecialchars( $nt->getText() );
+       protected function contributionsSub( $userObj ) {
+               if ( $userObj->isAnon() ) {
+                       $user = htmlspecialchars( $userObj->getName() );
                } else {
-                       $user = Linker::link( $nt, htmlspecialchars( $nt->getText() ) );
+                       $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
                }
-               $userObj = User::newFromName( $nt->getText(), /* check for username validity not needed */ false );
-               $talk = $nt->getTalkPage();
+               $nt = $userObj->getUserPage();
+               $talk = $userObj->getTalkPage();
                if( $talk ) {
                        $tools = self::getUserLinks( $nt, $talk, $userObj, $this->getUser() );
-                       $links = $this->getLang()->pipeList( $tools );
+                       $links = $this->getLanguage()->pipeList( $tools );
 
                        // Show a note if the user is blocked and display the last block log entry.
                        if ( $userObj->isBlocked() ) {
@@ -240,7 +239,7 @@ class SpecialContributions extends SpecialPage {
                                                        $userObj->isAnon() ?
                                                                'sp-contributions-blocked-notice-anon' :
                                                                'sp-contributions-blocked-notice',
-                                                       $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice'
+                                                       $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
                                                ),
                                                'offset' => '' # don't use WebRequest parameter offset
                                        )
@@ -252,10 +251,11 @@ class SpecialContributions extends SpecialPage {
                // languages that want to put the "for" bit right after $user but before
                // $links.  If 'contribsub' is around, use it for reverse compatibility,
                // otherwise use 'contribsub2'.
-               if( wfEmptyMsg( 'contribsub' ) ) {
-                       return wfMsgHtml( 'contribsub2', $user, $links );
+               $oldMsg = $this->msg( 'contribsub' );
+               if ( $oldMsg->exists() ) {
+                       return $oldMsg->rawParams( "$user ($links)" );
                } else {
-                       return wfMsgHtml( 'contribsub', "$user ($links)" );
+                       return $this->msg( 'contribsub2' )->rawParams( $user, $links );
                }
        }
 
@@ -353,6 +353,10 @@ class SpecialContributions extends SpecialPage {
                        $this->opts['namespace'] = '';
                }
 
+               if( !isset( $this->opts['nsInvert'] ) ) {
+                       $this->opts['nsInvert'] = '';
+               }
+
                if( !isset( $this->opts['contribs'] ) ) {
                        $this->opts['contribs'] = 'user';
                }
@@ -369,8 +373,8 @@ class SpecialContributions extends SpecialPage {
                        $this->opts['target'] = '';
                }
 
-               if( !isset( $this->opts['tagFilter'] ) ) {
-                       $this->opts['tagFilter'] = '';
+               if( !isset( $this->opts['tagfilter'] ) ) {
+                       $this->opts['tagfilter'] = '';
                }
 
                if( !isset( $this->opts['topOnly'] ) ) {
@@ -380,7 +384,7 @@ class SpecialContributions extends SpecialPage {
                $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'class' => 'mw-contributions-form' ) );
 
                # Add hidden params for tracking except for parameters in $skipParameters
-               $skipParameters = array( 'namespace', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly' );
+               $skipParameters = array( 'namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly' );
                foreach ( $this->opts as $name => $value ) {
                        if( in_array( $name, $skipParameters ) ) {
                                continue;
@@ -388,7 +392,7 @@ class SpecialContributions extends SpecialPage {
                        $f .= "\t" . Html::hidden( $name, $value ) . "\n";
                }
 
-               $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagFilter'] );
+               $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] );
 
                $f .=   Xml::fieldset( wfMsg( 'sp-contributions-search' ) ) .
                        Xml::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parsemag' ) ),
@@ -403,6 +407,7 @@ class SpecialContributions extends SpecialPage {
                                Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
                                Xml::namespaceSelector( $this->opts['namespace'], '' )
                        ) .
+                       Xml::checkLabel( wfMsg('invert'), 'nsInvert', 'nsInvert', $this->opts['nsInvert'] ) . ' ' .
                        Xml::checkLabel( wfMsg( 'history-show-deleted' ),
                                'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'] ) . '<br />' .
                        Xml::tags( 'p', null, Xml::checkLabel( wfMsg( 'sp-contributions-toponly' ),
@@ -444,7 +449,8 @@ class ContribsPager extends ReverseChronologicalPager {
                $this->target = isset( $options['target'] ) ? $options['target'] : '';
                $this->contribs = isset( $options['contribs'] ) ? $options['contribs'] : 'users';
                $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
-               $this->tagFilter = isset( $options['tagFilter'] ) ? $options['tagFilter'] : false;
+               $this->tagFilter = isset( $options['tagfilter'] ) ? $options['tagfilter'] : false;
+               $this->nsInvert = isset( $options['nsInvert'] ) ? $options['nsInvert'] : false;
 
                $this->deletedOnly = !empty( $options['deletedOnly'] );
                $this->topOnly = !empty( $options['topOnly'] );
@@ -467,6 +473,7 @@ class ContribsPager extends ReverseChronologicalPager {
 
                $user = $this->getUser();
                $conds = array_merge( $userCond, $this->getNamespaceCond() );
+
                // Paranoia: avoid brute force searches (bug 17342)
                if( !$user->isAllowed( 'deletedhistory' ) ) {
                        $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0';
@@ -476,9 +483,9 @@ class ContribsPager extends ReverseChronologicalPager {
                }
 
                # Don't include orphaned revisions
-               $join_cond['page'] = array( 'INNER JOIN', 'page_id = rev_page' );
+               $join_cond['page'] = Revision::pageJoinCond();
                # Get the current user name for accounts
-               $join_cond['user'] = array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' );
+               $join_cond['user'] = Revision::userJoinCond();
 
                $queryInfo = array(
                        'tables'     => $tables,
@@ -538,7 +545,11 @@ class ContribsPager extends ReverseChronologicalPager {
 
        function getNamespaceCond() {
                if( $this->namespace !== '' ) {
-                       return array( 'page_namespace' => (int)$this->namespace );
+                       if ( $this->nsInvert ) {
+                               return array( 'page_namespace != ' . (int)$this->namespace );
+                       } else {
+                               return array( 'page_namespace' => (int)$this->namespace );
+                       }
                } else {
                        return array();
                }
@@ -549,18 +560,14 @@ class ContribsPager extends ReverseChronologicalPager {
        }
 
        function doBatchLookups() {
-               global $wgRCShowChangedSize;
-
-               $this->mParentLens = array();
-               if ( $wgRCShowChangedSize ) {
-                       $this->mResult->rewind();
-                       $revIds = array();
-                       foreach ( $this->mResult as $row ) {
-                               $revIds[] = $row->rev_parent_id;
-                       }
-                       $this->mParentLens = $this->getParentLengths( $revIds );
-                       $this->mResult->rewind(); // reset
+               $this->mResult->rewind();
+               $revIds = array();
+               foreach ( $this->mResult as $row ) {
+                       $revIds[] = $row->rev_parent_id;
                }
+               $this->mParentLens = $this->getParentLengths( $revIds );
+               $this->mResult->rewind(); // reset
+
                if ( $this->contribs === 'newbie' ) { // multiple users
                        # Do a link batch query
                        $this->mResult->seek( 0 );
@@ -575,7 +582,7 @@ class ContribsPager extends ReverseChronologicalPager {
                }
        }
 
-       /*
+       /**
         * Do a batched query to get the parent revision lengths
         */
        private function getParentLengths( array $revIds ) {
@@ -667,8 +674,8 @@ class ContribsPager extends ReverseChronologicalPager {
                        $chardiff = ' ';
                }
 
-               $comment = $this->getLang()->getDirMark() . Linker::revComment( $rev, false, true );
-               $date = $this->getLang()->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
+               $comment = $this->getLanguage()->getDirMark() . Linker::revComment( $rev, false, true );
+               $date = $this->getLanguage()->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
                if( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
                        $d = Linker::linkKnown(
                                $page,