本文整理汇总了PHP中Interwiki::isValidInterwiki方法的典型用法代码示例。如果您正苦于以下问题:PHP Interwiki::isValidInterwiki方法的具体用法?PHP Interwiki::isValidInterwiki怎么用?PHP Interwiki::isValidInterwiki使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interwiki
的用法示例。
在下文中一共展示了Interwiki::isValidInterwiki方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: secureAndSplit
/**
* Secure and split - main initialisation function for this object
*
* Assumes that mDbkeyform has been set, and is urldecoded
* and uses underscores, but not otherwise munged. This function
* removes illegal characters, splits off the interwiki and
* namespace prefixes, sets the other forms, and canonicalizes
* everything.
*
* @return Bool true on success
*/
private function secureAndSplit()
{
global $wgContLang, $wgLocalInterwiki;
# Initialisation
$this->mInterwiki = $this->mFragment = '';
$this->mNamespace = $this->mDefaultNamespace;
# Usually NS_MAIN
$dbkey = $this->mDbkeyform;
# Strip Unicode bidi override characters.
# Sometimes they slip into cut-n-pasted page titles, where the
# override chars get included in list displays.
$dbkey = preg_replace('/\\xE2\\x80[\\x8E\\x8F\\xAA-\\xAE]/S', '', $dbkey);
# Clean up whitespace
# Note: use of the /u option on preg_replace here will cause
# input with invalid UTF-8 sequences to be nullified out in PHP 5.2.x,
# conveniently disabling them.
$dbkey = preg_replace('/[ _\\xA0\\x{1680}\\x{180E}\\x{2000}-\\x{200A}\\x{2028}\\x{2029}\\x{202F}\\x{205F}\\x{3000}]+/u', '_', $dbkey);
$dbkey = trim($dbkey, '_');
if ($dbkey == '') {
return false;
}
if (false !== strpos($dbkey, UTF8_REPLACEMENT)) {
# Contained illegal UTF-8 sequences or forbidden Unicode chars.
return false;
}
$this->mDbkeyform = $dbkey;
# Initial colon indicates main namespace rather than specified default
# but should not create invalid {ns,title} pairs such as {0,Project:Foo}
if (':' == $dbkey[0]) {
$this->mNamespace = NS_MAIN;
$dbkey = substr($dbkey, 1);
# remove the colon but continue processing
$dbkey = trim($dbkey, '_');
# remove any subsequent whitespace
}
# Namespace or interwiki prefix
$firstPass = true;
$prefixRegexp = "/^(.+?)_*:_*(.*)\$/S";
do {
$m = array();
if (preg_match($prefixRegexp, $dbkey, $m)) {
$p = $m[1];
if (($ns = $wgContLang->getNsIndex($p)) !== false) {
# Ordinary namespace
$dbkey = $m[2];
$this->mNamespace = $ns;
# For Talk:X pages, check if X has a "namespace" prefix
if ($ns == NS_TALK && preg_match($prefixRegexp, $dbkey, $x)) {
if ($wgContLang->getNsIndex($x[1])) {
# Disallow Talk:File:x type titles...
return false;
} elseif (Interwiki::isValidInterwiki($x[1])) {
# Disallow Talk:Interwiki:x type titles...
return false;
}
}
} elseif (Interwiki::isValidInterwiki($p)) {
if (!$firstPass) {
# Can't make a local interwiki link to an interwiki link.
# That's just crazy!
return false;
}
# Interwiki link
$dbkey = $m[2];
$this->mInterwiki = $wgContLang->lc($p);
# Redundant interwiki prefix to the local wiki
if ($wgLocalInterwiki !== false && 0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) {
if ($dbkey == '') {
# Can't have an empty self-link
return false;
}
$this->mInterwiki = '';
$firstPass = false;
# Do another namespace split...
continue;
}
# If there's an initial colon after the interwiki, that also
# resets the default namespace
if ($dbkey !== '' && $dbkey[0] == ':') {
$this->mNamespace = NS_MAIN;
$dbkey = substr($dbkey, 1);
}
}
# If there's no recognized interwiki or namespace,
# then let the colon expression be part of the title.
}
break;
} while (true);
# We already know that some pages won't be in the database!
//.........这里部分代码省略.........
示例2: splitTitleString
/**
* Normalizes and splits a title string.
*
* This function removes illegal characters, splits off the interwiki and
* namespace prefixes, sets the other forms, and canonicalizes
* everything.
*
* @todo this method is only exposed as a temporary measure to ease refactoring.
* It was copied with minimal changes from Title::secureAndSplit().
*
* @todo This method should be split up and an appropriate interface
* defined for use by the Title class.
*
* @param string $text
* @param int $defaultNamespace
*
* @throws MalformedTitleException If $text is not a valid title string.
* @return array A mapp with the fields 'interwiki', 'fragment', 'namespace',
* 'user_case_dbkey', and 'dbkey'.
*/
public function splitTitleString($text, $defaultNamespace = NS_MAIN)
{
$dbkey = str_replace(' ', '_', $text);
# Initialisation
$parts = array('interwiki' => '', 'local_interwiki' => false, 'fragment' => '', 'namespace' => $defaultNamespace, 'dbkey' => $dbkey, 'user_case_dbkey' => $dbkey);
# Strip Unicode bidi override characters.
# Sometimes they slip into cut-n-pasted page titles, where the
# override chars get included in list displays.
$dbkey = preg_replace('/\\xE2\\x80[\\x8E\\x8F\\xAA-\\xAE]/S', '', $dbkey);
# Clean up whitespace
# Note: use of the /u option on preg_replace here will cause
# input with invalid UTF-8 sequences to be nullified out in PHP 5.2.x,
# conveniently disabling them.
$dbkey = preg_replace('/[ _\\xA0\\x{1680}\\x{180E}\\x{2000}-\\x{200A}\\x{2028}\\x{2029}\\x{202F}\\x{205F}\\x{3000}]+/u', '_', $dbkey);
$dbkey = trim($dbkey, '_');
if (strpos($dbkey, UtfNormal\Constants::UTF8_REPLACEMENT) !== false) {
# Contained illegal UTF-8 sequences or forbidden Unicode chars.
throw new MalformedTitleException('title-invalid-utf8', $text);
}
$parts['dbkey'] = $dbkey;
# Initial colon indicates main namespace rather than specified default
# but should not create invalid {ns,title} pairs such as {0,Project:Foo}
if ($dbkey !== '' && ':' == $dbkey[0]) {
$parts['namespace'] = NS_MAIN;
$dbkey = substr($dbkey, 1);
# remove the colon but continue processing
$dbkey = trim($dbkey, '_');
# remove any subsequent whitespace
}
if ($dbkey == '') {
throw new MalformedTitleException('title-invalid-empty', $text);
}
# Namespace or interwiki prefix
$prefixRegexp = "/^(.+?)_*:_*(.*)\$/S";
do {
$m = array();
if (preg_match($prefixRegexp, $dbkey, $m)) {
$p = $m[1];
if (($ns = $this->language->getNsIndex($p)) !== false) {
# Ordinary namespace
$dbkey = $m[2];
$parts['namespace'] = $ns;
# For Talk:X pages, check if X has a "namespace" prefix
if ($ns == NS_TALK && preg_match($prefixRegexp, $dbkey, $x)) {
if ($this->language->getNsIndex($x[1])) {
# Disallow Talk:File:x type titles...
throw new MalformedTitleException('title-invalid-talk-namespace', $text);
} elseif (Interwiki::isValidInterwiki($x[1])) {
// TODO: get rid of global state!
# Disallow Talk:Interwiki:x type titles...
throw new MalformedTitleException('title-invalid-talk-namespace', $text);
}
}
} elseif (Interwiki::isValidInterwiki($p)) {
# Interwiki link
$dbkey = $m[2];
$parts['interwiki'] = $this->language->lc($p);
# Redundant interwiki prefix to the local wiki
foreach ($this->localInterwikis as $localIW) {
if (0 == strcasecmp($parts['interwiki'], $localIW)) {
if ($dbkey == '') {
# Empty self-links should point to the Main Page, to ensure
# compatibility with cross-wiki transclusions and the like.
$mainPage = Title::newMainPage();
return array('interwiki' => $mainPage->getInterwiki(), 'local_interwiki' => true, 'fragment' => $mainPage->getFragment(), 'namespace' => $mainPage->getNamespace(), 'dbkey' => $mainPage->getDBkey(), 'user_case_dbkey' => $mainPage->getUserCaseDBKey());
}
$parts['interwiki'] = '';
# local interwikis should behave like initial-colon links
$parts['local_interwiki'] = true;
# Do another namespace split...
continue 2;
}
}
# If there's an initial colon after the interwiki, that also
# resets the default namespace
if ($dbkey !== '' && $dbkey[0] == ':') {
$parts['namespace'] = NS_MAIN;
$dbkey = substr($dbkey, 1);
}
}
//.........这里部分代码省略.........
示例3: 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;
}
示例4: 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');
}
示例5: secureAndSplit
/**
* Secure and split - main initialisation function for this object
*
* Assumes that mDbkeyform has been set, and is urldecoded
* and uses underscores, but not otherwise munged. This function
* removes illegal characters, splits off the interwiki and
* namespace prefixes, sets the other forms, and canonicalizes
* everything.
* @return \type{\bool} true on success
*/
private function secureAndSplit()
{
global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
# Initialisation
static $rxTc = false;
if (!$rxTc) {
# Matching titles will be held as illegal.
$rxTc = '/' . '[^' . Title::legalChars() . ']' . '|%[0-9A-Fa-f]{2}' . '|&[A-Za-z0-9\\x80-\\xff]+;' . '|&#[0-9]+;' . '|&#x[0-9A-Fa-f]+;' . '/S';
}
$this->mInterwiki = $this->mFragment = '';
$this->mNamespace = $this->mDefaultNamespace;
# Usually NS_MAIN
$dbkey = $this->mDbkeyform;
# Strip Unicode bidi override characters.
# Sometimes they slip into cut-n-pasted page titles, where the
# override chars get included in list displays.
$dbkey = preg_replace('/\\xE2\\x80[\\x8E\\x8F\\xAA-\\xAE]/S', '', $dbkey);
# Clean up whitespace
#
$dbkey = preg_replace('/[ _]+/', '_', $dbkey);
$dbkey = trim($dbkey, '_');
if ('' == $dbkey) {
return false;
}
if (false !== strpos($dbkey, UTF8_REPLACEMENT)) {
# Contained illegal UTF-8 sequences or forbidden Unicode chars.
return false;
}
$this->mDbkeyform = $dbkey;
# Initial colon indicates main namespace rather than specified default
# but should not create invalid {ns,title} pairs such as {0,Project:Foo}
if (':' == $dbkey[0]) {
$this->mNamespace = NS_MAIN;
$dbkey = substr($dbkey, 1);
# remove the colon but continue processing
$dbkey = trim($dbkey, '_');
# remove any subsequent whitespace
}
# Namespace or interwiki prefix
$firstPass = true;
do {
$m = array();
if (preg_match("/^(.+?)_*:_*(.*)\$/S", $dbkey, $m)) {
$p = $m[1];
if ($ns = $wgContLang->getNsIndex($p)) {
# Ordinary namespace
$dbkey = $m[2];
$this->mNamespace = $ns;
} elseif (Interwiki::isValidInterwiki($p)) {
if (!$firstPass) {
# Can't make a local interwiki link to an interwiki link.
# That's just crazy!
return false;
}
# Interwiki link
$dbkey = $m[2];
$this->mInterwiki = $wgContLang->lc($p);
# Redundant interwiki prefix to the local wiki
if (0 == strcasecmp($this->mInterwiki, $wgLocalInterwiki)) {
if ($dbkey == '') {
# Can't have an empty self-link
return false;
}
$this->mInterwiki = '';
$firstPass = false;
# Do another namespace split...
continue;
}
# If there's an initial colon after the interwiki, that also
# resets the default namespace
if ($dbkey !== '' && $dbkey[0] == ':') {
$this->mNamespace = NS_MAIN;
$dbkey = substr($dbkey, 1);
}
}
# If there's no recognized interwiki or namespace,
# then let the colon expression be part of the title.
}
break;
} while (true);
# We already know that some pages won't be in the database!
#
if ('' != $this->mInterwiki || NS_SPECIAL == $this->mNamespace) {
$this->mArticleID = 0;
}
$fragment = strstr($dbkey, '#');
if (false !== $fragment) {
$this->setFragment($fragment);
$dbkey = substr($dbkey, 0, strlen($dbkey) - strlen($fragment));
# remove whitespace again: prevents "Foo_bar_#"
//.........这里部分代码省略.........