本文整理汇总了PHP中MWNamespace::getAssociated方法的典型用法代码示例。如果您正苦于以下问题:PHP MWNamespace::getAssociated方法的具体用法?PHP MWNamespace::getAssociated怎么用?PHP MWNamespace::getAssociated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MWNamespace
的用法示例。
在下文中一共展示了MWNamespace::getAssociated方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
function register()
{
global $wgContLang, $wgNamespaceAliases, $wgNonincludableNamespaces;
$lib = array('loadSiteStats' => array($this, 'loadSiteStats'), 'getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'));
$info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
if (!self::$namespacesCache) {
$namespaces = array();
$namespacesByName = array();
foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
$canonical = MWNamespace::getCanonicalName($ns);
$namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !($wgNonincludableNamespaces && in_array($ns, $wgNonincludableNamespaces)), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'aliases' => array());
if ($ns >= NS_MAIN) {
$namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
$namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
$namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
} else {
$namespaces[$ns]['subject'] = $ns;
}
$namespacesByName[strtr($title, ' ', '_')] = $ns;
if ($canonical) {
$namespacesByName[$canonical] = $ns;
}
}
$aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
foreach ($aliases as $title => $ns) {
if (!isset($namespacesByName[$title])) {
$ct = count($namespaces[$ns]['aliases']);
$namespaces[$ns]['aliases'][$ct + 1] = $title;
$namespacesByName[$title] = $ns;
}
}
$namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->text();
self::$namespacesCache = $namespaces;
}
$info['namespaces'] = self::$namespacesCache;
if (self::$siteStatsLoaded) {
$stats = $this->loadSiteStats();
$info['stats'] = $stats[0];
}
$this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
}
示例2: register
function register()
{
global $wgContLang, $wgNamespaceAliases, $wgDisableCounters;
$lib = array('getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'), 'interwikiMap' => array($this, 'interwikiMap'));
$info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
if (!self::$namespacesCache || self::$namespacesCacheLang !== $wgContLang->getCode()) {
$namespaces = array();
$namespacesByName = array();
foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
$canonical = MWNamespace::getCanonicalName($ns);
$namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !MWNamespace::isNonincludable($ns), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'defaultContentModel' => MWNamespace::getNamespaceContentModel($ns), 'aliases' => array());
if ($ns >= NS_MAIN) {
$namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
$namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
$namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
} else {
$namespaces[$ns]['subject'] = $ns;
}
$namespacesByName[strtr($title, ' ', '_')] = $ns;
if ($canonical) {
$namespacesByName[$canonical] = $ns;
}
}
$aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
foreach ($aliases as $title => $ns) {
if (!isset($namespacesByName[$title]) && isset($namespaces[$ns])) {
$ct = count($namespaces[$ns]['aliases']);
$namespaces[$ns]['aliases'][$ct + 1] = $title;
$namespacesByName[$title] = $ns;
}
}
$namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->inContentLanguage()->text();
self::$namespacesCache = $namespaces;
self::$namespacesCacheLang = $wgContLang->getCode();
}
$info['namespaces'] = self::$namespacesCache;
$info['stats'] = array('pages' => (int) SiteStats::pages(), 'articles' => (int) SiteStats::articles(), 'files' => (int) SiteStats::images(), 'edits' => (int) SiteStats::edits(), 'views' => $wgDisableCounters ? null : (int) SiteStats::views(), 'users' => (int) SiteStats::users(), 'activeUsers' => (int) SiteStats::activeUsers(), 'admins' => (int) SiteStats::numberingroup('sysop'));
return $this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
}
示例3: buildMainQueryConds
/**
* Return an array of conditions depending of options set in $opts
*
* @param FormOptions $opts
* @return array
*/
public function buildMainQueryConds(FormOptions $opts)
{
$dbr = $this->getDB();
$user = $this->getUser();
$conds = [];
// It makes no sense to hide both anons and logged-in users. When this occurs, try a guess on
// what the user meant and either show only bots or force anons to be shown.
$botsonly = false;
$hideanons = $opts['hideanons'];
if ($opts['hideanons'] && $opts['hideliu']) {
if ($opts['hidebots']) {
$hideanons = false;
} else {
$botsonly = true;
}
}
// Toggles
if ($opts['hideminor']) {
$conds['rc_minor'] = 0;
}
if ($opts['hidebots']) {
$conds['rc_bot'] = 0;
}
if ($user->useRCPatrol() && $opts['hidepatrolled']) {
$conds['rc_patrolled'] = 0;
}
if ($botsonly) {
$conds['rc_bot'] = 1;
} else {
if ($opts['hideliu']) {
$conds[] = 'rc_user = 0';
}
if ($hideanons) {
$conds[] = 'rc_user != 0';
}
}
if ($opts['hidemyself']) {
if ($user->getId()) {
$conds[] = 'rc_user != ' . $dbr->addQuotes($user->getId());
} else {
$conds[] = 'rc_user_text != ' . $dbr->addQuotes($user->getName());
}
}
if ($this->getConfig()->get('RCWatchCategoryMembership') && $opts['hidecategorization'] === true) {
$conds[] = 'rc_type != ' . $dbr->addQuotes(RC_CATEGORIZE);
}
// Namespace filtering
if ($opts['namespace'] !== '') {
$selectedNS = $dbr->addQuotes($opts['namespace']);
$operator = $opts['invert'] ? '!=' : '=';
$boolean = $opts['invert'] ? 'AND' : 'OR';
// Namespace association (bug 2429)
if (!$opts['associated']) {
$condition = "rc_namespace {$operator} {$selectedNS}";
} else {
// Also add the associated namespace
$associatedNS = $dbr->addQuotes(MWNamespace::getAssociated($opts['namespace']));
$condition = "(rc_namespace {$operator} {$selectedNS} " . $boolean . " rc_namespace {$operator} {$associatedNS})";
}
$conds[] = $condition;
}
return $conds;
}
示例4: buildMainQueryConds
/**
* Return an array of conditions depending of options set in $opts
*
* @param FormOptions $opts
* @return array
*/
public function buildMainQueryConds(FormOptions $opts)
{
$dbr = wfGetDB(DB_SLAVE);
$conds = array();
# It makes no sense to hide both anons and logged-in users
# Where this occurs, force anons to be shown
$forcebot = false;
if ($opts['hideanons'] && $opts['hideliu']) {
# Check if the user wants to show bots only
if ($opts['hidebots']) {
$opts['hideanons'] = false;
} else {
$forcebot = true;
$opts['hidebots'] = false;
}
}
// Calculate cutoff
$cutoff_unixtime = time() - $opts['days'] * 86400;
$cutoff_unixtime = $cutoff_unixtime - $cutoff_unixtime % 86400;
$cutoff = $dbr->timestamp($cutoff_unixtime);
$fromValid = preg_match('/^[0-9]{14}$/', $opts['from']);
if ($fromValid && $opts['from'] > wfTimestamp(TS_MW, $cutoff)) {
$cutoff = $dbr->timestamp($opts['from']);
} else {
$opts->reset('from');
}
$conds[] = 'rc_timestamp >= ' . $dbr->addQuotes($cutoff);
$hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
$hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
$hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
if ($opts['hideminor']) {
$conds['rc_minor'] = 0;
}
if ($opts['hidebots']) {
$conds['rc_bot'] = 0;
}
if ($hidePatrol) {
$conds['rc_patrolled'] = 0;
}
if ($forcebot) {
$conds['rc_bot'] = 1;
}
if ($hideLoggedInUsers) {
$conds[] = 'rc_user = 0';
}
if ($hideAnonymousUsers) {
$conds[] = 'rc_user != 0';
}
if ($opts['hidemyself']) {
if ($this->getUser()->getId()) {
$conds[] = 'rc_user != ' . $dbr->addQuotes($this->getUser()->getId());
} else {
$conds[] = 'rc_user_text != ' . $dbr->addQuotes($this->getUser()->getName());
}
}
# Namespace filtering
if ($opts['namespace'] !== '') {
$selectedNS = $dbr->addQuotes($opts['namespace']);
$operator = $opts['invert'] ? '!=' : '=';
$boolean = $opts['invert'] ? 'AND' : 'OR';
# namespace association (bug 2429)
if (!$opts['associated']) {
$condition = "rc_namespace {$operator} {$selectedNS}";
} else {
# Also add the associated namespace
$associatedNS = $dbr->addQuotes(MWNamespace::getAssociated($opts['namespace']));
$condition = "(rc_namespace {$operator} {$selectedNS} " . $boolean . " rc_namespace {$operator} {$associatedNS})";
}
$conds[] = $condition;
}
return $conds;
}
示例5: getNamespaceCond
function getNamespaceCond()
{
if ($this->namespace !== '') {
$selectedNS = $this->mDb->addQuotes($this->namespace);
$eq_op = $this->nsInvert ? '!=' : '=';
$bool_op = $this->nsInvert ? 'AND' : 'OR';
if (!$this->associated) {
return array("page_namespace {$eq_op} {$selectedNS}");
} else {
$associatedNS = $this->mDb->addQuotes(MWNamespace::getAssociated($this->namespace));
return array("page_namespace {$eq_op} {$selectedNS} " . $bool_op . " page_namespace {$eq_op} {$associatedNS}");
}
} else {
return array();
}
}
示例6: testGetAssociatedExceptionsForNsSpecial
/**
* @expectedException MWException
*/
public function testGetAssociatedExceptionsForNsSpecial()
{
$this->assertNull(MWNamespace::getAssociated(NS_SPECIAL));
}
示例7: execute
//.........这里部分代码省略.........
);
$this->customFilters = array();
wfRunHooks( 'SpecialWatchlistFilters', array( $this, &$this->customFilters ) );
foreach ( $this->customFilters as $key => $params ) {
$defaults[$key] = $params['default'];
}
# Extract variables from the request, falling back to user preferences or
# other default values if these don't exist
$values = array();
$values['days'] = floatval( $request->getVal( 'days', $defaults['days'] ) );
$values['hideMinor'] = (int)$request->getBool( 'hideMinor', $defaults['hideMinor'] );
$values['hideBots'] = (int)$request->getBool( 'hideBots', $defaults['hideBots'] );
$values['hideAnons'] = (int)$request->getBool( 'hideAnons', $defaults['hideAnons'] );
$values['hideLiu'] = (int)$request->getBool( 'hideLiu', $defaults['hideLiu'] );
$values['hideOwn'] = (int)$request->getBool( 'hideOwn', $defaults['hideOwn'] );
$values['hidePatrolled'] = (int)$request->getBool( 'hidePatrolled', $defaults['hidePatrolled'] );
$values['extended'] = (int)$request->getBool( 'extended', $defaults['extended'] );
foreach ( $this->customFilters as $key => $params ) {
$values[$key] = (int)$request->getBool( $key, $defaults[$key] );
}
# Get namespace value, if supplied, and prepare a WHERE fragment
$nameSpace = $request->getIntOrNull( 'namespace' );
$invert = $request->getBool( 'invert' );
$associated = $request->getBool( 'associated' );
if ( !is_null( $nameSpace ) ) {
$eq_op = $invert ? '!=' : '=';
$bool_op = $invert ? 'AND' : 'OR';
$nameSpace = intval( $nameSpace ); // paranioa
if ( !$associated ) {
$nameSpaceClause = "rc_namespace $eq_op $nameSpace";
} else {
$associatedNS = MWNamespace::getAssociated( $nameSpace );
$nameSpaceClause =
"rc_namespace $eq_op $nameSpace " .
$bool_op .
" rc_namespace $eq_op $associatedNS";
}
} else {
$nameSpace = '';
$nameSpaceClause = '';
}
$values['namespace'] = $nameSpace;
$values['invert'] = $invert;
$values['associated'] = $associated;
// Dump everything here
$nondefaults = array();
foreach ( $defaults as $name => $defValue ) {
wfAppendToArrayIfNotDefault( $name, $values[$name], $defaults, $nondefaults );
}
if ( ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) && $request->getVal( 'reset' ) &&
$request->wasPosted() )
{
$user->clearAllNotifications();
$output->redirect( $this->getTitle()->getFullURL( $nondefaults ) );
return;
}
# Possible where conditions
$conds = array();
if ( $values['days'] > 0 ) {
$conds[] = 'rc_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( time() - intval( $values['days'] * 86400 ) ) );
示例8: onUnwatchArticleComplete
/**
* Handles removed watched articles to the global watch list.
*
* @access public
* @param object User object of the user who unwatched this page.
* @param object Article object of the unwatched page.
* @return boolean True
*/
public static function onUnwatchArticleComplete(User $user, WikiPage $article)
{
if (!$article->mDataLoaded) {
$article->loadPageData();
}
$curseUser = \CurseAuthUser::getInstance($user);
if (!$curseUser->getId() || $article->mTitle->mArticleID < 1) {
return true;
}
//The newFromUser function will check if the user is valid. False will be return if not.
$gwl = globalWatchlist::newFromUser($user);
if ($gwl !== false && $gwl->removeArticle($article) === true) {
//If removing the specific page the user requested to unwatch was successful then we need to remove the associated namespace page.
$title = Title::newFromText($article->mTitle->getText(), MWNamespace::getAssociated($article->mTitle->mNamespace));
$associated = new WikiPage($title);
if (!$associated->mDataLoaded) {
$associated->loadPageData();
}
$gwl->removeArticle($associated);
//Save since at least the requested page to unwatch was successful lets save it. If the $associated page is not removed successfully we do not want it to stop the process.
$success = $gwl->save();
}
return true;
}
示例9: execute
/**
* Execute
* @param $par Parameter passed to the page
*/
function execute($par)
{
global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
$user = $this->getUser();
$output = $this->getOutput();
# Anons don't get a watchlist
if ($user->isAnon()) {
$output->setPageTitle($this->msg('watchnologin'));
$output->setRobotPolicy('noindex,nofollow');
$llink = Linker::linkKnown(SpecialPage::getTitleFor('Userlogin'), $this->msg('loginreqlink')->escaped(), array(), array('returnto' => $this->getTitle()->getPrefixedText()));
$output->addHTML($this->msg('watchlistanontext')->rawParams($llink)->parse());
return;
}
// Add feed links
$wlToken = $user->getOption('watchlisttoken');
if (!$wlToken) {
$wlToken = MWCryptRand::generateHex(40);
$user->setOption('watchlisttoken', $wlToken);
$user->saveSettings();
}
$this->addFeedLinks(array('action' => 'feedwatchlist', 'allrev' => 'allrev', 'wlowner' => $user->getName(), 'wltoken' => $wlToken));
$this->setHeaders();
$this->outputHeader();
$output->addSubtitle($this->msg('watchlistfor2', $user->getName())->rawParams(SpecialEditWatchlist::buildTools(null)));
$request = $this->getRequest();
$mode = SpecialEditWatchlist::getMode($request, $par);
if ($mode !== false) {
# TODO: localise?
switch ($mode) {
case SpecialEditWatchlist::EDIT_CLEAR:
$mode = 'clear';
break;
case SpecialEditWatchlist::EDIT_RAW:
$mode = 'raw';
break;
default:
$mode = null;
}
$title = SpecialPage::getTitleFor('EditWatchlist', $mode);
$output->redirect($title->getLocalUrl());
return;
}
$nitems = $this->countItems();
if ($nitems == 0) {
$output->addWikiMsg('nowatchlist');
return;
}
// @TODO: use FormOptions!
$defaults = array('days' => floatval($user->getOption('watchlistdays')), 'hideMinor' => (int) $user->getBoolOption('watchlisthideminor'), 'hideBots' => (int) $user->getBoolOption('watchlisthidebots'), 'hideAnons' => (int) $user->getBoolOption('watchlisthideanons'), 'hideLiu' => (int) $user->getBoolOption('watchlisthideliu'), 'hidePatrolled' => (int) $user->getBoolOption('watchlisthidepatrolled'), 'hideOwn' => (int) $user->getBoolOption('watchlisthideown'), 'namespace' => 'all', 'invert' => false, 'associated' => false);
$this->customFilters = array();
wfRunHooks('SpecialWatchlistFilters', array($this, &$this->customFilters));
foreach ($this->customFilters as $key => $params) {
$defaults[$key] = $params['msg'];
}
# Extract variables from the request, falling back to user preferences or
# other default values if these don't exist
$prefs['days'] = floatval($user->getOption('watchlistdays'));
$prefs['hideminor'] = $user->getBoolOption('watchlisthideminor');
$prefs['hidebots'] = $user->getBoolOption('watchlisthidebots');
$prefs['hideanons'] = $user->getBoolOption('watchlisthideanons');
$prefs['hideliu'] = $user->getBoolOption('watchlisthideliu');
$prefs['hideown'] = $user->getBoolOption('watchlisthideown');
$prefs['hidepatrolled'] = $user->getBoolOption('watchlisthidepatrolled');
# Get query variables
$values = array();
$values['days'] = $request->getVal('days', $prefs['days']);
$values['hideMinor'] = (int) $request->getBool('hideMinor', $prefs['hideminor']);
$values['hideBots'] = (int) $request->getBool('hideBots', $prefs['hidebots']);
$values['hideAnons'] = (int) $request->getBool('hideAnons', $prefs['hideanons']);
$values['hideLiu'] = (int) $request->getBool('hideLiu', $prefs['hideliu']);
$values['hideOwn'] = (int) $request->getBool('hideOwn', $prefs['hideown']);
$values['hidePatrolled'] = (int) $request->getBool('hidePatrolled', $prefs['hidepatrolled']);
foreach ($this->customFilters as $key => $params) {
$values[$key] = (int) $request->getBool($key);
}
# Get namespace value, if supplied, and prepare a WHERE fragment
$nameSpace = $request->getIntOrNull('namespace');
$invert = $request->getBool('invert');
$associated = $request->getBool('associated');
if (!is_null($nameSpace)) {
$eq_op = $invert ? '!=' : '=';
$bool_op = $invert ? 'AND' : 'OR';
$nameSpace = intval($nameSpace);
// paranioa
if (!$associated) {
$nameSpaceClause = "rc_namespace {$eq_op} {$nameSpace}";
} else {
$associatedNS = MWNamespace::getAssociated($nameSpace);
$nameSpaceClause = "rc_namespace {$eq_op} {$nameSpace} " . $bool_op . " rc_namespace {$eq_op} {$associatedNS}";
}
} else {
$nameSpace = '';
$nameSpaceClause = '';
}
$values['namespace'] = $nameSpace;
$values['invert'] = $invert;
//.........这里部分代码省略.........