本文整理汇总了PHP中Linker::getLinkColour方法的典型用法代码示例。如果您正苦于以下问题:PHP Linker::getLinkColour方法的具体用法?PHP Linker::getLinkColour怎么用?PHP Linker::getLinkColour使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Linker
的用法示例。
在下文中一共展示了Linker::getLinkColour方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLinkColour
public function getLinkColour($t, $threshold)
{
return Linker::getLinkColour($t, $threshold);
}
示例2: doVariants
//.........这里部分代码省略.........
if ($textVariant === $text) {
continue;
}
$variantTitle = Title::makeTitle($ns, $textVariant);
if (is_null($variantTitle)) {
continue;
}
// Self-link checking for mixed/different variant titles. At this point, we
// already know the exact title does not exist, so the link cannot be to a
// variant of the current title that exists as a separate page.
if ($variantTitle->equals($parentTitle) && !$title->hasFragment()) {
$this->internals[$ns][$index]['selflink'] = true;
continue 2;
}
$linkBatch->addObj($variantTitle);
$variantMap[$variantTitle->getPrefixedDBkey()][] = "{$ns}:{$index}";
}
}
// process categories, check if a category exists in some variant
$categoryMap = array();
// maps $category_variant => $category (dbkeys)
$varCategories = array();
// category replacements oldDBkey => newDBkey
foreach ($output->getCategoryLinks() as $category) {
$categoryTitle = Title::makeTitleSafe(NS_CATEGORY, $category);
$linkBatch->addObj($categoryTitle);
$variants = $wgContLang->autoConvertToAllVariants($category);
foreach ($variants as $variant) {
if ($variant !== $category) {
$variantTitle = Title::makeTitleSafe(NS_CATEGORY, $variant);
if (is_null($variantTitle)) {
continue;
}
$linkBatch->addObj($variantTitle);
$categoryMap[$variant] = array($category, $categoryTitle);
}
}
}
if (!$linkBatch->isEmpty()) {
// construct query
$dbr = wfGetDB(DB_SLAVE);
$fields = array('page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest');
if ($wgContentHandlerUseDB) {
$fields[] = 'page_content_model';
}
$varRes = $dbr->select('page', $fields, $linkBatch->constructSet('page', $dbr), __METHOD__);
$linkcolour_ids = array();
// for each found variants, figure out link holders and replace
foreach ($varRes as $s) {
$variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
$varPdbk = $variantTitle->getPrefixedDBkey();
$vardbk = $variantTitle->getDBkey();
$holderKeys = array();
if (isset($variantMap[$varPdbk])) {
$holderKeys = $variantMap[$varPdbk];
$linkCache->addGoodLinkObjFromRow($variantTitle, $s);
$output->addLink($variantTitle, $s->page_id);
}
// loop over link holders
foreach ($holderKeys as $key) {
list($ns, $index) = explode(':', $key, 2);
$entry =& $this->internals[$ns][$index];
$pdbk = $entry['pdbk'];
if (!isset($colours[$pdbk]) || $colours[$pdbk] === 'new') {
// found link in some of the variants, replace the link holder data
$entry['title'] = $variantTitle;
$entry['pdbk'] = $varPdbk;
// set pdbk and colour
# @todo FIXME: Convoluted data flow
# The redirect status and length is passed to getLinkColour via the LinkCache
# Use formal parameters instead
$colours[$varPdbk] = Linker::getLinkColour($variantTitle, $threshold);
$linkcolour_ids[$s->page_id] = $pdbk;
}
}
// check if the object is a variant of a category
if (isset($categoryMap[$vardbk])) {
list($oldkey, $oldtitle) = $categoryMap[$vardbk];
if (!isset($varCategories[$oldkey]) && !$oldtitle->exists()) {
$varCategories[$oldkey] = $vardbk;
}
}
}
Hooks::run('GetLinkColours', array($linkcolour_ids, &$colours));
// rebuild the categories in original order (if there are replacements)
if (count($varCategories) > 0) {
$newCats = array();
$originalCats = $output->getCategories();
foreach ($originalCats as $cat => $sortkey) {
// make the replacement
if (array_key_exists($cat, $varCategories)) {
$newCats[$varCategories[$cat]] = $sortkey;
} else {
$newCats[$cat] = $sortkey;
}
}
$output->setCategoryLinks($newCats);
}
}
}
示例3: testGetLinkColour
/**
* @covers Linker::getLinkColour
*/
public function testGetLinkColour()
{
$this->hideDeprecated('Linker::getLinkColour');
$linkCache = MediaWikiServices::getInstance()->getLinkCache();
$foobarTitle = Title::makeTitle(NS_MAIN, 'FooBar');
$redirectTitle = Title::makeTitle(NS_MAIN, 'Redirect');
$userTitle = Title::makeTitle(NS_USER, 'Someuser');
$linkCache->addGoodLinkObj(1, $foobarTitle, 10, 0);
$linkCache->addGoodLinkObj(2, $redirectTitle, 10, 1);
$linkCache->addGoodLinkObj(3, $userTitle, 10, 0);
$this->assertEquals('', Linker::getLinkColour($foobarTitle, 0));
$this->assertEquals('stub', Linker::getLinkColour($foobarTitle, 20));
$this->assertEquals('mw-redirect', Linker::getLinkColour($redirectTitle, 0));
$this->assertEquals('', Linker::getLinkColour($userTitle, 20));
}
示例4: doVariants
/**
* Modify $this->internals and $colours according to language variant linking rules
*/
protected function doVariants(&$colours)
{
global $wgContLang;
$linkBatch = new LinkBatch();
$variantMap = array();
// maps $pdbkey_Variant => $keys (of link holders)
$output = $this->parent->getOutput();
$linkCache = LinkCache::singleton();
$threshold = $this->parent->getOptions()->getStubThreshold();
$titlesToBeConverted = '';
$titlesAttrs = array();
// Concatenate titles to a single string, thus we only need auto convert the
// single string to all variants. This would improve parser's performance
// significantly.
foreach ($this->internals as $ns => $entries) {
foreach ($entries as $index => $entry) {
$pdbk = $entry['pdbk'];
// we only deal with new links (in its first query)
if (!isset($colours[$pdbk])) {
$title = $entry['title'];
$titleText = $title->getText();
$titlesAttrs[] = array('ns' => $ns, 'key' => "{$ns}:{$index}", 'titleText' => $titleText);
// separate titles with \0 because it would never appears
// in a valid title
$titlesToBeConverted .= $titleText . "";
}
}
}
// Now do the conversion and explode string to text of titles
$titlesAllVariants = $wgContLang->autoConvertToAllVariants($titlesToBeConverted);
$allVariantsName = array_keys($titlesAllVariants);
foreach ($titlesAllVariants as &$titlesVariant) {
$titlesVariant = explode("", $titlesVariant);
}
$l = count($titlesAttrs);
// Then add variants of links to link batch
for ($i = 0; $i < $l; $i++) {
foreach ($allVariantsName as $variantName) {
$textVariant = $titlesAllVariants[$variantName][$i];
if ($textVariant != $titlesAttrs[$i]['titleText']) {
$variantTitle = Title::makeTitle($titlesAttrs[$i]['ns'], $textVariant);
if (is_null($variantTitle)) {
continue;
}
$linkBatch->addObj($variantTitle);
$variantMap[$variantTitle->getPrefixedDBkey()][] = $titlesAttrs[$i]['key'];
}
}
}
// process categories, check if a category exists in some variant
$categoryMap = array();
// maps $category_variant => $category (dbkeys)
$varCategories = array();
// category replacements oldDBkey => newDBkey
foreach ($output->getCategoryLinks() as $category) {
$variants = $wgContLang->autoConvertToAllVariants($category);
foreach ($variants as $variant) {
if ($variant != $category) {
$variantTitle = Title::newFromDBkey(Title::makeName(NS_CATEGORY, $variant));
if (is_null($variantTitle)) {
continue;
}
$linkBatch->addObj($variantTitle);
$categoryMap[$variant] = $category;
}
}
}
if (!$linkBatch->isEmpty()) {
// construct query
$dbr = wfGetDB(DB_SLAVE);
$varRes = $dbr->select('page', array('page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest'), $linkBatch->constructSet('page', $dbr), __METHOD__);
$linkcolour_ids = array();
// for each found variants, figure out link holders and replace
foreach ($varRes as $s) {
$variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
$varPdbk = $variantTitle->getPrefixedDBkey();
$vardbk = $variantTitle->getDBkey();
$holderKeys = array();
if (isset($variantMap[$varPdbk])) {
$holderKeys = $variantMap[$varPdbk];
$linkCache->addGoodLinkObjFromRow($variantTitle, $s);
$output->addLink($variantTitle, $s->page_id);
}
// loop over link holders
foreach ($holderKeys as $key) {
list($ns, $index) = explode(':', $key, 2);
$entry =& $this->internals[$ns][$index];
$pdbk = $entry['pdbk'];
if (!isset($colours[$pdbk])) {
// found link in some of the variants, replace the link holder data
$entry['title'] = $variantTitle;
$entry['pdbk'] = $varPdbk;
// set pdbk and colour
# @todo FIXME: Convoluted data flow
# The redirect status and length is passed to getLinkColour via the LinkCache
# Use formal parameters instead
$colours[$varPdbk] = Linker::getLinkColour($variantTitle, $threshold);
//.........这里部分代码省略.........
示例5: getLinkColour
/**
* @deprecated since 1.28, use LinkRenderer::getLinkClasses() instead
*/
public function getLinkColour($t, $threshold)
{
wfDeprecated(__METHOD__, '1.28');
return Linker::getLinkColour($t, $threshold);
}