本文整理汇总了PHP中LinkCache类的典型用法代码示例。如果您正苦于以下问题:PHP LinkCache类的具体用法?PHP LinkCache怎么用?PHP LinkCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LinkCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
global $wgCityId;
$db = wfGetDB(DB_MASTER);
(new WikiaSQL())->SELECT('*')->FROM('page')->WHERE('page_is_redirect')->EQUAL_TO(1)->runLoop($db, function ($a, $row) use($db) {
$title = Title::newFromID($row->page_id);
if (!$title->isDeleted()) {
$rev = Revision::newFromTitle($title);
$text = $rev->getText();
$rt = Title::newFromRedirectRecurse($text);
if (!$rt) {
// page is marked as redirect but $text is not valid redirect
$this->output('Fixed ID: ' . $title->getArticleID() . ' Title: ' . $title->getText() . "\n");
// Fix page table
(new WikiaSQL())->UPDATE('page')->SET('page_is_redirect', 0)->WHERE('page_id')->EQUAL_TO($row->page_id)->RUN($db);
// remove redirect from redirect table
(new WikiaSQL())->DELETE('redirect')->WHERE('rd_from')->EQUAL_TO($row->page_id)->RUN($db);
// clear cache
LinkCache::singleton()->addGoodLinkObj($row->page_id, $title, strlen($text), 0, $rev->getId());
if ($title->getNamespace() == NS_FILE) {
RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect($title);
}
}
}
});
}
示例2: setUp
protected function setUp()
{
parent::setUp();
$this->pages_to_delete = array();
LinkCache::singleton()->clear();
# avoid cached redirect status, etc
}
示例3: fixLinksFromArticle
function fixLinksFromArticle( $id ) {
global $wgTitle, $wgParser;
$wgTitle = Title::newFromID( $id );
$dbw = wfGetDB( DB_MASTER );
$linkCache =& LinkCache::singleton();
$linkCache->clear();
if ( is_null( $wgTitle ) ) {
return;
}
$dbw->begin();
$revision = Revision::newFromTitle( $wgTitle );
if ( !$revision ) {
return;
}
$options = new ParserOptions;
$parserOutput = $wgParser->parse( $revision->getText(), $wgTitle, $options, true, true, $revision->getId() );
$update = new LinksUpdate( $wgTitle, $parserOutput, false );
$update->doUpdate();
$dbw->commit();
}
示例4: run
/**
* Run a refreshLinks job
* @return boolean success
*/
function run()
{
global $wgParser;
wfProfileIn(__METHOD__);
$linkCache =& LinkCache::singleton();
$linkCache->clear();
if (is_null($this->title)) {
$this->error = "refreshLinks: Invalid title";
wfProfileOut(__METHOD__);
return false;
}
$revision = Revision::newFromTitle($this->title);
if (!$revision) {
$this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"';
wfProfileOut(__METHOD__);
return false;
}
wfProfileIn(__METHOD__ . '-parse');
$options = new ParserOptions();
$parserOutput = $wgParser->parse($revision->getText(), $this->title, $options, true, true, $revision->getId());
wfProfileOut(__METHOD__ . '-parse');
wfProfileIn(__METHOD__ . '-update');
$update = new LinksUpdate($this->title, $parserOutput, false);
$update->doUpdate();
wfProfileOut(__METHOD__ . '-update');
wfProfileOut(__METHOD__);
return true;
}
示例5: run
/**
* Run job
* @return boolean success
*/
function run()
{
wfProfileIn('SMWUpdateJob::run (SMW)');
global $wgParser;
LinkCache::singleton()->clear();
if (is_null($this->title)) {
$this->error = "SMWUpdateJob: Invalid title";
wfProfileOut('SMWUpdateJob::run (SMW)');
return false;
} elseif (!$this->title->exists()) {
smwfGetStore()->deleteSubject($this->title);
// be sure to clear the data
wfProfileOut('SMWUpdateJob::run (SMW)');
return true;
}
$revision = Revision::newFromTitle($this->title);
if (!$revision) {
$this->error = 'SMWUpdateJob: Page exists but no revision was found for "' . $this->title->getPrefixedDBkey() . '"';
wfProfileOut('SMWUpdateJob::run (SMW)');
return false;
}
wfProfileIn(__METHOD__ . '-parse');
$options = new ParserOptions();
$output = $wgParser->parse($revision->getText(), $this->title, $options, true, true, $revision->getID());
wfProfileOut(__METHOD__ . '-parse');
wfProfileIn(__METHOD__ . '-update');
SMWParseData::storeData($output, $this->title, false);
wfProfileOut(__METHOD__ . '-update');
wfProfileOut('SMWUpdateJob::run (SMW)');
return true;
}
示例6: testEditUserTalkFlyoutSectionLinkFragment
/**
* @dataProvider provider_editUserTalk
*/
public function testEditUserTalkFlyoutSectionLinkFragment($pattern, $sectionTitle, $format)
{
// Required hack so parser doesnt turn the links into redlinks which contain no fragment
global $wgUser;
LinkCache::singleton()->addGoodLinkObj(42, $wgUser->getTalkPage());
$event = $this->mockEvent('edit-user-talk', array('section-title' => $sectionTitle));
$this->assertRegExp($pattern, $this->format($event, $format));
}
示例7: runParser
/**
* Parse the text from a given Revision
*
* @param Revision $revision
*/
function runParser(Revision $revision)
{
$content = $revision->getContent();
$content->getParserOutput($revision->getTitle(), $revision->getId());
if ($this->clearLinkCache) {
$this->linkCache->clear();
}
}
示例8: testGetLinkClasses
public function testGetLinkClasses()
{
$wanCache = ObjectCache::getMainWANInstance();
$titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
$linkCache = new LinkCache($titleFormatter, $wanCache);
$foobarTitle = new TitleValue(NS_MAIN, 'FooBar');
$redirectTitle = new TitleValue(NS_MAIN, 'Redirect');
$userTitle = new TitleValue(NS_USER, 'Someuser');
$linkCache->addGoodLinkObj(1, $foobarTitle, 10, 0);
$linkCache->addGoodLinkObj(2, $redirectTitle, 10, 1);
$linkCache->addGoodLinkObj(3, $userTitle, 10, 0);
$linkRenderer = new LinkRenderer($titleFormatter, $linkCache);
$linkRenderer->setStubThreshold(0);
$this->assertEquals('', $linkRenderer->getLinkClasses($foobarTitle));
$linkRenderer->setStubThreshold(20);
$this->assertEquals('stub', $linkRenderer->getLinkClasses($foobarTitle));
$linkRenderer->setStubThreshold(0);
$this->assertEquals('mw-redirect', $linkRenderer->getLinkClasses($redirectTitle));
$linkRenderer->setStubThreshold(20);
$this->assertEquals('', $linkRenderer->getLinkClasses($userTitle));
}
示例9: run
/**
* Run a refreshLinks2 job
* @return boolean success
*/
function run()
{
global $wgParser;
wfProfileIn(__METHOD__);
$linkCache = LinkCache::singleton();
$linkCache->clear();
if (is_null($this->title)) {
$this->error = "refreshLinks2: Invalid title";
wfProfileOut(__METHOD__);
return false;
}
if (!isset($this->params['start']) || !isset($this->params['end'])) {
$this->error = "refreshLinks2: Invalid params";
wfProfileOut(__METHOD__);
return false;
}
$start = intval($this->params['start']);
$end = intval($this->params['end']);
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select(array('templatelinks', 'page'), array('page_namespace', 'page_title'), array('page_id=tl_from', "tl_from >= '{$start}'", "tl_from <= '{$end}'", 'tl_namespace' => $this->title->getNamespace(), 'tl_title' => $this->title->getDBkey()), __METHOD__);
# Not suitable for page load triggered job running!
# Gracefully switch to refreshLinks jobs if this happens.
if (php_sapi_name() != 'cli') {
$jobs = array();
while ($row = $dbr->fetchObject($res)) {
$title = Title::makeTitle($row->page_namespace, $row->page_title);
$jobs[] = new RefreshLinksJob($title, '');
}
Job::batchInsert($jobs);
return true;
}
# Re-parse each page that transcludes this page and update their tracking links...
while ($row = $dbr->fetchObject($res)) {
$title = Title::makeTitle($row->page_namespace, $row->page_title);
$revision = Revision::newFromTitle($title);
if (!$revision) {
$this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
wfProfileOut(__METHOD__);
return false;
}
wfProfileIn(__METHOD__ . '-parse');
$options = new ParserOptions();
$parserOutput = $wgParser->parse($revision->getText(), $title, $options, true, true, $revision->getId());
wfProfileOut(__METHOD__ . '-parse');
wfProfileIn(__METHOD__ . '-update');
$update = new LinksUpdate($title, $parserOutput, false);
$update->doUpdate();
wfProfileOut(__METHOD__ . '-update');
wfProfileOut(__METHOD__);
}
return true;
}
示例10: run
/**
* Run a refreshLinks2 job
* @return boolean success
*/
function run()
{
global $wgParser, $wgContLang;
wfProfileIn(__METHOD__);
$linkCache = LinkCache::singleton();
$linkCache->clear();
if (is_null($this->title)) {
$this->error = "refreshLinks2: Invalid title";
wfProfileOut(__METHOD__);
return false;
}
if (!isset($this->params['start']) || !isset($this->params['end'])) {
$this->error = "refreshLinks2: Invalid params";
wfProfileOut(__METHOD__);
return false;
}
// Back compat for pre-r94435 jobs
$table = isset($this->params['table']) ? $this->params['table'] : 'templatelinks';
$titles = $this->title->getBacklinkCache()->getLinks($table, $this->params['start'], $this->params['end']);
# Not suitable for page load triggered job running!
# Gracefully switch to refreshLinks jobs if this happens.
if (php_sapi_name() != 'cli') {
$jobs = array();
foreach ($titles as $title) {
$jobs[] = new RefreshLinksJob($title, '');
}
Job::batchInsert($jobs);
wfProfileOut(__METHOD__);
return true;
}
$options = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
# Re-parse each page that transcludes this page and update their tracking links...
foreach ($titles as $title) {
$revision = Revision::newFromTitle($title);
if (!$revision) {
$this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
wfProfileOut(__METHOD__);
return false;
}
wfProfileIn(__METHOD__ . '-parse');
$parserOutput = $wgParser->parse($revision->getText(), $title, $options, true, true, $revision->getId());
wfProfileOut(__METHOD__ . '-parse');
wfProfileIn(__METHOD__ . '-update');
$update = new LinksUpdate($title, $parserOutput, false);
$update->doUpdate();
wfProfileOut(__METHOD__ . '-update');
wfWaitForSlaves();
}
wfProfileOut(__METHOD__);
return true;
}
示例11: run
/**
* Run method
* @return boolean success
*/
function run()
{
global $wgParser, $wgContLang;
$linkCache =& LinkCache::singleton();
$linkCache->clear();
smwLog("start", "RF", "category refactoring");
$article = new Article($this->updatetitle);
$latestrevision = Revision::newFromTitle($this->updatetitle);
smwLog("oldtitle: " . $this->oldtitle, "RF", "category refactoring");
smwLog("newtitle: " . $this->newtitle, "RF", "category refactoring");
if (!$latestrevision) {
$this->error = "SMW_UpdateCategoriesAfterMoveJob: Article not found " . $this->updatetitle->getPrefixedDBkey() . " ";
wfDebug($this->error);
return false;
}
$oldtext = $latestrevision->getRawText();
//Category X moved to Y
// Links changed accordingly:
$cat = $wgContLang->getNsText(NS_CATEGORY);
$catlcfirst = strtolower(substr($cat, 0, 1)) . substr($cat, 1);
$oldtitlelcfirst = strtolower(substr($this->oldtitle, 0, 1)) . substr($this->oldtitle, 1);
// [[[C|c]ategory:[S|s]omeCategory]] -> [[[C|c]ategory:[S|s]omeOtherCategory]]
$search[0] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\]\\])';
$replace[0] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}]]';
$search[1] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\]\\])';
$replace[1] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}]]';
$search[2] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\]\\])';
$replace[2] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}]]';
$search[3] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\]\\])';
$replace[3] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}]]';
// [[[C|c]ategory:[S|s]omeCategory | m]] -> [[[C|c]ategory:[S|s]omeOtherCategory | m ]]
$search[4] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\|([^]]*)\\]\\])';
$replace[4] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}|${5}]]';
$search[5] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $this->oldtitle . '(\\s*)\\|([^]]*)\\]\\])';
$replace[5] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}|${5}]]';
$search[6] = '(\\[\\[(\\s*)' . $cat . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\|([^]]*)\\]\\])';
$replace[6] = '[[${1}' . $cat . '${2}:${3}' . $this->newtitle . '${4}|${5}]]';
$search[7] = '(\\[\\[(\\s*)' . $catlcfirst . '(\\s*):(\\s*)' . $oldtitlelcfirst . '(\\s*)\\|([^]]*)\\]\\])';
$replace[7] = '[[${1}' . $catlcfirst . '${2}:${3}' . $this->newtitle . '${4}|${5}]]';
$newtext = preg_replace($search, $replace, $oldtext);
$summary = 'Link(s) to ' . $this->newtitle . ' updated after page move by SMW_UpdateCategoriesAfterMoveJob. ' . $this->oldtitle . ' has been moved to ' . $this->newtitle;
$article->doEdit($newtext, $summary, EDIT_FORCE_BOT);
smwLog("finished editing article", "RF", "category refactoring");
$options = new ParserOptions();
$wgParser->parse($newtext, $this->updatetitle, $options, true, true, $latestrevision->getId());
smwLog("finished parsing semantic data", "RF", "category refactoring");
return true;
}
示例12: run
/**
* Run a refreshLinks2 job
* @return boolean success
*/
function run()
{
global $wgUpdateRowsPerJob;
$linkCache = LinkCache::singleton();
$linkCache->clear();
if (is_null($this->title)) {
$this->error = "refreshLinks2: Invalid title";
return false;
}
// Back compat for pre-r94435 jobs
$table = isset($this->params['table']) ? $this->params['table'] : 'templatelinks';
// Avoid slave lag when fetching templates.
// When the outermost job is run, we know that the caller that enqueued it must have
// committed the relevant changes to the DB by now. At that point, record the master
// position and pass it along as the job recursively breaks into smaller range jobs.
// Hopefully, when leaf jobs are popped, the slaves will have reached that position.
if (isset($this->params['masterPos'])) {
$masterPos = $this->params['masterPos'];
} elseif (wfGetLB()->getServerCount() > 1) {
$masterPos = wfGetLB()->getMasterPos();
} else {
$masterPos = false;
}
$tbc = $this->title->getBacklinkCache();
$jobs = array();
// jobs to insert
if (isset($this->params['start']) && isset($this->params['end'])) {
# This is a partition job to trigger the insertion of leaf jobs...
$jobs = array_merge($jobs, $this->getSingleTitleJobs($table, $masterPos));
} else {
# This is a base job to trigger the insertion of partitioned jobs...
if ($tbc->getNumLinks($table, $wgUpdateRowsPerJob + 1) <= $wgUpdateRowsPerJob) {
# Just directly insert the single per-title jobs
$jobs = array_merge($jobs, $this->getSingleTitleJobs($table, $masterPos));
} else {
# Insert the partition jobs to make per-title jobs
foreach ($tbc->partition($table, $wgUpdateRowsPerJob) as $batch) {
list($start, $end) = $batch;
$jobs[] = new RefreshLinksJob2($this->title, array('table' => $table, 'start' => $start, 'end' => $end, 'masterPos' => $masterPos) + $this->getRootJobParams());
}
}
}
if (count($jobs)) {
JobQueueGroup::singleton()->push($jobs);
}
return true;
}
示例13: run
/**
* Run method
* @return boolean success
*/
function run()
{
global $wgParser;
$linkCache =& LinkCache::singleton();
$linkCache->clear();
smwLog("start", "RF", "property refactoring");
$article = new Article($this->updatetitle);
$latestrevision = Revision::newFromTitle($this->updatetitle);
smwLog("oldtitle: " . $this->oldtitle, "RF", "property refactoring");
smwLog("newtitle: " . $this->newtitle, "RF", "property refactoring");
if (!$latestrevision) {
$this->error = "SMW_UpdatePropertiesAfterMoveJob: Article not found " . $this->updatetitle->getPrefixedDBkey() . " ";
wfDebug($this->error);
return false;
}
$oldtext = $latestrevision->getRawText();
//Page X moved to Y
// Links changed accordingly:
// [[X::m]] -> [[Y::m]]
$search[0] = '(\\[\\[(\\s*)' . $this->oldtitle . '(\\s*)::([^]]*)\\]\\])';
$replace[0] = '[[${1}' . $this->newtitle . '${2}::${3}]]';
// [[X:=m]] -> [[Y:=m]]
$search[1] = '(\\[\\[(\\s*)' . $this->oldtitle . '(\\s*):=([^]]*)\\]\\])';
$replace[1] = '[[${1}' . $this->newtitle . '${2}:=${3}]]';
// TODO check if the wiki is case sensitive on the first letter
// This is not the case for the Halo wikis
$oldtitlelcfirst = strtolower(substr($this->oldtitle, 0, 1)) . substr($this->oldtitle, 1);
// [[x::m]] -> [[Y::m]]
$search[2] = '(\\[\\[(\\s*)' . $oldtitlelcfirst . '(\\s*)::([^]]*)\\]\\])';
$replace[2] = '[[${1}' . $this->newtitle . '${2}::${3}]]';
// [[x:=m]] -> [[Y:=m]]
$search[3] = '(\\[\\[(\\s*)' . $oldtitlelcfirst . '(\\s*):=([^]]*)\\]\\])';
$replace[3] = '[[${1}' . $this->newtitle . '${2}:=${3}]]';
$newtext = preg_replace($search, $replace, $oldtext);
$summary = 'Link(s) to ' . $this->newtitle . ' updated after page move by SMW_UpdatePropertiesAfterMoveJob. ' . $this->oldtitle . ' has been moved to ' . $this->newtitle;
$article->doEdit($newtext, $summary, EDIT_FORCE_BOT);
smwLog("finished editing article", "RF", "property refactoring");
$options = new ParserOptions();
$wgParser->parse($newtext, $this->updatetitle, $options, true, true, $latestrevision->getId());
smwLog("finished parsing semantic data", "RF", "property refactoring");
return true;
}
示例14: statelessFetchTemplate
/**
* Static function to get a template
* Can be overridden via ParserOptions::setTemplateCallback().
*
* @param Title $title
* @param Parser $parser
*
* @return array
*/
static function statelessFetchTemplate($title, $parser = false)
{
$text = $skip = false;
$finalTitle = $title;
$deps = array();
# Loop to fetch the article, with up to 1 redirect
for ($i = 0; $i < 2 && is_object($title); $i++) {
# Give extensions a chance to select the revision instead
$id = false;
# Assume current
wfRunHooks('BeforeParserFetchTemplateAndtitle', array($parser, $title, &$skip, &$id));
if ($skip) {
$text = false;
$deps[] = array('title' => $title, 'page_id' => $title->getArticleID(), 'rev_id' => null);
break;
}
# Get the revision
$rev = $id ? Revision::newFromId($id) : Revision::newFromTitle($title, false, Revision::READ_NORMAL);
$rev_id = $rev ? $rev->getId() : 0;
# If there is no current revision, there is no page
if ($id === false && !$rev) {
$linkCache = LinkCache::singleton();
$linkCache->addBadLinkObj($title);
}
$deps[] = array('title' => $title, 'page_id' => $title->getArticleID(), 'rev_id' => $rev_id);
if ($rev && !$title->equals($rev->getTitle())) {
# We fetched a rev from a different title; register it too...
$deps[] = array('title' => $rev->getTitle(), 'page_id' => $rev->getPage(), 'rev_id' => $rev_id);
}
if ($rev) {
$content = $rev->getContent();
$text = $content ? $content->getWikitextForTransclusion() : null;
if ($text === false || $text === null) {
$text = false;
break;
}
} elseif ($title->getNamespace() == NS_MEDIAWIKI) {
global $wgContLang;
$message = wfMessage($wgContLang->lcfirst($title->getText()))->inContentLanguage();
if (!$message->exists()) {
$text = false;
break;
}
$content = $message->content();
$text = $message->plain();
} else {
break;
}
if (!$content) {
break;
}
# Redirect?
$finalTitle = $title;
$title = $content->getRedirectTarget();
}
return array('text' => $text, 'finalTitle' => $finalTitle, 'deps' => $deps);
}
示例15: updateRevisionOn
/**
* Update the page record to point to a newly saved revision.
*
* @param IDatabase $dbw
* @param Revision $revision For ID number, and text used to set
* length and redirect status fields
* @param int $lastRevision If given, will not overwrite the page field
* when different from the currently set value.
* Giving 0 indicates the new page flag should be set on.
* @param bool $lastRevIsRedirect If given, will optimize adding and
* removing rows in redirect table.
* @return bool Success; false if the page row was missing or page_latest changed
*/
public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
{
global $wgContentHandlerUseDB;
// Assertion to try to catch T92046
if ((int) $revision->getId() === 0) {
throw new InvalidArgumentException(__METHOD__ . ': Revision has ID ' . var_export($revision->getId(), 1));
}
$content = $revision->getContent();
$len = $content ? $content->getSize() : 0;
$rt = $content ? $content->getUltimateRedirectTarget() : null;
$conditions = ['page_id' => $this->getId()];
if (!is_null($lastRevision)) {
// An extra check against threads stepping on each other
$conditions['page_latest'] = $lastRevision;
}
$row = ['page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($revision->getTimestamp()), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len];
if ($wgContentHandlerUseDB) {
$row['page_content_model'] = $revision->getContentModel();
}
$dbw->update('page', $row, $conditions, __METHOD__);
$result = $dbw->affectedRows() > 0;
if ($result) {
$this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
$this->setLastEdit($revision);
$this->mLatest = $revision->getId();
$this->mIsRedirect = (bool) $rt;
// Update the LinkCache.
LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel());
}
return $result;
}