protected function invalidateTitle(\Title $title)
 {
     global $wgParsoidCacheServers, $wgContentNamespaces;
     if (!in_array($title->getNamespace(), $wgContentNamespaces)) {
         return false;
     }
     # First request the new version
     $parsoidInfo = array();
     $parsoidInfo['cacheID'] = $title->getPreviousRevisionID($title->getLatestRevID());
     $parsoidInfo['changedTitle'] = $this->title->getPrefixedDBkey();
     $requests = array();
     foreach ($wgParsoidCacheServers as $server) {
         $singleUrl = $this->getParsoidURL($title);
         $requests[] = array('url' => $singleUrl, 'headers' => array('X-Parsoid: ' . json_encode($parsoidInfo), 'Cache-control: no-cache'));
         $this->wikiaLog(array("action" => "invalidateTitle", "get_url" => $singleUrl));
     }
     $this->checkCurlResults(\CurlMultiClient::request($requests));
     # And now purge the previous revision so that we make efficient use of
     # the Varnish cache space without relying on LRU. Since the URL
     # differs we can't use implicit refresh.
     $requests = array();
     foreach ($wgParsoidCacheServers as $server) {
         // @TODO: this triggers a getPreviousRevisionID() query per server
         $singleUrl = $this->getParsoidURL($title, true);
         $requests[] = array('url' => $singleUrl);
         $this->wikiaLog(array("action" => "invalidateTitle", "purge_url" => $singleUrl));
     }
     $options = \CurlMultiClient::getDefaultOptions();
     $options[CURLOPT_CUSTOMREQUEST] = "PURGE";
     return $this->checkCurlResults(\CurlMultiClient::request($requests, $options));
 }
 function getRevId()
 {
     if ($this->mId) {
         return $this->mId;
     } else {
         return $this->mTitle->getLatestRevID();
     }
 }
 /**
  * Driver function that handles updating assessment data in database
  * @param Title $titleObj Title object of the subject page
  * @param array $assessmentData Data for all assessments compiled
  */
 public static function doUpdates($titleObj, $assessmentData)
 {
     global $wgUpdateRowsPerQuery;
     $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
     $ticket = $factory->getEmptyTransactionTicket(__METHOD__);
     $pageId = $titleObj->getArticleID();
     $revisionId = $titleObj->getLatestRevID();
     // Compile a list of projects to find out which ones to be deleted afterwards
     $projects = array();
     foreach ($assessmentData as $parserData) {
         // For each project, get the corresponding ID from page_assessments_projects table
         $projectId = self::getProjectId($parserData[0]);
         if ($projectId === false) {
             $projectId = self::insertProject($parserData[0]);
         }
         $projects[$parserData[0]] = $projectId;
     }
     $projectsInDb = self::getAllProjects($pageId, self::READ_LATEST);
     $toInsert = array_diff($projects, $projectsInDb);
     $toDelete = array_diff($projectsInDb, $projects);
     $toUpdate = array_intersect($projects, $projectsInDb);
     $i = 0;
     // Add and update records to the database
     foreach ($assessmentData as $parserData) {
         $projectId = $projects[$parserData[0]];
         if ($projectId) {
             $class = $parserData[1];
             $importance = $parserData[2];
             $values = array('pa_page_id' => $pageId, 'pa_project_id' => $projectId, 'pa_class' => $class, 'pa_importance' => $importance, 'pa_page_revision' => $revisionId);
             if (in_array($projectId, $toInsert)) {
                 self::insertRecord($values);
             } elseif (in_array($projectId, $toUpdate)) {
                 self::updateRecord($values);
             }
             // Check for database lag if there's a huge number of assessments
             if ($i > 0 && $i % $wgUpdateRowsPerQuery == 0) {
                 $factory->commitAndWaitForReplication(__METHOD__, $ticket);
             }
             $i++;
         }
     }
     // Delete records from the database
     foreach ($toDelete as $project) {
         $values = array('pa_page_id' => $pageId, 'pa_project_id' => $project);
         self::deleteRecord($values);
         // Check for database lag if there's a huge number of deleted assessments
         if ($i > 0 && $i % $wgUpdateRowsPerQuery == 0) {
             $factory->commitAndWaitForReplication(__METHOD__, $ticket);
         }
         $i++;
     }
     return;
 }
 /**
  * doSaveComment -- save comment
  *
  * @access public
  *
  * @param string $text
  * @param User $user
  * @param Title $title
  * @param int $commentId
  * @param bool $force
  * @param string $summary
  * @param bool $preserveMetadata : hack to fix bug 102384 (prevent metadata override when trying to modify one of metadata keys)
  *
  * @return Array|false TODO: Document what the array contains.
  */
 public function doSaveComment($text, $user, $title = null, $commentId = 0, $force = false, $summary = '', $preserveMetadata = false)
 {
     global $wgTitle;
     wfProfileIn(__METHOD__);
     $metadata = $this->mMetadata;
     $this->load(true);
     if ($force || $this->canEdit()) {
         if (wfReadOnly()) {
             wfProfileOut(__METHOD__);
             return false;
         }
         if (!$text || !strlen($text)) {
             wfProfileOut(__METHOD__);
             return false;
         }
         if (empty($this->mTitle) && !$commentId) {
             wfProfileOut(__METHOD__);
             return false;
         }
         $commentTitle = $this->mTitle ? $this->mTitle : Title::newFromId($commentId);
         /**
          * because we save different title via Ajax request
          */
         $origTitle = $wgTitle;
         $wgTitle = $commentTitle;
         /**
          * add article using EditPage class (for hooks)
          */
         $article = new Article($commentTitle, intval($this->mLastRevId));
         if ($preserveMetadata) {
             $this->mMetadata = $metadata;
         }
         $retval = self::doSaveAsArticle($text, $article, $user, $this->mMetadata, $summary);
         if (!empty($title)) {
             $purgeTarget = $title;
         } else {
             $purgeTarget = $origTitle;
         }
         ArticleCommentList::purgeCache($purgeTarget);
         $res = [$retval, $article];
     } else {
         $res = false;
     }
     $this->mLastRevId = $this->mTitle->getLatestRevID(Title::GAID_FOR_UPDATE);
     $this->mLastRevision = Revision::newFromId($this->mLastRevId);
     wfProfileOut(__METHOD__);
     return $res;
 }
 public static function getUserNameFromRevision(Title $title)
 {
     $rev = Revision::newFromId($title->getLatestRevID());
     if (!empty($rev)) {
         $user = User::newFromId($rev->getUser());
         if (!empty($user)) {
             $userName = $user->getName();
         } else {
             $userName = self::getCommentByAnonMsg();
         }
     }
     return $userName;
 }
Example #6
0
 /**
  * Wrapper around Revision::newFromTitle to allow passing additional parameters
  * without passing them on to it.
  *
  * @since 1.24
  * @param Title $title
  * @param Parser|bool $parser
  * @return Revision|bool False if missing
  */
 public static function statelessFetchRevision(Title $title, $parser = false)
 {
     $pageId = $title->getArticleID();
     $revId = $title->getLatestRevID();
     $rev = Revision::newKnownCurrent(wfGetDB(DB_REPLICA), $pageId, $revId);
     if ($rev) {
         $rev->setTitle($title);
     }
     return $rev;
 }