Add a context to ChangeTags::buildTagFilterSelector
authoramritsreekumar <amrit.sreekumar@gmail.com>
Sat, 15 Oct 2016 19:15:06 +0000 (00:45 +0530)
committerUmherirrender <umherirrender_de.wp@web.de>
Sat, 26 Nov 2016 10:36:28 +0000 (10:36 +0000)
A IContextSource is added as parameter to ChangeTags::buildTagFilterSelector static function, which can be used to avoid the globals.

Bug: T105649
Change-Id: I50ca27c75b4807f5e4391648bfd5cac9169517e9

includes/changetags/ChangeTags.php

index e3035be..bfabd51 100644 (file)
@@ -668,12 +668,20 @@ class ChangeTags {
         * @param string $selected Tag to select by default
         * @param bool $ooui Use an OOUI TextInputWidget as selector instead of a non-OOUI input field
         *        You need to call OutputPage::enableOOUI() yourself.
+        * @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 can change in the future
         * @return array an array of (label, selector)
         */
-       public static function buildTagFilterSelector( $selected = '', $ooui = false ) {
-               global $wgUseTagFilter;
+       public static function buildTagFilterSelector(
+               $selected = '', $ooui = false, IContextSource $context = null
+       ) {
+               if ( !$context ) {
+                       $context = RequestContext::getMain();
+               }
 
-               if ( !$wgUseTagFilter || !count( self::listDefinedTags() ) ) {
+               $config = $context->getConfig();
+               if ( !$config->get( 'UseTagFilter' ) || !count( self::listDefinedTags() ) ) {
                        return [];
                }
 
@@ -681,7 +689,7 @@ class ChangeTags {
                        Html::rawElement(
                                'label',
                                [ 'for' => 'tagfilter' ],
-                               wfMessage( 'tag-filter' )->parse()
+                               $context->msg( 'tag-filter' )->parse()
                        )
                ];