jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/358030 )
Change subject: Break long lines - includes / tests ...................................................................... Break long lines - includes / tests Prepare to make phpcs pass Change-Id: I567813e0953d5f9d0d1bcaeebc751fd702845ca2 --- M includes/Banner.php M includes/BannerMessage.php M includes/BannerMessageGroup.php M includes/BannerRenderer.php M includes/CNDeviceTarget.php M includes/Campaign.php M includes/CampaignLog.php M includes/HtmlFormElements/HTMLCentralNoticeBanner.php M tests/BannerTest.php M tests/CentralNoticeTest.php M tests/HistoryTest.php 11 files changed, 146 insertions(+), 64 deletions(-) Approvals: Reedy: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Banner.php b/includes/Banner.php index 49e36fe..2a331d6 100644 --- a/includes/Banner.php +++ b/includes/Banner.php @@ -79,7 +79,8 @@ /** @var bool True if archived and hidden from default view. */ protected $archived = false; - /** @var string[] Devices this banner should be allocated to in the form {Device ID => Device header name} */ + /** @var string[] Devices this banner should be allocated to in the form + * {Device ID => Device header name} */ protected $devices = array(); /** @var string[] Names of enabled mixins */ @@ -345,7 +346,9 @@ $keystr[] = "{$key} = {$value}"; } $keystr = implode( " AND ", $keystr ); - throw new BannerExistenceException( "No banner exists where {$keystr}. Could not load." ); + throw new BannerExistenceException( + "No banner exists where {$keystr}. Could not load." + ); } // Set the dirty flag to not dirty because we just loaded clean data @@ -570,7 +573,9 @@ // when a deprecated mixin is being used; but also when we // do deprecate something we should make sure nothing is using // it! - wfLogWarning( "Mixin does not exist: {$row->mixin_name}, included from banner {$this->name}" ); + wfLogWarning( + "Mixin does not exist: {$row->mixin_name}, included from banner {$this->name}" + ); } $this->mixins[$row->mixin_name] = $wgCentralNoticeBannerMixins[$row->mixin_name]; } @@ -880,7 +885,8 @@ $availableLangs = array(); // Bit of an ugly hack to get just the banner prefix - $prefix = $this->getMessageField( '' )->getDbKey( null, $inTranslation ? NS_CN_BANNER : NS_MEDIAWIKI ); + $prefix = $this->getMessageField( '' ) + ->getDbKey( null, $inTranslation ? NS_CN_BANNER : NS_MEDIAWIKI ); $db = CNDatabase::getDb(); $result = $db->select( 'page', @@ -892,7 +898,12 @@ __METHOD__ ); while ( $row = $result->fetchRow() ) { - if ( preg_match( "/\Q{$prefix}\E([^\/]+)(?:\/([a-z_]+))?/", $row['page_title'], $matches ) ) { + if ( + preg_match( + "/\Q{$prefix}\E([^\/]+)(?:\/([a-z_]+))?/", $row['page_title'], + $matches + ) + ) { if ( isset( $matches[2] ) ) { $lang = $matches[2]; } else { @@ -1206,17 +1217,26 @@ foreach ( $res as $row ) { $banners[ ] = array( - 'name' => $row->tmp_name, // name of the banner - 'weight' => intval( $row->tmp_weight ), // weight assigned to the banner - 'display_anon' => intval( $row->tmp_display_anon ), // display to anonymous users? - 'display_account' => intval( $row->tmp_display_account ), // display to logged in users? - 'fundraising' => intval( $row->tmp_category === 'fundraising' ), // fundraising banner? - 'device' => $row->dev_name, // device this banner can target - 'campaign' => $row->not_name, // campaign the banner is assigned to - 'campaign_z_index' => $row->not_preferred, // z level of the campaign + // name of the banner + 'name' => $row->tmp_name, + // weight assigned to the banner + 'weight' => intval( $row->tmp_weight ), + // display to anonymous users? + 'display_anon' => intval( $row->tmp_display_anon ), + // display to logged in users? + 'display_account' => intval( $row->tmp_display_account ), + // fundraising banner? + 'fundraising' => intval( $row->tmp_category === 'fundraising' ), + // device this banner can target + 'device' => $row->dev_name, + // campaign the banner is assigned to + 'campaign' => $row->not_name, + // z level of the campaign + 'campaign_z_index' => $row->not_preferred, 'campaign_num_buckets' => intval( $row->not_buckets ), 'campaign_throttle' => intval( $row->not_throttle ), - 'bucket' => ( intval( $row->not_buckets ) == 1 ) ? 0 : intval( $row->asn_bucket ), + 'bucket' => ( intval( $row->not_buckets ) == 1 ) + ? 0 : intval( $row->asn_bucket ), ); } } @@ -1241,7 +1261,8 @@ $details = array( 'anon' => (int)$banner->allocateToAnon(), 'account' => (int)$banner->allocateToLoggedIn(), - 'fundraising' => (int)($banner->getCategory() === 'fundraising'), // TODO: Death to this! + // TODO: Death to this! + 'fundraising' => (int)($banner->getCategory() === 'fundraising'), 'category' => $banner->getCategory(), 'controller_mixin' => implode( ",", array_keys( $banner->getMixins() ) ), 'devices' => array_values( $banner->getDevices() ), @@ -1426,7 +1447,9 @@ } elseif ( $this->id !== null ) { $selector = array( 'tmp_id' => $this->id ); } else { - throw new BannerDataException( 'Cannot determine banner existence without name or ID.' ); + throw new BannerDataException( + 'Cannot determine banner existence without name or ID.' + ); } $row = $db->selectRow( 'cn_templates', 'tmp_name', $selector ); if ( $row ) { diff --git a/includes/BannerMessage.php b/includes/BannerMessage.php index 7afdb80..b530268 100644 --- a/includes/BannerMessage.php +++ b/includes/BannerMessage.php @@ -32,7 +32,9 @@ } elseif ( $namespace === NS_CN_BANNER ) { return "{$this->banner_name}-{$this->name}/{$lang}"; } else { - throw new RangeException( "Namespace '$namespace' not known for having CentralNotice messages." ); + throw new RangeException( + "Namespace '$namespace' not known for having CentralNotice messages." + ); } } diff --git a/includes/BannerMessageGroup.php b/includes/BannerMessageGroup.php index adb3e0d..35ced52 100644 --- a/includes/BannerMessageGroup.php +++ b/includes/BannerMessageGroup.php @@ -121,7 +121,11 @@ */ static function getTranslateGroupName( $bannerName ) { if ( strpos( $bannerName, 'Centralnotice-template' ) === 0 ) { - return str_replace( 'Centralnotice-template', BannerMessageGroup::TRANSLATE_GROUP_NAME_BASE, $bannerName ); + return str_replace( + 'Centralnotice-template', + BannerMessageGroup::TRANSLATE_GROUP_NAME_BASE, + $bannerName + ); } else { return BannerMessageGroup::TRANSLATE_GROUP_NAME_BASE . '-' . $bannerName; } @@ -152,7 +156,8 @@ // Deal with an aggregate group object having changed $groups = $group->getGroups(); foreach ( $groups as $subgroup ) { - BannerMessageGroup::updateBannerGroupStateHook( $subgroup, $code, $currentState, $newState ); + BannerMessageGroup::updateBannerGroupStateHook( + $subgroup, $code, $currentState, $newState ); } } elseif ( ( $group instanceof BannerMessageGroup ) @@ -201,7 +206,8 @@ array( 'ready', array( 'PROOFREAD' => 'MAX' ) ), array( 'proofreading', array( 'TRANSLATED' => 'MAX' ) ), array( 'progress', array( 'UNTRANSLATED' => 'NONZERO' ) ), - array( 'unset', array( 'UNTRANSLATED' => 'MAX', 'OUTDATED' => 'ZERO', 'TRANSLATED' => 'ZERO' ) ), + array( 'unset', array( 'UNTRANSLATED' => 'MAX', 'OUTDATED' => 'ZERO', + 'TRANSLATED' => 'ZERO' ) ), ), ); @@ -256,7 +262,9 @@ public static function getLanguagesInState( $banner, $state ) { if ( !BannerMessageGroup::isUsingGroupReview() ) { - throw new LogicException( 'CentralNotice is not using group review. Cannot query group review state.' ); + throw new LogicException( + 'CentralNotice is not using group review. Cannot query group review state.' + ); } $groupName = BannerMessageGroup::getTranslateGroupName( $banner ); diff --git a/includes/BannerRenderer.php b/includes/BannerRenderer.php index 663b699..8bd5216 100644 --- a/includes/BannerRenderer.php +++ b/includes/BannerRenderer.php @@ -37,7 +37,9 @@ * * @param boolean $debug If false, minify the output. */ - function __construct( IContextSource $context, Banner $banner, $campaignName = null, $debug = false ) { + function __construct( + IContextSource $context, Banner $banner, $campaignName = null, $debug = false + ) { $this->context = $context; $this->banner = $banner; @@ -120,7 +122,8 @@ /** * Get the body of the banner, with all transformations applied. * - * FIXME: "->inLanguage( $context->getLanguage() )" is necessary due to a bug in DerivativeContext + * FIXME: "->inLanguage( $context->getLanguage() )" is necessary due to a bug + * in DerivativeContext * * @return string HTML fragment for the banner body. */ diff --git a/includes/CNDeviceTarget.php b/includes/CNDeviceTarget.php index 5595c2a..6a40141 100644 --- a/includes/CNDeviceTarget.php +++ b/includes/CNDeviceTarget.php @@ -7,9 +7,11 @@ /** * Get a listing of all known targetable devices. * - * @param bool $flip If true will return {<header string value>: {'id': <id>, 'label': <wiki text label>}} + * @param bool $flip If true will return + * {<header string value>: {'id': <id>, 'label': <wiki text label>}} * - * @return array Array of devices in format {id: {'header': <internal string value>, 'label': <wiki text label>}} + * @return array Array of devices in format + * {id: {'header': <internal string value>, 'label': <wiki text label>}} */ public static function getAvailableDevices( $flip = false ) { $dbr = CNDatabase::getDb(); @@ -121,7 +123,8 @@ 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[ ] = array( '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 e50d9d7..4715981 100644 --- a/includes/Campaign.php +++ b/includes/Campaign.php @@ -237,7 +237,8 @@ $this->throttle = (int)$row->not_throttle; } else { throw new CampaignExistenceException( - "Campaign could not be retrieved from database with id '{$this->id}' or name '{$this->name}'" + "Campaign could not be retrieved from database " . + "with id '{$this->id}' or name '{$this->name}'" ); } } @@ -595,7 +596,8 @@ 'INNER JOIN', 'notices.not_id = notice_mixins.nmxn_not_id' ), 'notice_mixin_params' => array( - 'LEFT OUTER JOIN', 'notice_mixins.nmxn_id = notice_mixin_params.nmxnp_notice_mixin_id' + 'LEFT OUTER JOIN', + 'notice_mixins.nmxn_id = notice_mixin_params.nmxnp_notice_mixin_id' ) ) ); @@ -1163,7 +1165,9 @@ * @param int $min The min that the value can take, default 0 * @throws InvalidArgumentException|RangeException */ - static function setNumericCampaignSetting( $noticeName, $settingName, $settingValue, $max = 1, $min = 0 ) { + static function setNumericCampaignSetting( + $noticeName, $settingName, $settingValue, $max = 1, $min = 0 + ) { if ( $max <= $min ) { throw new RangeException( 'Max must be greater than min.' ); } @@ -1381,8 +1385,9 @@ } } - static function campaignLogs( $campaign=false, $username=false, $start=false, $end=false, $limit=50, $offset=0 ) { - + static function campaignLogs( + $campaign=false, $username=false, $start=false, $end=false, $limit=50, $offset=0 + ) { $conds = array(); if ( $start ) { $conds[] = "notlog_timestamp >= $start"; diff --git a/includes/CampaignLog.php b/includes/CampaignLog.php index e0500c9..07e1147 100644 --- a/includes/CampaignLog.php +++ b/includes/CampaignLog.php @@ -1,7 +1,9 @@ <?php class CampaignLog { - private static $basic_fields = array( 'start', 'end', 'enabled', 'preferred', 'locked', 'geo', 'buckets' ); + private static $basic_fields = array( + 'start', 'end', 'enabled', 'preferred', 'locked', 'geo', 'buckets' + ); private static $list_fields = array( 'projects', 'languages', 'countries' ); private static $map_fields = array( 'banners' ); diff --git a/includes/HtmlFormElements/HTMLCentralNoticeBanner.php b/includes/HtmlFormElements/HTMLCentralNoticeBanner.php index 4a7d8d3..a892d7d 100644 --- a/includes/HtmlFormElements/HTMLCentralNoticeBanner.php +++ b/includes/HtmlFormElements/HTMLCentralNoticeBanner.php @@ -68,11 +68,15 @@ } public function getTableRow( $value ) { - throw new BadMethodCallException( "getTableRow() is not implemented for HTMLCentralNoticeBanner" ); + throw new BadMethodCallException( + "getTableRow() is not implemented for HTMLCentralNoticeBanner" + ); } public function getRaw( $value ) { - throw new BadMethodCallException( "getRaw() is not implemented for HTMLCentralNoticeBanner" ); + throw new BadMethodCallException( + "getRaw() is not implemented for HTMLCentralNoticeBanner" + ); } public function getDiv( $value ) { @@ -93,7 +97,8 @@ ) ); - // Make the label; this consists of a text link to the banner editor, and a series of status icons + // Make the label; this consists of a text link to the banner editor, + // and a series of status icons if ( array_key_exists( 'withlabel', $this->mParams ) ) { $bannerName = $this->mParams['banner']; $html .= Xml::openElement( 'div', array( 'class' => 'cn-banner-list-element-label' ) ); diff --git a/tests/BannerTest.php b/tests/BannerTest.php index c65b899..2343618 100644 --- a/tests/BannerTest.php +++ b/tests/BannerTest.php @@ -39,20 +39,30 @@ $this->assertFalse( $banner->exists(), 'Test precondition failed! Banner already exists!' ); // Run down the basic metadata and ensure it is in fact empty - $this->assertEquals( null, $banner->getId(), 'New banner ID is not null; probably already exists!' ); - $this->assertEquals( BannerTest::TEST_BANNER_NAME, $banner->getName(), 'Banner name did not get set' ); - $this->assertFalse( $banner->allocateToAnon(), 'Initial anonymous allocation is set to true' ); - $this->assertFalse( $banner->allocateToLoggedIn(), 'Initial logged in allocation is set to true' ); - $this->assertEquals( '{{{campaign}}}', $banner->getCategory(), 'Initial category is not equal to {{{campaign}}}' ); - $this->assertFalse( $banner->isArchived(), 'Initial banner is archived?' ); + $this->assertEquals( null, $banner->getId(), + 'New banner ID is not null; probably already exists!' ); + $this->assertEquals( BannerTest::TEST_BANNER_NAME, $banner->getName(), + 'Banner name did not get set' ); + $this->assertFalse( $banner->allocateToAnon(), + 'Initial anonymous allocation is set to true' ); + $this->assertFalse( $banner->allocateToLoggedIn(), + 'Initial logged in allocation is set to true' ); + $this->assertEquals( '{{{campaign}}}', $banner->getCategory(), + 'Initial category is not equal to {{{campaign}}}' ); + $this->assertFalse( $banner->isArchived(), + 'Initial banner is archived?' ); // More complex metadata should also be empty - $this->assertEquals( array(), $banner->getDevices(), 'Initial banner has associated device targets' ); - $this->assertEquals( array(), $banner->getMixins(), 'Initial banner has associated mixins' ); - $this->assertEquals( array(), $banner->getPriorityLanguages(), 'Initial banner has priority languages' ); + $this->assertEquals( array(), $banner->getDevices(), + 'Initial banner has associated device targets' ); + $this->assertEquals( array(), $banner->getMixins(), + 'Initial banner has associated mixins' ); + $this->assertEquals( array(), $banner->getPriorityLanguages(), + 'Initial banner has priority languages' ); // And the body content should also be empty - $this->assertEquals( '', $banner->getBodyContent(), 'Initial banner has non empty body content' ); + $this->assertEquals( '', $banner->getBodyContent(), + 'Initial banner has non empty body content' ); // And finally; save this empty banner $banner->save(); @@ -73,19 +83,27 @@ // Run down the basic metadata and ensure it is in fact empty $this->assertNotEquals( -1, $banner->getId(), 'Test banner has no ID' ); - $this->assertEquals( BannerTest::TEST_BANNER_NAME, $banner->getName(), 'Banner name did not get saved' ); - $this->assertFalse( $banner->allocateToAnon(), 'Initial anonymous allocation is set to true' ); - $this->assertFalse( $banner->allocateToLoggedIn(), 'Initial logged in allocation is set to true' ); - $this->assertEquals( '{{{campaign}}}', $banner->getCategory(), 'Initial category is not equal to {{{campaign}}}' ); + $this->assertEquals( BannerTest::TEST_BANNER_NAME, $banner->getName(), + 'Banner name did not get saved' ); + $this->assertFalse( $banner->allocateToAnon(), + 'Initial anonymous allocation is set to true' ); + $this->assertFalse( $banner->allocateToLoggedIn(), + 'Initial logged in allocation is set to true' ); + $this->assertEquals( '{{{campaign}}}', $banner->getCategory(), + 'Initial category is not equal to {{{campaign}}}' ); $this->assertFalse( $banner->isArchived(), 'Initial banner is archived?' ); // More complex metadata should also be empty - $this->assertEquals( array(), $banner->getDevices(), 'Initial banner has associated device targets' ); - $this->assertEquals( array(), $banner->getMixins(), 'Initial banner has associated mixins' ); - $this->assertEquals( array(), $banner->getPriorityLanguages(), 'Initial banner has priority languages' ); + $this->assertEquals( array(), $banner->getDevices(), + 'Initial banner has associated device targets' ); + $this->assertEquals( array(), $banner->getMixins(), + 'Initial banner has associated mixins' ); + $this->assertEquals( array(), $banner->getPriorityLanguages(), + 'Initial banner has priority languages' ); // And the body content should also be empty - $this->assertEquals( '', $banner->getBodyContent(), 'Initial banner has non empty body content' ); + $this->assertEquals( '', $banner->getBodyContent(), + 'Initial banner has non empty body content' ); } /** @@ -107,12 +125,17 @@ $banner->save(); // Can we retrieve it from the same object? - $this->assertTrue( $banner->allocateToAnon(), "Failed retrieve anon allocation from initial" ); - $this->assertTrue( $banner->allocateToLoggedIn(), "Failed retrieve logged in allocation from initial" ); - $this->assertEquals( 'testCategory', $banner->getCategory(), "Failed retrieve category from initial" ); + $this->assertTrue( $banner->allocateToAnon(), + "Failed retrieve anon allocation from initial" ); + $this->assertTrue( $banner->allocateToLoggedIn(), + "Failed retrieve logged in allocation from initial" ); + $this->assertEquals( 'testCategory', $banner->getCategory(), + "Failed retrieve category from initial" ); - $this->assertEquals( array( 'desktop' ), array_values( $banner->getDevices() ), 'Failed devices retrieve from initial' ); - $this->assertEquals( array( 'en', 'ru' ), $banner->getPriorityLanguages(), "Failed prilang retrieve from initial" ); + $this->assertEquals( array( 'desktop' ), array_values( $banner->getDevices() ), + 'Failed devices retrieve from initial' ); + $this->assertEquals( array( 'en', 'ru' ), $banner->getPriorityLanguages(), + "Failed prilang retrieve from initial" ); // Can we retrieve it from a different object $banner2 = Banner::fromName( BannerTest::TEST_BANNER_NAME ); @@ -120,11 +143,13 @@ $this->assertTrue( $banner2->allocateToLoggedIn(), "Failed loggedin allocation from copy" ); $this->assertEquals( 'testCategory', $banner2->getCategory(), "Failed category from copy" ); - $this->assertEquals( array( 'desktop' ), array_values( $banner2->getDevices() ), "Failed devices from copy" ); + $this->assertEquals( array( 'desktop' ), array_values( $banner2->getDevices() ), + "Failed devices from copy" ); global $wgNoticeUseTranslateExtension; if ( $wgNoticeUseTranslateExtension ) { - $this->assertEquals( array( 'en', 'ru' ), $banner2->getPriorityLanguages(), "Failed languages from copy" ); + $this->assertEquals( array( 'en', 'ru' ), $banner2->getPriorityLanguages(), + "Failed languages from copy" ); } } @@ -137,11 +162,13 @@ $banner->setAllocation( $anon, $loggedIn ); $banner->save(); $this->assertEquals( $anon, $banner->allocateToAnon(), "Testing initial anon" ); - $this->assertEquals( $loggedIn, $banner->allocateToLoggedIn(), "Testing initial logged in" ); + $this->assertEquals( $loggedIn, $banner->allocateToLoggedIn(), + "Testing initial logged in" ); $banner2 = Banner::fromName( BannerTest::TEST_BANNER_NAME ); $this->assertEquals( $anon, $banner2->allocateToAnon(), "Testing post save anon" ); - $this->assertEquals( $loggedIn, $banner2->allocateToLoggedIn(), "Testing post save logged in" ); + $this->assertEquals( $loggedIn, $banner2->allocateToLoggedIn(), + "Testing post save logged in" ); } public function providerSetAllocation() { diff --git a/tests/CentralNoticeTest.php b/tests/CentralNoticeTest.php index 5a9a759..cd51e5d 100644 --- a/tests/CentralNoticeTest.php +++ b/tests/CentralNoticeTest.php @@ -76,7 +76,10 @@ $displayAccount = true; $fundraising = true; - $this->campaignBannersJson = '[{"name":"PHPUnitTestBanner","weight":25,"display_anon":1,"display_account":1,"fundraising":1,"device":"desktop","campaign":"PHPUnitTestCampaign","campaign_z_index":"1","campaign_num_buckets":1,"campaign_throttle":100,"bucket":0}]'; + $this->campaignBannersJson = '[{"name":"PHPUnitTestBanner","weight":25,"display_anon":1,' . + '"display_account":1,"fundraising":1,"device":"desktop",' . + '"campaign":"PHPUnitTestCampaign","campaign_z_index":"1","campaign_num_buckets":1,' . + '"campaign_throttle":100,"bucket":0}]'; Banner::addTemplate( $bannerName, $body, $this->userUser, $displayAnon, $displayAccount, $fundraising ); diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php index 5f080f0..a5754ad 100644 --- a/tests/HistoryTest.php +++ b/tests/HistoryTest.php @@ -39,7 +39,8 @@ $made_by_ts = wfTimestamp( TS_MW ); $this->assertEquals( 1, count( Campaign::getHistoricalCampaigns( $made_by_ts ) ) ); - $initialSettings = Campaign::getCampaignSettings( $this->cnFixtures->spec['campaigns'][0]['name'] ); + $initialSettings = Campaign::getCampaignSettings( + $this->cnFixtures->spec['campaigns'][0]['name'] ); sleep( 2 ); -- To view, visit https://gerrit.wikimedia.org/r/358030 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I567813e0953d5f9d0d1bcaeebc751fd702845ca2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CentralNotice Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org> Gerrit-Reviewer: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits