static function clearRows() { self::$backlinkRows = array(); self::$sourceArticleIds = array(); }
ini_set("include_path", dirname(__FILE__) . "/../../../maintenance/"); require_once "commandLine.inc"; $dbr = wfGetDB(DB_SLAVE); global $wgContentNamespaces, $wgTitle, $wgOut, $wgArticle; $contentNamespaces = implode(', ', $wgContentNamespaces); $res = $dbr->query("SELECT COUNT(*) AS `count` FROM `page` WHERE page_is_redirect = 0 AND page_namespace IN ({$contentNamespaces});"); $row = $res->fetchRow(); $count = $row['count']; $slice = 1000; for ($i = 0; $i <= $count; $i += $slice) { $sql = "SELECT page_id FROM page WHERE page_is_redirect = 0 AND page_namespace IN ({$contentNamespaces}) LIMIT {$i},{$slice}"; $res = $dbr->query($sql); $counter = 0; while ($row = $res->fetchRow()) { $pageid = $row['page_id']; $page = F::build('Article', array($pageid), 'newFromID'); if (!$page instanceof Article) { continue; } $wgArticle = $page; // hack: setting wgTitle as rendering fails otherwise $wgTitle = $page->getTitle(); echo "\t{$wgTitle} (id: {$pageid}, " . $counter++ . " of batch " . (int) $i / $slice . " of " . (int) ($count / $slice) . ")\n"; // hack: setting action=render to exclude "Related Pages" and other unwanted stuff $page->doPurge(); $page->render(); unset($page); $wgOut->clearHTML(); Backlinks::clearRows(); } }
<?php /** * @package MediaWiki * @addtopackage maintenance */ ini_set("include_path", dirname(__FILE__) . "/../../../maintenance/"); require_once "commandLine.inc"; global $wgEnableBacklinksExt; $wgEnableBacklinksExt = true; include "{$IP}/extensions/wikia/Backlinks/Backlinks.setup.php"; echo Backlinks::initTable() . "\n";
/** * This method does the brunt of the work for populating an array with the values * we need when servicing the backend search indexer processes * @see WikiaSearchIndexer::getPages() * @see WikiaSearchController::getPage() * @param int $pageId * @throws WikiaException * @return array result */ public function getPage($pageId) { wfProfileIn(__METHOD__); $result = array(); $page = F::build('Article', array($pageId), 'newFromID'); if (!$page instanceof Article) { throw new WikiaException('Invalid Article ID'); } if (!$this->parserHookActive) { $this->app->registerHook('ParserClearState', 'WikiaSearchIndexer', 'onParserClearState'); $this->parserHookActive = true; } // hack: setting wgTitle as rendering fails otherwise $wgTitle = $this->wg->Title; $this->wg->Title = $page->getTitle(); // hack: setting action=render to exclude "Related Pages" and other unwanted stuff $wgRequest = $this->wg->Request; $this->wg->Request->setVal('action', 'render'); if ($page->isRedirect()) { $redirectPage = F::build('Article', array($page->getRedirectTarget())); $redirectPage->loadContent(); // hack: setting wgTitle as rendering fails otherwise $this->wg->Title = $page->getRedirectTarget(); $redirectPage->render(); $canonical = $page->getRedirectTarget()->getPrefixedText(); } else { $page->render(); $canonical = ''; } $html = $this->wg->Out->getHTML(); $namespace = $this->wg->Title->getNamespace(); $isVideo = false; $isImage = false; if ($namespace == NS_FILE && ($file = $this->wf->findFile($this->wg->Title->getText()))) { $detail = WikiaFileHelper::getMediaDetail($this->wg->Title); $isVideo = WikiaFileHelper::isVideoFile($file); $isImage = $detail['mediaType'] == 'image' && !$isVideo; $metadata = $file->getMetadata(); if ($metadata !== "0") { $metadata = unserialize($metadata); $fileParams = array('description', 'keywords') + ($isVideo ? array('movieTitleAndYear', 'videoTitle') : array()); foreach ($fileParams as $datum) { $html .= isset($metadata[$datum]) ? ' ' . $metadata[$datum] : ''; } } } $title = $page->getTitle()->getText(); if (in_array($namespace, array(NS_WIKIA_FORUM_BOARD_THREAD, NS_USER_WALL_MESSAGE))) { $wm = WallMessage::newFromId($page->getId()); $wm->load(); if ($wm->isMain()) { $title = $wm->getMetaTitle(); } else { if ($main = $wm->getTopParentObj() and !empty($main)) { $main->load(); $title = $main->getMetaTitle(); } } } // clear output buffer in case we want get more pages $this->wg->Out->clearHTML(); $result['wid'] = empty($this->wg->ExternalSharedDB) ? $this->wg->SearchWikiId : (int) $this->wg->CityId; $result['pageid'] = $pageId; $result['id'] = $result['wid'] . '_' . $result['pageid']; $result['title'] = $title; $result['canonical'] = $canonical; $result['html'] = html_entity_decode($html, ENT_COMPAT, 'UTF-8'); $result['url'] = $page->getTitle()->getFullUrl(); $result['ns'] = $page->getTitle()->getNamespace(); $result['host'] = substr($this->wg->Server, 7); $result['lang'] = $this->wg->Lang->mCode; # these need to be strictly typed as bool strings since they're passed via http when in the hands of the worker $result['iscontent'] = in_array($result['ns'], $this->wg->ContentNamespaces) ? 'true' : 'false'; $result['is_main_page'] = $page->getId() == Title::newMainPage()->getArticleId() && $page->getId() != 0 ? 'true' : 'false'; $result['is_redirect'] = $canonical == '' ? 'false' : 'true'; $result['is_video'] = $isVideo ? 'true' : 'false'; $result['is_image'] = $isImage ? 'true' : 'false'; if ($this->wg->EnableBacklinksExt && $this->wg->IndexBacklinks) { $result['backlink_text'] = Backlinks::getForArticle($page); } $result = array_merge($result, $this->getPageMetaData($page)); // restore global state $this->wg->Title = $wgTitle; $this->wg->Request = $wgRequest; wfProfileOut(__METHOD__); return $result; }