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

Move Paste line range reading code into AphrontRequest

Summary: Ref T13088. This lifts the code for parsing "$x-y" line ranges in URIs into AphrontRequest so Diffusion, Paste, Harbormaster, etc., can share it.

Test Plan: Viewed lines, line ranges, no lines, negative line ranges, line ranges with 0, and extremely long line ranges in Paste.

Maniphest Tasks: T13088

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

+56 -21
+48
src/aphront/AphrontRequest.php
··· 49 49 return idx($this->uriData, $key, $default); 50 50 } 51 51 52 + /** 53 + * Read line range parameter data from the request. 54 + * 55 + * Applications like Paste, Diffusion, and Harbormaster use "$12-14" in the 56 + * URI to allow users to link to particular lines. 57 + * 58 + * @param string URI data key to pull line range information from. 59 + * @param int|null Maximum length of the range. 60 + * @return null|pair<int, int> Null, or beginning and end of the range. 61 + */ 62 + public function getURILineRange($key, $limit) { 63 + $range = $this->getURIData($key); 64 + if (!strlen($range)) { 65 + return null; 66 + } 67 + 68 + $range = explode('-', $range, 2); 69 + 70 + foreach ($range as $key => $value) { 71 + $value = (int)$value; 72 + if (!$value) { 73 + // If either value is "0", discard the range. 74 + return null; 75 + } 76 + $range[$key] = $value; 77 + } 78 + 79 + // If the range is like "$10", treat it like "$10-10". 80 + if (count($range) == 1) { 81 + $range[] = head($range); 82 + } 83 + 84 + // If the range is "$7-5", treat it like "$5-7". 85 + if ($range[1] < $range[0]) { 86 + $range = array_reverse($range); 87 + } 88 + 89 + // If the user specified something like "$1-999999999" and we have a limit, 90 + // clamp it to a more reasonable range. 91 + if ($limit !== null) { 92 + if ($range[1] - $range[0] > $limit) { 93 + $range[1] = $range[0] + $limit; 94 + } 95 + } 96 + 97 + return $range; 98 + } 99 + 52 100 public function setApplicationConfiguration( 53 101 $application_configuration) { 54 102 $this->applicationConfiguration = $application_configuration;
+8 -21
src/applications/paste/controller/PhabricatorPasteViewController.php
··· 2 2 3 3 final class PhabricatorPasteViewController extends PhabricatorPasteController { 4 4 5 - private $highlightMap; 6 - 7 5 public function shouldAllowPublic() { 8 6 return true; 9 7 } 10 8 11 - public function willProcessRequest(array $data) { 12 - $raw_lines = idx($data, 'lines'); 13 - $map = array(); 14 - if ($raw_lines) { 15 - $lines = explode('-', $raw_lines); 16 - $first = idx($lines, 0, 0); 17 - $last = idx($lines, 1); 18 - if ($last) { 19 - $min = min($first, $last); 20 - $max = max($first, $last); 21 - $map = array_fuse(range($min, $max)); 22 - } else { 23 - $map[$first] = $first; 24 - } 25 - } 26 - $this->highlightMap = $map; 27 - } 28 - 29 9 public function handleRequest(AphrontRequest $request) { 30 10 $viewer = $request->getViewer(); 31 11 $id = $request->getURIData('id'); ··· 40 20 return new Aphront404Response(); 41 21 } 42 22 23 + $lines = $request->getURILineRange('lines', 1000); 24 + if ($lines) { 25 + $map = range($lines[0], $lines[1]); 26 + } else { 27 + $map = array(); 28 + } 29 + 43 30 $header = $this->buildHeaderView($paste); 44 31 $curtain = $this->buildCurtain($paste); 45 32 46 33 $subheader = $this->buildSubheaderView($paste); 47 - $source_code = $this->buildSourceCodeView($paste, $this->highlightMap); 34 + $source_code = $this->buildSourceCodeView($paste, $map); 48 35 49 36 require_celerity_resource('paste-css'); 50 37