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

Allow PhameBlog to take a full URI instead of just a domain name

Summary: Ref T9897. This moves "Domain" to "DomainFullURI" to allow setting of https or for some reason, a port. I guess.

Test Plan: Try to break by setting a path, or fake protocol. Set to http, or https, see correct redirects. Verify domain still gets written.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9897

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

+63 -47
+2
resources/sql/autopatches/20160623.phame.blog.fulldomain.1.sql
··· 1 + ALTER TABLE {$NAMESPACE}_phame.phame_blog 2 + ADD domainFullURI VARCHAR(128) COLLATE {$COLLATE_TEXT};
+3
resources/sql/autopatches/20160623.phame.blog.fulldomain.2.sql
··· 1 + UPDATE {$NAMESPACE}_phame.phame_blog 2 + SET domainFullURI = CONCAT('http://', domain, '/') 3 + WHERE domain IS NOT NULL;
+3
resources/sql/autopatches/20160623.phame.blog.fulldomain.3.sql
··· 1 + UPDATE {$NAMESPACE}_phame.phame_blogtransaction 2 + SET transactionType = 'phame.blog.full.domain' 3 + WHERE transactionType = 'phame.blog.domain';
+4 -5
src/applications/phame/controller/blog/PhameBlogManageController.php
··· 97 97 $properties = id(new PHUIPropertyListView()) 98 98 ->setUser($viewer); 99 99 100 - $domain = $blog->getDomain(); 101 - if (!$domain) { 102 - $domain = phutil_tag('em', array(), pht('No external domain')); 100 + $full_domain = $blog->getDomainFullURI(); 101 + if (!$full_domain) { 102 + $full_domain = phutil_tag('em', array(), pht('No external domain')); 103 103 } 104 - 105 - $properties->addProperty(pht('Domain'), $domain); 104 + $properties->addProperty(pht('Full Domain'), $full_domain); 106 105 107 106 $parent_site = $blog->getParentSite(); 108 107 if (!$parent_site) {
+7 -7
src/applications/phame/editor/PhameBlogEditEngine.php
··· 94 94 ->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION) 95 95 ->setValue($object->getDescription()), 96 96 id(new PhabricatorTextEditField()) 97 - ->setKey('domain') 98 - ->setLabel(pht('Custom Domain')) 99 - ->setDescription(pht('Blog domain name.')) 100 - ->setConduitDescription(pht('Change the blog domain.')) 101 - ->setConduitTypeDescription(pht('New blog domain.')) 102 - ->setValue($object->getDomain()) 103 - ->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN), 97 + ->setKey('domainFullURI') 98 + ->setLabel(pht('Full Domain URI')) 99 + ->setDescription(pht('Blog full domain URI.')) 100 + ->setConduitDescription(pht('Change the blog full domain URI.')) 101 + ->setConduitTypeDescription(pht('New blog full domain URI.')) 102 + ->setValue($object->getDomainFullURI()) 103 + ->setTransactionType(PhameBlogTransaction::TYPE_FULLDOMAIN), 104 104 id(new PhabricatorTextEditField()) 105 105 ->setKey('parentSite') 106 106 ->setLabel(pht('Parent Site'))
+20 -9
src/applications/phame/editor/PhameBlogEditor.php
··· 17 17 $types[] = PhameBlogTransaction::TYPE_NAME; 18 18 $types[] = PhameBlogTransaction::TYPE_SUBTITLE; 19 19 $types[] = PhameBlogTransaction::TYPE_DESCRIPTION; 20 - $types[] = PhameBlogTransaction::TYPE_DOMAIN; 20 + $types[] = PhameBlogTransaction::TYPE_FULLDOMAIN; 21 21 $types[] = PhameBlogTransaction::TYPE_PARENTSITE; 22 22 $types[] = PhameBlogTransaction::TYPE_PARENTDOMAIN; 23 23 $types[] = PhameBlogTransaction::TYPE_STATUS; ··· 38 38 return $object->getSubtitle(); 39 39 case PhameBlogTransaction::TYPE_DESCRIPTION: 40 40 return $object->getDescription(); 41 - case PhameBlogTransaction::TYPE_DOMAIN: 42 - return $object->getDomain(); 41 + case PhameBlogTransaction::TYPE_FULLDOMAIN: 42 + return $object->getDomainFullURI(); 43 43 case PhameBlogTransaction::TYPE_PARENTSITE: 44 44 return $object->getParentSite(); 45 45 case PhameBlogTransaction::TYPE_PARENTDOMAIN: ··· 61 61 case PhameBlogTransaction::TYPE_PARENTSITE: 62 62 case PhameBlogTransaction::TYPE_PARENTDOMAIN: 63 63 return $xaction->getNewValue(); 64 - case PhameBlogTransaction::TYPE_DOMAIN: 64 + case PhameBlogTransaction::TYPE_FULLDOMAIN: 65 65 $domain = $xaction->getNewValue(); 66 66 if (!strlen($xaction->getNewValue())) { 67 67 return null; ··· 81 81 return $object->setSubtitle($xaction->getNewValue()); 82 82 case PhameBlogTransaction::TYPE_DESCRIPTION: 83 83 return $object->setDescription($xaction->getNewValue()); 84 - case PhameBlogTransaction::TYPE_DOMAIN: 85 - return $object->setDomain($xaction->getNewValue()); 84 + case PhameBlogTransaction::TYPE_FULLDOMAIN: 85 + $new_value = $xaction->getNewValue(); 86 + if (strlen($new_value)) { 87 + $uri = new PhutilURI($new_value); 88 + $domain = $uri->getDomain(); 89 + $object->setDomain($domain); 90 + } else { 91 + $object->setDomain(null); 92 + } 93 + $object->setDomainFullURI($new_value); 94 + return; 86 95 case PhameBlogTransaction::TYPE_STATUS: 87 96 return $object->setStatus($xaction->getNewValue()); 88 97 case PhameBlogTransaction::TYPE_PARENTSITE: ··· 102 111 case PhameBlogTransaction::TYPE_NAME: 103 112 case PhameBlogTransaction::TYPE_SUBTITLE: 104 113 case PhameBlogTransaction::TYPE_DESCRIPTION: 105 - case PhameBlogTransaction::TYPE_DOMAIN: 114 + case PhameBlogTransaction::TYPE_FULLDOMAIN: 106 115 case PhameBlogTransaction::TYPE_PARENTSITE: 107 116 case PhameBlogTransaction::TYPE_PARENTDOMAIN: 108 117 case PhameBlogTransaction::TYPE_STATUS: ··· 156 165 $errors[] = $error; 157 166 } 158 167 break; 159 - case PhameBlogTransaction::TYPE_DOMAIN: 168 + case PhameBlogTransaction::TYPE_FULLDOMAIN: 160 169 if (!$xactions) { 161 170 continue; 162 171 } ··· 185 194 nonempty(last($xactions), null)); 186 195 $errors[] = $error; 187 196 } 197 + $domain = new PhutilURI($custom_domain); 198 + $domain = $domain->getDomain(); 188 199 $duplicate_blog = id(new PhameBlogQuery()) 189 200 ->setViewer(PhabricatorUser::getOmnipotentUser()) 190 - ->withDomain($custom_domain) 201 + ->withDomain($domain) 191 202 ->executeOne(); 192 203 if ($duplicate_blog && $duplicate_blog->getID() != $object->getID()) { 193 204 $error = new PhabricatorApplicationTransactionValidationError(
+17 -19
src/applications/phame/storage/PhameBlog.php
··· 18 18 protected $subtitle; 19 19 protected $description; 20 20 protected $domain; 21 + protected $domainFullURI; 21 22 protected $parentSite; 22 23 protected $parentDomain; 23 24 protected $configData; ··· 46 47 'subtitle' => 'text64', 47 48 'description' => 'text', 48 49 'domain' => 'text128?', 50 + 'domainFullURI' => 'text128?', 49 51 'parentSite' => 'text128', 50 52 'parentDomain' => 'text128', 51 53 'status' => 'text32', ··· 112 114 * 113 115 * @return string 114 116 */ 115 - public function validateCustomDomain($custom_domain) { 116 - $example_domain = 'blog.example.com'; 117 + public function validateCustomDomain($domain_full_uri) { 118 + $example_domain = 'http://blog.example.com/'; 117 119 $label = pht('Invalid'); 118 120 119 121 // note this "uri" should be pretty busted given the desired input 120 122 // so just use it to test if there's a protocol specified 121 - $uri = new PhutilURI($custom_domain); 122 - if ($uri->getProtocol()) { 123 - return array( 124 - $label, 125 - pht( 126 - 'The custom domain should not include a protocol. Just provide '. 127 - 'the bare domain name (for example, "%s").', 128 - $example_domain), 129 - ); 130 - } 123 + $uri = new PhutilURI($domain_full_uri); 124 + $domain = $uri->getDomain(); 125 + $protocol = $uri->getProtocol(); 126 + $path = $uri->getPath(); 127 + $supported_protocols = array('http', 'https'); 131 128 132 - if ($uri->getPort()) { 129 + if (!in_array($protocol, $supported_protocols)) { 133 130 return array( 134 131 $label, 135 132 pht( 136 - 'The custom domain should not include a port number. Just provide '. 137 - 'the bare domain name (for example, "%s").', 133 + 'The custom domain should include a valid protocol in the URI '. 134 + '(for example, "%s"). Valid protocols are "http" or "https".', 138 135 $example_domain), 139 - ); 136 + ); 140 137 } 141 138 142 - if (strpos($custom_domain, '/') !== false) { 139 + if (strlen($path) && $path != '/') { 143 140 return array( 144 141 $label, 145 142 pht( ··· 150 147 ); 151 148 } 152 149 153 - if (strpos($custom_domain, '.') === false) { 150 + if (strpos($domain, '.') === false) { 154 151 return array( 155 152 $label, 156 153 pht( ··· 191 188 } 192 189 193 190 public function getExternalLiveURI() { 194 - $uri = new PhutilURI('http://'.$this->getDomain().'/'); 191 + $uri = new PhutilURI($this->getDomainFullURI()); 192 + PhabricatorEnv::requireValidRemoteURIForLink($uri); 195 193 return (string)$uri; 196 194 } 197 195
+7 -7
src/applications/phame/storage/PhameBlogTransaction.php
··· 6 6 const TYPE_NAME = 'phame.blog.name'; 7 7 const TYPE_SUBTITLE = 'phame.blog.subtitle'; 8 8 const TYPE_DESCRIPTION = 'phame.blog.description'; 9 - const TYPE_DOMAIN = 'phame.blog.domain'; 9 + const TYPE_FULLDOMAIN = 'phame.blog.full.domain'; 10 10 const TYPE_STATUS = 'phame.blog.status'; 11 11 const TYPE_PARENTSITE = 'phame.blog.parent.site'; 12 12 const TYPE_PARENTDOMAIN = 'phame.blog.parent.domain'; ··· 46 46 } 47 47 break; 48 48 case self::TYPE_DESCRIPTION: 49 - case self::TYPE_DOMAIN: 49 + case self::TYPE_FULLDOMAIN: 50 50 return 'fa-pencil'; 51 51 case self::TYPE_STATUS: 52 52 if ($new == PhameBlog::STATUS_ARCHIVED) { ··· 85 85 case self::TYPE_NAME: 86 86 case self::TYPE_SUBTITLE: 87 87 case self::TYPE_DESCRIPTION: 88 - case self::TYPE_DOMAIN: 88 + case self::TYPE_FULLDOMAIN: 89 89 case self::TYPE_PARENTSITE: 90 90 case self::TYPE_PARENTDOMAIN: 91 91 $tags[] = self::MAILTAG_DETAILS; ··· 140 140 '%s updated the blog\'s description.', 141 141 $this->renderHandleLink($author_phid)); 142 142 break; 143 - case self::TYPE_DOMAIN: 143 + case self::TYPE_FULLDOMAIN: 144 144 return pht( 145 - '%s updated the blog\'s domain to "%s".', 145 + '%s updated the blog\'s full domain to "%s".', 146 146 $this->renderHandleLink($author_phid), 147 147 $new); 148 148 break; ··· 230 230 $this->renderHandleLink($author_phid), 231 231 $this->renderHandleLink($object_phid)); 232 232 break; 233 - case self::TYPE_DOMAIN: 233 + case self::TYPE_FULLDOMAIN: 234 234 return pht( 235 - '%s updated the domain for %s.', 235 + '%s updated the full domain for %s.', 236 236 $this->renderHandleLink($author_phid), 237 237 $this->renderHandleLink($object_phid)); 238 238 break;