@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.

Make remarkup rules runtime-pluggable in a reasonable way

Summary:
Gets rid of some old Differential-specific nonsense and replaces it with general runtime-pluggable Remarkup rules.

Facebook: This removes two options which may be in use. Have any classes being added via config here just subclass the new abstract bases instead. This should take 5 seconds to fix. You can adjust order by overriding `getPriority()` on the rules, if necessary.

Test Plan: See comments.

Reviewers: btrahan

Reviewed By: btrahan

CC: FacebookPOC, andrewjcg, aran

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

+60 -47
-8
conf/default.conf.php
··· 827 827 828 828 'differential.revision-custom-detail-renderer' => null, 829 829 830 - // Array for custom remarkup rules. The array should have a list of 831 - // class names of classes that extend PhutilRemarkupRule 832 - 'differential.custom-remarkup-rules' => null, 833 - 834 - // Array for custom remarkup block rules. The array should have a list of 835 - // class names of classes that extend PhutilRemarkupEngineBlockRule 836 - 'differential.custom-remarkup-block-rules' => null, 837 - 838 830 // List of file regexps where whitespace is meaningful and should not 839 831 // use 'ignore-all' by default 840 832 'differential.whitespace-matters' => array(
+4
src/__phutil_library_map__.php
··· 1592 1592 'PhabricatorRemarkupBlockInterpreterFiglet' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterFiglet.php', 1593 1593 'PhabricatorRemarkupBlockInterpreterGraphviz' => 'infrastructure/markup/interpreter/PhabricatorRemarkupBlockInterpreterGraphviz.php', 1594 1594 'PhabricatorRemarkupControl' => 'view/form/control/PhabricatorRemarkupControl.php', 1595 + 'PhabricatorRemarkupCustomBlockRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomBlockRule.php', 1596 + 'PhabricatorRemarkupCustomInlineRule' => 'infrastructure/markup/rule/PhabricatorRemarkupCustomInlineRule.php', 1595 1597 'PhabricatorRemarkupRuleEmbedFile' => 'applications/files/remarkup/PhabricatorRemarkupRuleEmbedFile.php', 1596 1598 'PhabricatorRemarkupRuleImageMacro' => 'applications/macro/remarkup/PhabricatorRemarkupRuleImageMacro.php', 1597 1599 'PhabricatorRemarkupRuleMeme' => 'applications/macro/remarkup/PhabricatorRemarkupRuleMeme.php', ··· 3886 3888 'PhabricatorRemarkupBlockInterpreterFiglet' => 'PhutilRemarkupBlockInterpreter', 3887 3889 'PhabricatorRemarkupBlockInterpreterGraphviz' => 'PhutilRemarkupBlockInterpreter', 3888 3890 'PhabricatorRemarkupControl' => 'AphrontFormTextAreaControl', 3891 + 'PhabricatorRemarkupCustomBlockRule' => 'PhutilRemarkupEngineBlockRule', 3892 + 'PhabricatorRemarkupCustomInlineRule' => 'PhutilRemarkupRule', 3889 3893 'PhabricatorRemarkupRuleEmbedFile' => 'PhabricatorRemarkupRuleObject', 3890 3894 'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule', 3891 3895 'PhabricatorRemarkupRuleMeme' => 'PhutilRemarkupRule',
+7
src/applications/config/check/PhabricatorSetupCheckExtraConfig.php
··· 141 141 142 142 $ancient_config = array_fill_keys($auth_config, $reason_auth); 143 143 144 + $markup_reason = pht( 145 + 'Custom remarkup rules are now added by subclassing '. 146 + 'PhabricatorRemarkupCustomInlineRule or '. 147 + 'PhabricatorRemarkupCustomBlockRule.'); 148 + 144 149 $ancient_config += array( 145 150 'phid.external-loaders' => 146 151 pht( ··· 155 160 'Maniphest fields are now defined in '. 156 161 '`maniphest.custom-field-definitions`. Existing definitions have '. 157 162 'been migrated.'), 163 + 'differential.custom-remarkup-rules' => $markup_reason, 164 + 'differential.custom-remarkup-block-rules' => $markup_reason, 158 165 ); 159 166 160 167 return $ancient_config;
-19
src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
··· 20 20 ->setBaseClass('DifferentialRevisionDetailRenderer') 21 21 ->setDescription(pht("Custom revision detail renderer.")), 22 22 $this->newOption( 23 - 'differential.custom-remarkup-rules', 24 - 'list<string>', 25 - array()) 26 - ->setSummary(pht('Custom remarkup rules.')) 27 - ->setDescription( 28 - pht( 29 - "Array for custom remarkup rules. The array should have a list ". 30 - "of class names of classes that extend PhutilRemarkupRule")), 31 - $this->newOption( 32 - 'differential.custom-remarkup-block-rules', 33 - 'list<string>', 34 - array()) 35 - ->setSummary(pht('Custom remarkup block rules.')) 36 - ->setDescription( 37 - pht( 38 - "Array for custom remarkup block rules. The array should have a ". 39 - "list of class names of classes that extend ". 40 - "PhutilRemarkupEngineBlockRule")), 41 - $this->newOption( 42 23 'differential.whitespace-matters', 43 24 'list<regex>', 44 25 array(
+29 -20
src/infrastructure/markup/PhabricatorMarkupEngine.php
··· 201 201 private function getMarkupFieldKey( 202 202 PhabricatorMarkupInterface $object, 203 203 $field) { 204 - return $object->getMarkupFieldKey($field).'@'.$this->version; 204 + 205 + $custom = array_merge( 206 + self::loadCustomInlineRules(), 207 + self::loadCustomBlockRules()); 208 + 209 + $custom = mpull($custom, 'getRuleVersion', null); 210 + ksort($custom); 211 + $custom = PhabricatorHash::digestForIndex(serialize($custom)); 212 + 213 + return $object->getMarkupFieldKey($field).'@'.$this->version.'@'.$custom; 205 214 } 206 215 207 216 ··· 328 337 */ 329 338 public static function newDifferentialMarkupEngine(array $options = array()) { 330 339 return self::newMarkupEngine(array( 331 - 'custom-inline' => PhabricatorEnv::getEnvConfig( 332 - 'differential.custom-remarkup-rules'), 333 - 'custom-block' => PhabricatorEnv::getEnvConfig( 334 - 'differential.custom-remarkup-block-rules'), 335 340 'differential.diff' => idx($options, 'differential.diff'), 336 341 )); 337 342 } ··· 381 386 'pygments' => PhabricatorEnv::getEnvConfig('pygments.enabled'), 382 387 'youtube' => PhabricatorEnv::getEnvConfig( 383 388 'remarkup.enable-embedded-youtube'), 384 - 'custom-inline' => array(), 385 - 'custom-block' => array(), 386 389 'differential.diff' => null, 387 390 'header.generate-toc' => false, 388 391 'macros' => true, ··· 419 422 $rules[] = new PhutilRemarkupRuleEscapeRemarkup(); 420 423 $rules[] = new PhutilRemarkupRuleMonospace(); 421 424 422 - $custom_rule_classes = $options['custom-inline']; 423 - if ($custom_rule_classes) { 424 - foreach ($custom_rule_classes as $custom_rule_class) { 425 - $rules[] = newv($custom_rule_class, array()); 426 - } 427 - } 428 425 429 426 $rules[] = new PhutilRemarkupRuleDocumentLink(); 430 427 ··· 450 447 $rules[] = new PhutilRemarkupRuleItalic(); 451 448 $rules[] = new PhutilRemarkupRuleDel(); 452 449 450 + foreach (self::loadCustomInlineRules() as $rule) { 451 + $rules[] = $rule; 452 + } 453 + 453 454 $blocks = array(); 454 455 $blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule(); 455 456 $blocks[] = new PhutilRemarkupEngineRemarkupLiteralBlockRule(); ··· 461 462 $blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule(); 462 463 $blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule(); 463 464 $blocks[] = new PhutilRemarkupEngineRemarkupInterpreterRule(); 465 + $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule(); 464 466 465 - $custom_block_rule_classes = $options['custom-block']; 466 - if ($custom_block_rule_classes) { 467 - foreach ($custom_block_rule_classes as $custom_block_rule_class) { 468 - $blocks[] = newv($custom_block_rule_class, array()); 469 - } 467 + foreach (self::loadCustomBlockRules() as $rule) { 468 + $blocks[] = $rule; 470 469 } 471 - 472 - $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule(); 473 470 474 471 foreach ($blocks as $block) { 475 472 $block->setMarkupRules($rules); ··· 562 559 } 563 560 564 561 return $best; 562 + } 563 + 564 + private static function loadCustomInlineRules() { 565 + return id(new PhutilSymbolLoader()) 566 + ->setAncestorClass('PhabricatorRemarkupCustomInlineRule') 567 + ->loadObjects(); 568 + } 569 + 570 + private static function loadCustomBlockRules() { 571 + return id(new PhutilSymbolLoader()) 572 + ->setAncestorClass('PhabricatorRemarkupCustomBlockRule') 573 + ->loadObjects(); 565 574 } 566 575 567 576 }
+10
src/infrastructure/markup/rule/PhabricatorRemarkupCustomBlockRule.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorRemarkupCustomBlockRule 4 + extends PhutilRemarkupEngineBlockRule { 5 + 6 + public function getRuleVersion() { 7 + return 1; 8 + } 9 + 10 + }
+10
src/infrastructure/markup/rule/PhabricatorRemarkupCustomInlineRule.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorRemarkupCustomInlineRule 4 + extends PhutilRemarkupRule { 5 + 6 + public function getRuleVersion() { 7 + return 1; 8 + } 9 + 10 + }