From 124026a712c77886d7df04df406593b1f3f7ea70 Mon Sep 17 00:00:00 2001 From: Aashaka Shah Date: Fri, 29 Jan 2016 18:33:41 +0530 Subject: [PATCH] Add IContextSource as parameter to ChangeTags::formatSummaryRow Using IContextSource avoids the use of $wgLang and wfMessage which make use of global $wgTtle. Add IContextSource as parameter to ChangeTags::formatSummaryRow to avoid globals. Define an IContextSource instance in all functions which reference ChangeTags::formatSummaryRow and pass it in ChangeTags::formatSummaryRow function call. Also make the default value of IContextSource $context as null in parameter, to avoid breaking changes for old callers in extensions. Document default null value of IContextSource and add a @note to prefer IContextSource over null value. Remove trailing whitespace, and make code order according to parameter order. Bug: T105648 Change-Id: Ib54a6a96b73f6cd8fcdf8e520db2448a1e811cfa --- includes/actions/HistoryAction.php | 6 +++++- includes/changes/ChangesList.php | 3 ++- includes/changetags/ChangeTags.php | 14 +++++++++----- includes/changetags/ChangeTagsLogItem.php | 6 +++++- includes/changetags/ChangeTagsRevisionItem.php | 6 +++++- includes/diff/DifferenceEngine.php | 4 ++-- includes/logging/LogEventsList.php | 6 +++++- includes/revisiondelete/RevDelRevisionItem.php | 6 +++++- includes/specials/SpecialContributions.php | 3 ++- includes/specials/SpecialNewpages.php | 3 ++- includes/specials/SpecialUndelete.php | 8 ++++++-- 11 files changed, 48 insertions(+), 17 deletions(-) diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 43260d0d12..33a69fbf17 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -744,7 +744,11 @@ class HistoryPager extends ReverseChronologicalPager { } # Tags - list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' ); + list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( + $row->ts_tags, + 'history', + $this->getContext() + ); $classes = array_merge( $classes, $newClasses ); if ( $tagSummary !== '' ) { $s2 .= " $tagSummary"; diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index 1741e64c19..7aa2ed5e1c 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -590,7 +590,8 @@ class ChangesList extends ContextSource { list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow( $rc->mAttribs['ts_tags'], - 'changeslist' + 'changeslist', + $this->getContext() ); $classes = array_merge( $classes, $newClasses ); $s .= ' ' . $tagSummary; diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index a8c9f7b526..305eeab701 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -35,16 +35,20 @@ class ChangeTags { * @param string $tags Comma-separated list of tags * @param string $page A label for the type of action which is being displayed, * for example: 'history', 'contributions' or 'newpages' + * @param IContextSource|null $context + * @note Even though it takes null as a valid argument, an IContextSource is preferred + * in a new code, as the null value is subject to change in the future * @return array Array with two items: (html, classes) * - html: String: HTML for displaying the tags (empty string when param $tags is empty) * - classes: Array of strings: CSS classes used in the generated html, one class for each tag */ - public static function formatSummaryRow( $tags, $page ) { - global $wgLang; - + public static function formatSummaryRow( $tags, $page, IContextSource $context = null ) { if ( !$tags ) { return array( '', array() ); } + if ( !$context ) { + $context = RequestContext::getMain(); + } $classes = array(); @@ -71,9 +75,9 @@ class ChangeTags { return array( '', array() ); } - $markers = wfMessage( 'tag-list-wrapper' ) + $markers = $context->msg( 'tag-list-wrapper' ) ->numParams( count( $displayTags ) ) - ->rawParams( $wgLang->commaList( $displayTags ) ) + ->rawParams( $context->getLanguage()->commaList( $displayTags ) ) ->parse(); $markers = Xml::tags( 'span', array( 'class' => 'mw-tag-markers' ), $markers ); diff --git a/includes/changetags/ChangeTagsLogItem.php b/includes/changetags/ChangeTagsLogItem.php index 565d159aa9..24bded7498 100644 --- a/includes/changetags/ChangeTagsLogItem.php +++ b/includes/changetags/ChangeTagsLogItem.php @@ -91,7 +91,11 @@ class ChangeTagsLogItem extends RevisionItemBase { $attribs = array(); $tags = $this->getTags(); if ( $tags ) { - list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( $tags, 'edittags' ); + list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( + $tags, + 'edittags', + $this->list->getContext() + ); $content .= " $tagSummary"; $attribs['class'] = implode( ' ', $classes ); } diff --git a/includes/changetags/ChangeTagsRevisionItem.php b/includes/changetags/ChangeTagsRevisionItem.php index e90a1b4f3b..37d6a1aae1 100644 --- a/includes/changetags/ChangeTagsRevisionItem.php +++ b/includes/changetags/ChangeTagsRevisionItem.php @@ -49,7 +49,11 @@ class ChangeTagsRevisionItem extends RevisionItem { $attribs = array(); $tags = $this->getTags(); if ( $tags ) { - list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( $tags, 'edittags' ); + list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( + $tags, + 'edittags', + $this->list->getContext() + ); $content .= " $tagSummary"; $attribs['class'] = implode( ' ', $classes ); } diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index d588d51ca7..f59fd61aea 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -342,7 +342,7 @@ class DifferenceEngine extends ContextSource { $ldel = $this->revisionDeleteLink( $this->mOldRev ); $oldRevisionHeader = $this->getRevisionHeader( $this->mOldRev, 'complete' ); - $oldChangeTags = ChangeTags::formatSummaryRow( $this->mOldTags, 'diff' ); + $oldChangeTags = ChangeTags::formatSummaryRow( $this->mOldTags, 'diff', $this->getContext() ); $oldHeader = '
' . $oldRevisionHeader . '
' . '
' . @@ -403,7 +403,7 @@ class DifferenceEngine extends ContextSource { } $newRevisionHeader = $this->getRevisionHeader( $this->mNewRev, 'complete' ) . ' ' . implode( ' ', $formattedRevisionTools ); - $newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff' ); + $newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff', $this->getContext() ); $newHeader = '
' . $newRevisionHeader . '
' . '
' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) . diff --git a/includes/logging/LogEventsList.php b/includes/logging/LogEventsList.php index dcd7a45215..e93030f07b 100644 --- a/includes/logging/LogEventsList.php +++ b/includes/logging/LogEventsList.php @@ -331,7 +331,11 @@ class LogEventsList extends ContextSource { $del = $this->getShowHideLinks( $row ); // Any tags... - list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' ); + list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( + $row->ts_tags, + 'logevent', + $this->getContext() + ); $classes = array_merge( array( 'mw-logline-' . $entry->getType() ), $newClasses diff --git a/includes/revisiondelete/RevDelRevisionItem.php b/includes/revisiondelete/RevDelRevisionItem.php index e52d07cd24..754e68f2fc 100644 --- a/includes/revisiondelete/RevDelRevisionItem.php +++ b/includes/revisiondelete/RevDelRevisionItem.php @@ -164,7 +164,11 @@ class RevDelRevisionItem extends RevDelItem { $attribs = array(); $tags = $this->getTags(); if ( $tags ) { - list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( $tags, 'revisiondelete' ); + list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( + $tags, + 'revisiondelete', + $this->list->getContext() + ); $content .= " $tagSummary"; $attribs['class'] = implode( ' ', $classes ); } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index ab6614bc12..4c4f528d1c 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -1122,7 +1122,8 @@ 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"; diff --git a/includes/specials/SpecialNewpages.php b/includes/specials/SpecialNewpages.php index 5d3700d5ea..e24764abb4 100644 --- a/includes/specials/SpecialNewpages.php +++ b/includes/specials/SpecialNewpages.php @@ -359,7 +359,8 @@ class SpecialNewpages extends IncludableSpecialPage { if ( isset( $result->ts_tags ) ) { list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $result->ts_tags, - 'newpages' + 'newpages', + $this->getContext() ); $classes = array_merge( $classes, $newClasses ); } else { diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index f99a52dc76..f8c2dee51a 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -1142,7 +1142,7 @@ class SpecialUndelete extends SpecialPage { array( 'ts_rev_id' => $rev->getId() ), __METHOD__ ); - $tagSummary = ChangeTags::formatSummaryRow( $tags, 'deleteddiff' ); + $tagSummary = ChangeTags::formatSummaryRow( $tags, 'deleteddiff', $this->getContext() ); // FIXME This is reimplementing DifferenceEngine#getRevisionHeader // and partially #showDiffPage, but worse @@ -1461,7 +1461,11 @@ class SpecialUndelete extends SpecialPage { // Tags $attribs = array(); - list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'deletedhistory' ); + list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( + $row->ts_tags, + 'deletedhistory', + $this->getContext() + ); if ( $classes ) { $attribs['class'] = implode( ' ', $classes ); } -- 2.20.1