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;
}
Ejemplo n.º 2
0
 /**
  * @param $subject
  * @return Title
  */
 function newThreadTitle($subject)
 {
     return Threads::newThreadTitle($subject, $this->article);
 }
Ejemplo n.º 3
0
 static function validateSubject($subject, &$title, $replyTo, $article)
 {
     $t = null;
     $ok = true;
     while (!$t) {
         try {
             global $wgUser;
             if (!$replyTo && $subject) {
                 $t = Threads::newThreadTitle($subject, $article);
             } elseif ($replyTo) {
                 $t = Threads::newReplyTitle($replyTo, $wgUser);
             }
             if ($t) {
                 break;
             }
         } catch (Exception $e) {
         }
         $subject = md5(mt_rand());
         // Just a random title
         $ok = false;
     }
     $title = $t;
     return $ok;
 }