/**
  * Create file page by adding video category
  *
  * @param Title|string $title - Title text of a video
  * @param User|integer $user - A user ID
  * @param integer $flags - Edit flags to pass to the Article::doEdit method
  * @return Status|false $status - The status returned by Article::doEdit
  */
 public function addCategoryVideos($title, $user, $flags = EDIT_NEW)
 {
     wfProfileIn(__METHOD__);
     if (is_string($title)) {
         $title = Title::newFromText($title, NS_FILE);
     }
     $status = false;
     if ($title instanceof Title && !$title->exists()) {
         if (!is_object($user)) {
             $user = User::newFromId($user);
         }
         $content = '[[' . WikiaFileHelper::getVideosCategory() . ']]';
         $article = new Article($title);
         $status = $article->doEdit($content, wfMessage('videohandler-log-add-video')->inContentLanguage()->plain(), $flags, false, $user);
     }
     wfProfileOut(__METHOD__);
     return $status;
 }
Exemplo n.º 2
0
 public static function work($wiki_id, $dryRun)
 {
     $app = F::app();
     echo "Wiki {$wiki_id}\n";
     if (wfReadOnly()) {
         die("Error: In read only mode.\n");
     }
     try {
         $db = wfGetDB(DB_SLAVE);
     } catch (Exception $e) {
         die("Error: Could not connect to database: " . $e->getMessage() . "\n");
     }
     if (!$db->tableExists('video_info')) {
         die("Error: video_info table NOT found.");
     }
     $result = $db->select(array('video_info'), array('video_title'), array('premium' => 1), __METHOD__);
     $counter = 1;
     $success = 0;
     $categoryExists = 0;
     $failed = 0;
     $total = $result->numRows();
     if ($total) {
         $botUser = User::newFromName('WikiaBot');
         $content = '[[' . WikiaFileHelper::getVideosCategory() . ']]';
         while ($result && ($row = $db->fetchRow($result))) {
             echo "\tWiki {$wiki_id}: [{$counter} of {$total}] Title:" . $row['video_title'];
             $title = Title::newFromText($row['video_title'], NS_FILE);
             if ($title instanceof Title) {
                 $status = Status::newGood();
                 if ($title->exists()) {
                     $article = Article::newFromID($title->getArticleID());
                     $oldContent = $article->getContent();
                     if (!strstr($oldContent, $content)) {
                         $content = $oldContent . $content;
                         if (!$dryRun) {
                             $status = $article->doEdit($content, 'added video category', EDIT_UPDATE | EDIT_SUPPRESS_RC | EDIT_FORCE_BOT, false, $botUser);
                         }
                     } else {
                         $failed++;
                         $categoryExists++;
                         $status = null;
                         echo "...FAILED (video category exists).\n";
                     }
                 } else {
                     $article = new Article($title);
                     if (!$dryRun) {
                         $status = $article->doEdit($content, 'created video', EDIT_NEW | EDIT_SUPPRESS_RC | EDIT_FORCE_BOT, false, $botUser);
                     }
                 }
                 if ($status instanceof Status) {
                     if ($status->isOK()) {
                         $success++;
                         echo "...DONE.\n";
                     } else {
                         $failed++;
                         echo "...FAILED (" . $status->getMessage() . ").\n";
                     }
                 }
             } else {
                 $failed++;
                 echo "...FAILED (Title not found).\n";
             }
             $counter++;
         }
     }
     $db->freeResult($result);
     echo "Wiki {$wiki_id}: Total videos: {$total}, Success: {$success}, Failed: {$failed} (Video category exists: {$categoryExists})\n\n";
 }