Esempio n. 1
0
 /**
  * Add a title to the link cache, return the page_id or zero if non-existent
  *
  * @param LinkTarget $nt LinkTarget object to add
  * @return int Page ID or zero
  */
 public function addLinkObj(LinkTarget $nt)
 {
     $key = $this->titleFormatter->getPrefixedDBkey($nt);
     if ($this->isBadLink($key) || $nt->isExternal() || $nt->inNamespace(NS_SPECIAL)) {
         return 0;
     }
     $id = $this->getGoodLinkID($key);
     if ($id != 0) {
         return $id;
     }
     if ($key === '') {
         return 0;
     }
     // Some fields heavily used for linking...
     $db = $this->mForUpdate ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE);
     $row = $db->selectRow('page', self::getSelectFields(), ['page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey()], __METHOD__);
     if ($row !== false) {
         $this->addGoodLinkObjFromRow($nt, $row);
         $id = intval($row->page_id);
     } else {
         $this->addBadLinkObj($nt);
         $id = 0;
     }
     return $id;
 }
 /**
  * Returns a wikitext link to the given page, using the given surface text.
  *
  * @param TitleValue $page The link's target
  * @param string $text The link's surface text (will be derived from $page if not given).
  *
  * @return string
  */
 public function renderWikitextLink(TitleValue $page, $text = null)
 {
     if ($text === null) {
         $text = $this->formatter->getFullText($page);
     }
     $name = $this->formatter->getFullText($page);
     return '[[:' . $name . '|' . wfEscapeWikiText($text) . ']]';
 }
Esempio n. 3
0
 /**
  * Add a title to the link cache, return the page_id or zero if non-existent
  *
  * @param LinkTarget $nt LinkTarget object to add
  * @return int Page ID or zero
  */
 public function addLinkObj(LinkTarget $nt)
 {
     $key = $this->titleFormatter->getPrefixedDBkey($nt);
     if ($this->isBadLink($key) || $nt->isExternal() || $nt->inNamespace(NS_SPECIAL)) {
         return 0;
     }
     $id = $this->getGoodLinkID($key);
     if ($id != 0) {
         return $id;
     }
     if ($key === '') {
         return 0;
     }
     // Cache template/file pages as they are less often viewed but heavily used
     if ($this->mForUpdate) {
         $row = $this->fetchPageRow(wfGetDB(DB_MASTER), $nt);
     } elseif ($this->isCacheable($nt)) {
         // These pages are often transcluded heavily, so cache them
         $cache = $this->wanCache;
         $row = $cache->getWithSetCallback($cache->makeKey('page', $nt->getNamespace(), sha1($nt->getDBkey())), $cache::TTL_DAY, function ($curValue, &$ttl, array &$setOpts) use($cache, $nt) {
             $dbr = wfGetDB(DB_REPLICA);
             $setOpts += Database::getCacheSetOptions($dbr);
             $row = $this->fetchPageRow($dbr, $nt);
             $mtime = $row ? wfTimestamp(TS_UNIX, $row->page_touched) : false;
             $ttl = $cache->adaptiveTTL($mtime, $ttl);
             return $row;
         });
     } else {
         $row = $this->fetchPageRow(wfGetDB(DB_REPLICA), $nt);
     }
     if ($row) {
         $this->addGoodLinkObjFromRow($nt, $row);
         $id = intval($row->page_id);
     } else {
         $this->addBadLinkObj($nt);
         $id = 0;
     }
     return $id;
 }