示例#1
0
 /**
  * Get the Language being used for this instance.
  * IndexPager extends ContextSource as of 1.19.
  *
  * @since 0.1
  *
  * @return Language
  */
 public function getLanguage()
 {
     return method_exists($this->context, 'getLanguage') ? $this->context->getLanguage() : $this->context->getLang();
 }
示例#2
0
 /**
  * Add the video into the database
  *
  * @param $url String: URL to the video on the provider service
  * @param $type String: (internal) provider name in lowercase
  * @param $categories String: pipe-separated list of categories
  * @param $watch Boolean: add the new video page to the user's watchlist?
  */
 public function addVideo($url, $type, $categories, $watch = false)
 {
     $user = $this->context->getUser();
     $dbw = wfGetDB(DB_MASTER);
     $now = $dbw->timestamp();
     $desc = wfMsgForContent('video-log-added-entry', Title::makeTitle(NS_VIDEO, $this->getName())->getPrefixedText());
     // Test to see if the row exists using INSERT IGNORE
     // This avoids race conditions by locking the row until the commit, and also
     // doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('video', array('video_name' => $this->getName(), 'video_url' => $url, 'video_type' => $type, 'video_user_id' => $user->getID(), 'video_user_name' => $user->getName(), 'video_timestamp' => $now), __METHOD__, 'IGNORE');
     $categoryWikiText = '';
     if ($dbw->affectedRows() == 0) {
         $desc = wfMsgForContent('video-log-updated-entry', Title::makeTitle(NS_VIDEO, $this->getName())->getPrefixedText());
         // Clear cache
         global $wgMemc;
         $key = $this->getCacheKey();
         $wgMemc->delete($key);
         // Collision, this is an update of a video
         // Insert previous contents into oldvideo
         $dbw->insertSelect('oldvideo', 'video', array('ov_name' => 'video_name', 'ov_archive_name' => $dbw->addQuotes(gmdate('YmdHis') . "!{$this->getName()}"), 'ov_url' => 'video_url', 'ov_type' => 'video_type', 'ov_user_id' => 'video_user_id', 'ov_user_name' => 'video_user_name', 'ov_timestamp' => 'video_timestamp'), array('video_name' => $this->getName()), __METHOD__);
         // Update the current video row
         $dbw->update('video', array('video_url' => $url, 'video_type' => $type, 'video_user_id' => $user->getID(), 'video_user_name' => $user->getName(), 'video_timestamp' => $now), array('video_name' => $this->getName()), __METHOD__);
     }
     $descTitle = $this->getTitle();
     $article = new Article($descTitle);
     $watch = $watch || $user->isWatched($descTitle);
     // Get the localized category name
     $videoCategoryName = wfMsgForContent('video-category-name');
     if ($categories) {
         $categories .= "|{$videoCategoryName}";
     } else {
         $categories = "{$videoCategoryName}";
     }
     // Loop through category variable and individually build Category Tab for Wiki text
     if ($categories) {
         $categories_array = explode('|', $categories);
         foreach ($categories_array as $ctg) {
             $ctg = trim($ctg);
             if ($ctg) {
                 $catName = $this->context->getLang()->getNsText(NS_CATEGORY);
                 $tag = "[[{$catName}:{$ctg}]]";
                 if (strpos($categoryWikiText, $tag) === false) {
                     $categoryWikiText .= "\n{$tag}";
                 }
             }
         }
     }
     if ($descTitle->exists()) {
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $descTitle->purgeSquid();
     } else {
         // New video; create the description page.
         // Supress the recent changes bc it will appear in the log/video
         $article->doEdit($categoryWikiText, $desc, EDIT_SUPPRESS_RC);
     }
     if ($watch) {
         $user->addWatch($descTitle);
     }
     // Add the log entry
     $log = new LogPage('video');
     $log->addEntry('video', $descTitle, $desc);
     // Commit the transaction now, in case something goes wrong later
     // The most important thing is that videos don't get lost, especially archives
     $dbw->commit();
 }
示例#3
0
 /**
  * Get the language of the user doing the action
  *
  * @return Language object
  */
 public function getLang()
 {
     return $this->context->getLang();
 }