Page MenuHomePhabricator

Render feed to text properly and add human-readable text to Feed hooks
Closed, ResolvedPublic

Description

A couple of related use cases, brought to the forefront by the Differential feed changes:

  • The FeedStory handler in the bot is really hacky, but enjoys a fair amount of use in the wild. We should reduce its terribleness.
  • The HTTP hooks for feed have no high-level / human-readable information anymore.

Approaching both of these probably involves:

  • Fix feed rendering into plaintext (no strip_tags() / htmlentitydecode() garbage).
  • Add reasonable plaintext blobs to feed.query and the HTTP hooks.

Overall goals are: get rid of the garbage code on this pathway; make these APIs consumable for "post a human-readable notification somewhere" without rewriting feed rendering on the far side.

Event Timeline

epriestley raised the priority of this task from to Normal.
epriestley updated the task description. (Show Details)
epriestley added a project: Feed.

@spicyj fixed the immediate issue here, but we should really get rid of all this htmlspecialchars_decode() / strip_tags() junk, because it's really gross and broken.

The implementations of various FeedStory::renderText() methods look like this now:

$html_title = $this->renderView()->getTitle();
$text_title = crimes_against_humanity($html_title);
return $text_title;

Instead, they should look something like this:

$this->setRenderingMode('text');
$title = $this->renderTitle();
$this->setRenderingMode('default');

return $title;

In the 'text' rendering mode, methods like linkTo() should render text instead of HTML. This might need to be propagated into ApplicationTransactions (since most title rendering is there now). A lot of those methods look like this now:

public function getTitleForFeed(PhabricatorFeedStory $story) {
  $author_phid = $this->getAuthorPHID();
  $author_link = $this->renderHandleLink($author_phid);

  // ...

}

Making them call $story->linkTo($author_phid) instead might be a clean way to get a proper text/html result. Otherwise you could put state on ApplicationTransaction (this might be easier with handle management). Basically:

  • The same code should be able to render text and HTML.
  • Whether we're currently rendering text or HTML should mostly be hidden behind the scenes.
  • The only thing that changes in 99% of cases is handles, so just make those do the right thing and everything else should pretty much work.

Ultimate goal here is to have reasonable text representations of stories with no strip_tags() / htmlspecialchars_decode() / crimes_against_humanity() calls in the codebase.