Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13999669
D14883.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D14883.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2687,6 +2687,7 @@
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
'PhabricatorPasteEditEngine' => 'applications/paste/editor/PhabricatorPasteEditEngine.php',
'PhabricatorPasteEditor' => 'applications/paste/editor/PhabricatorPasteEditor.php',
+ 'PhabricatorPasteFilenameContextFreeGrammar' => 'applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php',
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
@@ -6987,6 +6988,7 @@
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
'PhabricatorPasteEditEngine' => 'PhabricatorEditEngine',
'PhabricatorPasteEditor' => 'PhabricatorApplicationTransactionEditor',
+ 'PhabricatorPasteFilenameContextFreeGrammar' => 'PhutilContextFreeGrammar',
'PhabricatorPasteListController' => 'PhabricatorPasteController',
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
diff --git a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
--- a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
+++ b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
@@ -74,6 +74,22 @@
return $sum;
}
+ protected function newEmptyTransaction() {
+ throw new PhutilMethodNotImplementedException();
+ }
+
+ protected function newTransaction($type, $value, $metadata = array()) {
+ $xaction = $this->newEmptyTransaction()
+ ->setTransactionType($type)
+ ->setNewValue($value);
+
+ foreach ($metadata as $key => $value) {
+ $xaction->setMetadataValue($key, $value);
+ }
+
+ return $xaction;
+ }
+
@@ -89,7 +105,6 @@
}
}
-
public function loadPhabrictorUserPHID() {
return $this->loadOneRandom('PhabricatorUser')->getPHID();
}
diff --git a/src/applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php b/src/applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php
new file mode 100644
--- /dev/null
+++ b/src/applications/paste/lipsum/PhabricatorPasteFilenameContextFreeGrammar.php
@@ -0,0 +1,87 @@
+<?php
+
+final class PhabricatorPasteFilenameContextFreeGrammar
+ extends PhutilContextFreeGrammar {
+
+ protected function getRules() {
+ return array(
+ 'start' => array(
+ '[scripty]',
+ ),
+ 'scripty' => array(
+ '[thing]',
+ '[thing]',
+ '[thing]_[tail]',
+ '[action]_[thing]',
+ '[action]_[thing]',
+ '[action]_[thing]_[tail]',
+ '[scripty]_and_[scripty]',
+ ),
+ 'tail' => array(
+ 'script',
+ 'helper',
+ 'backup',
+ 'pro',
+ '[tail]_[tail]',
+ ),
+ 'thing' => array(
+ '[thingnoun]',
+ '[thingadjective]_[thingnoun]',
+ '[thingadjective]_[thingadjective]_[thingnoun]',
+ ),
+ 'thingnoun' => array(
+ 'backup',
+ 'backups',
+ 'database',
+ 'databases',
+ 'table',
+ 'tables',
+ 'memory',
+ 'disk',
+ 'disks',
+ 'user',
+ 'users',
+ 'account',
+ 'accounts',
+ 'shard',
+ 'shards',
+ 'node',
+ 'nodes',
+ 'host',
+ 'hosts',
+ 'account',
+ 'accounts',
+ ),
+ 'thingadjective' => array(
+ 'backup',
+ 'database',
+ 'memory',
+ 'disk',
+ 'user',
+ 'account',
+ 'forgotten',
+ 'lost',
+ 'elder',
+ 'ancient',
+ 'legendary',
+ ),
+ 'action' => array(
+ 'manage',
+ 'update',
+ 'compact',
+ 'quick',
+ 'probe',
+ 'sync',
+ 'undo',
+ 'administrate',
+ 'assess',
+ 'purge',
+ 'cancel',
+ 'entomb',
+ 'accelerate',
+ 'plan',
+ ),
+ );
+ }
+
+}
diff --git a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
--- a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
+++ b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
@@ -7,92 +7,93 @@
return pht('Pastes');
}
- // Better Support for this in the future
- public $supportedLanguages = array(
- 'Java' => 'java',
- 'PHP' => 'php',
- );
-
public function generateObject() {
- $author = $this->loadPhabrictorUser();
- $authorphid = $author->getPHID();
- $language = $this->generateLanguage();
- $content = $this->generateContent($language);
- $title = $this->generateTitle($language);
- $paste_file = PhabricatorFile::newFromFileData(
- $content,
- array(
- 'name' => $title,
- 'mime-type' => 'text/plain; charset=utf-8',
- 'authorPHID' => $authorphid,
- ));
- $policy = $this->generatePolicy();
- $filephid = $paste_file->getPHID();
- $parentphid = $this->loadPhabrictorPastePHID();
- $paste = PhabricatorPaste::initializeNewPaste($author)
- ->setParentPHID($parentphid)
- ->setTitle($title)
- ->setLanguage($language)
- ->setViewPolicy($policy)
- ->setEditPolicy($policy)
- ->setFilePHID($filephid)
- ->save();
+ $author = $this->loadRandomUser();
+
+ list($name, $language, $content) = $this->newPasteContent();
+
+ $paste = PhabricatorPaste::initializeNewPaste($author);
+
+ $xactions = array();
+
+ $xactions[] = $this->newTransaction(
+ PhabricatorPasteTransaction::TYPE_TITLE,
+ $name);
+
+ $xactions[] = $this->newTransaction(
+ PhabricatorPasteTransaction::TYPE_LANGUAGE,
+ $language);
+
+ $xactions[] = $this->newTransaction(
+ PhabricatorPasteTransaction::TYPE_CONTENT,
+ $content);
+
+ $editor = id(new PhabricatorPasteEditor())
+ ->setActor($author)
+ ->setContentSource($this->getLipsumContentSource())
+ ->setContinueOnNoEffect(true)
+ ->applyTransactions($paste, $xactions);
+
return $paste;
}
- private function loadPhabrictorPastePHID() {
- $random = rand(0, 1);
- if ($random == 1) {
- $paste = id($this->loadOneRandom('PhabricatorPaste'));
- if ($paste) {
- return $paste->getPHID();
- }
- }
- return null;
+ protected function newEmptyTransaction() {
+ return new PhabricatorPasteTransaction();
}
- public function generateTitle($language = null) {
- $taskgen = new PhutilLipsumContextFreeGrammar();
- // Remove Punctuation
- $title = preg_replace('/[^a-zA-Z 0-9]+/', '', $taskgen->generate());
- // Capitalize First Letters
- $title = ucwords($title);
- // Remove Spaces
- $title = preg_replace('/\s+/', '', $title);
- if ($language == null ||
- !in_array($language, array_keys($this->supportedLanguages))) {
- return $title.'.txt';
- } else {
- return $title.'.'.$this->supportedLanguages[$language];
+ private function newPasteContent() {
+ $languages = array(
+ 'txt' => array(),
+ 'php' => array(
+ 'content' => 'PhutilPHPCodeSnippetContextFreeGrammar',
+ ),
+ 'java' => array(
+ 'content' => 'PhutilJavaCodeSnippetContextFreeGrammar',
+ ),
+ );
+
+ $language = array_rand($languages);
+ $spec = $languages[$language];
+
+ $title_generator = idx($spec, 'title');
+ if (!$title_generator) {
+ $title_generator = 'PhabricatorPasteFilenameContextFreeGrammar';
}
- }
- public function generateLanguage() {
- $supplemented_lang = $this->supportedLanguages;
- $supplemented_lang['lipsum'] = 'txt';
- return array_rand($supplemented_lang);
- }
+ $content_generator = idx($spec, 'content');
+ if (!$content_generator) {
+ $content_generator = 'PhutilLipsumContextFreeGrammar';
+ }
- public function generateContent($language = null) {
- if ($language == null ||
- !in_array($language, array_keys($this->supportedLanguages))) {
- return id(new PhutilLipsumContextFreeGrammar())
- ->generateSeveral(rand(30, 40));
- } else {
- $cfg_class = 'Phutil'.$language.'CodeSnippetContextFreeGrammar';
- return newv($cfg_class, array())->generate();
- }
- }
+ $title = newv($title_generator, array())
+ ->generate();
- public function generatePolicy() {
- // Make sure 4/5th of all generated Pastes are viewable to all
- switch (rand(0, 4)) {
- case 0:
- return PhabricatorPolicies::POLICY_PUBLIC;
+ $content = newv($content_generator, array())
+ ->generateSeveral($this->roll(4, 12, 10));
+
+ // Usually add the language as a suffix.
+ if ($this->roll(1, 20) > 2) {
+ $title = $title.'.'.$language;
+ }
+
+ switch ($this->roll(1, 20)) {
case 1:
- return PhabricatorPolicies::POLICY_NOONE;
+ // On critical miss, set a different, random language.
+ $highlight_as = array_rand($languages);
+ break;
+ case 18:
+ case 19:
+ case 20:
+ // Sometimes set it to the correct language.
+ $highlight_as = $language;
+ break;
default:
- return PhabricatorPolicies::POLICY_USER;
+ // Usually leave it as autodetect.
+ $highlight_as = '';
+ break;
}
+
+ return array($title, $highlight_as, $content);
}
+
}
diff --git a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
--- a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
+++ b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
@@ -51,16 +51,8 @@
return $project;
}
- private function newTransaction($type, $value, $metadata = array()) {
- $xaction = id(new PhabricatorProjectTransaction())
- ->setTransactionType($type)
- ->setNewValue($value);
-
- foreach ($metadata as $key => $value) {
- $xaction->setMetadataValue($key, $value);
- }
-
- return $xaction;
+ protected function newEmptyTransaction() {
+ return new PhabricatorProjectTransaction();
}
public function newProjectTitle() {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 25, 4:19 PM (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6720098
Default Alt Text
D14883.diff (10 KB)
Attached To
Mode
D14883: Improve lispum generation of pastes
Attached
Detach File
Event Timeline
Log In to Comment