本文整理汇总了PHP中Interwiki::getAllPrefixes方法的典型用法代码示例。如果您正苦于以下问题:PHP Interwiki::getAllPrefixes方法的具体用法?PHP Interwiki::getAllPrefixes怎么用?PHP Interwiki::getAllPrefixes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interwiki
的用法示例。
在下文中一共展示了Interwiki::getAllPrefixes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wfGlobalInterwikis
function wfGlobalInterwikis($prefix, &$iwData)
{
global $wgInterwikiCentralDB;
// docs/hooks.txt says: Return true without providing an interwiki to continue interwiki search.
if ($wgInterwikiCentralDB === null || $wgInterwikiCentralDB === wfWikiId()) {
// No global set or this is global, nothing to add
return true;
}
if (!Language::fetchLanguageName($prefix)) {
// Check if prefix exists locally and skip
foreach (Interwiki::getAllPrefixes(null) as $id => $localPrefixInfo) {
if ($prefix === $localPrefixInfo['iw_prefix']) {
return true;
}
}
$dbr = wfGetDB(DB_SLAVE, array(), $wgInterwikiCentralDB);
$res = $dbr->selectRow('interwiki', '*', array('iw_prefix' => $prefix), __METHOD__);
if (!$res) {
return true;
}
// Excplicitly make this an array since it's expected to be one
$iwData = (array) $res;
// At this point, we can safely return false because we know that we have something
return false;
}
return true;
}
示例2: getSiteSelector
/**
* Get a list of languages available for this project
* @return string parsed Html
*/
private function getSiteSelector()
{
$selector = '';
$count = 0;
$language = $this->getLanguage();
foreach (Interwiki::getAllPrefixes(true) as $interwiki) {
$code = $interwiki['iw_prefix'];
$name = $language->fetchLanguageName($code);
if (!$name) {
continue;
}
$title = Title::newFromText("{$code}:");
if ($title) {
$url = $title->getFullURL();
} else {
$url = '';
}
$attrs = array('href' => $url);
$count++;
if ($code == $this->getConfig()->get('LanguageCode')) {
$attrs['class'] = 'selected';
}
$selector .= Html::openElement('li');
$selector .= Html::element('a', $attrs, $name);
$selector .= Html::closeElement('li');
}
if ($selector && $count > 1) {
$selector = <<<HTML
\t\t\t<p>{$this->msg('mobile-frontend-settings-site-description', $count)->parse()}</p>
\t\t\t<ul id='mw-mf-language-list'>
\t\t\t\t{$selector}
\t\t\t</ul>
HTML;
}
return $selector;
}
示例3: appendInterwikiMap
protected function appendInterwikiMap($property, $filter)
{
$local = null;
if ($filter === 'local') {
$local = 1;
} elseif ($filter === '!local') {
$local = 0;
} elseif ($filter) {
ApiBase::dieDebug(__METHOD__, "Unknown filter={$filter}");
}
$params = $this->extractRequestParams();
$langCode = isset($params['inlanguagecode']) ? $params['inlanguagecode'] : '';
if ($langCode) {
$langNames = Language::getTranslatedLanguageNames($langCode);
} else {
$langNames = Language::getLanguageNames();
}
$getPrefixes = Interwiki::getAllPrefixes($local);
$data = array();
foreach ($getPrefixes as $row) {
$prefix = $row['iw_prefix'];
$val = array();
$val['prefix'] = $prefix;
if ($row['iw_local'] == '1') {
$val['local'] = '';
}
// $val['trans'] = intval( $row['iw_trans'] ); // should this be exposed?
if (isset($langNames[$prefix])) {
$val['language'] = $langNames[$prefix];
}
$val['url'] = wfExpandUrl($row['iw_url'], PROTO_CURRENT);
if (isset($row['iw_wikiid'])) {
$val['wikiid'] = $row['iw_wikiid'];
}
if (isset($row['iw_api'])) {
$val['api'] = $row['iw_api'];
}
$data[] = $val;
}
$this->getResult()->setIndexedTagName($data, 'iw');
return $this->getResult()->addValue('query', $property, $data);
}
示例4: showList
function showList()
{
$canModify = $this->canModify();
$this->getOutput()->addWikiMsg('interwiki_intro');
$this->getOutput()->addHTML(Html::rawElement('table', array('class' => 'mw-interwikitable wikitable intro'), self::addInfoRow('start', 'interwiki_prefix', 'interwiki_prefix_intro') . self::addInfoRow('start', 'interwiki_url', 'interwiki_url_intro') . self::addInfoRow('start', 'interwiki_local', 'interwiki_local_intro') . self::addInfoRow('end', 'interwiki_0', 'interwiki_local_0_intro') . self::addInfoRow('end', 'interwiki_1', 'interwiki_local_1_intro') . self::addInfoRow('start', 'interwiki_trans', 'interwiki_trans_intro') . self::addInfoRow('end', 'interwiki_0', 'interwiki_trans_0_intro') . self::addInfoRow('end', 'interwiki_1', 'interwiki_trans_1_intro')) . "\n");
$this->getOutput()->addWikiMsg('interwiki_intro_footer');
if ($canModify) {
$addtext = wfMessage('interwiki_addtext')->escaped();
$addlink = Linker::linkKnown($this->getTitle('add'), $addtext);
$this->getOutput()->addHTML('<p class="mw-interwiki-addlink">' . $addlink . '</p>');
}
if (!method_exists('Interwiki', 'getAllPrefixes')) {
# version 2.0 is not backwards compatible (but still display nice error)
$this->error('interwiki_error');
return;
}
$iwPrefixes = Interwiki::getAllPrefixes(null);
if (!is_array($iwPrefixes) || count($iwPrefixes) == 0) {
# If the interwiki table is empty, display an error message
$this->error('interwiki_error');
return;
}
$out = '';
# Output the table header
$out .= Html::openElement('table', array('class' => 'mw-interwikitable wikitable sortable body')) . "\n";
$out .= Html::openElement('tr', array('id' => 'interwikitable-header')) . Html::element('th', null, wfMessage('interwiki_prefix')) . Html::element('th', null, wfMessage('interwiki_url')) . Html::element('th', null, wfMessage('interwiki_local')) . Html::element('th', null, wfMessage('interwiki_trans')) . ($canModify ? Html::element('th', array('class' => 'unsortable'), wfMessage('interwiki_edit')) : '');
$out .= Html::closeElement('tr') . "\n";
$selfTitle = $this->getTitle();
foreach ($iwPrefixes as $i => $iwPrefix) {
$out .= Html::openElement('tr', array('class' => 'mw-interwikitable-row'));
$out .= Html::element('td', array('class' => 'mw-interwikitable-prefix'), htmlspecialchars($iwPrefix['iw_prefix']));
$out .= Html::element('td', array('class' => 'mw-interwikitable-url'), $iwPrefix['iw_url']);
$out .= Html::element('td', array('class' => 'mw-interwikitable-local'), isset($iwPrefix['iw_local']) ? wfMessage('interwiki_' . $iwPrefix['iw_local']) : '-');
$out .= Html::element('td', array('class' => 'mw-interwikitable-trans'), isset($iwPrefix['iw_trans']) ? wfMessage('interwiki_' . $iwPrefix['iw_trans']) : '-');
if ($canModify) {
$out .= Html::rawElement('td', array('class' => 'mw-interwikitable-modify'), Linker::linkKnown($selfTitle, wfMessage('edit')->escaped(), array(), array('action' => 'edit', 'prefix' => $iwPrefix['iw_prefix'])) . wfMessage('comma-separator') . Linker::linkKnown($selfTitle, wfMessage('delete')->escaped(), array(), array('action' => 'delete', 'prefix' => $iwPrefix['iw_prefix'])));
}
$out .= Html::closeElement('tr') . "\n";
}
$out .= Html::closeElement('table');
$this->getOutput()->addHTML($out);
}
示例5: showList
function showList()
{
global $wgInterwikiCentralDB, $wgInterwikiViewOnly;
$canModify = $this->canModify();
// Build lists
if (!method_exists('Interwiki', 'getAllPrefixes')) {
// version 2.0 is not backwards compatible (but will still display a nice error)
$this->error('interwiki_error');
return;
}
$iwPrefixes = Interwiki::getAllPrefixes(null);
$iwGlobalPrefixes = array();
if ($wgInterwikiCentralDB !== null && $wgInterwikiCentralDB !== wfWikiId()) {
// Fetch list from global table
$dbrCentralDB = wfGetDB(DB_SLAVE, array(), $wgInterwikiCentralDB);
$res = $dbrCentralDB->select('interwiki', '*', false, __METHOD__);
$retval = array();
foreach ($res as $row) {
$row = (array) $row;
if (!Language::fetchLanguageName($row['iw_prefix'])) {
$retval[] = $row;
}
}
$iwGlobalPrefixes = $retval;
}
// Split out language links
$iwLocalPrefixes = array();
$iwLanguagePrefixes = array();
foreach ($iwPrefixes as $iwPrefix) {
if (Language::fetchLanguageName($iwPrefix['iw_prefix'])) {
$iwLanguagePrefixes[] = $iwPrefix;
} else {
$iwLocalPrefixes[] = $iwPrefix;
}
}
// Page intro content
$this->getOutput()->addWikiMsg('interwiki_intro');
// Add 'view log' link when possible
if ($wgInterwikiViewOnly === false) {
$logLink = Linker::link(SpecialPage::getTitleFor('Log', 'interwiki'), $this->msg('interwiki-logtext')->escaped());
$this->getOutput()->addHTML('<p class="mw-interwiki-log">' . $logLink . '</p>');
}
// Add 'add' link
if ($canModify) {
if (count($iwGlobalPrefixes) !== 0) {
$addtext = $this->msg('interwiki-addtext-local')->escaped();
} else {
$addtext = $this->msg('interwiki_addtext')->escaped();
}
$addlink = Linker::linkKnown($this->getPageTitle('add'), $addtext);
$this->getOutput()->addHTML('<p class="mw-interwiki-addlink">' . $addlink . '</p>');
}
$this->getOutput()->addWikiMsg('interwiki-legend');
if (!is_array($iwPrefixes) || count($iwPrefixes) === 0) {
if (!is_array($iwGlobalPrefixes) || count($iwGlobalPrefixes) === 0) {
// If the interwiki table(s) are empty, display an error message
$this->error('interwiki_error');
return;
}
}
// Add the global table
if (count($iwGlobalPrefixes) !== 0) {
$this->getOutput()->addHTML('<h2 id="interwikitable-global">' . $this->msg('interwiki-global-links')->parse() . '</h2>');
$this->getOutput()->addWikiMsg('interwiki-global-description');
// $canModify is false here because this is just a display of remote data
$this->makeTable(false, $iwGlobalPrefixes);
}
// Add the local table
if (count($iwLocalPrefixes) !== 0) {
if (count($iwGlobalPrefixes) !== 0) {
$this->getOutput()->addHTML('<h2 id="interwikitable-local">' . $this->msg('interwiki-local-links')->parse() . '</h2>');
$this->getOutput()->addWikiMsg('interwiki-local-description');
} else {
$this->getOutput()->addHTML('<h2 id="interwikitable-local">' . $this->msg('interwiki-links')->parse() . '</h2>');
$this->getOutput()->addWikiMsg('interwiki-description');
}
$this->makeTable($canModify, $iwLocalPrefixes);
}
// Add the language table
if (count($iwLanguagePrefixes) !== 0) {
$this->getOutput()->addHTML('<h2 id="interwikitable-language">' . $this->msg('interwiki-language-links')->parse() . '</h2>');
$this->getOutput()->addWikiMsg('interwiki-language-description');
$this->makeTable($canModify, $iwLanguagePrefixes);
}
}
示例6: appendInterwikiMap
protected function appendInterwikiMap($property, $filter)
{
$local = null;
if ($filter === 'local') {
$local = 1;
} elseif ($filter === '!local') {
$local = 0;
} elseif ($filter) {
ApiBase::dieDebug(__METHOD__, "Unknown filter={$filter}");
}
$params = $this->extractRequestParams();
$langCode = isset($params['inlanguagecode']) ? $params['inlanguagecode'] : '';
$langNames = Language::fetchLanguageNames($langCode);
$getPrefixes = Interwiki::getAllPrefixes($local);
$extraLangPrefixes = $this->getConfig()->get('ExtraInterlanguageLinkPrefixes');
$localInterwikis = $this->getConfig()->get('LocalInterwikis');
$data = array();
foreach ($getPrefixes as $row) {
$prefix = $row['iw_prefix'];
$val = array();
$val['prefix'] = $prefix;
if (isset($row['iw_local']) && $row['iw_local'] == '1') {
$val['local'] = '';
}
if ($row['iw_trans'] == '1') {
$val['trans'] = '';
}
if (isset($langNames[$prefix])) {
$val['language'] = $langNames[$prefix];
}
if (in_array($prefix, $localInterwikis)) {
$val['localinterwiki'] = '';
}
if (in_array($prefix, $extraLangPrefixes)) {
$val['extralanglink'] = '';
$linktext = wfMessage("interlanguage-link-{$prefix}");
if (!$linktext->isDisabled()) {
$val['linktext'] = $linktext->text();
}
$sitename = wfMessage("interlanguage-link-sitename-{$prefix}");
if (!$sitename->isDisabled()) {
$val['sitename'] = $sitename->text();
}
}
$val['url'] = wfExpandUrl($row['iw_url'], PROTO_CURRENT);
if (substr($row['iw_url'], 0, 2) == '//') {
$val['protorel'] = '';
}
if (isset($row['iw_wikiid'])) {
$val['wikiid'] = $row['iw_wikiid'];
}
if (isset($row['iw_api'])) {
$val['api'] = $row['iw_api'];
}
$data[] = $val;
}
$this->getResult()->setIndexedTagName($data, 'iw');
return $this->getResult()->addValue('query', $property, $data);
}
示例7: getInterwikiList
/**
* Get the interwiki list
*
* @return array
*/
private function getInterwikiList()
{
$result = Interwiki::getAllPrefixes();
$prefixes = array();
foreach ($result as $row) {
$prefixes[] = $row['iw_prefix'];
}
return $prefixes;
}
示例8: showList
function showList()
{
$canModify = $this->canModify();
$this->getOutput()->addWikiMsg('interwiki_intro');
// Make collapsible.
$this->getOutput()->addHTML(Html::openElement('div', array('class' => 'mw-collapsible mw-collapsed', 'data-collapsetext' => $this->msg('interwiki-legend-hide')->escaped(), 'data-expandtext' => $this->msg('interwiki-legend-show')->escaped())));
$this->getOutput()->addHTML(Html::rawElement('table', array('class' => 'mw-interwikitable wikitable intro'), $this->addInfoRow('start', 'interwiki_prefix', 'interwiki_prefix_intro') . "\n" . $this->addInfoRow('start', 'interwiki_url', 'interwiki_url_intro') . "\n" . $this->addInfoRow('start', 'interwiki_local', 'interwiki_local_intro') . "\n" . $this->addInfoRow('end', 'interwiki_0', 'interwiki_local_0_intro') . "\n" . $this->addInfoRow('end', 'interwiki_1', 'interwiki_local_1_intro') . "\n" . $this->addInfoRow('start', 'interwiki_trans', 'interwiki_trans_intro') . "\n" . $this->addInfoRow('end', 'interwiki_0', 'interwiki_trans_0_intro') . "\n" . $this->addInfoRow('end', 'interwiki_1', 'interwiki_trans_1_intro') . "\n"));
$this->getOutput()->addHTML(Html::closeElement('div'));
// end collapsible.
if ($canModify) {
$this->getOutput()->addHTML("<br />" . $this->msg('interwiki_intro_footer')->parse());
$addtext = $this->msg('interwiki_addtext')->escaped();
$addlink = Linker::linkKnown($this->getTitle('add'), $addtext);
$this->getOutput()->addHTML('<p class="mw-interwiki-addlink">' . $addlink . '</p>');
}
if (!method_exists('Interwiki', 'getAllPrefixes')) {
# version 2.0 is not backwards compatible (but still display nice error)
$this->error('interwiki_error');
return;
}
$iwPrefixes = Interwiki::getAllPrefixes(null);
if (!is_array($iwPrefixes) || count($iwPrefixes) === 0) {
# If the interwiki table is empty, display an error message
$this->error('interwiki_error');
return;
}
# Output the existing Interwiki prefixes table header
$out = '';
$out .= Html::openElement('table', array('class' => 'mw-interwikitable wikitable sortable body')) . "\n";
$out .= Html::openElement('tr', array('id' => 'interwikitable-header')) . Html::element('th', null, $this->msg('interwiki_prefix')->text()) . Html::element('th', null, $this->msg('interwiki_url')->text()) . Html::element('th', null, $this->msg('interwiki_local')->text()) . Html::element('th', null, $this->msg('interwiki_trans')->text()) . ($canModify ? Html::element('th', array('class' => 'unsortable'), $this->msg('interwiki_edit')->text()) : '');
$out .= Html::closeElement('tr') . "\n";
$selfTitle = $this->getTitle();
# Output the existing Interwiki prefixes table rows
foreach ($iwPrefixes as $iwPrefix) {
$out .= Html::openElement('tr', array('class' => 'mw-interwikitable-row'));
$out .= Html::element('td', array('class' => 'mw-interwikitable-prefix'), $iwPrefix['iw_prefix']);
$out .= Html::element('td', array('class' => 'mw-interwikitable-url'), $iwPrefix['iw_url']);
$attribs = array('class' => 'mw-interwikitable-local');
// Green background for cells with "yes".
if ($iwPrefix['iw_local']) {
$attribs['style'] = 'background: lime;';
}
// The messages interwiki_0 and interwiki_1 are used here.
$contents = isset($iwPrefix['iw_local']) ? $this->msg('interwiki_' . $iwPrefix['iw_local'])->text() : '-';
$out .= Html::element('td', $attribs, $contents);
$attribs = array('class' => 'mw-interwikitable-trans');
// Green background for cells with "yes".
if ($iwPrefix['iw_trans']) {
$attribs['style'] = 'background: lime;';
}
// The messages interwiki_0 and interwiki_1 are used here.
$contents = isset($iwPrefix['iw_trans']) ? $this->msg('interwiki_' . $iwPrefix['iw_trans'])->text() : '-';
$out .= Html::element('td', $attribs, $contents);
// Additional column when the interwiki table can be modified.
if ($canModify) {
$out .= Html::rawElement('td', array('class' => 'mw-interwikitable-modify'), Linker::linkKnown($selfTitle, $this->msg('edit')->escaped(), array(), array('action' => 'edit', 'prefix' => $iwPrefix['iw_prefix'])) . $this->msg('comma-separator') . Linker::linkKnown($selfTitle, $this->msg('delete')->escaped(), array(), array('action' => 'delete', 'prefix' => $iwPrefix['iw_prefix'])));
}
$out .= Html::closeElement('tr') . "\n";
}
$out .= Html::closeElement('table');
$this->getOutput()->addHTML($out);
}
示例9: 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');
}
示例10: interwikiMap
public function interwikiMap($filter = null)
{
global $wgLocalInterwikis, $wgExtraInterlanguageLinkPrefixes;
$this->checkTypeOptional('interwikiMap', 1, $filter, 'string', null);
$local = null;
if ($filter === 'local') {
$local = 1;
} elseif ($filter === '!local') {
$local = 0;
} elseif ($filter !== null) {
throw new Scribunto_LuaError("bad argument #1 to 'interwikiMap' (unknown filter '{$filter}')");
}
$cacheKey = $filter === null ? 'null' : $filter;
if (!isset(self::$interwikiMapCache[$cacheKey])) {
// Not expensive because we can have a max of three cache misses in the
// entire page parse.
$interwikiMap = array();
$prefixes = Interwiki::getAllPrefixes($local);
foreach ($prefixes as $row) {
$prefix = $row['iw_prefix'];
$val = array('prefix' => $prefix, 'url' => wfExpandUrl($row['iw_url'], PROTO_RELATIVE), 'isProtocolRelative' => substr($row['iw_url'], 0, 2) === '//', 'isLocal' => isset($row['iw_local']) && $row['iw_local'] == '1', 'isTranscludable' => isset($row['iw_trans']) && $row['iw_trans'] == '1', 'isCurrentWiki' => in_array($prefix, $wgLocalInterwikis), 'isExtraLanguageLink' => in_array($prefix, $wgExtraInterlanguageLinkPrefixes));
if ($val['isExtraLanguageLink']) {
$displayText = wfMessage("interlanguage-link-{$prefix}");
if (!$displayText->isDisabled()) {
$val['displayText'] = $displayText->text();
}
$tooltip = wfMessage("interlanguage-link-sitename-{$prefix}");
if (!$tooltip->isDisabled()) {
$val['tooltip'] = $tooltip->text();
}
}
$interwikiMap[$prefix] = $val;
}
self::$interwikiMapCache[$cacheKey] = $interwikiMap;
}
return array(self::$interwikiMapCache[$cacheKey]);
}