function createPost($info, $subject, $super = null) { $userName = $info['user']; if (strpos($userName, '#') !== false) { $pos = strpos($userName, '#'); $userName = substr($userName, 0, $pos); } $user = User::newFromName($userName, false); if (!$user) { throw new MWException("Username " . $info['user'] . " is invalid."); } global $article; if ($super) { $title = Threads::newReplyTitle($super, $user); } else { $title = Threads::newThreadTitle($subject, $article); } print "Creating thread {$title} as a subthread of " . ($super ? $super->title() : 'none') . "\n"; $root = new Article($title); $root->doEdit($info['content'], 'Imported from JSON', EDIT_NEW, false, $user); $t = LqtView::postEditUpdates($super ? 'reply' : 'new', $super, $root, $article, $subject, 'Imported from JSON', null); $t = Threads::withId($t->id()); // Some weirdness. return $t; }