From 94f35cb322e159b0f01cfbded892c81b9bb59125 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 28 Mar 2013 12:43:08 +0100 Subject: [PATCH] Reduced indentation levels, broke long lines Also removed some unneeded else blocks to ensure more consistent return values. Change-Id: Icf1d6fecfbd512fadad61442c968f0ef1ba30a88 --- includes/specials/SpecialContributions.php | 348 +++++++++++++-------- 1 file changed, 211 insertions(+), 137 deletions(-) diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 75983e83ab..e985811947 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -28,7 +28,6 @@ */ class SpecialContributions extends SpecialPage { - protected $opts; public function __construct() { @@ -89,11 +88,17 @@ class SpecialContributions extends SpecialPage { if ( $this->opts['contribs'] != 'newbie' ) { $target = $nt->getText(); $out->addSubtitle( $this->contributionsSub( $userObj ) ); - $out->setHTMLTitle( $this->msg( 'pagetitle', $this->msg( 'contributions-title', $target )->plain() ) ); + $out->setHTMLTitle( $this->msg( + 'pagetitle', + $this->msg( 'contributions-title', $target )->plain() + ) ); $this->getSkin()->setRelevantUser( $userObj ); } else { $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub' ) ); - $out->setHTMLTitle( $this->msg( 'pagetitle', $this->msg( 'sp-contributions-newbies-title' )->plain() ) ); + $out->setHTMLTitle( $this->msg( + 'pagetitle', + $this->msg( 'sp-contributions-newbies-title' )->plain() + ) ); } if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) { @@ -103,10 +108,8 @@ class SpecialContributions extends SpecialPage { } $this->opts['associated'] = $request->getBool( 'associated' ); - - $this->opts['nsInvert'] = (bool) $request->getVal( 'nsInvert' ); - - $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 @@ -162,7 +165,6 @@ class SpecialContributions extends SpecialPage { $this->addFeedLinks( array( 'action' => 'feedcontributions', 'user' => $target ) ); if ( wfRunHooks( 'SpecialContributionsBeforeMainOutput', array( $id ) ) ) { - $out->addHTML( $this->getForm() ); $pager = new ContribsPager( $this->getContext(), array( @@ -176,18 +178,20 @@ class SpecialContributions extends SpecialPage { 'nsInvert' => $this->opts['nsInvert'], 'associated' => $this->opts['associated'], ) ); + if ( !$pager->getNumRows() ) { $out->addWikiMsg( 'nocontribs', $target ); } else { # Show a message about slave lag, if applicable $lag = wfGetLB()->safeGetLag( $pager->getDatabase() ); - if ( $lag > 0 ) + if ( $lag > 0 ) { $out->showLagWarning( $lag ); + } $out->addHTML( '

' . $pager->getNavigationBar() . '

' . - $pager->getBody() . - '

' . $pager->getNavigationBar() . '

' + $pager->getBody() . + '

' . $pager->getNavigationBar() . '

' ); } $out->preventClickjacking( $pager->getPreventClickjacking() ); @@ -195,16 +199,16 @@ class SpecialContributions extends SpecialPage { # Show the appropriate "footer" message - WHOIS tools, etc. if ( $this->opts['contribs'] == 'newbie' ) { $message = 'sp-contributions-footer-newbies'; - } elseif( IP::isIPAddress( $target ) ) { + } elseif ( IP::isIPAddress( $target ) ) { $message = 'sp-contributions-footer-anon'; - } elseif( $userObj->isAnon() ) { + } elseif ( $userObj->isAnon() ) { // No message for non-existing users $message = ''; } else { $message = 'sp-contributions-footer'; } - if( $message ) { + if ( $message ) { if ( !$this->msg( $message, $target )->isDisabled() ) { $out->wrapWikiMsg( "", @@ -267,9 +271,9 @@ class SpecialContributions extends SpecialPage { if ( $oldMsg->exists() ) { $linksWithParentheses = $this->msg( 'parentheses' )->rawParams( $links )->escaped(); return $oldMsg->rawParams( "$user $linksWithParentheses" ); - } else { - return $this->msg( 'contribsub2' )->rawParams( $user, $links ); } + + return $this->msg( 'contribsub2' )->rawParams( $user, $links ); } /** @@ -309,9 +313,7 @@ class SpecialContributions extends SpecialPage { SpecialPage::getTitleFor( 'Log', 'block' ), $this->msg( 'sp-contributions-blocklog' )->escaped(), array(), - array( - 'page' => $userpage->getPrefixedText() - ) + array( 'page' => $userpage->getPrefixedText() ) ); } # Uploads @@ -398,10 +400,28 @@ class SpecialContributions extends SpecialPage { $this->opts['topOnly'] = false; } - $form = Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'class' => 'mw-contributions-form' ) ); + $form = Html::openElement( + 'form', + array( + 'method' => 'get', + 'action' => $wgScript, + 'class' => 'mw-contributions-form' + ) + ); # Add hidden params for tracking except for parameters in $skipParameters - $skipParameters = array( 'namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly', 'associated' ); + $skipParameters = array( + 'namespace', + 'nsInvert', + 'deletedOnly', + 'target', + 'contribs', + 'year', + 'month', + 'topOnly', + 'associated' + ); + foreach ( $this->opts as $name => $value ) { if ( in_array( $name, $skipParameters ) ) { continue; @@ -412,80 +432,102 @@ class SpecialContributions extends SpecialPage { $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ); if ( $tagFilter ) { - $filterSelection = - Html::rawElement( 'td', array( 'class' => 'mw-label' ), array_shift( $tagFilter ) ) . - Html::rawElement( 'td', array( 'class' => 'mw-input' ), implode( ' ', $tagFilter ) ); + $filterSelection = Html::rawElement( + 'td', + array( 'class' => 'mw-label' ), + array_shift( $tagFilter ) + ); + $filterSelection .= Html::rawElement( + 'td', + array( 'class' => 'mw-input' ), + implode( ' ', $tagFilter ) + ); } else { $filterSelection = Html::rawElement( 'td', array( 'colspan' => 2 ), '' ); } - $targetSelection = Html::rawElement( 'td', array( 'colspan' => 2 ), - Xml::radioLabel( - $this->msg( 'sp-contributions-newbies' )->text(), - 'contribs', - 'newbie', - 'newbie', - $this->opts['contribs'] == 'newbie', - array( 'class' => 'mw-input' ) - ) . '
' . - Xml::radioLabel( - $this->msg( 'sp-contributions-username' )->text(), - 'contribs', - 'user', - 'user', - $this->opts['contribs'] == 'user', - array( 'class' => 'mw-input' ) - ) . ' ' . - Html::input( - 'target', - $this->opts['target'], - 'text', - array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) + - ( $this->opts['target'] ? array() : array( 'autofocus' ) + $labelNewbies = Xml::radioLabel( + $this->msg( 'sp-contributions-newbies' )->text(), + 'contribs', + 'newbie', + 'newbie', + $this->opts['contribs'] == 'newbie', + array( 'class' => 'mw-input' ) + ); + $labelUsername = Xml::radioLabel( + $this->msg( 'sp-contributions-username' )->text(), + 'contribs', + 'user', + 'user', + $this->opts['contribs'] == 'user', + array( 'class' => 'mw-input' ) + ); + $input = Html::input( + 'target', + $this->opts['target'], + 'text', + array( 'size' => '40', 'required' => '', 'class' => 'mw-input' ) + + ( $this->opts['target'] ? array() : array( 'autofocus' ) ) - ) . ' ' + ); + $targetSelection = Html::rawElement( + 'td', + array( 'colspan' => 2 ), + $labelNewbies . '
' . $labelUsername . ' ' . $input . ' ' ); - $namespaceSelection = - Xml::tags( 'td', array( 'class' => 'mw-label' ), - Xml::label( - $this->msg( 'namespace' )->text(), - 'namespace', - '' - ) - ) . - Html::rawElement( 'td', null, - Html::namespaceSelector( array( - 'selected' => $this->opts['namespace'], - 'all' => '', - ), array( - 'name' => 'namespace', - 'id' => 'namespace', + $namespaceSelection = Xml::tags( + 'td', + array( 'class' => 'mw-label' ), + Xml::label( + $this->msg( 'namespace' )->text(), + 'namespace', + '' + ) + ); + $namespaceSelection .= Html::rawElement( + 'td', + null, + Html::namespaceSelector( + array( 'selected' => $this->opts['namespace'], 'all' => '' ), + array( + 'name' => 'namespace', + 'id' => 'namespace', 'class' => 'namespaceselector', - ) ) . - ' ' . - Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ), - Xml::checkLabel( - $this->msg( 'invert' )->text(), - 'nsInvert', - 'nsInvert', - $this->opts['nsInvert'], - array( 'title' => $this->msg( 'tooltip-invert' )->text(), 'class' => 'mw-input' ) - ) . ' ' - ) . - Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ), - Xml::checkLabel( - $this->msg( 'namespace_association' )->text(), - 'associated', - 'associated', - $this->opts['associated'], - array( 'title' => $this->msg( 'tooltip-namespace_association' )->text(), 'class' => 'mw-input' ) - ) . ' ' ) - ); + ) . ' ' . + Html::rawElement( + 'span', + array( 'style' => 'white-space: nowrap' ), + Xml::checkLabel( + $this->msg( 'invert' )->text(), + 'nsInvert', + 'nsInvert', + $this->opts['nsInvert'], + array( + 'title' => $this->msg( 'tooltip-invert' )->text(), + 'class' => 'mw-input' + ) + ) . ' ' + ) . + Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ), + Xml::checkLabel( + $this->msg( 'namespace_association' )->text(), + 'associated', + 'associated', + $this->opts['associated'], + array( + 'title' => $this->msg( 'tooltip-namespace_association' )->text(), + 'class' => 'mw-input' + ) + ) . ' ' + ) + ); if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) { - $deletedOnlyCheck = Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ), + $deletedOnlyCheck = Html::rawElement( + 'span', + array( 'style' => 'white-space: nowrap' ), Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(), 'deletedOnly', @@ -498,46 +540,50 @@ class SpecialContributions extends SpecialPage { $deletedOnlyCheck = ''; } - $extraOptions = Html::rawElement( 'td', array( 'colspan' => 2 ), - $deletedOnlyCheck . - Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ), - Xml::checkLabel( - $this->msg( 'sp-contributions-toponly' )->text(), - 'topOnly', - 'mw-show-top-only', - $this->opts['topOnly'], - array( 'class' => 'mw-input' ) - ) + $checkLabelTopOnly = Html::rawElement( + 'span', + array( 'style' => 'white-space: nowrap' ), + Xml::checkLabel( + $this->msg( 'sp-contributions-toponly' )->text(), + 'topOnly', + 'mw-show-top-only', + $this->opts['topOnly'], + array( 'class' => 'mw-input' ) ) ); + $extraOptions = Html::rawElement( + 'td', + array( 'colspan' => 2 ), + $deletedOnlyCheck . $checkLabelTopOnly + ); $dateSelectionAndSubmit = Xml::tags( 'td', array( 'colspan' => 2 ), Xml::dateMenu( $this->opts['year'], $this->opts['month'] ) . ' ' . - Xml::submitButton( - $this->msg( 'sp-contributions-submit' )->text(), - array( 'class' => 'mw-submit' ) - ) + Xml::submitButton( + $this->msg( 'sp-contributions-submit' )->text(), + array( 'class' => 'mw-submit' ) + ) ); - $form .= - Xml::fieldset( $this->msg( 'sp-contributions-search' )->text() ) . - Html::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" . - Html::rawElement( 'tr', array(), $targetSelection ) . "\n" . - Html::rawElement( 'tr', array(), $namespaceSelection ) . "\n" . - Html::rawElement( 'tr', array(), $filterSelection ) . "\n" . - Html::rawElement( 'tr', array(), $extraOptions ) . "\n" . - Html::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n" - ); + $form .= Xml::fieldset( $this->msg( 'sp-contributions-search' )->text() ); + $form .= Html::rawElement( 'table', array( 'class' => 'mw-contributions-table' ), "\n" . + Html::rawElement( 'tr', array(), $targetSelection ) . "\n" . + Html::rawElement( 'tr', array(), $namespaceSelection ) . "\n" . + Html::rawElement( 'tr', array(), $filterSelection ) . "\n" . + Html::rawElement( 'tr', array(), $extraOptions ) . "\n" . + Html::rawElement( 'tr', array(), $dateSelectionAndSubmit ) . "\n" + ); $explain = $this->msg( 'sp-contributions-explain' ); if ( !$explain->isBlank() ) { $form .= "

{$explain->parse()}

"; } - $form .= Xml::closeElement( 'fieldset' ) . - Xml::closeElement( 'form' ); + + $form .= Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ); + return $form; } @@ -564,7 +610,15 @@ class ContribsPager extends ReverseChronologicalPager { function __construct( IContextSource $context, array $options ) { parent::__construct( $context ); - $msgs = array( 'uctop', 'diff', 'newarticle', 'rollbacklink', 'diff', 'hist', 'rev-delundel', 'pipe-separator' ); + $msgs = array( + 'diff', + 'hist', + 'newarticle', + 'pipe-separator', + 'rev-delundel', + 'rollbacklink', + 'uctop' + ); foreach ( $msgs as $msg ) { $this->messages[$msg] = $this->msg( $msg )->escaped(); @@ -603,7 +657,11 @@ class ContribsPager extends ReverseChronologicalPager { * @return ResultWrapper */ function reallyDoQuery( $offset, $limit, $descending ) { - list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo( $offset, $limit, $descending ); + list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo( + $offset, + $limit, + $descending + ); $pager = $this; /* @@ -673,15 +731,15 @@ class ContribsPager extends ReverseChronologicalPager { $join_cond['user'] = Revision::userJoinCond(); $queryInfo = array( - 'tables' => $tables, - 'fields' => array_merge( + 'tables' => $tables, + 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields(), array( 'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'page_is_redirect', 'page_len' ) ), - 'conds' => $conds, - 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ), + 'conds' => $conds, + 'options' => array( 'USE INDEX' => array( 'revision' => $index ) ), 'join_conds' => $join_cond ); @@ -709,7 +767,7 @@ class ContribsPager extends ReverseChronologicalPager { # ignore local groups with the bot right # @todo FIXME: Global groups may have 'bot' rights $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' ); - if( count( $groupsWithBotPermission ) ) { + if ( count( $groupsWithBotPermission ) ) { $tables[] = 'user_groups'; $condition[] = 'ug_group IS NULL'; $join_conds['user_groups'] = array( @@ -729,12 +787,15 @@ class ContribsPager extends ReverseChronologicalPager { $index = 'usertext_timestamp'; } } + if ( $this->deletedOnly ) { $condition[] = 'rev_deleted != 0'; } + if ( $this->topOnly ) { $condition[] = 'rev_id = page_latest'; } + return array( $tables, $index, $condition, $join_conds ); } @@ -746,20 +807,20 @@ class ContribsPager extends ReverseChronologicalPager { if ( !$this->associated ) { return array( "page_namespace $eq_op $selectedNS" ); - } else { - $associatedNS = $this->mDb->addQuotes( - MWNamespace::getAssociated( $this->namespace ) - ); - return array( - "page_namespace $eq_op $selectedNS " . - $bool_op . - " page_namespace $eq_op $associatedNS" - ); } - } else { - return array(); + $associatedNS = $this->mDb->addQuotes( + MWNamespace::getAssociated( $this->namespace ) + ); + + return array( + "page_namespace $eq_op $selectedNS " . + $bool_op . + " page_namespace $eq_op $associatedNS" + ); } + + return array(); } function getIndexField() { @@ -773,7 +834,7 @@ class ContribsPager extends ReverseChronologicalPager { $batch = new LinkBatch(); # Give some pointers to make (last) links foreach ( $this->mResult as $row ) { - if( isset( $row->rev_parent_id ) && $row->rev_parent_id ) { + if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) { $revIds[] = $row->rev_parent_id; } if ( isset( $row->rev_id ) ) { @@ -830,7 +891,7 @@ class ContribsPager extends ReverseChronologicalPager { */ wfSuppressWarnings(); $rev = new Revision( $row ); - $validRevision = (bool) $rev->getId(); + $validRevision = (bool)$rev->getId(); wfRestoreWarnings(); if ( $validRevision ) { @@ -850,8 +911,8 @@ class ContribsPager extends ReverseChronologicalPager { $topmarktext .= '' . $this->messages['uctop'] . ''; # Add rollback link if ( !$row->page_is_new && $page->quickUserCan( 'rollback', $user ) - && $page->quickUserCan( 'edit', $user ) ) - { + && $page->quickUserCan( 'edit', $user ) + ) { $this->preventClickjacking(); $topmarktext .= ' ' . Linker::generateRollback( $rev, $this->getContext() ); } @@ -881,11 +942,18 @@ class ContribsPager extends ReverseChronologicalPager { // For some reason rev_parent_id isn't populated for this row. // Its rumoured this is true on wikipedia for some revisions (bug 34922). // Next best thing is to have the total number of bytes. - $chardiff = ' . . ' . Linker::formatRevisionSize( $row->rev_len ) . ' . . '; + $chardiff = ' . . '; + $chardiff .= Linker::formatRevisionSize( $row->rev_len ); + $chardiff .= ' . . '; } else { $parentLen = isset( $this->mParentLens[$row->rev_parent_id] ) ? $this->mParentLens[$row->rev_parent_id] : 0; - $chardiff = ' . . ' . ChangesList::showCharacterDifference( - $parentLen, $row->rev_len, $this->getContext() ) . ' . . '; + $chardiff = ' . . '; + $chardiff .= ChangesList::showCharacterDifference( + $parentLen, + $row->rev_len, + $this->getContext() + ); + $chardiff .= ' . . '; } $lang = $this->getLanguage(); @@ -932,7 +1000,9 @@ class ContribsPager extends ReverseChronologicalPager { $del .= ' '; } - $diffHistLinks = $this->msg( 'parentheses' )->rawParams( $difftext . $this->messages['pipe-separator'] . $histlink )->escaped(); + $diffHistLinks = $this->msg( 'parentheses' ) + ->rawParams( $difftext . $this->messages['pipe-separator'] . $histlink ) + ->escaped(); $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} {$link}{$userlink} {$comment} {$topmarktext}"; # Denote if username is redacted for this edit @@ -941,7 +1011,10 @@ class ContribsPager extends ReverseChronologicalPager { } # Tags, if any. - list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'contributions' ); + list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( + $row->ts_tags, + 'contributions' + ); $classes = array_merge( $classes, $newClasses ); $ret .= " $tagSummary"; } @@ -966,7 +1039,8 @@ class ContribsPager extends ReverseChronologicalPager { */ function getSqlComment() { if ( $this->namespace || $this->deletedOnly ) { - return 'contributions page filtered for namespace or RevisionDeleted edits'; // potentially slow, see CR r58153 + // potentially slow, see CR r58153 + return 'contributions page filtered for namespace or RevisionDeleted edits'; } else { return 'contributions page unfiltered'; } -- 2.20.1