Add IContextSource as parameter to ChangeTags::formatSummaryRow
authorAashaka Shah <aashaka96@gmail.com>
Fri, 29 Jan 2016 13:03:41 +0000 (18:33 +0530)
committerAashaka Shah <aashaka96@gmail.com>
Thu, 4 Feb 2016 18:02:24 +0000 (23:32 +0530)
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
includes/changes/ChangesList.php
includes/changetags/ChangeTags.php
includes/changetags/ChangeTagsLogItem.php
includes/changetags/ChangeTagsRevisionItem.php
includes/diff/DifferenceEngine.php
includes/logging/LogEventsList.php
includes/revisiondelete/RevDelRevisionItem.php
includes/specials/SpecialContributions.php
includes/specials/SpecialNewpages.php
includes/specials/SpecialUndelete.php

index 43260d0..33a69fb 100644 (file)
@@ -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";
index 1741e64..7aa2ed5 100644 (file)
@@ -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;
index a8c9f7b..305eeab 100644 (file)
@@ -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 );
 
index 565d159..24bded7 100644 (file)
@@ -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 );
                }
index e90a1b4..37d6a1a 100644 (file)
@@ -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 );
                }
index d588d51..f59fd61 100644 (file)
@@ -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 = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' .
                                '<div id="mw-diff-otitle2">' .
@@ -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 = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
                        '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
index dcd7a45..e93030f 100644 (file)
@@ -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
index e52d07c..754e68f 100644 (file)
@@ -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 );
                }
index ab6614b..4c4f528 100644 (file)
@@ -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";
index 5d3700d..e24764a 100644 (file)
@@ -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 {
index f99a52d..f8c2dee 100644 (file)
@@ -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 );
                }