X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fspecials%2FSpecialContributions.php;h=7b8aa4c5f8a7219ff676632c7d3a9f035738de73;hp=ab6614bc1230e2576d97c64229dd16f2144bfd1e;hb=e3bd13db0c285f312e31bb1b7271af4628cca80c;hpb=072e84d2480446f3b76c6cffe9cd414de5b0860c diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index ab6614bc12..7b8aa4c5f8 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -40,7 +40,7 @@ class SpecialContributions extends IncludableSpecialPage { $out->addModuleStyles( 'mediawiki.special' ); $this->addHelpLink( 'Help:User contributions' ); - $this->opts = array(); + $this->opts = []; $request = $this->getRequest(); if ( $par !== null ) { @@ -85,7 +85,7 @@ class SpecialContributions extends IncludableSpecialPage { return; } - $id = $userObj->getID(); + $id = $userObj->getId(); if ( $this->opts['contribs'] != 'newbie' ) { $target = $nt->getText(); @@ -132,10 +132,10 @@ class SpecialContributions extends IncludableSpecialPage { $feedType = $request->getVal( 'feed' ); - $feedParams = array( + $feedParams = [ 'action' => 'feedcontributions', 'user' => $target, - ); + ]; if ( $this->opts['topOnly'] ) { $feedParams['toponly'] = true; } @@ -174,11 +174,11 @@ class SpecialContributions extends IncludableSpecialPage { // Add RSS/atom links $this->addFeedLinks( $feedParams ); - if ( Hooks::run( 'SpecialContributionsBeforeMainOutput', array( $id, $userObj, $this ) ) ) { + if ( Hooks::run( 'SpecialContributionsBeforeMainOutput', [ $id, $userObj, $this ] ) ) { if ( !$this->including() ) { $out->addHTML( $this->getForm() ); } - $pager = new ContribsPager( $this->getContext(), array( + $pager = new ContribsPager( $this->getContext(), [ 'target' => $target, 'contribs' => $this->opts['contribs'], 'namespace' => $this->opts['namespace'], @@ -190,7 +190,7 @@ class SpecialContributions extends IncludableSpecialPage { 'newOnly' => $this->opts['newOnly'], 'nsInvert' => $this->opts['nsInvert'], 'associated' => $this->opts['associated'], - ) ); + ] ); if ( !$pager->getNumRows() ) { $out->addWikiMsg( 'nocontribs', $target ); @@ -228,7 +228,7 @@ class SpecialContributions extends IncludableSpecialPage { if ( !$this->msg( $message, $target )->isDisabled() ) { $out->wrapWikiMsg( "", - array( $message, $target ) ); + [ $message, $target ] ); } } } @@ -248,10 +248,10 @@ class SpecialContributions extends IncludableSpecialPage { if ( !User::isIP( $userObj->getName() ) ) { $this->getOutput()->wrapWikiMsg( "
\n\$1\n
", - array( + [ 'contributions-userdoesnotexist', wfEscapeWikiText( $userObj->getName() ), - ) + ] ); if ( !$this->including() ) { $this->getOutput()->setStatusCode( 404 ); @@ -284,17 +284,17 @@ class SpecialContributions extends IncludableSpecialPage { 'block', $nt, '', - array( + [ 'lim' => 1, 'showIfEmpty' => false, - 'msgKey' => array( + 'msgKey' => [ $userObj->isAnon() ? 'sp-contributions-blocked-notice-anon' : 'sp-contributions-blocked-notice', $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice' - ), + ], 'offset' => '' # don't use WebRequest parameter offset - ) + ] ); } } @@ -340,8 +340,8 @@ class SpecialContributions extends IncludableSpecialPage { $tools[] = Linker::linkKnown( SpecialPage::getTitleFor( 'Log', 'block' ), $this->msg( 'sp-contributions-blocklog' )->escaped(), - array(), - array( 'page' => $userpage->getPrefixedText() ) + [], + [ 'page' => $userpage->getPrefixedText() ] ); # Suppression log link (bug 59120) @@ -349,8 +349,8 @@ class SpecialContributions extends IncludableSpecialPage { $tools[] = Linker::linkKnown( SpecialPage::getTitleFor( 'Log', 'suppress' ), $this->msg( 'sp-contributions-suppresslog' )->escaped(), - array(), - array( 'offender' => $username ) + [], + [ 'offender' => $username ] ); } } @@ -384,7 +384,7 @@ class SpecialContributions extends IncludableSpecialPage { ); } - Hooks::run( 'ContributionsToolLinks', array( $id, $userpage, &$tools ) ); + Hooks::run( 'ContributionsToolLinks', [ $id, $userpage, &$tools ] ); return $tools; } @@ -443,15 +443,15 @@ class SpecialContributions extends IncludableSpecialPage { $form = Html::openElement( 'form', - array( + [ 'method' => 'get', 'action' => wfScript(), 'class' => 'mw-contributions-form' - ) + ] ); # Add hidden params for tracking except for parameters in $skipParameters - $skipParameters = array( + $skipParameters = [ 'namespace', 'nsInvert', 'deletedOnly', @@ -463,7 +463,7 @@ class SpecialContributions extends IncludableSpecialPage { 'newOnly', 'associated', 'tagfilter' - ); + ]; foreach ( $this->opts as $name => $value ) { if ( in_array( $name, $skipParameters ) ) { @@ -477,11 +477,11 @@ class SpecialContributions extends IncludableSpecialPage { if ( $tagFilter ) { $filterSelection = Html::rawElement( 'td', - array(), + [], implode( ' ', $tagFilter ) ); } else { - $filterSelection = Html::rawElement( 'td', array( 'colspan' => 2 ), '' ); + $filterSelection = Html::rawElement( 'td', [ 'colspan' => 2 ], '' ); } $this->getOutput()->addModules( 'mediawiki.userSuggest' ); @@ -492,7 +492,7 @@ class SpecialContributions extends IncludableSpecialPage { 'newbie', 'newbie', $this->opts['contribs'] == 'newbie', - array( 'class' => 'mw-input' ) + [ 'class' => 'mw-input' ] ); $labelUsername = Xml::radioLabel( $this->msg( 'sp-contributions-username' )->text(), @@ -500,139 +500,145 @@ class SpecialContributions extends IncludableSpecialPage { 'user', 'user', $this->opts['contribs'] == 'user', - array( 'class' => 'mw-input' ) + [ 'class' => 'mw-input' ] ); $input = Html::input( 'target', $this->opts['target'], 'text', - array( + [ 'size' => '40', 'required' => '', - 'class' => array( + 'class' => [ 'mw-input', 'mw-ui-input-inline', 'mw-autocomplete-user', // used by mediawiki.userSuggest - ), - ) + ( + ], + ] + ( // Only autofocus if target hasn't been specified or in non-newbies mode ( $this->opts['contribs'] === 'newbie' || $this->opts['target'] ) - ? array() : array( 'autofocus' => true ) + ? [] : [ 'autofocus' => true ] ) ); $targetSelection = Html::rawElement( 'td', - array( 'colspan' => 2 ), + [ 'colspan' => 2 ], $labelNewbies . '
' . $labelUsername . ' ' . $input . ' ' ); $namespaceSelection = Xml::tags( 'td', - array(), + [], Xml::label( $this->msg( 'namespace' )->text(), 'namespace', '' ) . Html::namespaceSelector( - array( 'selected' => $this->opts['namespace'], 'all' => '' ), - array( + [ 'selected' => $this->opts['namespace'], 'all' => '' ], + [ 'name' => 'namespace', 'id' => 'namespace', 'class' => 'namespaceselector', - ) + ] ) . ' ' . Html::rawElement( 'span', - array( 'class' => 'mw-input-with-label' ), + [ 'class' => 'mw-input-with-label' ], 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( 'class' => 'mw-input-with-label' ), + Html::rawElement( 'span', [ 'class' => 'mw-input-with-label' ], Xml::checkLabel( $this->msg( 'namespace_association' )->text(), 'associated', 'associated', $this->opts['associated'], - array( + [ 'title' => $this->msg( 'tooltip-namespace_association' )->text(), 'class' => 'mw-input' - ) + ] ) . ' ' ) ); + $filters = []; + if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) { - $deletedOnlyCheck = Html::rawElement( + $filters[] = Html::rawElement( 'span', - array( 'class' => 'mw-input-with-label' ), + [ 'class' => 'mw-input-with-label' ], Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(), 'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'], - array( 'class' => 'mw-input' ) + [ 'class' => 'mw-input' ] ) ); - } else { - $deletedOnlyCheck = ''; } - $checkLabelTopOnly = Html::rawElement( + $filters[] = Html::rawElement( 'span', - array( 'class' => 'mw-input-with-label' ), + [ 'class' => 'mw-input-with-label' ], Xml::checkLabel( $this->msg( 'sp-contributions-toponly' )->text(), 'topOnly', 'mw-show-top-only', $this->opts['topOnly'], - array( 'class' => 'mw-input' ) + [ 'class' => 'mw-input' ] ) ); - $checkLabelNewOnly = Html::rawElement( + $filters[] = Html::rawElement( 'span', - array( 'class' => 'mw-input-with-label' ), + [ 'class' => 'mw-input-with-label' ], Xml::checkLabel( $this->msg( 'sp-contributions-newonly' )->text(), 'newOnly', 'mw-show-new-only', $this->opts['newOnly'], - array( 'class' => 'mw-input' ) + [ 'class' => 'mw-input' ] ) ); + + Hooks::run( + 'SpecialContributions::getForm::filters', + [ $this, &$filters ] + ); + $extraOptions = Html::rawElement( 'td', - array( 'colspan' => 2 ), - $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly + [ 'colspan' => 2 ], + implode( '', $filters ) ); - $dateSelectionAndSubmit = Xml::tags( 'td', array( 'colspan' => 2 ), + $dateSelectionAndSubmit = Xml::tags( 'td', [ 'colspan' => 2 ], Xml::dateMenu( $this->opts['year'] === '' ? MWTimestamp::getInstance()->format( 'Y' ) : $this->opts['year'], $this->opts['month'] ) . ' ' . Html::submitButton( $this->msg( 'sp-contributions-submit' )->text(), - array( 'class' => 'mw-submit' ), array( 'mw-ui-progressive' ) + [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ] ) ); $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" + $form .= Html::rawElement( 'table', [ 'class' => 'mw-contributions-table' ], "\n" . + Html::rawElement( 'tr', [], $targetSelection ) . "\n" . + Html::rawElement( 'tr', [], $namespaceSelection ) . "\n" . + Html::rawElement( 'tr', [], $filterSelection ) . "\n" . + Html::rawElement( 'tr', [], $extraOptions ) . "\n" . + Html::rawElement( 'tr', [], $dateSelectionAndSubmit ) . "\n" ); $explain = $this->msg( 'sp-contributions-explain' ); @@ -657,7 +663,7 @@ class SpecialContributions extends IncludableSpecialPage { $user = User::newFromName( $search ); if ( !$user ) { // No prefix suggestion for invalid user - return array(); + return []; } // Autocomplete subpage as user list - public to allow caching return UserNamePrefixSearch::search( 'public', $search, $limit, $offset ); @@ -691,12 +697,12 @@ class ContribsPager extends ReverseChronologicalPager { function __construct( IContextSource $context, array $options ) { parent::__construct( $context ); - $msgs = array( + $msgs = [ 'diff', 'hist', 'pipe-separator', 'uctop' - ); + ]; foreach ( $msgs as $msg ) { $this->messages[$msg] = $this->msg( $msg )->escaped(); @@ -765,15 +771,15 @@ class ContribsPager extends ReverseChronologicalPager { * $limit: see phpdoc above * $descending: see phpdoc above */ - $data = array( $this->mDb->select( + $data = [ $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds - ) ); + ) ]; Hooks::run( 'ContribsPager::reallyDoQuery', - array( &$data, $this, $offset, $limit, $descending ) + [ &$data, $this, $offset, $limit, $descending ] ); - $result = array(); + $result = []; // loop all results and collect them in an array foreach ( $data as $query ) { @@ -818,23 +824,23 @@ class ContribsPager extends ReverseChronologicalPager { # Get the current user name for accounts $join_cond['user'] = Revision::userJoinCond(); - $options = array(); + $options = []; if ( $index ) { - $options['USE INDEX'] = array( 'revision' => $index ); + $options['USE INDEX'] = [ 'revision' => $index ]; } - $queryInfo = array( + $queryInfo = [ 'tables' => $tables, 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields(), - array( 'page_namespace', 'page_title', 'page_is_new', - 'page_latest', 'page_is_redirect', 'page_len' ) + [ 'page_namespace', 'page_title', 'page_is_new', + 'page_latest', 'page_is_redirect', 'page_len' ] ), 'conds' => $conds, 'options' => $options, 'join_conds' => $join_cond - ); + ]; ChangeTags::modifyDisplayQuery( $queryInfo['tables'], @@ -845,15 +851,15 @@ class ContribsPager extends ReverseChronologicalPager { $this->tagFilter ); - Hooks::run( 'ContribsPager::getQueryInfo', array( &$this, &$queryInfo ) ); + Hooks::run( 'ContribsPager::getQueryInfo', [ &$this, &$queryInfo ] ); return $queryInfo; } function getUserCond() { - $condition = array(); - $join_conds = array(); - $tables = array( 'revision', 'page', 'user' ); + $condition = []; + $join_conds = []; + $tables = [ 'revision', 'page', 'user' ]; $index = false; if ( $this->contribs == 'newbie' ) { $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ ); @@ -864,12 +870,12 @@ class ContribsPager extends ReverseChronologicalPager { if ( count( $groupsWithBotPermission ) ) { $tables[] = 'user_groups'; $condition[] = 'ug_group IS NULL'; - $join_conds['user_groups'] = array( - 'LEFT JOIN', array( + $join_conds['user_groups'] = [ + 'LEFT JOIN', [ 'ug_user = rev_user', 'ug_group' => $groupsWithBotPermission - ) - ); + ] + ]; } } else { $uid = User::idFromName( $this->target ); @@ -894,7 +900,7 @@ class ContribsPager extends ReverseChronologicalPager { $condition[] = 'rev_parent_id = 0'; } - return array( $tables, $index, $condition, $join_conds ); + return [ $tables, $index, $condition, $join_conds ]; } function getNamespaceCond() { @@ -904,21 +910,21 @@ class ContribsPager extends ReverseChronologicalPager { $bool_op = $this->nsInvert ? 'AND' : 'OR'; if ( !$this->associated ) { - return array( "page_namespace $eq_op $selectedNS" ); + return [ "page_namespace $eq_op $selectedNS" ]; } $associatedNS = $this->mDb->addQuotes( MWNamespace::getAssociated( $this->namespace ) ); - return array( + return [ "page_namespace $eq_op $selectedNS " . $bool_op . " page_namespace $eq_op $associatedNS" - ); + ]; } - return array(); + return []; } function getIndexField() { @@ -928,14 +934,16 @@ class ContribsPager extends ReverseChronologicalPager { function doBatchLookups() { # Do a link batch query $this->mResult->seek( 0 ); - $revIds = array(); + $parentRevIds = []; + $this->mParentLens = []; $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 ) { - $revIds[] = $row->rev_parent_id; + $parentRevIds[] = $row->rev_parent_id; } if ( isset( $row->rev_id ) ) { + $this->mParentLens[$row->rev_id] = $row->rev_len; if ( $this->contribs === 'newbie' ) { // multiple users $batch->add( NS_USER, $row->user_name ); $batch->add( NS_USER_TALK, $row->user_name ); @@ -943,7 +951,11 @@ class ContribsPager extends ReverseChronologicalPager { $batch->add( $row->page_namespace, $row->page_title ); } } - $this->mParentLens = Revision::getParentLengths( $this->mDbSecondary, $revIds ); + # Fetch rev_len for revisions not already scanned above + $this->mParentLens += Revision::getParentLengths( + $this->mDbSecondary, + array_diff( $parentRevIds, array_keys( $this->mParentLens ) ) + ); $batch->execute(); $this->mResult->seek( 0 ); } @@ -977,7 +989,7 @@ class ContribsPager extends ReverseChronologicalPager { function formatRow( $row ) { $ret = ''; - $classes = array(); + $classes = []; /* * There may be more than just revision rows. To make sure that we'll only be processing @@ -996,14 +1008,14 @@ class ContribsPager extends ReverseChronologicalPager { MediaWiki\restoreWarnings(); if ( $validRevision ) { - $classes = array(); + $classes = []; $page = Title::newFromRow( $row ); $link = Linker::link( $page, htmlspecialchars( $page->getPrefixedText() ), - array( 'class' => 'mw-contributions-title' ), - $page->isRedirect() ? array( 'redirect' => 'no' ) : array() + [ 'class' => 'mw-contributions-title' ], + $page->isRedirect() ? [ 'redirect' => 'no' ] : [] ); # Mark current revisions $topmarktext = ''; @@ -1023,11 +1035,11 @@ class ContribsPager extends ReverseChronologicalPager { $difftext = Linker::linkKnown( $page, $this->messages['diff'], - array(), - array( + [], + [ 'diff' => 'prev', 'oldid' => $row->rev_id - ) + ] ); } else { $difftext = $this->messages['diff']; @@ -1035,8 +1047,8 @@ class ContribsPager extends ReverseChronologicalPager { $histlink = Linker::linkKnown( $page, $this->messages['hist'], - array(), - array( 'action' => 'history' ) + [], + [ 'action' => 'history' ] ); if ( $row->rev_parent_id === null ) { @@ -1068,8 +1080,8 @@ class ContribsPager extends ReverseChronologicalPager { $d = Linker::linkKnown( $page, htmlspecialchars( $date ), - array( 'class' => 'mw-changeslist-date' ), - array( 'oldid' => intval( $row->rev_id ) ) + [ 'class' => 'mw-changeslist-date' ], + [ 'oldid' => intval( $row->rev_id ) ] ); } else { $d = htmlspecialchars( $date ); @@ -1122,20 +1134,21 @@ class ContribsPager extends ReverseChronologicalPager { # Tags, if any. list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, - 'contributions' + 'contributions', + $this->getContext() ); $classes = array_merge( $classes, $newClasses ); $ret .= " $tagSummary"; } // Let extensions add data - Hooks::run( 'ContributionsLineEnding', array( $this, &$ret, $row, &$classes ) ); + Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes ] ); - if ( $classes === array() && $ret === '' ) { + if ( $classes === [] && $ret === '' ) { wfDebug( "Dropping Special:Contribution row that could not be formatted\n" ); $ret = "\n"; } else { - $ret = Html::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n"; + $ret = Html::rawElement( 'li', [ 'class' => $classes ], $ret ) . "\n"; } return $ret;