Umherirrender has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/358050 )
Change subject: Use short array syntax - includes ...................................................................... Use short array syntax - includes Change-Id: Icdc4f74595a7fa25976340f18c97caf5aeb1269b --- M includes/AllocationCalculator.php M includes/Banner.php M includes/BannerMessage.php M includes/BannerMessageGroup.php M includes/BannerRenderer.php M includes/CNBannerPager.php M includes/CNCampaignPager.php M includes/CNChoiceDataResourceLoaderModule.php M includes/CNDatabase.php M includes/CNDeviceTarget.php M includes/Campaign.php M includes/CampaignLog.php M includes/ChoiceDataProvider.php M includes/GeoTarget.php M includes/MixinController.php 15 files changed, 404 insertions(+), 404 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice refs/changes/50/358050/1 diff --git a/includes/AllocationCalculator.php b/includes/AllocationCalculator.php index f4a5919..b6d40e3 100644 --- a/includes/AllocationCalculator.php +++ b/includes/AllocationCalculator.php @@ -49,7 +49,7 @@ */ public static function filterChoiceData( &$choiceData, $country, $status, $device ) { - $filteredChoiceData = array(); + $filteredChoiceData = []; foreach ( $choiceData as $campaign ) { @@ -110,7 +110,7 @@ // and higher integers represent higher priority. These values are // defined by class constants in CentralNotice. - $campaignsByPriority = array(); + $campaignsByPriority = []; foreach ( $filteredChoiceData as &$campaign ) { $priority = $campaign['preferred']; $campaignsByPriority[$priority][] = &$campaign; @@ -206,7 +206,7 @@ */ public static function makePossibleBanners( $campaign, $bucket, $status, $device ) { - $banners = array(); + $banners = []; foreach ( $campaign['banners'] as $banner ) { @@ -294,7 +294,7 @@ // Go through all campaings to make a flat list of banners from all of // them, and calculate overall relative allocations. - $possibleBannersAllCampaigns = array(); + $possibleBannersAllCampaigns = []; foreach ( $campaigns as $campaign ) { $possibleBanners = AllocationCalculator::makePossibleBanners( diff --git a/includes/Banner.php b/includes/Banner.php index eeca71b..a59c2ca 100644 --- a/includes/Banner.php +++ b/includes/Banner.php @@ -48,14 +48,14 @@ * * @var null|bool[] */ - protected $dirtyFlags = array( + protected $dirtyFlags = [ 'content' => null, 'messages' => null, 'basic' => null, 'devices' => null, 'mixins' => null, 'prioritylang' => null, - ); + ]; // <editor-fold desc="Properties"> // !!! NOTE !!! It is not recommended to use directly. It is almost always more @@ -81,13 +81,13 @@ /** @var string[] Devices this banner should be allocated to in the form * {Device ID => Device header name} */ - protected $devices = array(); + protected $devices = []; /** @var string[] Names of enabled mixins */ - protected $mixins = array(); + protected $mixins = []; /** @var string[] Language codes considered a priority for translation. */ - protected $priorityLanguages = array(); + protected $priorityLanguages = []; /** @var string Wikitext content of the banner */ protected $bodyContent = ''; @@ -262,10 +262,10 @@ 'tmp_category', '', __METHOD__, - array( 'DISTINCT', 'ORDER BY tmp_category ASC' ) + [ 'DISTINCT', 'ORDER BY tmp_category ASC' ] ); - $categories = array(); + $categories = []; foreach ( $res as $row ) { $categories[$row->tmp_category] = $row->tmp_category; } @@ -309,24 +309,24 @@ // What are we using to select on? if ( $this->name !== null ) { - $selector = array( 'tmp_name' => $this->name ); + $selector = [ 'tmp_name' => $this->name ]; } elseif ( $this->id !== null ) { - $selector = array( 'tmp_id' => $this->id ); + $selector = [ 'tmp_id' => $this->id ]; } else { throw new BannerDataException( 'Cannot retrieve banner data without name or ID.' ); } // Query! $rowRes = $db->select( - array( 'templates' => 'cn_templates' ), - array( + [ 'templates' => 'cn_templates' ], + [ 'tmp_id', 'tmp_name', 'tmp_display_anon', 'tmp_display_account', 'tmp_archived', 'tmp_category' - ), + ], $selector, __METHOD__ ); @@ -341,7 +341,7 @@ $this->archived = (bool)$row->tmp_archived; $this->category = $row->tmp_category; } else { - $keystr = array(); + $keystr = []; foreach ( $selector as $key => $value ) { $keystr[] = "{$key} = {$value}"; } @@ -368,7 +368,7 @@ * @param IDatabase $db */ protected function initializeDbBasicData( IDatabase $db ) { - $db->insert( 'cn_templates', array( 'tmp_name' => $this->name ), __METHOD__ ); + $db->insert( 'cn_templates', [ 'tmp_name' => $this->name ], __METHOD__ ); $this->id = $db->insertId(); } @@ -379,15 +379,15 @@ protected function saveBasicData( IDatabase $db ) { if ( $this->dirtyFlags['basic'] ) { $db->update( 'cn_templates', - array( + [ 'tmp_display_anon' => (int)$this->allocateAnon, 'tmp_display_account' => (int)$this->allocateLoggedIn, 'tmp_archived' => (int)$this->archived, 'tmp_category' => $this->category, - ), - array( + ], + [ 'tmp_id' => $this->id - ), + ], __METHOD__ ); } @@ -425,7 +425,7 @@ sort( $devices ); if ( $devices != $this->devices ) { - $this->devices = array(); + $this->devices = []; foreach ( $devices as $device ) { if ( !$device ) { @@ -456,15 +456,15 @@ $db = CNDatabase::getDb(); $rowObj = $db->select( - array( + [ 'tdev' => 'cn_template_devices', 'devices' => 'cn_known_devices' - ), - array( 'devices.dev_id', 'dev_name' ), - array( + ], + [ 'devices.dev_id', 'dev_name' ], + [ 'tdev.tmp_id' => $this->getId(), 'tdev.dev_id = devices.dev_id' - ), + ], __METHOD__ ); @@ -490,13 +490,13 @@ protected function saveDeviceTargetData( IDatabase $db ) { if ( $this->dirtyFlags['devices'] ) { // Remove all entries from the table for this banner - $db->delete( 'cn_template_devices', array( 'tmp_id' => $this->getId() ), __METHOD__ ); + $db->delete( 'cn_template_devices', [ 'tmp_id' => $this->getId() ], __METHOD__ ); // Add the new device mappings if ( $this->devices ) { - $modifyArray = array(); + $modifyArray = []; foreach ( $this->devices as $deviceId => $deviceName ) { - $modifyArray[] = array( 'tmp_id' => $this->getId(), 'dev_id' => $deviceId ); + $modifyArray[] = [ 'tmp_id' => $this->getId(), 'dev_id' => $deviceId ]; } $db->insert( 'cn_template_devices', $modifyArray, __METHOD__ ); } @@ -535,7 +535,7 @@ $this->markMixinDataDirty(); } - $this->mixins = array(); + $this->mixins = []; foreach ( $mixins as $mixin ) { if ( !array_key_exists( $mixin, $wgCentralNoticeBannerMixins ) ) { throw new RangeException( "Mixin does not exist: {$mixin}" ); @@ -559,13 +559,13 @@ $dbr = CNDatabase::getDb(); $result = $dbr->select( 'cn_template_mixins', 'mixin_name', - array( + [ "tmp_id" => $this->getId(), - ), + ], __METHOD__ ); - $this->mixins = array(); + $this->mixins = []; foreach ( $result as $row ) { if ( !array_key_exists( $row->mixin_name, $wgCentralNoticeBannerMixins ) ) { // We only want to warn here otherwise we'd never be able to @@ -596,7 +596,7 @@ protected function saveMixinData( IDatabase $db ) { if ( $this->dirtyFlags['mixins'] ) { $db->delete( 'cn_template_mixins', - array( 'tmp_id' => $this->getId() ), + [ 'tmp_id' => $this->getId() ], __METHOD__ ); @@ -606,11 +606,11 @@ continue; } $db->insert( 'cn_template_mixins', - array( + [ 'tmp_id' => $this->getId(), 'page_id' => 0, // TODO: What were we going to use this for again? 'mixin_name' => $name, - ), + ], __METHOD__ ); } @@ -852,7 +852,7 @@ $expanded .= $renderer->getPreloadJsRaw(); // Extract message fields from the banner body - $fields = array(); + $fields = []; $allowedChars = Title::legalChars(); // We're using a janky custom syntax to pass arguments to a field message: // "{{{fieldname:arg1|arg2}}}" @@ -882,7 +882,7 @@ */ function getAvailableLanguages( $inTranslation = false ) { global $wgLanguageCode; - $availableLangs = array(); + $availableLangs = []; // Bit of an ugly hack to get just the banner prefix $prefix = $this->getMessageField( '' ) @@ -891,10 +891,10 @@ $db = CNDatabase::getDb(); $result = $db->select( 'page', 'page_title', - array( + [ 'page_namespace' => $inTranslation ? NS_CN_BANNER : NS_MEDIAWIKI, 'page_title' . $db->buildLike( $prefix, $db->anyString() ), - ), + ], __METHOD__ ); // @codingStandardsIgnoreStart @@ -1081,7 +1081,7 @@ $bannerObj = Banner::fromName( $name ); $id = $bannerObj->getId(); $dbr = CNDatabase::getDb(); - $res = $dbr->select( 'cn_assignments', 'asn_id', array( 'tmp_id' => $id ), __METHOD__ ); + $res = $dbr->select( 'cn_assignments', 'asn_id', [ 'tmp_id' => $id ], __METHOD__ ); if ( $dbr->numRows( $res ) > 0 ) { throw new LogicException( 'Cannot remove a template still bound to a campaign!' ); @@ -1093,7 +1093,7 @@ // Delete banner record from the CentralNotice cn_templates table $dbw = CNDatabase::getDb(); $dbw->delete( 'cn_templates', - array( 'tmp_id' => $id ), + [ 'tmp_id' => $id ], __METHOD__ ); @@ -1140,11 +1140,11 @@ // There should only ever be one tag applied to a banner object Banner::removeTag( $tag, $pageId ); - $conds = array( + $conds = [ 'rt_page' => $pageId, 'rt_type' => RevTag::getType( $tag ), 'rt_revision' => $revisionId - ); + ]; if ( $bannerId !== null ) { $conds['rt_value'] = $bannerId; @@ -1162,10 +1162,10 @@ protected static function removeTag( $tag, $pageId ) { $dbw = CNDatabase::getDb(); - $conds = array( + $conds = [ 'rt_page' => $pageId, 'rt_type' => RevTag::getType( $tag ) - ); + ]; $dbw->delete( 'revtag', $conds, __METHOD__ ); } @@ -1179,19 +1179,19 @@ static function getCampaignBanners( $campaigns ) { $dbr = CNDatabase::getDb(); - $banners = array(); + $banners = []; if ( $campaigns ) { $res = $dbr->select( // Aliases (keys) are needed to avoid problems with table prefixes - array( + [ 'notices' => 'cn_notices', 'templates' => 'cn_templates', 'known_devices' => 'cn_known_devices', 'template_devices' => 'cn_template_devices', 'assignments' => 'cn_assignments', - ), - array( + ], + [ 'tmp_name', 'tmp_weight', 'tmp_display_anon', @@ -1203,24 +1203,24 @@ 'not_buckets', 'not_throttle', 'dev_name', - ), - array( + ], + [ 'notices.not_id' => $campaigns, 'notices.not_id = assignments.not_id', 'known_devices.dev_id = template_devices.dev_id', 'assignments.tmp_id = templates.tmp_id' - ), + ], __METHOD__, - array(), - array( - 'template_devices' => array( + [], + [ + 'template_devices' => [ 'LEFT JOIN', 'template_devices.tmp_id = assignments.tmp_id' - ) - ) + ] + ] ); foreach ( $res as $row ) { - $banners[ ] = array( + $banners[ ] = [ // name of the banner 'name' => $row->tmp_name, // weight assigned to the banner @@ -1241,7 +1241,7 @@ 'campaign_throttle' => intval( $row->not_throttle ), 'bucket' => ( intval( $row->not_buckets ) == 1 ) ? 0 : intval( $row->asn_bucket ), - ); + ]; } } return $banners; @@ -1262,7 +1262,7 @@ throw new RangeException( "Banner doesn't exist!" ); } - $details = array( + $details = [ 'anon' => (int)$banner->allocateToAnon(), 'account' => (int)$banner->allocateToLoggedIn(), // TODO: Death to this! @@ -1270,7 +1270,7 @@ 'category' => $banner->getCategory(), 'controller_mixin' => implode( ",", array_keys( $banner->getMixins() ) ), 'devices' => array_values( $banner->getDevices() ), - ); + ]; if ( $detailed ) { $details['prioritylangs'] = $banner->getPriorityLanguages(); @@ -1295,13 +1295,13 @@ $newestLog = $dbr->selectRow( "cn_template_log", - array( + [ "log_id" => "MAX(tmplog_id)", - ), - array( + ], + [ "tmplog_timestamp <= $ts", "tmplog_template_id = $id", - ), + ], __METHOD__ ); @@ -1311,14 +1311,14 @@ $row = $dbr->selectRow( "cn_template_log", - array( + [ "display_anon" => "tmplog_end_anon", "display_account" => "tmplog_end_account", "fundraising" => "tmplog_end_fundraising", - ), - array( + ], + [ "tmplog_id = {$newestLog->log_id}", - ), + ], __METHOD__ ); $banner['display_anon'] = (int) $row->display_anon; @@ -1327,7 +1327,7 @@ $banner['fundraising'] = (int) $row->fundraising; // XXX - $banner['devices'] = array( "desktop" ); + $banner['devices'] = [ "desktop" ]; return $banner; } @@ -1349,13 +1349,13 @@ */ static function addTemplate( $name, $body, $user, $displayAnon, $displayAccount, $fundraising = false, - $mixins = array(), $priorityLangs = array(), $devices = null, + $mixins = [], $priorityLangs = [], $devices = null, $summary = null ) { // Default initial value for devices if ( $devices === null ) { - $devices = array( 'desktop' ); + $devices = [ 'desktop' ]; } if ( $name == '' || !Banner::isValidBannerName( $name ) || $body == '' ) { @@ -1395,14 +1395,14 @@ $summary = ''; } - $endSettings = array(); + $endSettings = []; if ( $action !== 'removed' ) { $endSettings = Banner::getBannerSettings( $this->getName(), true ); } $dbw = CNDatabase::getDb(); - $log = array( + $log = [ 'tmplog_timestamp' => $dbw->timestamp(), 'tmplog_user_id' => $user->getId(), 'tmplog_action' => $action, @@ -1410,7 +1410,7 @@ 'tmplog_template_name' => $this->getName(), 'tmplog_content_change'=> (int)$this->dirtyFlags['content'], 'tmplog_comment' => $summary, - ); + ]; foreach ( $endSettings as $key => $value ) { if ( is_array( $value ) ) { @@ -1447,9 +1447,9 @@ public function exists() { $db = CNDatabase::getDb(); if ( $this->name !== null ) { - $selector = array( 'tmp_name' => $this->name ); + $selector = [ 'tmp_name' => $this->name ]; } elseif ( $this->id !== null ) { - $selector = array( 'tmp_id' => $this->id ); + $selector = [ 'tmp_id' => $this->id ]; } else { throw new BannerDataException( 'Cannot determine banner existence without name or ID.' diff --git a/includes/BannerMessage.php b/includes/BannerMessage.php index b530268..e53adb8 100644 --- a/includes/BannerMessage.php +++ b/includes/BannerMessage.php @@ -137,8 +137,8 @@ $var = false; $page->doUpdateRestrictions( - array( 'edit' => $wgNoticeProtectGroup, 'move' => $wgNoticeProtectGroup ), - array( 'edit' => 'infinity', 'move' => 'infinity' ), + [ 'edit' => $wgNoticeProtectGroup, 'move' => $wgNoticeProtectGroup ], + [ 'edit' => 'infinity', 'move' => 'infinity' ], $var, 'Auto protected by CentralNotice -- Only edit via Special:CentralNotice.', $user diff --git a/includes/BannerMessageGroup.php b/includes/BannerMessageGroup.php index 78a1d73..40764ac 100644 --- a/includes/BannerMessageGroup.php +++ b/includes/BannerMessageGroup.php @@ -37,7 +37,7 @@ * @return array */ public function getKeys() { - $keys = array(); + $keys = []; $banner = Banner::fromName( $this->bannerName ); $fields = $banner->getMessageFieldsFromCache(); @@ -63,7 +63,7 @@ * @return array Array of message keys with definitions. */ public function getDefinitions() { - $definitions = array(); + $definitions = []; $banner = Banner::fromName( $this->bannerName ); $fields = $banner->getMessageFieldsFromCache(); @@ -194,19 +194,19 @@ } public function getMessageGroupStates() { - $conf = array( - 'progress' => array( 'color' => 'E00' ), - 'proofreading' => array( 'color' => 'FFBF00' ), - 'ready' => array( 'color' => 'FF0' ), - 'published' => array( 'color' => 'AEA', 'right' => 'centralnotice-admin' ), - 'state conditions' => array( - array( 'ready', array( 'PROOFREAD' => 'MAX' ) ), - array( 'proofreading', array( 'TRANSLATED' => 'MAX' ) ), - array( 'progress', array( 'UNTRANSLATED' => 'NONZERO' ) ), - array( 'unset', array( 'UNTRANSLATED' => 'MAX', 'OUTDATED' => 'ZERO', - 'TRANSLATED' => 'ZERO' ) ), - ), - ); + $conf = [ + 'progress' => [ 'color' => 'E00' ], + 'proofreading' => [ 'color' => 'FFBF00' ], + 'ready' => [ 'color' => 'FF0' ], + 'published' => [ 'color' => 'AEA', 'right' => 'centralnotice-admin' ], + 'state conditions' => [ + [ 'ready', [ 'PROOFREAD' => 'MAX' ] ], + [ 'proofreading', [ 'TRANSLATED' => 'MAX' ] ], + [ 'progress', [ 'UNTRANSLATED' => 'NONZERO' ] ], + [ 'unset', [ 'UNTRANSLATED' => 'MAX', 'OUTDATED' => 'ZERO', + 'TRANSLATED' => 'ZERO' ] ], + ], + ]; return new MessageGroupStates( $conf ); } @@ -224,22 +224,22 @@ $dbr = CNDatabase::getDb( DB_MASTER ); // Create the base aggregate group - $conf = array(); - $conf['BASIC'] = array( + $conf = []; + $conf['BASIC'] = [ 'id' => BannerMessageGroup::TRANSLATE_GROUP_NAME_BASE, 'label' => 'CentralNotice Banners', 'description' => '{{int:centralnotice-aggregate-group-desc}}', 'meta' => 1, 'class' => 'AggregateMessageGroup', 'namespace' => NS_CN_BANNER, - ); - $conf['GROUPS'] = array(); + ]; + $conf['GROUPS'] = []; // Find all the banners marked for translation - $tables = array( 'page', 'revtag' ); - $vars = array( 'page_id', 'page_namespace', 'page_title', ); - $conds = array( 'page_id=rt_page', 'rt_type' => RevTag::getType( 'banner:translate' ) ); - $options = array( 'GROUP BY' => 'rt_page' ); + $tables = [ 'page', 'revtag' ]; + $vars = [ 'page_id', 'page_namespace', 'page_title', ]; + $conds = [ 'page_id=rt_page', 'rt_type' => RevTag::getType( 'banner:translate' ) ]; + $options = [ 'GROUP BY' => 'rt_page' ]; $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options ); foreach ( $res as $r ) { @@ -270,14 +270,14 @@ $result = $db->select( 'translate_groupreviews', 'tgr_lang', - array( + [ 'tgr_group' => $groupName, 'tgr_state' => $state, - ), + ], __METHOD__ ); - $langs = array(); + $langs = []; // @codingStandardsIgnoreStart while ( $row = $result->fetchRow() ) { // @codingStandardsIgnoreEnd diff --git a/includes/BannerRenderer.php b/includes/BannerRenderer.php index d682d22..de3562d 100644 --- a/includes/BannerRenderer.php +++ b/includes/BannerRenderer.php @@ -62,7 +62,7 @@ return Linker::link( SpecialPage::getTitleFor( 'CentralNoticeBanners', "edit/{$this->banner->getName()}" ), htmlspecialchars( $this->banner->getName() ), - array( 'class' => 'cn-banner-title' ) + [ 'class' => 'cn-banner-title' ] ); } @@ -79,7 +79,7 @@ return Linker::link( SpecialPage::getTitleFor( 'CentralNoticeBanners', "edit/{$name}" ), htmlspecialchars( $name ), - array( 'class' => 'cn-banner-title' ) + [ 'class' => 'cn-banner-title' ] ); } @@ -101,10 +101,10 @@ $previewUrl = $wgNoticeBannerPreview . "{$bannerName}/{$bannerName}_{$lang}.png"; $preview = Html::element( 'img', - array( + [ 'src' => $previewUrl, 'alt' => $bannerName, - ) + ] ); $label = $this->context->msg( 'centralnotice-preview', $lang )->text(); @@ -112,10 +112,10 @@ return Xml::fieldset( $label, $preview, - array( + [ 'class' => 'cn-bannerpreview', 'id' => Sanitizer::escapeId( "cn-banner-preview-{$this->banner->getName()}" ), - ) + ] ); } @@ -212,7 +212,7 @@ function substituteMagicWords( $contents ) { return preg_replace_callback( '/{{{([^}:]+)(?:[:]([^}]*))?}}}/', - array( $this, 'renderMagicWord' ), + [ $this, 'renderMagicWord' ], $contents ); } @@ -223,7 +223,7 @@ * @return array List of magic word names. */ function getMagicWords() { - $words = array( 'banner', 'campaign' ); + $words = [ 'banner', 'campaign' ]; $words = array_merge( $words, $this->mixinController->getMagicWords() ); return $words; } @@ -247,7 +247,7 @@ } elseif ( $field === 'campaign' ) { return $this->campaignName; } - $params = array(); + $params = []; if ( isset( $re_matches[2] ) ) { $params = explode( "|", $re_matches[2] ); } diff --git a/includes/CNBannerPager.php b/includes/CNBannerPager.php index b206ac6..b0dba9b 100644 --- a/includes/CNBannerPager.php +++ b/includes/CNBannerPager.php @@ -11,10 +11,10 @@ protected $filter = ''; /** @var array HTMLFormFields to add to the results before every banner entry */ - protected $prependPrototypes = array(); + protected $prependPrototypes = []; /** @var array HTMLFormFields to add to the results after every banner entry */ - protected $appendPrototypes = array(); + protected $appendPrototypes = []; /** @var string 'Section' attribute to apply to the banner elements generated */ protected $formSection = null; @@ -31,8 +31,8 @@ * @param bool $editable */ function __construct( SpecialCentralNoticeBanners $hostSpecialPage, - $formSection = null, $prependPrototypes = array(), - $appendPrototypes = array(), $bannerFilter = '', $editable = false + $formSection = null, $prependPrototypes = [], + $appendPrototypes = [], $bannerFilter = '', $editable = false ) { $this->editable = $editable; $this->filter = $bannerFilter; @@ -45,7 +45,7 @@ $this->hostSpecialPage = $hostSpecialPage; // Override paging defaults list( $this->mLimit, $this->mOffset ) = $this->mRequest->getLimitOffset( 20, '' ); - $this->mLimitsShown = array( 20, 50, 100 ); + $this->mLimitsShown = [ 20, 50, 100 ]; // Get the database object $this->mDb = CNDatabase::getDb(); @@ -59,10 +59,10 @@ // Sets mNavigation bar with the default text which we will then wrap parent::getNavigationBar(); - $this->mNavigationBar = array( + $this->mNavigationBar = [ 'class' => 'HTMLBannerPagerNavigation', 'value' => $this->mNavigationBar - ); + ]; if ( $this->formSection ) { $this->mNavigationBar['section'] = $this->formSection; @@ -85,7 +85,7 @@ $likeArray = $this->mDb->anyString(); } else { $anyStringToken = $this->mDb->anyString(); - $tempArray = array( $anyStringToken ); + $tempArray = [ $anyStringToken ]; foreach ( $likeArray as $likePart ) { $tempArray[ ] = $likePart; $tempArray[ ] = $anyStringToken; @@ -93,11 +93,11 @@ $likeArray = $tempArray; } - return array( - 'tables' => array( 'templates' => 'cn_templates' ), - 'fields' => array( 'templates.tmp_name', 'templates.tmp_id' ), - 'conds' => array( 'templates.tmp_name' . $this->mDb->buildLike( $likeArray ) ), - ); + return [ + 'tables' => [ 'templates' => 'cn_templates' ], + 'fields' => [ 'templates.tmp_name', 'templates.tmp_id' ], + 'conds' => [ 'templates.tmp_name' . $this->mDb->buildLike( $likeArray ) ], + ]; } /** @@ -117,7 +117,7 @@ * @return array HTMLFormElement classes */ function formatRow( $row ) { - $retval = array(); + $retval = []; $bannerId = $row->tmp_id; $bannerName = $row->tmp_name; @@ -131,11 +131,11 @@ } // Now do the banner - $retval["cn-banner-list-element-$bannerId"] = array( + $retval["cn-banner-list-element-$bannerId"] = [ 'class' => 'HTMLCentralNoticeBanner', 'banner' => $bannerName, 'withlabel' => true, - ); + ]; if ( $this->formSection ) { $retval["cn-banner-list-element-$bannerId"]['section'] = $this->formSection; } @@ -177,7 +177,7 @@ # Don't use any extra rows returned by the query $numRows = min( $this->mResult->numRows(), $this->mLimit ); - $retval = array(); + $retval = []; if ( $numRows ) { if ( $this->mIsBackwards ) { @@ -227,7 +227,7 @@ public function getDiv( $value ) { $html = Xml::openElement( 'div', - array( 'class' => "cn-banner-list-pager-nav", ) + [ 'class' => "cn-banner-list-pager-nav", ] ); $html .= $this->getInputHTML( $value ); $html .= Xml::closeElement( 'div' ); diff --git a/includes/CNCampaignPager.php b/includes/CNCampaignPager.php index 5eec1d9..fa3024d 100644 --- a/includes/CNCampaignPager.php +++ b/includes/CNCampaignPager.php @@ -56,11 +56,11 @@ * @see IndexPager::getQueryInfo() */ public function getQueryInfo() { - $pagerQuery = array( - 'tables' => array( + $pagerQuery = [ + 'tables' => [ 'notices' => 'cn_notices', - ), - 'fields' => array( + ], + 'fields' => [ 'notices.not_id', 'not_name', 'not_start', @@ -89,17 +89,17 @@ 'np_project', 'np_notice_id = notices.not_id' ) . ' AS projects', - ), - 'conds' => array(), - ); + ], + 'conds' => [], + ]; if ( $this->assignedBannerId ) { // Query for only campaigns associated with a specific banner id. $pagerQuery['tables']['assignments'] = 'cn_assignments'; - $pagerQuery['conds'] = array( + $pagerQuery['conds'] = [ 'notices.not_id = assignments.not_id', 'assignments.tmp_id = ' . (int)$this->assignedBannerId - ); + ]; } return $pagerQuery; @@ -119,7 +119,7 @@ public function getFieldNames() { if ( !$this->fieldNames ) { - $this->fieldNames = array( + $this->fieldNames = [ 'not_name' => $this->msg( 'centralnotice-notice-name' )->text(), 'projects' => $this->msg( 'centralnotice-projects' )->text(), 'languages' => $this->msg( 'centralnotice-languages' )->text(), @@ -131,7 +131,7 @@ 'not_throttle' => $this->msg( 'centralnotice-throttle' )->text(), 'not_locked' => $this->msg( 'centralnotice-locked' )->text(), 'not_archived' => $this->msg( 'centralnotice-archive-campaign' )->text() - ); + ]; } return $this->fieldNames; @@ -146,15 +146,15 @@ $htmlOut .= Xml::openElement( 'fieldset', - array( + [ 'class' => 'prefsection', 'id' => 'cn-campaign-pager', 'data-editable' => ( $this->editable ? 1 : 0 ) - ) + ] ); // Filters - $htmlOut .= Xml::openElement( 'div', array( 'class' => 'cn-formsection-emphasis' ) ); + $htmlOut .= Xml::openElement( 'div', [ 'class' => 'cn-formsection-emphasis' ] ); $htmlOut .= Xml::checkLabel( $this->msg( 'centralnotice-archive-show' )->text(), 'centralnotice-showarchived', @@ -173,18 +173,18 @@ $rowIsLocked = ( $this->mCurrentRow->not_locked == '1' ); $rowIsArchived = ( $this->mCurrentRow->not_archived == '1' ); $name = $this->mCurrentRow->not_name; - $readonly = array( 'disabled' => 'disabled' ); + $readonly = [ 'disabled' => 'disabled' ]; switch ( $fieldName ) { case 'not_name': return Linker::link( SpecialPage::getTitleFor( 'CentralNotice' ), htmlspecialchars( $value ), - array(), - array( + [], + [ 'subaction' => 'noticeDetail', 'notice' => $value - ) + ] ); case 'projects': @@ -218,12 +218,12 @@ $rowIsEnabled, array_replace( ( !$this->editable || $rowIsLocked || $rowIsArchived ) - ? $readonly : array(), - array( + ? $readonly : [], + [ 'data-campaign-name' => $name, 'data-initial-value' => $rowIsEnabled, 'class' => 'noshiftselect mw-cn-input-check-sort' - ) + ] ) ); @@ -251,12 +251,12 @@ // Otherwise we create a dead-end state of locked and // archived. ( !$this->editable ) - ? $readonly : array(), - array( + ? $readonly : [], + [ 'data-campaign-name' => $name, 'data-initial-value' => $rowIsLocked, 'class' => 'noshiftselect mw-cn-input-check-sort' - ) + ] ) ); @@ -266,12 +266,12 @@ $rowIsArchived, array_replace( ( !$this->editable || $rowIsLocked || $rowIsEnabled ) - ? $readonly : array(), - array( + ? $readonly : [], + [ 'data-campaign-name' => $name, 'data-initial-value' => $rowIsArchived, 'class' => 'noshiftselect mw-cn-input-check-sort' - ) + ] ) ); } @@ -343,7 +343,7 @@ if ( $this->editable ) { $htmlOut .= Xml::openElement( 'div', - array( 'class' => 'cn-buttons cn-formsection-emphasis' ) ); + [ 'class' => 'cn-buttons cn-formsection-emphasis' ] ); $htmlOut .= $this->onSpecialCN->makeSummaryField(); @@ -351,10 +351,10 @@ 'centralnoticesubmit', false, $this->msg( 'centralnotice-modify' )->text(), - array( + [ 'type' => 'button', 'id' => 'cn-campaign-pager-submit' - ) + ] ); $htmlOut .= Xml::closeElement( 'div' ); diff --git a/includes/CNChoiceDataResourceLoaderModule.php b/includes/CNChoiceDataResourceLoaderModule.php index d7c19ab..c5a013c 100644 --- a/includes/CNChoiceDataResourceLoaderModule.php +++ b/includes/CNChoiceDataResourceLoaderModule.php @@ -12,7 +12,7 @@ /** * @see ResourceLoaderModule::targets */ - protected $targets = array( 'desktop', 'mobile' ); + protected $targets = [ 'desktop', 'mobile' ]; const API_REQUEST_TIMEOUT = 20; @@ -31,7 +31,7 @@ wfLogWarning( 'Couldn\'t fetch banner choice data via API. ' . '$$wgCentralNoticeApiUrl = ' . $wgCentralNoticeApiUrl ); - return array(); + return []; } } else { $choices = ChoiceDataProvider::getChoices( $project, $language ); @@ -53,18 +53,18 @@ global $wgCentralNoticeApiUrl; // Make the URl - $q = array( + $q = [ 'action' => 'centralnoticechoicedata', 'project' => $project, 'language' => $language, 'format' => 'json', 'formatversion' => 2 // Prevents stripping of false values 8p - ); + ]; $url = wfAppendQuery( $wgCentralNoticeApiUrl, $q ); $apiResult = Http::get( $url, - array( 'timeout' => self::API_REQUEST_TIMEOUT * 0.8 ) ); + [ 'timeout' => self::API_REQUEST_TIMEOUT * 0.8 ] ); if ( !$apiResult ) { wfLogWarning( 'Couldn\'t get banner choice data via API.' ); @@ -128,18 +128,18 @@ // signature) emit a warning, but don't stop the show. if ( !$context ) { wfLogWarning( '$context is required for campaign mixins.' ); - return array(); + return []; } // Get the choices (possible campaigns and banners) for this user $choices = $this->getChoices( $context ); if ( !$choices ) { // If there are no choices, no dependencies - return array(); + return []; } // Run through the choices to get all needed mixin RL modules - $dependencies = array(); + $dependencies = []; foreach ( $choices as $choice ) { foreach ( $choice['mixins'] as $mixinName => $mixinParams ) { diff --git a/includes/CNDatabase.php b/includes/CNDatabase.php index 6291094..55f28d4 100644 --- a/includes/CNDatabase.php +++ b/includes/CNDatabase.php @@ -58,7 +58,7 @@ if ( $wgCentralDBname === false || $wgCentralDBname === $wgDBname ) { return wfGetDB( $target ); } else { - return wfGetDB( $target, array(), $wgCentralDBname ); + return wfGetDB( $target, [], $wgCentralDBname ); } } } diff --git a/includes/CNDeviceTarget.php b/includes/CNDeviceTarget.php index b171ef7..a1b1956 100644 --- a/includes/CNDeviceTarget.php +++ b/includes/CNDeviceTarget.php @@ -16,24 +16,24 @@ public static function getAvailableDevices( $flip = false ) { $dbr = CNDatabase::getDb(); - $devices = array(); + $devices = []; $res = $dbr->select( - array( 'known_devices' => 'cn_known_devices' ), - array( 'dev_id', 'dev_name', 'dev_display_label' ) + [ 'known_devices' => 'cn_known_devices' ], + [ 'dev_id', 'dev_name', 'dev_display_label' ] ); foreach ( $res as $row ) { if ( $flip ) { - $devices[ $row->dev_name ] = array( + $devices[ $row->dev_name ] = [ 'label' => $row->dev_display_label, 'id' => intval( $row->dev_id ), - ); + ]; } else { - $devices[ intval( $row->dev_id ) ] = array( + $devices[ intval( $row->dev_id ) ] = [ 'header' => $row->dev_name, 'label' => $row->dev_display_label, - ); + ]; } } @@ -51,18 +51,18 @@ public static function getDevicesAssociatedWithBanner( $bannerId ) { $dbr = CNDatabase::getDb(); - $devices = array(); + $devices = []; $res = $dbr->select( - array( + [ 'tdev' => 'cn_template_devices', 'devices' => 'cn_known_devices' - ), - array( 'devices.dev_id', 'dev_name' ), - array( + ], + [ 'devices.dev_id', 'dev_name' ], + [ 'tdev.tmp_id' => $bannerId, 'tdev.dev_id = devices.dev_id' - ), + ], __METHOD__ ); @@ -85,10 +85,10 @@ $db->insert( 'cn_known_devices', - array( + [ 'dev_name' => $deviceName, 'dev_display_label' => $displayLabel - ), + ], __METHOD__ ); @@ -112,19 +112,19 @@ // Remove all entries from the table for this banner $db->delete( 'cn_template_devices', - array( 'tmp_id' => $bannerId ), + [ 'tmp_id' => $bannerId ], __METHOD__ ); // Add the new device mappings if ( $newDevices ) { - $modifyArray = array(); + $modifyArray = []; foreach ( $newDevices as $device ) { if ( !array_key_exists( $device, $knownDevices ) ) { throw new RangeException( "Device name '$device' not known! Cannot add." ); } - $modifyArray[ ] = array( 'tmp_id' => $bannerId, - 'dev_id' => $knownDevices[ $device ][ 'id' ] ); + $modifyArray[ ] = [ 'tmp_id' => $bannerId, + 'dev_id' => $knownDevices[ $device ][ 'id' ] ]; } $db->insert( 'cn_template_devices', $modifyArray, __METHOD__ ); } diff --git a/includes/Campaign.php b/includes/Campaign.php index 7dd9111..177a411 100644 --- a/includes/Campaign.php +++ b/includes/Campaign.php @@ -197,17 +197,17 @@ // What selector are we using? if ( $this->id !== null ) { - $selector = array( 'not_id' => $this->id ); + $selector = [ 'not_id' => $this->id ]; } elseif ( $this->name !== null ) { - $selector = array( 'not_name' => $this->name ); + $selector = [ 'not_name' => $this->name ]; } else { throw new CampaignExistenceException( "No valid database key available for campaign." ); } // Get campaign info from database $row = $db->selectRow( - array( 'notices' => 'cn_notices' ), - array( + [ 'notices' => 'cn_notices' ], + [ 'not_id', 'not_name', 'not_start', @@ -219,7 +219,7 @@ 'not_geo', 'not_buckets', 'not_throttle', - ), + ], $selector, __METHOD__ ); @@ -254,7 +254,7 @@ $dbr = CNDatabase::getDb(); $eCampaignName = htmlspecialchars( $campaignName ); - return (bool)$dbr->selectRow( 'cn_notices', 'not_name', array( 'not_name' => $eCampaignName ) ); + return (bool)$dbr->selectRow( 'cn_notices', 'not_name', [ 'not_name' => $eCampaignName ] ); } /** @@ -275,7 +275,7 @@ */ static function getCampaigns( $project = null, $language = null, $location = null, $date = null, $enabled = true, $archived = false ) { - $notices = array(); + $notices = []; // Database setup $dbr = CNDatabase::getDb(); @@ -292,11 +292,11 @@ $encTimestamp = $dbr->addQuotes( $dbr->timestamp() ); } - $tables = array( 'notices' => 'cn_notices' ); - $conds = array( + $tables = [ 'notices' => 'cn_notices' ]; + $conds = [ "not_start <= $encTimestamp", "not_end >= $encTimestamp", - ); + ]; if ( $enabled ) { $conds[ 'not_enabled' ] = 1; @@ -376,8 +376,8 @@ // Get campaign info from database $row = $dbr->selectRow( - array( 'notices' => 'cn_notices' ), - array( + [ 'notices' => 'cn_notices' ], + [ 'not_id', 'not_start', 'not_end', @@ -388,12 +388,12 @@ 'not_geo', 'not_buckets', 'not_throttle', - ), - array( 'not_name' => $campaignName ), + ], + [ 'not_name' => $campaignName ], __METHOD__ ); if ( $row ) { - $campaign = array( + $campaign = [ 'start' => $row->not_start, 'end' => $row->not_end, 'enabled' => $row->not_enabled, @@ -403,7 +403,7 @@ 'geo' => $row->not_geo, 'buckets' => $row->not_buckets, 'throttle' => $row->not_throttle, - ); + ]; } else { return false; } @@ -416,7 +416,7 @@ $campaign[ 'countries' ] = implode( ", ", $geo_countries ); $bannersIn = Banner::getCampaignBanners( $row->not_id ); - $bannersOut = array(); + $bannersOut = []; // All we want are the banner names, weights, and buckets foreach ( $bannersIn as $key => $row ) { $outKey = $bannersIn[ $key ][ 'name' ]; @@ -455,23 +455,23 @@ $dbr = CNDatabase::getDb(); $res = $dbr->select( "cn_notice_log", - array( + [ "log_id" => "MAX(notlog_id)", - ), - array( + ], + [ "notlog_timestamp <= $ts", - ), + ], __METHOD__, - array( + [ "GROUP BY" => "notlog_not_id", - ) + ] ); - $campaigns = array(); + $campaigns = []; foreach ( $res as $row ) { $singleRes = $dbr->select( "cn_notice_log", - array( + [ "id" => "notlog_not_id", "name" => "notlog_not_name", "enabled" => "notlog_end_enabled", @@ -483,13 +483,13 @@ "banners" => "notlog_end_banners", "bucket_count" => "notlog_end_buckets", "throttle" => "notlog_end_throttle", - ), - array( + ], + [ "notlog_id = {$row->log_id}", "notlog_end_start <= $ts", "notlog_end_end >= $ts", "notlog_end_enabled = 1", - ), + ], __METHOD__ ); @@ -501,16 +501,16 @@ $campaign['languages'] = explode( ", ", $campaign['languages'] ); $campaign['countries'] = explode( ", ", $campaign['countries'] ); if ( $campaign['banners'] === null ) { - $campaign['banners'] = array(); + $campaign['banners'] = []; } else { $campaign['banners'] = FormatJson::decode( $campaign['banners'], true ); if ( !is_array( current( $campaign['banners'] ) ) ) { // Old log format; only had weight foreach ( $campaign['banners'] as $key => &$value ) { - $value = array( + $value = [ 'weight' => $value, 'bucket' => 0 - ); + ]; } } } @@ -527,17 +527,17 @@ $historical_banner['label'] = wfMessage( 'centralnotice-damaged-log', $name ); $historical_banner['display_anon'] = $historical_banner['anon']; $historical_banner['display_account'] = $historical_banner['account']; - $historical_banner['devices'] = array( 'desktop' ); + $historical_banner['devices'] = [ 'desktop' ]; } $banner['name'] = $name; $banner['label'] = $name; - $campaign_info = array( + $campaign_info = [ 'campaign' => $campaign['name'], 'campaign_z_index' => $campaign['preferred'], 'campaign_num_buckets' => $campaign['bucket_count'], 'campaign_throttle' => $campaign['throttle'], - ); + ]; $banner = array_merge( $banner, $campaign_info, $historical_banner ); } @@ -571,42 +571,42 @@ $dbr = CNDatabase::getDb(); // Prepare query conditions - $conds = array( 'notices.not_name' => $campaignName ); + $conds = [ 'notices.not_name' => $campaignName ]; if ( $compact ) { $conds['notice_mixins.nmxn_enabled'] = 1; } $dbRows = $dbr->select( - array( + [ 'notices' => 'cn_notices', 'notice_mixins' => 'cn_notice_mixins', 'notice_mixin_params' => 'cn_notice_mixin_params' - ), - array( + ], + [ 'notice_mixins.nmxn_mixin_name', 'notice_mixins.nmxn_enabled', 'notice_mixin_params.nmxnp_param_name', 'notice_mixin_params.nmxnp_param_value' - ), + ], $conds, __METHOD__, - array(), - array( - 'notice_mixins' => array( + [], + [ + 'notice_mixins' => [ 'INNER JOIN', 'notices.not_id = notice_mixins.nmxn_not_id' - ), - 'notice_mixin_params' => array( + ], + 'notice_mixin_params' => [ 'LEFT OUTER JOIN', 'notice_mixins.nmxn_id = notice_mixin_params.nmxnp_notice_mixin_id' - ) - ) + ] + ] ); // Build up the results // We expect a row for every parameter name-value pair for every mixin, // and maybe some with null name-value pairs (for mixins with no // parameters). - $campaignMixins = array(); + $campaignMixins = []; foreach ( $dbRows as $dbRow ) { $mixinName = $dbRow->nmxn_mixin_name; @@ -622,13 +622,13 @@ // Data structure depends on $compact if ( $compact ) { - $campaignMixins[$mixinName] = array(); + $campaignMixins[$mixinName] = []; } else { - $campaignMixins[$mixinName] = array( + $campaignMixins[$mixinName] = [ 'enabled' => (bool) $dbRow->nmxn_enabled, - 'parameters' => array() - ); + 'parameters' => [] + ]; } } @@ -728,7 +728,7 @@ // Note: the need to fetch the ID here highlights the need for some // kind of ORM. $noticeId = $dbw->selectRow( 'cn_notices', 'not_id', - array( 'not_name' => $campaignName ) )->not_id; + [ 'not_name' => $campaignName ] )->not_id; if ( $enable ) { @@ -739,24 +739,24 @@ $dbw->upsert( 'cn_notice_mixins', - array( + [ 'nmxn_not_id' => $noticeId, 'nmxn_mixin_name' => $mixinName, 'nmxn_enabled' => 1 - ), - array( 'nmxn_not_id', 'nmxn_mixin_name' ), - array( + ], + [ 'nmxn_not_id', 'nmxn_mixin_name' ], + [ 'nmxn_enabled' => 1 - ) + ] ); $noticeMixinId = $dbw->selectRow( 'cn_notice_mixins', 'nmxn_id', - array( + [ 'nmxn_not_id' => $noticeId, 'nmxn_mixin_name' => $mixinName - ) + ] )->nmxn_id; foreach ( $params as $paramName => $paramVal ) { @@ -782,15 +782,15 @@ $dbw->upsert( 'cn_notice_mixin_params', - array( + [ 'nmxnp_notice_mixin_id' => $noticeMixinId, 'nmxnp_param_name' => $paramName, 'nmxnp_param_value' => $paramVal - ), - array( 'nmxnp_notice_mixin_id', 'nmxnp_param_name' ), - array( + ], + [ 'nmxnp_notice_mixin_id', 'nmxnp_param_name' ], + [ 'nmxnp_param_value' => $paramVal - ) + ] ); } @@ -802,11 +802,11 @@ // table. $dbw->update( 'cn_notice_mixins', - array( 'nmxn_enabled' => 0 ), - array( + [ 'nmxn_enabled' => 0 ], + [ 'nmxn_not_id' => $noticeId, 'nmxn_mixin_name' => $mixinName - ) + ] ); } } @@ -819,7 +819,7 @@ static function getAllCampaignNames() { $dbr = CNDatabase::getDb(); $res = $dbr->select( 'cn_notices', 'not_name', null, __METHOD__ ); - $notices = array(); + $notices = []; foreach ( $res as $row ) { $notices[ ] = $row->not_name; } @@ -858,7 +858,7 @@ } if ( !$geo_countries ) { - $geo_countries = array(); + $geo_countries = []; } $dbw = CNDatabase::getDb( DB_MASTER ); @@ -868,49 +868,49 @@ $endTs = wfTimestamp( TS_MW, $endTime ); $dbw->insert( 'cn_notices', - array( 'not_name' => $noticeName, + [ 'not_name' => $noticeName, 'not_enabled' => (int)$enabled, 'not_start' => $dbw->timestamp( $startTs ), 'not_end' => $dbw->timestamp( $endTs ), 'not_geo' => (int)$geotargeted, 'not_throttle' => $throttle, 'not_preferred' => $priority, - ) + ] ); $not_id = $dbw->insertId(); if ( $not_id ) { // Do multi-row insert for campaign projects - $insertArray = array(); + $insertArray = []; foreach ( $projects as $project ) { - $insertArray[ ] = array( 'np_notice_id' => $not_id, 'np_project' => $project ); + $insertArray[ ] = [ 'np_notice_id' => $not_id, 'np_project' => $project ]; } $dbw->insert( 'cn_notice_projects', $insertArray, - __METHOD__, array( 'IGNORE' ) ); + __METHOD__, [ 'IGNORE' ] ); // Do multi-row insert for campaign languages - $insertArray = array(); + $insertArray = []; foreach ( $project_languages as $code ) { - $insertArray[ ] = array( 'nl_notice_id' => $not_id, 'nl_language' => $code ); + $insertArray[ ] = [ 'nl_notice_id' => $not_id, 'nl_language' => $code ]; } $dbw->insert( 'cn_notice_languages', $insertArray, - __METHOD__, array( 'IGNORE' ) ); + __METHOD__, [ 'IGNORE' ] ); if ( $geotargeted ) { // Do multi-row insert for campaign countries - $insertArray = array(); + $insertArray = []; foreach ( $geo_countries as $code ) { - $insertArray[ ] = array( 'nc_notice_id' => $not_id, 'nc_country' => $code ); + $insertArray[ ] = [ 'nc_notice_id' => $not_id, 'nc_country' => $code ]; } $dbw->insert( 'cn_notice_countries', $insertArray, - __METHOD__, array( 'IGNORE' ) ); + __METHOD__, [ 'IGNORE' ] ); } $dbw->endAtomic( __METHOD__ ); // Log the creation of the campaign - $beginSettings = array(); - $endSettings = array( + $beginSettings = []; + $endSettings = [ 'projects' => implode( ", ", $projects ), 'languages' => implode( ", ", $project_languages ), 'countries' => implode( ", ", $geo_countries ), @@ -921,7 +921,7 @@ 'locked' => 0, 'geo' => (int)$geotargeted, 'throttle' => $throttle, - ); + ]; Campaign::logCampaignChange( 'created', $not_id, $user, $beginSettings, $endSettings, $summary ); @@ -944,7 +944,7 @@ $dbr = CNDatabase::getDb( DB_MASTER ); $res = $dbr->select( 'cn_notices', 'not_name, not_locked', - array( 'not_name' => $campaignName ) + [ 'not_name' => $campaignName ] ); if ( $dbr->numRows( $res ) < 1 ) { return 'centralnotice-remove-notice-doesnt-exist'; @@ -966,11 +966,11 @@ $dbw = CNDatabase::getDb( DB_MASTER ); $dbw->startAtomic( __METHOD__ ); - $dbw->delete( 'cn_assignments', array( 'not_id' => $campaignId ) ); - $dbw->delete( 'cn_notices', array( 'not_name' => $campaignName ) ); - $dbw->delete( 'cn_notice_languages', array( 'nl_notice_id' => $campaignId ) ); - $dbw->delete( 'cn_notice_projects', array( 'np_notice_id' => $campaignId ) ); - $dbw->delete( 'cn_notice_countries', array( 'nc_notice_id' => $campaignId ) ); + $dbw->delete( 'cn_assignments', [ 'not_id' => $campaignId ] ); + $dbw->delete( 'cn_notices', [ 'not_name' => $campaignName ] ); + $dbw->delete( 'cn_notice_languages', [ 'nl_notice_id' => $campaignId ] ); + $dbw->delete( 'cn_notice_projects', [ 'np_notice_id' => $campaignId ] ); + $dbw->delete( 'cn_notice_countries', [ 'nc_notice_id' => $campaignId ] ); $dbw->endAtomic( __METHOD__ ); } @@ -989,10 +989,10 @@ $noticeId = Campaign::getNoticeId( $eNoticeName ); $templateId = Banner::fromName( $templateName )->getId(); $res = $dbw->select( 'cn_assignments', 'asn_id', - array( + [ 'tmp_id' => $templateId, 'not_id' => $noticeId - ) + ] ); if ( $dbw->numRows( $res ) > 0 ) { @@ -1001,12 +1001,12 @@ $noticeId = Campaign::getNoticeId( $eNoticeName ); $dbw->insert( 'cn_assignments', - array( + [ 'tmp_id' => $templateId, 'tmp_weight' => $weight, 'not_id' => $noticeId, 'asn_bucket' => $bucket, - ) + ] ); return true; @@ -1019,7 +1019,7 @@ $dbw = CNDatabase::getDb( DB_MASTER ); $noticeId = Campaign::getNoticeId( $noticeName ); $templateId = Banner::fromName( $templateName )->getId(); - $dbw->delete( 'cn_assignments', array( 'tmp_id' => $templateId, 'not_id' => $noticeId ) ); + $dbw->delete( 'cn_assignments', [ 'tmp_id' => $templateId, 'not_id' => $noticeId ] ); } /** @@ -1030,7 +1030,7 @@ static function getNoticeId( $noticeName ) { $dbr = CNDatabase::getDb(); $eNoticeName = htmlspecialchars( $noticeName ); - $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) ); + $row = $dbr->selectRow( 'cn_notices', 'not_id', [ 'not_name' => $eNoticeName ] ); if ( $row ) { return $row->not_id; } else { @@ -1044,7 +1044,7 @@ static function getNoticeName( $noticeId ) { $dbr = CNDatabase::getDb(); if ( is_numeric( $noticeId ) ) { - $row = $dbr->selectRow( 'cn_notices', 'not_name', array( 'not_id' => $noticeId ) ); + $row = $dbr->selectRow( 'cn_notices', 'not_name', [ 'not_id' => $noticeId ] ); if ( $row ) { return $row->not_name; } @@ -1055,11 +1055,11 @@ static function getNoticeProjects( $noticeName ) { $dbr = CNDatabase::getDb(); $eNoticeName = htmlspecialchars( $noticeName ); - $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) ); - $projects = array(); + $row = $dbr->selectRow( 'cn_notices', 'not_id', [ 'not_name' => $eNoticeName ] ); + $projects = []; if ( $row ) { $res = $dbr->select( 'cn_notice_projects', 'np_project', - array( 'np_notice_id' => $row->not_id ) ); + [ 'np_notice_id' => $row->not_id ] ); foreach ( $res as $projectRow ) { $projects[ ] = $projectRow->np_project; } @@ -1071,11 +1071,11 @@ static function getNoticeLanguages( $noticeName ) { $dbr = CNDatabase::getDb(); $eNoticeName = htmlspecialchars( $noticeName ); - $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) ); - $languages = array(); + $row = $dbr->selectRow( 'cn_notices', 'not_id', [ 'not_name' => $eNoticeName ] ); + $languages = []; if ( $row ) { $res = $dbr->select( 'cn_notice_languages', 'nl_language', - array( 'nl_notice_id' => $row->not_id ) ); + [ 'nl_notice_id' => $row->not_id ] ); foreach ( $res as $langRow ) { $languages[ ] = $langRow->nl_language; } @@ -1087,11 +1087,11 @@ static function getNoticeCountries( $noticeName ) { $dbr = CNDatabase::getDb(); $eNoticeName = htmlspecialchars( $noticeName ); - $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) ); - $countries = array(); + $row = $dbr->selectRow( 'cn_notices', 'not_id', [ 'not_name' => $eNoticeName ] ); + $countries = []; if ( $row ) { $res = $dbr->select( 'cn_notice_countries', 'nc_country', - array( 'nc_notice_id' => $row->not_id ) ); + [ 'nc_notice_id' => $row->not_id ] ); foreach ( $res as $countryRow ) { $countries[ ] = $countryRow->nc_country; } @@ -1124,11 +1124,11 @@ $endDate = $dbw->timestamp( $end ); $dbw->update( 'cn_notices', - array( + [ 'not_start' => $startDate, 'not_end' => $endDate - ), - array( 'not_name' => $noticeName ) + ], + [ 'not_name' => $noticeName ] ); return true; @@ -1149,8 +1149,8 @@ $settingName = strtolower( $settingName ); $dbw = CNDatabase::getDb( DB_MASTER ); $dbw->update( 'cn_notices', - array( 'not_' . $settingName => (int)$settingValue ), - array( 'not_name' => $noticeName ) + [ 'not_' . $settingName => (int)$settingValue ], + [ 'not_name' => $noticeName ] ); } } @@ -1191,8 +1191,8 @@ $settingName = strtolower( $settingName ); $dbw = CNDatabase::getDb( DB_MASTER ); $dbw->update( 'cn_notices', - array( 'not_'.$settingName => $settingValue ), - array( 'not_name' => $noticeName ) + [ 'not_'.$settingName => $settingValue ], + [ 'not_name' => $noticeName ] ); } } @@ -1208,11 +1208,11 @@ $dbw = CNDatabase::getDb( DB_MASTER ); $noticeId = Campaign::getNoticeId( $noticeName ); $dbw->update( 'cn_assignments', - array( 'tmp_weight' => $weight ), - array( + [ 'tmp_weight' => $weight ], + [ 'tmp_id' => $templateId, 'not_id' => $noticeId - ) + ] ); } @@ -1228,11 +1228,11 @@ $dbw = CNDatabase::getDb( DB_MASTER ); $noticeId = Campaign::getNoticeId( $noticeName ); $dbw->update( 'cn_assignments', - array( 'asn_bucket' => $bucket ), - array( + [ 'asn_bucket' => $bucket ], + [ 'tmp_id' => $templateId, 'not_id' => $noticeId - ) + ] ); } @@ -1240,10 +1240,10 @@ static function updateProjectName( $notice, $projectName ) { $dbw = CNDatabase::getDb( DB_MASTER ); $dbw->update( 'cn_notices', - array( 'not_project' => $projectName ), - array( + [ 'not_project' => $projectName ], + [ 'not_name' => $notice - ) + ] ); } @@ -1255,21 +1255,21 @@ $oldProjects = Campaign::getNoticeProjects( $notice ); // Get the notice id - $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) ); + $row = $dbw->selectRow( 'cn_notices', 'not_id', [ 'not_name' => $notice ] ); // Add newly assigned projects $addProjects = array_diff( $newProjects, $oldProjects ); - $insertArray = array(); + $insertArray = []; foreach ( $addProjects as $project ) { - $insertArray[ ] = array( 'np_notice_id' => $row->not_id, 'np_project' => $project ); + $insertArray[ ] = [ 'np_notice_id' => $row->not_id, 'np_project' => $project ]; } - $dbw->insert( 'cn_notice_projects', $insertArray, __METHOD__, array( 'IGNORE' ) ); + $dbw->insert( 'cn_notice_projects', $insertArray, __METHOD__, [ 'IGNORE' ] ); // Remove disassociated projects $removeProjects = array_diff( $oldProjects, $newProjects ); if ( $removeProjects ) { $dbw->delete( 'cn_notice_projects', - array( 'np_notice_id' => $row->not_id, 'np_project' => $removeProjects ) + [ 'np_notice_id' => $row->not_id, 'np_project' => $removeProjects ] ); } @@ -1284,21 +1284,21 @@ $oldLanguages = Campaign::getNoticeLanguages( $notice ); // Get the notice id - $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) ); + $row = $dbw->selectRow( 'cn_notices', 'not_id', [ 'not_name' => $notice ] ); // Add newly assigned languages $addLanguages = array_diff( $newLanguages, $oldLanguages ); - $insertArray = array(); + $insertArray = []; foreach ( $addLanguages as $code ) { - $insertArray[ ] = array( 'nl_notice_id' => $row->not_id, 'nl_language' => $code ); + $insertArray[ ] = [ 'nl_notice_id' => $row->not_id, 'nl_language' => $code ]; } - $dbw->insert( 'cn_notice_languages', $insertArray, __METHOD__, array( 'IGNORE' ) ); + $dbw->insert( 'cn_notice_languages', $insertArray, __METHOD__, [ 'IGNORE' ] ); // Remove disassociated languages $removeLanguages = array_diff( $oldLanguages, $newLanguages ); if ( $removeLanguages ) { $dbw->delete( 'cn_notice_languages', - array( 'nl_notice_id' => $row->not_id, 'nl_language' => $removeLanguages ) + [ 'nl_notice_id' => $row->not_id, 'nl_language' => $removeLanguages ] ); } @@ -1313,21 +1313,21 @@ $oldCountries = Campaign::getNoticeCountries( $notice ); // Get the notice id - $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) ); + $row = $dbw->selectRow( 'cn_notices', 'not_id', [ 'not_name' => $notice ] ); // Add newly assigned countries $addCountries = array_diff( $newCountries, $oldCountries ); - $insertArray = array(); + $insertArray = []; foreach ( $addCountries as $code ) { - $insertArray[ ] = array( 'nc_notice_id' => $row->not_id, 'nc_country' => $code ); + $insertArray[ ] = [ 'nc_notice_id' => $row->not_id, 'nc_country' => $code ]; } - $dbw->insert( 'cn_notice_countries', $insertArray, __METHOD__, array( 'IGNORE' ) ); + $dbw->insert( 'cn_notice_countries', $insertArray, __METHOD__, [ 'IGNORE' ] ); // Remove disassociated countries $removeCountries = array_diff( $oldCountries, $newCountries ); if ( $removeCountries ) { $dbw->delete( 'cn_notice_countries', - array( 'nc_notice_id' => $row->not_id, 'nc_country' => $removeCountries ) + [ 'nc_notice_id' => $row->not_id, 'nc_country' => $removeCountries ] ); } @@ -1347,8 +1347,8 @@ * @return integer: ID of log entry (or null) */ static function logCampaignChange( - $action, $campaignId, $user, $beginSettings = array(), - $endSettings = array(), $summary = null + $action, $campaignId, $user, $beginSettings = [], + $endSettings = [], $summary = null ) { ChoiceDataProvider::invalidateCache(); @@ -1361,14 +1361,14 @@ if ( $user->getId() > 0 ) { // User::getID returns 0 for anonymous or non-existant users $dbw = CNDatabase::getDb( DB_MASTER ); - $log = array( + $log = [ 'notlog_timestamp' => $dbw->timestamp(), 'notlog_user_id' => $user->getId(), 'notlog_action' => $action, 'notlog_not_id' => $campaignId, 'notlog_not_name' => Campaign::getNoticeName( $campaignId ), 'notlog_comment' => $summary, - ); + ]; foreach ( $beginSettings as $key => $value ) { $log[ 'notlog_begin_' . $key ] = $value; @@ -1388,7 +1388,7 @@ static function campaignLogs( $campaign=false, $username=false, $start=false, $end=false, $limit=50, $offset=0 ) { - $conds = array(); + $conds = []; if ( $start ) { $conds[] = "notlog_timestamp >= $start"; } @@ -1409,13 +1409,13 @@ $dbr = CNDatabase::getDb(); $res = $dbr->select( 'cn_notice_log', '*', $conds, __METHOD__, - array( + [ "ORDER BY" => "notlog_timestamp DESC", "LIMIT" => $limit, "OFFSET" => $offset, - ) + ] ); - $logs = array(); + $logs = []; foreach ( $res as $row ) { $entry = new CampaignLog( $row ); $logs[] = array_merge( get_object_vars( $entry ), $entry->changes() ); diff --git a/includes/CampaignLog.php b/includes/CampaignLog.php index 9c8af04..47c7c2e 100644 --- a/includes/CampaignLog.php +++ b/includes/CampaignLog.php @@ -1,18 +1,18 @@ <?php class CampaignLog { - private static $basic_fields = array( + private static $basic_fields = [ 'start', 'end', 'enabled', 'preferred', 'locked', 'geo', 'buckets' - ); - private static $list_fields = array( 'projects', 'languages', 'countries' ); - private static $map_fields = array( 'banners' ); + ]; + private static $list_fields = [ 'projects', 'languages', 'countries' ]; + private static $map_fields = [ 'banners' ]; /** * @param stdClass|null $row */ function __construct( $row = null ) { - $begin = array(); - $end = array(); + $begin = []; + $end = []; if ( $row ) { $comma_explode = function( $str ) { return explode( ", ", $str ); @@ -61,8 +61,8 @@ # TODO: use in logpager function changes() { - $removed = array(); - $added = array(); + $removed = []; + $added = []; # XXX cannot use "this" in closures until php 5.4 $begin =& $this->begin; @@ -81,11 +81,11 @@ $diff_list = function( $name ) use ( &$removed, &$added, &$begin, &$end ) { if ( $begin[ $name ] !== $end[ $name ] ) { $removed[ $name ] = array_diff( $begin[ $name ], $end[ $name ] ); - if ( !$removed[ $name ] || $removed[ $name ] === array( "" ) ) { + if ( !$removed[ $name ] || $removed[ $name ] === [ "" ] ) { unset( $removed[ $name ] ); } $added[ $name ] = array_diff( $end[ $name ], $begin[ $name ] ); - if ( !$added[ $name ] || $added[ $name ] === array( "" ) ) { + if ( !$added[ $name ] || $added[ $name ] === [ "" ] ) { unset( $added[ $name ] ); } } @@ -124,6 +124,6 @@ $diff_map( $name ); } - return array( 'removed' => $removed, 'added' => $added ); + return [ 'removed' => $removed, 'added' => $added ]; } } diff --git a/includes/ChoiceDataProvider.php b/includes/ChoiceDataProvider.php index 71eeea5..78b2a86 100644 --- a/includes/ChoiceDataProvider.php +++ b/includes/ChoiceDataProvider.php @@ -85,25 +85,25 @@ // campaigns that will start during that interval. $start = $dbr->timestamp( time() + self::CACHE_TTL ); $end = $dbr->timestamp(); - $conds = array( + $conds = [ 'notices.not_start <= ' . $dbr->addQuotes( $start ), 'notices.not_end >= ' . $dbr->addQuotes( $end ), 'notices.not_enabled' => 1, 'notices.not_archived' => 0, 'notice_projects.np_project' => $project, 'notice_languages.nl_language' => $language - ); + ]; // Query campaigns and banners at once $dbRows = $dbr->select( - array( + [ 'notices' => 'cn_notices', 'assignments' => 'cn_assignments', 'templates' => 'cn_templates', 'notice_projects' => 'cn_notice_projects', 'notice_languages' => 'cn_notice_languages', - ), - array( + ], + [ 'notices.not_id', 'notices.not_name', 'notices.not_start', @@ -119,24 +119,24 @@ 'templates.tmp_display_anon', 'templates.tmp_display_account', 'templates.tmp_category' - ), + ], $conds, __METHOD__, - array(), - array( - 'assignments' => array( + [], + [ + 'assignments' => [ 'INNER JOIN', 'notices.not_id = assignments.not_id' - ), - 'templates' => array( + ], + 'templates' => [ 'INNER JOIN', 'assignments.tmp_id = templates.tmp_id' - ), - 'notice_projects' => array( + ], + 'notice_projects' => [ 'INNER JOIN', 'notices.not_id = notice_projects.np_notice_id' - ), - 'notice_languages' => array( + ], + 'notice_languages' => [ 'INNER JOIN', 'notices.not_id = notice_languages.nl_notice_id' - ) - ) + ] + ] ); // Pare it down into a nicer data structure and prepare the next queries. @@ -144,9 +144,9 @@ // data together. But before returning it, we'll change associative // arrays to indexed ones at levels where the keys are not needed by the // client. - $choices = array(); - $bannerIds = array(); - $assignmentKeysByBannerIdAndCampaignId = array(); + $choices = []; + $bannerIds = []; + $assignmentKeysByBannerIdAndCampaignId = []; foreach ( $dbRows as $dbRow ) { @@ -169,7 +169,7 @@ // repeated on every row for any campaign. Note that these // keys don't make it into data structure we return. if ( !isset ( $choices[$campaignId] ) ) { - $choices[$campaignId] = array( + $choices[$campaignId] = [ 'name' => $campaignName, 'start' => intval( wfTimestamp( TS_UNIX, $dbRow->not_start ) ), 'end' => intval( wfTimestamp( TS_UNIX, $dbRow->not_end ) ), @@ -177,23 +177,23 @@ 'throttle' => intval( $dbRow->not_throttle ), 'bucket_count' => intval( $dbRow->not_buckets ), 'geotargeted' => (bool) $dbRow->not_geo, - 'banners' => array() - ); + 'banners' => [] + ]; } // A temporary assignment key so we can get back to this part of the // data structure quickly and add in devices. $assignmentKey = $bannerId . ':' . $bucket; - $choices[$campaignId]['banners'][$assignmentKey] = array( + $choices[$campaignId]['banners'][$assignmentKey] = [ 'name' => $bannerName, 'bucket' => intval( $bucket ), 'weight' => intval( $dbRow->tmp_weight ), 'category' => $category, 'display_anon' => (bool) $dbRow->tmp_display_anon, 'display_account' => (bool) $dbRow->tmp_display_account, - 'devices' => array() // To be filled by the last query - ); + 'devices' => [] // To be filled by the last query + ]; $bannerIds[] = $bannerId; @@ -212,25 +212,25 @@ // We have to eliminate notices that are not geotargeted, since they // may have residual data in the cn_notice_countries table. $dbRows = $dbr->select( - array( + [ 'notices' => 'cn_notices', 'notice_countries' => 'cn_notice_countries', - ), - array( + ], + [ 'notices.not_id', 'notice_countries.nc_country' - ), - array( + ], + [ 'notices.not_geo' => 1, 'notices.not_id' => array_keys( $choices ) - ), + ], __METHOD__, - array(), - array( - 'notice_countries' => array( + [], + [ + 'notice_countries' => [ 'INNER JOIN', 'notices.not_id = notice_countries.nc_notice_id' - ) - ) + ] + ] ); // Add countries to our data structure. @@ -254,24 +254,24 @@ // Fetch the devices $dbRows = $dbr->select( - array( + [ 'template_devices' => 'cn_template_devices', 'known_devices' => 'cn_known_devices', - ), - array( + ], + [ 'template_devices.tmp_id', 'known_devices.dev_name' - ), - array( + ], + [ 'template_devices.tmp_id' => $bannerIds - ), + ], __METHOD__, - array(), - array( - 'known_devices' => array( + [], + [ + 'known_devices' => [ 'INNER JOIN', 'template_devices.dev_id = known_devices.dev_id' - ) - ) + ] + ] ); // Add devices to the data structure. diff --git a/includes/GeoTarget.php b/includes/GeoTarget.php index 0d01982..4ed0321 100644 --- a/includes/GeoTarget.php +++ b/includes/GeoTarget.php @@ -10,9 +10,9 @@ * @return array */ static function getCountriesList( $code ) { - $countries = array(); + $countries = []; - if ( is_callable( array( 'CountryNames', 'getNames' ) ) ) { + if ( is_callable( [ 'CountryNames', 'getNames' ] ) ) { // Retrieve the list of countries in user's language (via CLDR) $countries = CountryNames::getNames( $code ); } @@ -20,7 +20,7 @@ // If not via CLDR, we have our own list if ( !$countries ) { // Use this as fallback if CLDR extension is not enabled - $countries = array( + $countries = [ 'AF'=> 'Afghanistan', 'AL'=> 'Albania', 'DZ'=> 'Algeria', @@ -262,7 +262,7 @@ 'YE'=> 'Yemen', 'ZM'=> 'Zambia', 'ZW'=> 'Zimbabwe' - ); + ]; } // And we need to add MaxMind specific countries: http://www.maxmind.com/en/iso3166 diff --git a/includes/MixinController.php b/includes/MixinController.php index 60a5bc5..1fc506a 100644 --- a/includes/MixinController.php +++ b/includes/MixinController.php @@ -3,7 +3,7 @@ class MixinController { protected $mixins; - protected $magicWords = array(); + protected $magicWords = []; protected $uiContext; function __construct( IContextSource $uiContext, $mixins ) { @@ -45,7 +45,7 @@ } function getPreloadJsSnippets() { - $snippets = array(); + $snippets = []; foreach ( $this->mixins as $name => $info ) { if ( !empty( $info['preloadJs'] ) ) { $filename = $info['localBasePath'] . DIRECTORY_SEPARATOR . $info['preloadJs']; @@ -60,7 +60,7 @@ } function getResourceLoaderModules() { - $modules = array(); + $modules = []; foreach ( $this->mixins as $name => $info ) { if ( !empty( $info['resourceLoader'] ) ) { $modules[$name] = $info['resourceLoader']; @@ -73,7 +73,7 @@ $this->magicWords[$word] = $callback; } - function renderMagicWord( $word, $params = array() ) { + function renderMagicWord( $word, $params = [] ) { if ( array_key_exists( $word, $this->magicWords ) ) { $callback = $this->magicWords[$word]; if ( is_callable( $callback ) ) { -- To view, visit https://gerrit.wikimedia.org/r/358050 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icdc4f74595a7fa25976340f18c97caf5aeb1269b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CentralNotice Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits