From f5537fdff69fab977b1e5d296ea5941381cd9362 Mon Sep 17 00:00:00 2001 From: Josh Cox Date: Mon, 29 Aug 2016 22:00:27 -0400 Subject: [PATCH] Fix the feed line items for autodetect paste languages Summary: Fixes T11555. Previously changing the extension of a paste wouldn't change the syntax highlight language. Now it does. Also, feed items involving autodetect weren't rendering in a readable way. Test Plan: Created a paste named `paste.php` and let it autodetect language. Then edited the paste to be named paste.rainbow. It should now be highlighted in raiinnboow Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley, yelirekim Maniphest Tasks: T11555 Differential Revision: https://secure.phabricator.com/D16474 --- .../paste/query/PhabricatorPasteQuery.php | 2 ++ .../PhabricatorPasteLanguageTransaction.php | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/applications/paste/query/PhabricatorPasteQuery.php b/src/applications/paste/query/PhabricatorPasteQuery.php index 2bc9b35168..0d8b1542b7 100644 --- a/src/applications/paste/query/PhabricatorPasteQuery.php +++ b/src/applications/paste/query/PhabricatorPasteQuery.php @@ -173,6 +173,7 @@ final class PhabricatorPasteQuery 'P'.$paste->getID(), $paste->getFilePHID(), $paste->getLanguage(), + PhabricatorHash::digestForIndex($paste->getTitle()), )); } @@ -184,6 +185,7 @@ final class PhabricatorPasteQuery $paste->getFilePHID(), $paste->getLanguage(), 'snippet', + PhabricatorHash::digestForIndex($paste->getTitle()), )); } diff --git a/src/applications/paste/xaction/PhabricatorPasteLanguageTransaction.php b/src/applications/paste/xaction/PhabricatorPasteLanguageTransaction.php index 3497288b74..a0c060d430 100644 --- a/src/applications/paste/xaction/PhabricatorPasteLanguageTransaction.php +++ b/src/applications/paste/xaction/PhabricatorPasteLanguageTransaction.php @@ -13,12 +13,20 @@ final class PhabricatorPasteLanguageTransaction $object->setLanguage($value); } + private function renderLanguageValue($value) { + if (!strlen($value)) { + return $this->renderValue(pht('autodetect')); + } else { + return $this->renderValue($value); + } + } + public function getTitle() { return pht( "%s updated the paste's language from %s to %s.", $this->renderAuthor(), - $this->renderOldValue(), - $this->renderNewValue()); + $this->renderLanguageValue($this->getOldValue()), + $this->renderLanguageValue($this->getNewValue())); } public function getTitleForFeed() { @@ -26,8 +34,8 @@ final class PhabricatorPasteLanguageTransaction '%s updated the language for %s from %s to %s.', $this->renderAuthor(), $this->renderObject(), - $this->renderOldValue(), - $this->renderNewValue()); + $this->renderLanguageValue($this->getOldValue()), + $this->renderLanguageValue($this->getNewValue())); } }