本文整理汇总了PHP中MWNamespace::hasGenderDistinction方法的典型用法代码示例。如果您正苦于以下问题:PHP MWNamespace::hasGenderDistinction方法的具体用法?PHP MWNamespace::hasGenderDistinction怎么用?PHP MWNamespace::hasGenderDistinction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MWNamespace
的用法示例。
在下文中一共展示了MWNamespace::hasGenderDistinction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNamespaceName
/**
* @see TitleFormatter::getNamespaceName()
*
* @param int $namespace
* @param string $text
*
* @throws InvalidArgumentException If the namespace is invalid
* @return string
*/
public function getNamespaceName($namespace, $text)
{
if ($this->language->needsGenderDistinction() && MWNamespace::hasGenderDistinction($namespace)) {
// NOTE: we are assuming here that the title text is a user name!
$gender = $this->genderCache->getGenderOf($text, __METHOD__);
$name = $this->language->getGenderNsText($namespace, $gender);
} else {
$name = $this->language->getNsText($namespace);
}
if ($name === false) {
throw new InvalidArgumentException('Unknown namespace ID: ' . $namespace);
}
return $name;
}
示例2: doLinkBatch
/**
* Wrapper for doQuery that processes raw LinkBatch data.
*
* @param $data
* @param $caller
*/
public function doLinkBatch($data, $caller = '')
{
$users = array();
foreach ($data as $ns => $pagenames) {
if (!MWNamespace::hasGenderDistinction($ns)) {
continue;
}
foreach (array_keys($pagenames) as $username) {
if (isset($this->cache[$username])) {
continue;
}
$users[$username] = true;
}
}
$this->doQuery(array_keys($users), $caller);
}
示例3: 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);
}
示例4: 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);
}
示例5: doTitlesArray
/**
* Wrapper for doQuery that processes a title or string array.
*
* @since 1.20
* @param $titles List: array of Title objects or strings
* @param $caller String: the calling method
*/
public function doTitlesArray($titles, $caller = '')
{
$users = array();
foreach ($titles as $title) {
$titleObj = is_string($title) ? Title::newFromText($title) : $title;
if (!$titleObj) {
continue;
}
if (!MWNamespace::hasGenderDistinction($titleObj->getNamespace())) {
continue;
}
$users[] = $titleObj->getText();
}
$this->doQuery($users, $caller);
}
示例6: getNsText
/**
* Get the namespace text
*
* @return String: Namespace text
*/
public function getNsText()
{
global $wgContLang;
if ($this->mInterwiki != '') {
// This probably shouldn't even happen. ohh man, oh yuck.
// But for interwiki transclusion it sometimes does.
// Shit. Shit shit shit.
//
// Use the canonical namespaces if possible to try to
// resolve a foreign namespace.
if (MWNamespace::exists($this->mNamespace)) {
return MWNamespace::getCanonicalName($this->mNamespace);
}
}
// Strip off subpages
$pagename = $this->getText();
if (strpos($pagename, '/') !== false) {
list($username, ) = explode('/', $pagename, 2);
} else {
$username = $pagename;
}
if ($wgContLang->needsGenderDistinction() && MWNamespace::hasGenderDistinction($this->mNamespace)) {
$gender = GenderCache::singleton()->getGenderOf($username, __METHOD__);
return $wgContLang->getGenderNsText($this->mNamespace, $gender);
}
return $wgContLang->getNsText($this->mNamespace);
}
示例7: run
/**
* @param $resultPageSet ApiPageSet
* @return void
*/
private function run($resultPageSet = null)
{
$db = $this->getDB();
$params = $this->extractRequestParams();
// Page filters
$this->addTables('page');
if (!is_null($params['continue'])) {
$cont = explode('|', $params['continue']);
$this->dieContinueUsageIf(count($cont) != 1);
$op = $params['dir'] == 'descending' ? '<' : '>';
$cont_from = $db->addQuotes($cont[0]);
$this->addWhere("page_title {$op}= {$cont_from}");
}
if ($params['filterredir'] == 'redirects') {
$this->addWhereFld('page_is_redirect', 1);
} elseif ($params['filterredir'] == 'nonredirects') {
$this->addWhereFld('page_is_redirect', 0);
}
$this->addWhereFld('page_namespace', $params['namespace']);
$dir = $params['dir'] == 'descending' ? 'older' : 'newer';
$from = $params['from'] === null ? null : $this->titlePartToKey($params['from'], $params['namespace']);
$to = $params['to'] === null ? null : $this->titlePartToKey($params['to'], $params['namespace']);
$this->addWhereRange('page_title', $dir, $from, $to);
if (isset($params['prefix'])) {
$this->addWhere('page_title' . $db->buildLike($this->titlePartToKey($params['prefix'], $params['namespace']), $db->anyString()));
}
if (is_null($resultPageSet)) {
$selectFields = array('page_namespace', 'page_title', 'page_id');
} else {
$selectFields = $resultPageSet->getPageTableFields();
}
$this->addFields($selectFields);
$forceNameTitleIndex = true;
if (isset($params['minsize'])) {
$this->addWhere('page_len>=' . intval($params['minsize']));
$forceNameTitleIndex = false;
}
if (isset($params['maxsize'])) {
$this->addWhere('page_len<=' . intval($params['maxsize']));
$forceNameTitleIndex = false;
}
// Page protection filtering
if (count($params['prtype']) || $params['prexpiry'] != 'all') {
$this->addTables('page_restrictions');
$this->addWhere('page_id=pr_page');
$this->addWhere("pr_expiry > {$db->addQuotes($db->timestamp())} OR pr_expiry IS NULL");
if (count($params['prtype'])) {
$this->addWhereFld('pr_type', $params['prtype']);
if (isset($params['prlevel'])) {
// Remove the empty string and '*' from the prlevel array
$prlevel = array_diff($params['prlevel'], array('', '*'));
if (count($prlevel)) {
$this->addWhereFld('pr_level', $prlevel);
}
}
if ($params['prfiltercascade'] == 'cascading') {
$this->addWhereFld('pr_cascade', 1);
} elseif ($params['prfiltercascade'] == 'noncascading') {
$this->addWhereFld('pr_cascade', 0);
}
}
$forceNameTitleIndex = false;
if ($params['prexpiry'] == 'indefinite') {
$this->addWhere("pr_expiry = {$db->addQuotes($db->getInfinity())} OR pr_expiry IS NULL");
} elseif ($params['prexpiry'] == 'definite') {
$this->addWhere("pr_expiry != {$db->addQuotes($db->getInfinity())}");
}
$this->addOption('DISTINCT');
} elseif (isset($params['prlevel'])) {
$this->dieUsage('prlevel may not be used without prtype', 'params');
}
if ($params['filterlanglinks'] == 'withoutlanglinks') {
$this->addTables('langlinks');
$this->addJoinConds(array('langlinks' => array('LEFT JOIN', 'page_id=ll_from')));
$this->addWhere('ll_from IS NULL');
$forceNameTitleIndex = false;
} elseif ($params['filterlanglinks'] == 'withlanglinks') {
$this->addTables('langlinks');
$this->addWhere('page_id=ll_from');
$this->addOption('STRAIGHT_JOIN');
// We have to GROUP BY all selected fields to stop
// PostgreSQL from whining
$this->addOption('GROUP BY', $selectFields);
$forceNameTitleIndex = false;
}
if ($forceNameTitleIndex) {
$this->addOption('USE INDEX', 'name_title');
}
$limit = $params['limit'];
$this->addOption('LIMIT', $limit + 1);
$res = $this->select(__METHOD__);
//Get gender information
if (MWNamespace::hasGenderDistinction($params['namespace'])) {
$users = array();
foreach ($res as $row) {
$users[] = $row->page_title;
//.........这里部分代码省略.........
示例8: testHasGenderDistinction
public function testHasGenderDistinction()
{
// Namespaces with gender distinctions
$this->assertTrue(MWNamespace::hasGenderDistinction(NS_USER));
$this->assertTrue(MWNamespace::hasGenderDistinction(NS_USER_TALK));
// Other ones, "genderless"
$this->assertFalse(MWNamespace::hasGenderDistinction(NS_MEDIA));
$this->assertFalse(MWNamespace::hasGenderDistinction(NS_SPECIAL));
$this->assertFalse(MWNamespace::hasGenderDistinction(NS_MAIN));
$this->assertFalse(MWNamespace::hasGenderDistinction(NS_TALK));
}
示例9: processTitlesArray
/**
* Given an array of title strings, convert them into Title objects.
* Alternatively, an array of Title objects may be given.
* This method validates access rights for the title,
* and appends normalization values to the output.
*
* @param array $titles Array of Title objects or strings
* @return LinkBatch
*/
private function processTitlesArray($titles)
{
$usernames = array();
$linkBatch = new LinkBatch();
foreach ($titles as $title) {
if (is_string($title)) {
try {
$titleObj = Title::newFromTextThrow($title, $this->mDefaultNamespace);
} catch (MalformedTitleException $ex) {
// Handle invalid titles gracefully
$this->mAllPages[0][$title] = $this->mFakePageId;
$this->mInvalidTitles[$this->mFakePageId] = array('title' => $title, 'invalidreason' => $ex->getMessage());
$this->mFakePageId--;
continue;
// There's nothing else we can do
}
} else {
$titleObj = $title;
}
$unconvertedTitle = $titleObj->getPrefixedText();
$titleWasConverted = false;
if ($titleObj->isExternal()) {
// This title is an interwiki link.
$this->mInterwikiTitles[$unconvertedTitle] = $titleObj->getInterwiki();
} else {
// Variants checking
global $wgContLang;
if ($this->mConvertTitles && count($wgContLang->getVariants()) > 1 && !$titleObj->exists()) {
// Language::findVariantLink will modify titleText and titleObj into
// the canonical variant if possible
$titleText = is_string($title) ? $title : $titleObj->getPrefixedText();
$wgContLang->findVariantLink($titleText, $titleObj);
$titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
}
if ($titleObj->getNamespace() < 0) {
// Handle Special and Media pages
$titleObj = $titleObj->fixSpecialName();
$this->mSpecialTitles[$this->mFakePageId] = $titleObj;
$this->mFakePageId--;
} else {
// Regular page
$linkBatch->addObj($titleObj);
}
}
// Make sure we remember the original title that was
// given to us. This way the caller can correlate new
// titles with the originally requested when e.g. the
// namespace is localized or the capitalization is
// different
if ($titleWasConverted) {
$this->mConvertedTitles[$unconvertedTitle] = $titleObj->getPrefixedText();
// In this case the page can't be Special.
if (is_string($title) && $title !== $unconvertedTitle) {
$this->mNormalizedTitles[$title] = $unconvertedTitle;
}
} elseif (is_string($title) && $title !== $titleObj->getPrefixedText()) {
$this->mNormalizedTitles[$title] = $titleObj->getPrefixedText();
}
// Need gender information
if (MWNamespace::hasGenderDistinction($titleObj->getNamespace())) {
$usernames[] = $titleObj->getText();
}
}
// Get gender information
$genderCache = GenderCache::singleton();
$genderCache->doQuery($usernames, __METHOD__);
return $linkBatch;
}
示例10: getNsText
/**
* Get the namespace text
*
* @return String: Namespace text
*/
public function getNsText()
{
global $wgContLang;
if ($this->isExternal()) {
// This probably shouldn't even happen. ohh man, oh yuck.
// But for interwiki transclusion it sometimes does.
// Shit. Shit shit shit.
//
// Use the canonical namespaces if possible to try to
// resolve a foreign namespace.
if (MWNamespace::exists($this->mNamespace)) {
return MWNamespace::getCanonicalName($this->mNamespace);
}
}
if ($wgContLang->needsGenderDistinction() && MWNamespace::hasGenderDistinction($this->mNamespace)) {
$gender = GenderCache::singleton()->getGenderOf($this->getText(), __METHOD__);
return $wgContLang->getGenderNsText($this->mNamespace, $gender);
}
return $wgContLang->getNsText($this->mNamespace);
}
示例11: initFromQueryResult
/**
* Iterate through the result of the query on 'page' table,
* and for each row create and store title object and save any extra fields requested.
* @param $res ResultWrapper DB Query result
* @param $remaining array of either pageID or ns/title elements (optional).
* If given, any missing items will go to $mMissingPageIDs and $mMissingTitles
* @param $processTitles bool Must be provided together with $remaining.
* If true, treat $remaining as an array of [ns][title]
* If false, treat it as an array of [pageIDs]
*/
private function initFromQueryResult($res, &$remaining = null, $processTitles = null)
{
if (!is_null($remaining) && is_null($processTitles)) {
ApiBase::dieDebug(__METHOD__, 'Missing $processTitles parameter when $remaining is provided');
}
$usernames = array();
if ($res) {
foreach ($res as $row) {
$pageId = intval($row->page_id);
// Remove found page from the list of remaining items
if (isset($remaining)) {
if ($processTitles) {
unset($remaining[$row->page_namespace][$row->page_title]);
} else {
unset($remaining[$pageId]);
}
}
// Store any extra fields requested by modules
$this->processDbRow($row);
// Need gender information
if (MWNamespace::hasGenderDistinction($row->page_namespace)) {
$usernames[] = $row->page_title;
}
}
}
if (isset($remaining)) {
// Any items left in the $remaining list are added as missing
if ($processTitles) {
// The remaining titles in $remaining are non-existent pages
foreach ($remaining as $ns => $dbkeys) {
foreach (array_keys($dbkeys) as $dbkey) {
$title = Title::makeTitle($ns, $dbkey);
$this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
$this->mMissingTitles[$this->mFakePageId] = $title;
$this->mFakePageId--;
$this->mTitles[] = $title;
// need gender information
if (MWNamespace::hasGenderDistinction($ns)) {
$usernames[] = $dbkey;
}
}
}
} else {
// The remaining pageids do not exist
if (!$this->mMissingPageIDs) {
$this->mMissingPageIDs = array_keys($remaining);
} else {
$this->mMissingPageIDs = array_merge($this->mMissingPageIDs, array_keys($remaining));
}
}
}
// Get gender information
$genderCache = GenderCache::singleton();
$genderCache->doQuery($usernames, __METHOD__);
}
示例12: run
//.........这里部分代码省略.........
if (count($params['prtype']) || $params['prexpiry'] != 'all') {
$this->addTables('page_restrictions');
$this->addWhere('page_id=pr_page');
$this->addWhere("pr_expiry > {$db->addQuotes($db->timestamp())} OR pr_expiry IS NULL");
if (count($params['prtype'])) {
$this->addWhereFld('pr_type', $params['prtype']);
if (isset($params['prlevel'])) {
// Remove the empty string and '*' from the prlevel array
$prlevel = array_diff($params['prlevel'], ['', '*']);
if (count($prlevel)) {
$this->addWhereFld('pr_level', $prlevel);
}
}
if ($params['prfiltercascade'] == 'cascading') {
$this->addWhereFld('pr_cascade', 1);
} elseif ($params['prfiltercascade'] == 'noncascading') {
$this->addWhereFld('pr_cascade', 0);
}
}
$forceNameTitleIndex = false;
if ($params['prexpiry'] == 'indefinite') {
$this->addWhere("pr_expiry = {$db->addQuotes($db->getInfinity())} OR pr_expiry IS NULL");
} elseif ($params['prexpiry'] == 'definite') {
$this->addWhere("pr_expiry != {$db->addQuotes($db->getInfinity())}");
}
$this->addOption('DISTINCT');
} elseif (isset($params['prlevel'])) {
$this->dieUsage('prlevel may not be used without prtype', 'params');
}
if ($params['filterlanglinks'] == 'withoutlanglinks') {
$this->addTables('langlinks');
$this->addJoinConds(['langlinks' => ['LEFT JOIN', 'page_id=ll_from']]);
$this->addWhere('ll_from IS NULL');
$forceNameTitleIndex = false;
} elseif ($params['filterlanglinks'] == 'withlanglinks') {
$this->addTables('langlinks');
$this->addWhere('page_id=ll_from');
$this->addOption('STRAIGHT_JOIN');
// MySQL filesorts if we use a GROUP BY that works with the rules
// in the 1992 SQL standard (it doesn't like having the
// constant-in-WHERE page_namespace column in there). Using the
// 1999 rules works fine, but that breaks other DBs. Sigh.
/// @todo Once we drop support for 1992-rule DBs, we can simplify this.
$dbType = $db->getType();
if ($dbType === 'mysql' || $dbType === 'sqlite') {
// Ignore the rules, or 1999 rules if you count unique keys
// over non-NULL columns as satisfying the requirement for
// "functional dependency" and don't require including
// constant-in-WHERE columns in the GROUP BY.
$this->addOption('GROUP BY', ['page_title']);
} elseif ($dbType === 'postgres' && $db->getServerVersion() >= 9.1) {
// 1999 rules only counting primary keys
$this->addOption('GROUP BY', ['page_title', 'page_id']);
} else {
// 1992 rules
$this->addOption('GROUP BY', $selectFields);
}
$forceNameTitleIndex = false;
}
if ($forceNameTitleIndex) {
$this->addOption('USE INDEX', 'name_title');
}
$limit = $params['limit'];
$this->addOption('LIMIT', $limit + 1);
$res = $this->select(__METHOD__);
// Get gender information
if (MWNamespace::hasGenderDistinction($params['namespace'])) {
$users = [];
foreach ($res as $row) {
$users[] = $row->page_title;
}
GenderCache::singleton()->doQuery($users, __METHOD__);
$res->rewind();
// reset
}
$count = 0;
$result = $this->getResult();
foreach ($res as $row) {
if (++$count > $limit) {
// We've reached the one extra which shows that there are
// additional pages to be had. Stop here...
$this->setContinueEnumParameter('continue', $row->page_title);
break;
}
if (is_null($resultPageSet)) {
$title = Title::makeTitle($row->page_namespace, $row->page_title);
$vals = ['pageid' => intval($row->page_id), 'ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText()];
$fit = $result->addValue(['query', $this->getModuleName()], null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('continue', $row->page_title);
break;
}
} else {
$resultPageSet->processDbRow($row);
}
}
if (is_null($resultPageSet)) {
$result->addIndexedTagName(['query', $this->getModuleName()], 'p');
}
}