@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a lipsum generator for Badges

Summary: Ref T12319. Ref T12270. Allow badges to be generated with `bin/lipsum`. These aren't hugely sophisticated but I'm not sure about the fate of T9010 yet or what's happening with the quality levels, and didn't want to make those changes more difficult.

Test Plan:
- Used `bin/lipsum generate badges --force --quickly` to generate badges.
- Made some coffee and came back to 20K badges.

{F3422200}

Reviewers: chad

Reviewed By: chad

Subscribers: cspeckmim

Maniphest Tasks: T12319, T12270

Differential Revision: https://secure.phabricator.com/D17422

+163
+4
src/__phutil_library_map__.php
··· 2021 2021 'PhabricatorBadgesBadgeQualityTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeQualityTransaction.php', 2022 2022 'PhabricatorBadgesBadgeRevokeTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php', 2023 2023 'PhabricatorBadgesBadgeStatusTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeStatusTransaction.php', 2024 + 'PhabricatorBadgesBadgeTestDataGenerator' => 'applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php', 2024 2025 'PhabricatorBadgesBadgeTransactionType' => 'applications/badges/xaction/PhabricatorBadgesBadgeTransactionType.php', 2025 2026 'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php', 2026 2027 'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php', ··· 2035 2036 'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php', 2036 2037 'PhabricatorBadgesIconSet' => 'applications/badges/icon/PhabricatorBadgesIconSet.php', 2037 2038 'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php', 2039 + 'PhabricatorBadgesLootContextFreeGrammar' => 'applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php', 2038 2040 'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php', 2039 2041 'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php', 2040 2042 'PhabricatorBadgesProfileController' => 'applications/badges/controller/PhabricatorBadgesProfileController.php', ··· 6979 6981 'PhabricatorBadgesBadgeQualityTransaction' => 'PhabricatorBadgesBadgeTransactionType', 6980 6982 'PhabricatorBadgesBadgeRevokeTransaction' => 'PhabricatorBadgesBadgeTransactionType', 6981 6983 'PhabricatorBadgesBadgeStatusTransaction' => 'PhabricatorBadgesBadgeTransactionType', 6984 + 'PhabricatorBadgesBadgeTestDataGenerator' => 'PhabricatorTestDataGenerator', 6982 6985 'PhabricatorBadgesBadgeTransactionType' => 'PhabricatorModularTransactionType', 6983 6986 'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController', 6984 6987 'PhabricatorBadgesController' => 'PhabricatorController', ··· 6993 6996 'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor', 6994 6997 'PhabricatorBadgesIconSet' => 'PhabricatorIconSet', 6995 6998 'PhabricatorBadgesListController' => 'PhabricatorBadgesController', 6999 + 'PhabricatorBadgesLootContextFreeGrammar' => 'PhutilContextFreeGrammar', 6996 7000 'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver', 6997 7001 'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType', 6998 7002 'PhabricatorBadgesProfileController' => 'PhabricatorController',
+71
src/applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php
··· 1 + <?php 2 + 3 + final class PhabricatorBadgesBadgeTestDataGenerator 4 + extends PhabricatorTestDataGenerator { 5 + 6 + const GENERATORKEY = 'badges'; 7 + 8 + public function getGeneratorName() { 9 + return pht('Badges'); 10 + } 11 + 12 + public function generateObject() { 13 + $author = $this->loadRandomUser(); 14 + 15 + list($name, $description) = $this->newLoot(); 16 + 17 + $xactions = array(); 18 + 19 + $xactions[] = array( 20 + 'type' => 'name', 21 + 'value' => $name, 22 + ); 23 + 24 + $xactions[] = array( 25 + 'type' => 'description', 26 + 'value' => $description, 27 + ); 28 + 29 + $params = array( 30 + 'transactions' => $xactions, 31 + ); 32 + 33 + $result = id(new ConduitCall('badges.edit', $params)) 34 + ->setUser($author) 35 + ->execute(); 36 + 37 + return $result['object']['phid']; 38 + } 39 + 40 + private function newLoot() { 41 + $drop = id(new PhabricatorBadgesLootContextFreeGrammar()) 42 + ->generate(); 43 + 44 + $drop = preg_replace_callback( 45 + '/<(\d+)-(\d+)>/', 46 + array($this, 'rollDropValue'), 47 + $drop); 48 + 49 + $effect_pattern = '/\s*\(([^)]+)\)/'; 50 + 51 + $matches = null; 52 + if (preg_match_all($effect_pattern, $drop, $matches)) { 53 + $description = $matches[1]; 54 + $description = implode("\n", $description); 55 + } else { 56 + $description = ''; 57 + } 58 + 59 + $drop = preg_replace($effect_pattern, '', $drop); 60 + 61 + return array($drop, $description); 62 + } 63 + 64 + public function rollDropValue($matches) { 65 + $min = (int)$matches[1]; 66 + $max = (int)$matches[2]; 67 + return mt_rand($min, $max); 68 + } 69 + 70 + 71 + }
+88
src/applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php
··· 1 + <?php 2 + 3 + final class PhabricatorBadgesLootContextFreeGrammar 4 + extends PhutilContextFreeGrammar { 5 + 6 + protected function getRules() { 7 + return array( 8 + 'start' => array( 9 + '[jewelry]', 10 + ), 11 + 'jewelry' => array( 12 + 'Ring [jewelry-suffix]', 13 + 'Ring [jewelry-suffix]', 14 + '[jewelry-prefix] Ring', 15 + '[jewelry-prefix] Ring', 16 + 'Amulet [jewelry-suffix]', 17 + 'Amulet [jewelry-suffix]', 18 + '[jewelry-prefix] Amulet', 19 + '[jewelry-prefix] Amulet', 20 + '[jewelry-prefix] Ring [jewelry-suffix]', 21 + '[jewelry-prefix] Amulet [jewelry-suffix]', 22 + '[unique-jewelry]', 23 + ), 24 + 'jewelry-prefix' => array( 25 + '[mana-prefix]', 26 + ), 27 + 28 + 'jewelry-suffix' => array( 29 + '[dexterity-suffix]', 30 + '[dexterity-suffix-jewelry]', 31 + ), 32 + 'mana-prefix' => array( 33 + 'Hyena\'s (-<11-25> Mana)', 34 + 'Frog\'s (-<1-10> Mana)', 35 + 'Spider\'s (+<10-15> Mana)', 36 + 'Raven\'s (+<15-20> Mana)', 37 + 'Snake\'s (+<21-30> Mana)', 38 + 'Serpent\'s (+<31-40> Mana)', 39 + 'Drake\'s (+<41-50> Mana)', 40 + 'Dragon\'s (+<51-60> Mana)', 41 + ), 42 + 'dexterity-suffix' => array( 43 + 'of Paralysis (-<6-10> Dexterity)', 44 + 'of Atrophy (-<1-5> Dexterity)', 45 + 'of Dexterity (+<1-5> Dexterity)', 46 + 'of Skill (+<6-10> Dexterity)', 47 + 'of Accuracy (+<11-15> Dexterity)', 48 + 'of Precision (+<16-20> Dexterity)', 49 + ), 50 + 'dexterity-suffix-jewelry' => array( 51 + '[dexterity-suffix]', 52 + '[dexterity-suffix]', 53 + '[dexterity-suffix]', 54 + '[dexterity-suffix]', 55 + '[dexterity-suffix]', 56 + '[dexterity-suffix]', 57 + '[dexterity-suffix]', 58 + '[dexterity-suffix]', 59 + '[dexterity-suffix]', 60 + 'of Perfection (+<21-30> Dexterity)', 61 + ), 62 + 'unique-jewelry' => array( 63 + '[jewelry]', 64 + '[jewelry]', 65 + '[jewelry]', 66 + '[jewelry]', 67 + '[jewelry]', 68 + '[jewelry]', 69 + '[jewelry]', 70 + '[jewelry]', 71 + '[unique-ring]', 72 + '[unique-amulet]', 73 + ), 74 + 'unique-ring' => array( 75 + 'The Bleeder', 76 + 'The Bramble', 77 + 'Constricting Ring', 78 + 'Empyrean Band', 79 + 'Ring of Engagement', 80 + 'Ring of Regha', 81 + ), 82 + 'unique-amulet' => array( 83 + 'Optic Amulet', 84 + ), 85 + ); 86 + } 87 + 88 + }