(bug 24037) Add byte length of revision to Special:Contributions. Patch by Umherirrender
[lhc/web/wiklou.git] / includes / specials / SpecialContributions.php
index df4db79..6c732cb 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->setHTMLTitleMsg( '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->setHTMLTitleMsg( '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,6 +98,8 @@ class SpecialContributions extends SpecialPage {
                        $this->opts['namespace'] = '';
                }
 
+               $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
@@ -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,19 +208,18 @@ 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 );
@@ -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';
                }
@@ -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;
@@ -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' ),
@@ -445,6 +450,7 @@ class ContribsPager extends ReverseChronologicalPager {
                $this->contribs = isset( $options['contribs'] ) ? $options['contribs'] : 'users';
                $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
                $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';
@@ -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();
                }
@@ -701,6 +712,12 @@ class ContribsPager extends ReverseChronologicalPager {
                        $mflag = '';
                }
 
+               if ( !is_null( $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) {
+                       $mSize = $this->getSkin()->formatRevisionSize( $rev->getSize() );
+               } else {
+                       $mSize = '';
+               }
+
                // Don't show useless link to people who cannot hide revisions
                $canHide = $user->isAllowed( 'deleterevision' );
                if( $canHide || ($rev->getVisibility() && $user->isAllowed('deletedhistory')) ) {
@@ -721,7 +738,7 @@ class ContribsPager extends ReverseChronologicalPager {
                }
 
                $diffHistLinks = '(' . $difftext . $this->messages['pipe-separator'] . $histlink . ')';
-               $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}";
+               $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$mSize} {$comment} {$topmarktext}";
 
                # Denote if username is redacted for this edit
                if( $rev->isDeleted( Revision::DELETED_USER ) ) {