本文整理汇总了PHP中Interwiki::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Interwiki::fetch方法的具体用法?PHP Interwiki::fetch怎么用?PHP Interwiki::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interwiki
的用法示例。
在下文中一共展示了Interwiki::fetch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Execute the job
*
* @return bool
*/
public function run()
{
//sleep() could be added here to reduce unnecessary use
$ill = $this->params['ill'];
foreach ($ill as $lang => $pages) {
$iw = Interwiki::fetch($lang);
if (!$iw) {
continue;
}
$apiUrl = $iw->getAPI();
if (!$apiUrl) {
continue;
}
$apiUrl .= '?' . wfArrayToCGI(array('action' => 'purge', 'format' => 'json', 'titles' => implode('|', array_keys($pages))));
Http::post($apiUrl);
//TODO: error handling
}
return true;
}
示例2: getLocalURL
/**
* Get a URL with no fragment or server name (relative URL) from a Title object.
* If this page is generated with action=render, however,
* $wgServer is prepended to make an absolute URL.
*
* @see self::getFullURL to always get an absolute URL.
* @see self::getLinkURL to always get a URL that's the simplest URL that will be
* valid to link, locally, to the current Title.
* @see self::newFromText to produce a Title object.
*
* @param string|array $query An optional query string,
* not used for interwiki links. Can be specified as an associative array as well,
* e.g., array( 'action' => 'edit' ) (keys and values will be URL-escaped).
* Some query patterns will trigger various shorturl path replacements.
* @param array $query2 An optional secondary query array. This one MUST
* be an array. If a string is passed it will be interpreted as a deprecated
* variant argument and urlencoded into a variant= argument.
* This second query argument will be added to the $query
* The second parameter is deprecated since 1.19. Pass it as a key,value
* pair in the first parameter array instead.
*
* @return string String of the URL.
*/
public function getLocalURL($query = '', $query2 = false)
{
global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
$query = self::fixUrlQueryArgs($query, $query2);
$interwiki = Interwiki::fetch($this->mInterwiki);
if ($interwiki) {
$namespace = $this->getNsText();
if ($namespace != '') {
# Can this actually happen? Interwikis shouldn't be parsed.
# Yes! It can in interwiki transclusion. But... it probably shouldn't.
$namespace .= ':';
}
$url = $interwiki->getURL($namespace . $this->getDBkey());
$url = wfAppendQuery($url, $query);
} else {
$dbkey = wfUrlencode($this->getPrefixedDBkey());
if ($query == '') {
$url = str_replace('$1', $dbkey, $wgArticlePath);
Hooks::run('GetLocalURL::Article', array(&$this, &$url));
} else {
global $wgVariantArticlePath, $wgActionPaths, $wgContLang;
$url = false;
$matches = array();
if (!empty($wgActionPaths) && preg_match('/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches)) {
$action = urldecode($matches[2]);
if (isset($wgActionPaths[$action])) {
$query = $matches[1];
if (isset($matches[4])) {
$query .= $matches[4];
}
$url = str_replace('$1', $dbkey, $wgActionPaths[$action]);
if ($query != '') {
$url = wfAppendQuery($url, $query);
}
}
}
if ($url === false && $wgVariantArticlePath && $wgContLang->getCode() === $this->getPageLanguage()->getCode() && $this->getPageLanguage()->hasVariants() && preg_match('/^variant=([^&]*)$/', $query, $matches)) {
$variant = urldecode($matches[1]);
if ($this->getPageLanguage()->hasVariant($variant)) {
// Only do the variant replacement if the given variant is a valid
// variant for the page's language.
$url = str_replace('$2', urlencode($variant), $wgVariantArticlePath);
$url = str_replace('$1', $dbkey, $url);
}
}
if ($url === false) {
if ($query == '-') {
$query = '';
}
$url = "{$wgScript}?title={$dbkey}&{$query}";
}
}
Hooks::run('GetLocalURL::Internal', array(&$this, &$url, $query));
// @todo FIXME: This causes breakage in various places when we
// actually expected a local URL and end up with dupe prefixes.
if ($wgRequest->getVal('action') == 'render') {
$url = $wgServer . $url;
}
}
Hooks::run('GetLocalURL', array(&$this, &$url, $query));
return $url;
}
示例3: getFullURL
/**
* Get a real URL referring to this title, with interwiki link and
* fragment
*
* @param $query \twotypes{\string,\array} an optional query string, not used for interwiki
* links. Can be specified as an associative array as well, e.g.,
* array( 'action' => 'edit' ) (keys and values will be URL-escaped).
* @param $variant String language variant of url (for sr, zh..)
* @return String the URL
*/
public function getFullURL($query = '', $variant = false)
{
global $wgServer, $wgRequest;
if (is_array($query)) {
$query = wfArrayToCGI($query);
}
$interwiki = Interwiki::fetch($this->mInterwiki);
if (!$interwiki) {
$url = $this->getLocalURL($query, $variant);
// Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
// Correct fix would be to move the prepending elsewhere.
if ($wgRequest->getVal('action') != 'render') {
$url = $wgServer . $url;
}
} else {
$baseUrl = $interwiki->getURL();
$namespace = wfUrlencode($this->getNsText());
if ($namespace != '') {
# Can this actually happen? Interwikis shouldn't be parsed.
# Yes! It can in interwiki transclusion. But... it probably shouldn't.
$namespace .= ':';
}
$url = str_replace('$1', $namespace . $this->mUrlform, $baseUrl);
$url = wfAppendQuery($url, $query);
}
# Finally, add the fragment.
$url .= $this->getFragmentForURL();
wfRunHooks('GetFullURL', array(&$this, &$url, $query, $variant));
return $url;
}
示例4: newFromInterwiki
/**
* @param string $interwiki
* @param string $page
* @param bool $history
* @param bool $templates
* @param int $pageLinkDepth
* @return Status
*/
public static function newFromInterwiki($interwiki, $page, $history = false, $templates = false, $pageLinkDepth = 0)
{
if ($page == '') {
return Status::newFatal('import-noarticle');
}
# Look up the first interwiki prefix, and let the foreign site handle
# subsequent interwiki prefixes
$firstIwPrefix = strtok($interwiki, ':');
$firstIw = Interwiki::fetch($firstIwPrefix);
if (!$firstIw) {
return Status::newFatal('importbadinterwiki');
}
$additionalIwPrefixes = strtok('');
if ($additionalIwPrefixes) {
$additionalIwPrefixes .= ':';
}
# Have to do a DB-key replacement ourselves; otherwise spaces get
# URL-encoded to +, which is wrong in this case. Similar to logic in
# Title::getLocalURL
$link = $firstIw->getURL(strtr("{$additionalIwPrefixes}Special:Export/{$page}", ' ', '_'));
$params = array();
if ($history) {
$params['history'] = 1;
}
if ($templates) {
$params['templates'] = 1;
}
if ($pageLinkDepth) {
$params['pagelink-depth'] = $pageLinkDepth;
}
$url = wfAppendQuery($link, $params);
# For interwikis, use POST to avoid redirects.
return ImportStreamSource::newFromURL($url, "POST");
}
示例5: testArrayStorage
public function testArrayStorage()
{
$dewiki = ['iw_prefix' => 'de', 'iw_url' => 'http://de.wikipedia.org/wiki/', 'iw_local' => 1];
$zzwiki = ['iw_prefix' => 'zz', 'iw_url' => 'http://zzwiki.org/wiki/', 'iw_local' => 0];
$cdbData = $this->populateHash('en', [$dewiki], [$zzwiki]);
$this->setWgInterwikiCache($cdbData);
$this->assertEquals([$dewiki, $zzwiki], Interwiki::getAllPrefixes(), 'getAllPrefixes()');
$this->assertTrue(Interwiki::isValidInterwiki('de'), 'known prefix is valid');
$this->assertTrue(Interwiki::isValidInterwiki('zz'), 'known prefix is valid');
$interwiki = Interwiki::fetch('de');
$this->assertInstanceOf('Interwiki', $interwiki);
$this->assertSame('http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL');
$this->assertSame(true, $interwiki->isLocal(), 'isLocal');
$interwiki = Interwiki::fetch('zz');
$this->assertInstanceOf('Interwiki', $interwiki);
$this->assertSame('http://zzwiki.org/wiki/', $interwiki->getURL(), 'getURL');
$this->assertSame(false, $interwiki->isLocal(), 'isLocal');
}
示例6: getButtonHrefByObjectReference
/**
* Generate the URL out of the object reference
*
* @param string $objRef
* @return bool|string
*/
private function getButtonHrefByObjectReference($objRef)
{
$arrObjRef = explode('|', $objRef);
if (count($arrObjRef) > 1) {
list($wiki, $title) = $arrObjRef;
if (Interwiki::isValidInterwiki($wiki)) {
return str_replace('$1', $title, Interwiki::fetch($wiki)->getURL());
}
}
return false;
}