/** * Creates and returns the HTML for a single watchlist group. * * @since 0.1 * * @param SWLGroup $group * * @return string */ protected function getGroupHtml(SWLGroup $group) { $namespaces = $group->getNamespaces(); foreach ($namespaces as &$ns) { $ns = $ns == 0 ? 'Main' : MWNamespace::getCanonicalName($ns); } return Html::rawElement('fieldset', array('id' => 'swl_group_' . $group->getId(), 'groupid' => $group->getId(), 'class' => 'swl_group', 'groupname' => $group->getName(), 'categories' => implode('|', $group->getCategories()), 'namespaces' => implode('|', $namespaces), 'properties' => implode('|', $group->getProperties()), 'concepts' => implode('|', $group->getConcepts()), 'customTexts' => implode('|', $group->getSerializedCustomTexts())), Html::element('legend', array(), $this->msg('swl-group-legend')->text())); }
public function __construct() { global $wgContentStagingPrefix, $wgContentStagingNamespace, $wgContentStagingStages; $this->mwNamespaceIndex = isset($wgContentStagingNamespace) ? $wgContentStagingNamespace : 0; $this->mwNamespace = MWNamespace::getCanonicalName($this->mwNamespaceIndex) . ":"; $this->pagePrefix = isset($wgContentStagingPrefix) ? $wgContentStagingPrefix : "CMS"; # TODO: make the special page respect user defined names and number of stages $this->stages = isset($wgContentStagingStages) ? $wgContentStagingStages : array("test" => 0, "stage" => 0, "production" => 0); parent::__construct('ContentStaging', 'edit', true, false, 'default', false); }
/** * Show the special page * @param string|null $par */ public function execute($par) { $this->setHeaders(); $this->outputHeader(); $out = $this->getOutput(); $out->addModuleStyles('mediawiki.special'); $out->wrapWikiMsg("<div class=\"mw-listgrouprights-key\">\n\$1\n</div>", 'listgrouprights-key'); $out->addHTML(Xml::openElement('table', ['class' => 'wikitable mw-listgrouprights-table']) . '<tr>' . Xml::element('th', null, $this->msg('listgrouprights-group')->text()) . Xml::element('th', null, $this->msg('listgrouprights-rights')->text()) . '</tr>'); $config = $this->getConfig(); $groupPermissions = $config->get('GroupPermissions'); $revokePermissions = $config->get('RevokePermissions'); $addGroups = $config->get('AddGroups'); $removeGroups = $config->get('RemoveGroups'); $groupsAddToSelf = $config->get('GroupsAddToSelf'); $groupsRemoveFromSelf = $config->get('GroupsRemoveFromSelf'); $allGroups = array_unique(array_merge(array_keys($groupPermissions), array_keys($revokePermissions), array_keys($addGroups), array_keys($removeGroups), array_keys($groupsAddToSelf), array_keys($groupsRemoveFromSelf))); asort($allGroups); foreach ($allGroups as $group) { $permissions = isset($groupPermissions[$group]) ? $groupPermissions[$group] : []; $groupname = $group == '*' ? 'all' : $group; $msg = $this->msg('group-' . $groupname); $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname; $msg = $this->msg('grouppage-' . $groupname)->inContentLanguage(); $grouppageLocalized = !$msg->isBlank() ? $msg->text() : MWNamespace::getCanonicalName(NS_PROJECT) . ':' . $groupname; $grouppageLocalizedTitle = Title::newFromText($grouppageLocalized); if ($group == '*' || !$grouppageLocalizedTitle) { // Do not make a link for the generic * group or group with invalid group page $grouppage = htmlspecialchars($groupnameLocalized); } else { $grouppage = Linker::link($grouppageLocalizedTitle, htmlspecialchars($groupnameLocalized)); } if ($group === 'user') { // Link to Special:listusers for implicit group 'user' $grouplink = '<br />' . Linker::linkKnown(SpecialPage::getTitleFor('Listusers'), $this->msg('listgrouprights-members')->escaped()); } elseif (!in_array($group, $config->get('ImplicitGroups'))) { $grouplink = '<br />' . Linker::linkKnown(SpecialPage::getTitleFor('Listusers'), $this->msg('listgrouprights-members')->escaped(), [], ['group' => $group]); } else { // No link to Special:listusers for other implicit groups as they are unlistable $grouplink = ''; } $revoke = isset($revokePermissions[$group]) ? $revokePermissions[$group] : []; $addgroups = isset($addGroups[$group]) ? $addGroups[$group] : []; $removegroups = isset($removeGroups[$group]) ? $removeGroups[$group] : []; $addgroupsSelf = isset($groupsAddToSelf[$group]) ? $groupsAddToSelf[$group] : []; $removegroupsSelf = isset($groupsRemoveFromSelf[$group]) ? $groupsRemoveFromSelf[$group] : []; $id = $group == '*' ? false : Sanitizer::escapeId($group); $out->addHTML(Html::rawElement('tr', ['id' => $id], "\n\t\t\t\t<td>{$grouppage}{$grouplink}</td>\n\t\t\t\t\t<td>" . $this->formatPermissions($permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf) . '</td> ')); } $out->addHTML(Xml::closeElement('table')); $this->outputNamespaceProtectionInfo(); }
/** * Show the special page */ public function execute($par) { global $wgOut, $wgImplicitGroups, $wgMessageCache; global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups; global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf; $wgMessageCache->loadAllMessages(); $this->setHeaders(); $this->outputHeader(); $wgOut->addHTML(Xml::openElement('table', array('class' => 'wikitable mw-listgrouprights-table')) . '<tr>' . Xml::element('th', null, wfMsg('listgrouprights-group')) . Xml::element('th', null, wfMsg('listgrouprights-rights')) . '</tr>'); foreach ($wgGroupPermissions as $group => $permissions) { $groupname = $group == '*' ? 'all' : $group; // Replace * with a more descriptive groupname $msg = wfMsg('group-' . $groupname); if (wfEmptyMsg('group-' . $groupname, $msg) || $msg == '') { $groupnameLocalized = $groupname; } else { $groupnameLocalized = $msg; } $msg = wfMsgForContent('grouppage-' . $groupname); if (wfEmptyMsg('grouppage-' . $groupname, $msg) || $msg == '') { $grouppageLocalized = MWNamespace::getCanonicalName(NS_PROJECT) . ':' . $groupname; } else { $grouppageLocalized = $msg; } if ($group == '*') { // Do not make a link for the generic * group $grouppage = htmlspecialchars($groupnameLocalized); } else { $grouppage = $this->skin->link(Title::newFromText($grouppageLocalized), htmlspecialchars($groupnameLocalized)); } if ($group === 'user') { // Link to Special:listusers for implicit group 'user' $grouplink = '<br />' . $this->skin->link(SpecialPage::getTitleFor('Listusers'), wfMsgHtml('listgrouprights-members'), array(), array(), array('known', 'noclasses')); } elseif (!in_array($group, $wgImplicitGroups)) { $grouplink = '<br />' . $this->skin->link(SpecialPage::getTitleFor('Listusers'), wfMsgHtml('listgrouprights-members'), array(), array('group' => $group), array('known', 'noclasses')); } else { // No link to Special:listusers for other implicit groups as they are unlistable $grouplink = ''; } $revoke = isset($wgRevokePermissions[$group]) ? $wgRevokePermissions[$group] : array(); $addgroups = isset($wgAddGroups[$group]) ? $wgAddGroups[$group] : array(); $removegroups = isset($wgRemoveGroups[$group]) ? $wgRemoveGroups[$group] : array(); $addgroupsSelf = isset($wgGroupsAddToSelf[$group]) ? $wgGroupsAddToSelf[$group] : array(); $removegroupsSelf = isset($wgGroupsRemoveFromSelf[$group]) ? $wgGroupsRemoveFromSelf[$group] : array(); $wgOut->addHTML('<tr> <td>' . $grouppage . $grouplink . '</td> <td>' . self::formatPermissions($permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf) . '</td> </tr>'); } $wgOut->addHTML(Xml::closeElement('table') . "\n<br /><hr />\n"); $wgOut->wrapWikiMsg("<div class=\"mw-listgrouprights-key\">\n\$1\n</div>", 'listgrouprights-key'); }
public function getNamespaceName($ns) { $ns = intval($ns); if (!$ns) { $name = "Main"; } else { $name = MWNamespace::getCanonicalName($ns); if (empty($name)) { $name = "Namespace-{$ns}"; } } return $name; }
function select($table, $fields, $conds = '', $fname = 'DatabaseBase::select', $options = array()) { $row = array(); $title = false; if (isset($conds['page_title'])) { $title = $conds['page_title']; if ($conds['page_namespace'] && MWNamespace::getCanonicalName($conds['page_namespace'])) { $title = MWNamespace::getCanonicalName($conds['page_namespace']) . ':' . $title; } } if ($title && ($table == 'page' || is_array($table) && in_array('page', $table))) { if (preg_match('/Template:Pp-/i', $title)) { return false; } $textid = CachedStorage::fetchIdByTitle($title); if (!$textid) { $content = DumpReader::load_article($title); if (!$content) { wfDebug('no content for ' . $title); return false; } $textid = CachedStorage::set($title, $content); } } elseif (isset($conds['rev_id'])) { $textid = $conds['rev_id']; } if (!isset($textid)) { return $this->resultObject(array()); } if ($table == 'page') { // Given a page_title, get the id of text content. For efficiency, // we fetch the text and store it by ID to access in case 2. $row = array_fill_keys($fields, ''); $row['page_id'] = $textid; $row['page_title'] = $title; $row['page_latest'] = $textid; } elseif ($table == array('page', 'revision')) { // Redundantly return textid which is cache key to article wml. $fields[] = 'rev_user'; $fields[] = 'rev_user_text'; $row = array_fill_keys($fields, ''); $row['rev_id'] = $textid; $row['rev_text_id'] = $textid; } else { print_r($table); print_r($conds); } return $this->resultObject($row); }
/** * @param $contLang \Language * Used as local cache for getting string to remove */ private function getFilePrefixRegex($contLang) { $langCode = $contLang->getCode(); if (empty($this->filePrefixRegex[$langCode])) { $fileNamespaces = [\MWNamespace::getCanonicalName(NS_FILE), $contLang->getNamespaces()[NS_FILE]]; $aliases = $contLang->getNamespaceAliases(); foreach ($aliases as $alias => $namespaceId) { if ($namespaceId == NS_FILE) { $fileNamespaces[] = $alias; } } $this->filePrefixRegex[$langCode] = '^(' . implode('|', $fileNamespaces) . '):'; } return $this->filePrefixRegex[$langCode]; }
/** * Show the special page */ public function execute($par) { global $wgOut, $wgImplicitGroups, $wgMessageCache; global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups; $wgMessageCache->loadAllMessages(); $this->setHeaders(); $this->outputHeader(); $wgOut->addHTML(Xml::openElement('table', array('class' => 'mw-listgrouprights-table')) . '<tr>' . Xml::element('th', null, wfMsg('listgrouprights-group')) . Xml::element('th', null, wfMsg('listgrouprights-rights')) . '</tr>'); foreach ($wgGroupPermissions as $group => $permissions) { $groupname = $group == '*' ? 'all' : htmlspecialchars($group); // Replace * with a more descriptive groupname $msg = wfMsg('group-' . $groupname); if (wfEmptyMsg('group-' . $groupname, $msg) || $msg == '') { $groupnameLocalized = $groupname; } else { $groupnameLocalized = $msg; } $msg = wfMsgForContent('grouppage-' . $groupname); if (wfEmptyMsg('grouppage-' . $groupname, $msg) || $msg == '') { $grouppageLocalized = MWNamespace::getCanonicalName(NS_PROJECT) . ':' . $groupname; } else { $grouppageLocalized = $msg; } if ($group == '*') { // Do not make a link for the generic * group $grouppage = $groupnameLocalized; } else { $grouppage = $this->skin->makeLink($grouppageLocalized, $groupnameLocalized); } if ($group === 'user') { // Link to Special:listusers for implicit group 'user' $grouplink = '<br />' . $this->skin->makeKnownLinkObj(SpecialPage::getTitleFor('Listusers'), wfMsgHtml('listgrouprights-members'), ''); } elseif (!in_array($group, $wgImplicitGroups)) { $grouplink = '<br />' . $this->skin->makeKnownLinkObj(SpecialPage::getTitleFor('Listusers'), wfMsgHtml('listgrouprights-members'), 'group=' . $group); } else { // No link to Special:listusers for other implicit groups as they are unlistable $grouplink = ''; } $addgroups = isset($wgAddGroups[$group]) ? $wgAddGroups[$group] : array(); $removegroups = isset($wgRemoveGroups[$group]) ? $wgRemoveGroups[$group] : array(); $wgOut->addHTML('<tr> <td>' . $grouppage . $grouplink . '</td> <td>' . self::formatPermissions($permissions, $addgroups, $removegroups) . '</td> </tr>'); } $wgOut->addHTML(Xml::closeElement('table') . "\n"); }
/** * Show the special page */ public function execute($par) { global $wgImplicitGroups; global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups; global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf; $out = $this->getOutput(); $this->setHeaders(); $this->outputHeader(); $out->addModuleStyles('mediawiki.special'); $out->addHTML(Xml::openElement('table', array('class' => 'wikitable mw-listgrouprights-table')) . '<tr>' . Xml::element('th', null, wfMsg('listgrouprights-group')) . Xml::element('th', null, wfMsg('listgrouprights-rights')) . '</tr>'); $allGroups = array_unique(array_merge(array_keys($wgGroupPermissions), array_keys($wgRevokePermissions), array_keys($wgAddGroups), array_keys($wgRemoveGroups), array_keys($wgGroupsAddToSelf), array_keys($wgGroupsRemoveFromSelf))); asort($allGroups); foreach ($allGroups as $group) { $permissions = isset($wgGroupPermissions[$group]) ? $wgGroupPermissions[$group] : array(); $groupname = $group == '*' ? 'all' : $group; $msg = wfMessage('group-' . $groupname); $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname; $msg = wfMessage('grouppage-' . $groupname)->inContentLanguage(); $grouppageLocalized = !$msg->isBlank() ? $msg->text() : MWNamespace::getCanonicalName(NS_PROJECT) . ':' . $groupname; if ($group == '*') { // Do not make a link for the generic * group $grouppage = htmlspecialchars($groupnameLocalized); } else { $grouppage = Linker::link(Title::newFromText($grouppageLocalized), htmlspecialchars($groupnameLocalized)); } if ($group === 'user') { // Link to Special:listusers for implicit group 'user' $grouplink = '<br />' . Linker::link(SpecialPage::getTitleFor('Listusers'), wfMsgHtml('listgrouprights-members'), array(), array(), array('known', 'noclasses')); } elseif (!in_array($group, $wgImplicitGroups)) { $grouplink = '<br />' . Linker::link(SpecialPage::getTitleFor('Listusers'), wfMsgHtml('listgrouprights-members'), array(), array('group' => $group), array('known', 'noclasses')); } else { // No link to Special:listusers for other implicit groups as they are unlistable $grouplink = ''; } $revoke = isset($wgRevokePermissions[$group]) ? $wgRevokePermissions[$group] : array(); $addgroups = isset($wgAddGroups[$group]) ? $wgAddGroups[$group] : array(); $removegroups = isset($wgRemoveGroups[$group]) ? $wgRemoveGroups[$group] : array(); $addgroupsSelf = isset($wgGroupsAddToSelf[$group]) ? $wgGroupsAddToSelf[$group] : array(); $removegroupsSelf = isset($wgGroupsRemoveFromSelf[$group]) ? $wgGroupsRemoveFromSelf[$group] : array(); $id = $group == '*' ? false : Sanitizer::escapeId($group); $out->addHTML(Html::rawElement('tr', array('id' => $id), "\n\t\t\t\t<td>{$grouppage}{$grouplink}</td>\n\t\t\t\t\t<td>" . self::formatPermissions($permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf) . '</td> ')); } $out->addHTML(Xml::closeElement('table') . "\n<br /><hr />\n"); $out->wrapWikiMsg("<div class=\"mw-listgrouprights-key\">\n\$1\n</div>", 'listgrouprights-key'); }
protected function createPage($page, $text, $model = null) { if (is_string($page)) { if (!preg_match('/:/', $page) && ($model === null || $model === CONTENT_MODEL_WIKITEXT)) { $ns = $this->getDefaultWikitextNS(); $page = MWNamespace::getCanonicalName($ns) . ':' . $page; } $page = Title::newFromText($page); } if ($page instanceof Title) { $page = new WikiPage($page); } if ($page->exists()) { $page->doDeleteArticle("done"); } $content = ContentHandler::makeContent($text, $page->getTitle(), $model); $page->doEditContent($content, "testing", EDIT_NEW); return $page; }
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); }
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); }
/** * does $title article exist @help.wikia? * * @see SharedHelpHook */ function SharedHelpArticleExists($title) { global $wgMemc, $wgSharedDB, $wgHelpWikiId; wfProfileIn(__METHOD__); $exists = false; $sharedLinkKey = $wgSharedDB . ':sharedLinks:' . $wgHelpWikiId . ':' . MWNamespace::getCanonicalName($title->getNamespace()) . ':' . $title->getDBkey(); $sharedLink = $wgMemc->get($sharedLinkKey); if ($sharedLink) { $exists = true; } else { $sharedArticleKey = $wgSharedDB . ':sharedArticles:' . $wgHelpWikiId . ':' . MWNamespace::getCanonicalName($title->getNamespace()) . ':' . $title->getDBkey() . ':' . SHAREDHELP_CACHE_VERSION; $sharedArticle = $wgMemc->get($sharedArticleKey); if (!empty($sharedArticle['timestamp'])) { $exists = true; } else { wfProfileIn(__METHOD__ . '::query'); $dbr = wfGetDB(DB_SLAVE, array(), WikiFactory::IDtoDB($wgHelpWikiId)); $res = $dbr->select('page', 'page_id', array('page_namespace' => NS_HELP, 'page_title' => $title->getDBkey()), __METHOD__); if ($row = $dbr->fetchObject($res)) { if (!empty($row->page_id)) { $exists = true; } } wfProfileOut(__METHOD__ . '::query'); } if ($exists) { $wgMemc->set($sharedLinkKey, true); } } wfProfileOut(__METHOD__); return $exists; }
private function getGroupStats() { global $wgGroupPermissions, $wgImplicitGroups; $text = ''; foreach ($wgGroupPermissions as $group => $permissions) { # Skip generic * and implicit groups if (in_array($group, $wgImplicitGroups) || $group == '*') { continue; } $groupname = htmlspecialchars($group); $msg = $this->msg('group-' . $groupname); if ($msg->isBlank()) { $groupnameLocalized = $groupname; } else { $groupnameLocalized = $msg->text(); } $msg = $this->msg('grouppage-' . $groupname)->inContentLanguage(); if ($msg->isBlank()) { $grouppageLocalized = MWNamespace::getCanonicalName(NS_PROJECT) . ':' . $groupname; } else { $grouppageLocalized = $msg->text(); } $linkTarget = Title::newFromText($grouppageLocalized); $grouppage = Linker::link($linkTarget, htmlspecialchars($groupnameLocalized)); $grouplink = Linker::linkKnown(SpecialPage::getTitleFor('Listusers'), $this->msg('listgrouprights-members')->escaped(), array(), array('group' => $group)); # Add a class when a usergroup contains no members to allow hiding these rows $classZero = ''; $countUsers = SiteStats::numberingroup($groupname); if ($countUsers == 0) { $classZero = ' statistics-group-zero'; } $text .= $this->formatRow($grouppage . ' ' . $grouplink, $this->getLanguage()->formatNum($countUsers), array('class' => 'statistics-group-' . Sanitizer::escapeClass($group) . $classZero)); } return $text; }
/** * Formats wiki links and media links in text; all other wiki formatting * is ignored * * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser * @param string $comment Text to format links in. WARNING! Since the output of this * function is html, $comment must be sanitized for use as html. You probably want * to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling * this function. * @param Title|null $title An optional title object used to links to sections * @param bool $local Whether section links should refer to local page * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), * as used by WikiMap. * * @return string */ public static function formatLinksInComment($comment, $title = null, $local = false, $wikiId = null) { return preg_replace_callback('/ \\[\\[ :? # ignore optional leading colon ([^\\]|]+) # 1. link target; page names cannot include ] or | (?:\\| # 2. a pipe-separated substring; only the last is captured # Stop matching at | and ]] without relying on backtracking. ((?:]?[^\\]|])*+) )* \\]\\] ([^[]*) # 3. link trail (the text up until the next link) /x', function ($match) use($title, $local, $wikiId) { global $wgContLang; $medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|'; $medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):'; $comment = $match[0]; # fix up urlencoded title texts (copied from Parser::replaceInternalLinks) if (strpos($match[1], '%') !== false) { $match[1] = strtr(rawurldecode($match[1]), array('<' => '<', '>' => '>')); } # Handle link renaming [[foo|text]] will show link as "text" if ($match[2] != "") { $text = $match[2]; } else { $text = $match[1]; } $submatch = array(); $thelink = null; if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) { # Media link; trail not supported. $linkRegexp = '/\\[\\[(.*?)\\]\\]/'; $title = Title::makeTitleSafe(NS_FILE, $submatch[1]); if ($title) { $thelink = Linker::makeMediaLinkObj($title, $text); } } else { # Other kind of link if (preg_match($wgContLang->linkTrail(), $match[3], $submatch)) { $trail = $submatch[1]; } else { $trail = ""; } $linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/'; if (isset($match[1][0]) && $match[1][0] == ':') { $match[1] = substr($match[1], 1); } list($inside, $trail) = Linker::splitTrail($trail); $linkText = $text; $linkTarget = Linker::normalizeSubpageLink($title, $match[1], $linkText); $target = Title::newFromText($linkTarget); if ($target) { if ($target->getText() == '' && !$target->isExternal() && !$local && $title) { $newTarget = clone $title; $newTarget->setFragment('#' . $target->getFragment()); $target = $newTarget; } $thelink = Linker::makeCommentLink($target, $linkText . $inside, $wikiId) . $trail; } } if ($thelink) { // If the link is still valid, go ahead and replace it in! $comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1); } return $comment; }, $comment); }
/** * Adds the preferences of Semantic Watchlist to the list of available ones. * * @since 0.1 * * @param User $user * @param array $preferences * * @return true */ public static function onGetPreferences( User $user, array &$preferences ) { $groups = SWLGroups::getAll(); // Only show the email notification preference when email notifications are enabled. if ( $GLOBALS['egSWLEnableEmailNotify'] ) { $preferences['swl_email'] = array( 'type' => 'toggle', 'label-message' => 'swl-prefs-emailnofity', 'section' => 'swl/swlglobal', ); } // Only show the top link preference when it's enabled. if ( $GLOBALS['egSWLEnableTopLink'] ) { $preferences['swl_watchlisttoplink'] = array( 'type' => 'toggle', 'label-message' => 'swl-prefs-watchlisttoplink', 'section' => 'swl/swlglobal', ); } foreach ( $groups as /* SWLGroup */ $group ) { if ( count( $group->getProperties() ) == 0 ) { continue; } switch ( true ) { case count( $group->getCategories() ) > 0 : $type = 'category'; $name = $group->getCategories(); $name = $name[0]; break; case count( $group->getNamespaces() ) > 0 : $type = 'namespace'; $name = $group->getNamespaces(); $name = $name[0] == 0 ? wfMsg( 'main' ) : MWNamespace::getCanonicalName( $name[0] ); break; case count( $group->getConcepts() ) > 0 : $type = 'concept'; $name = $group->getConcepts(); $name = $name[0]; break; } $properties = $group->getProperties(); foreach ( $properties as &$property ) { $property = "''$property''"; } $preferences['swl_watchgroup_' . $group->getId()] = array( 'type' => 'toggle', 'label' => wfMsgExt( "swl-prefs-$type-label", 'parseinline', $group->getName(), count( $group->getProperties() ), $GLOBALS['wgLang']->listToText( $properties ), $name ), 'section' => 'swl/swlgroup', ); } return true; }
function __call($method, $args) { // Call the real method if it exists if (method_exists($this, $method)) { return $this->{$method}($args); } if (preg_match('/^assert(Has|Is|Can)(Not|)(Subject|Talk|Watchable|Content|Subpages|Capitalized)$/', $method, $m)) { # Interprets arguments: $ns = $args[0]; $msg = isset($args[1]) ? $args[1] : " dummy message"; # Forge the namespace constant name: if ($ns === 0) { $ns_name = "NS_MAIN"; } else { $ns_name = "NS_" . strtoupper(MWNamespace::getCanonicalName($ns)); } # ... and the MWNamespace method name $nsMethod = strtolower($m[1]) . $m[3]; $expect = $m[2] === ''; $expect_name = $expect ? 'TRUE' : 'FALSE'; return $this->assertEquals($expect, MWNamespace::$nsMethod($ns, $msg), "MWNamespace::{$nsMethod}( {$ns_name} ) should returns {$expect_name}"); } throw new Exception(__METHOD__ . " could not find a method named {$method}\n"); }
/** * Get an array containing the variables to be set in mw.config in JavaScript. * * DO NOT CALL THIS FROM OUTSIDE OF THIS CLASS OR Skin::makeGlobalVariablesScript(). * This is only public until that function is removed. You have been warned. * * Do not add things here which can be evaluated in ResourceLoaderStartupScript * - in other words, page-indendent/site-wide variables (without state). * You will only be adding bloat to the html page and causing page caches to * have to be purged on configuration changes. */ public function getJSVars() { global $wgUseAjax, $wgEnableMWSuggest, $wgContLang; $title = $this->getTitle(); $ns = $title->getNamespace(); $nsname = MWNamespace::exists($ns) ? MWNamespace::getCanonicalName($ns) : $title->getNsText(); if ($ns == NS_SPECIAL) { list($canonicalName, ) = SpecialPageFactory::resolveAlias($title->getDBkey()); } else { $canonicalName = false; # bug 21115 } $vars = array('wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => $canonicalName, 'wgNamespaceNumber' => $title->getNamespace(), 'wgPageName' => $title->getPrefixedDBKey(), 'wgTitle' => $title->getText(), 'wgCurRevisionId' => $title->getLatestRevID(), 'wgArticleId' => $title->getArticleId(), 'wgIsArticle' => $this->isArticle(), 'wgAction' => $this->getRequest()->getText('action', 'view'), 'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(), 'wgUserGroups' => $this->getUser()->getEffectiveGroups(), 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY'); if ($wgContLang->hasVariants()) { $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); } foreach ($title->getRestrictionTypes() as $type) { $vars['wgRestriction' . ucfirst($type)] = $title->getRestrictions($type); } if ($wgUseAjax && $wgEnableMWSuggest && !$this->getUser()->getOption('disablesuggest', false)) { $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces($this->getUser()); } if ($title->isMainPage()) { $vars['wgIsMainPage'] = true; } // Allow extensions to add their custom variables to the mw.config map. // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not // page-dependant but site-wide (without state). // Alternatively, you may want to use OutputPage->addJsConfigVars() instead. wfRunHooks('MakeGlobalVariablesScript', array(&$vars)); // Merge in variables from addJsConfigVars last return array_merge($vars, $this->mJsConfigVars); }
/** * Helper function to handle getPropertyValues(). */ public static function getSMWPropertyValues($store, $subject, $propID, $requestOptions = null) { // If SMW is not installed, exit out. if (!class_exists('SMWDIWikiPage')) { return array(); } if (is_null($subject)) { $page = null; } else { $page = SMWDIWikiPage::newFromTitle($subject); } $property = SMWDIProperty::newFromUserLabel($propID); $res = $store->getPropertyValues($page, $property, $requestOptions); $values = array(); foreach ($res as $value) { if ($value instanceof SMWDIUri) { $values[] = $value->getURI(); } elseif ($value instanceof SMWDIWikiPage) { $realValue = str_replace('_', ' ', $value->getDBKey()); if ($value->getNamespace() != 0) { $realValue = MWNamespace::getCanonicalName($value->getNamespace()) . ":{$realValue}"; } $values[] = $realValue; } else { // getSortKey() seems to return the correct // value for all the other data types. $values[] = str_replace('_', ' ', $value->getSortKey()); } } return $values; }
function efNamespacePathCallback(&$matches, $data) { $nstext = MWNamespace::getCanonicalName(intval($data['ns'])); $matches['title'] = $nstext . ':' . $data['page_title']; }
/** * Show the error text for a missing article. For articles in the MediaWiki * namespace, show the default message text. To be called from Article::view(). */ public function showMissingArticle() { global $wgSend404Code; $outputPage = $this->getContext()->getOutput(); // Whether the page is a root user page of an existing user (but not a subpage) $validUserPage = false; $title = $this->getTitle(); # Show info in user (talk) namespace. Does the user exist? Is he blocked? if ($title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK) { $parts = explode('/', $title->getText()); $rootPart = $parts[0]; $user = User::newFromName($rootPart, false); $ip = User::isIP($rootPart); $block = Block::newFromTarget($user, $user); if (!($user && $user->isLoggedIn()) && !$ip) { # User does not exist $outputPage->wrapWikiMsg("<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", array('userpage-userdoesnotexist-view', wfEscapeWikiText($rootPart))); } elseif (!is_null($block) && $block->getType() != Block::TYPE_AUTO) { # Show log extract if the user is currently blocked LogEventsList::showLogExtract($outputPage, 'block', MWNamespace::getCanonicalName(NS_USER) . ':' . $block->getTarget(), '', array('lim' => 1, 'showIfEmpty' => false, 'msgKey' => array('blocked-notice-logextract', $user->getName()))); $validUserPage = !$title->isSubpage(); } else { $validUserPage = !$title->isSubpage(); } } Hooks::run('ShowMissingArticle', array($this)); # Show delete and move logs if there were any such events. # The logging query can DOS the site when bots/crawlers cause 404 floods, # so be careful showing this. 404 pages must be cheap as they are hard to cache. $cache = ObjectCache::getMainStashInstance(); $key = wfMemcKey('page-recent-delete', md5($title->getPrefixedText())); $loggedIn = $this->getContext()->getUser()->isLoggedIn(); if ($loggedIn || $cache->get($key)) { $logTypes = array('delete', 'move'); $conds = array("log_action != 'revision'"); // Give extensions a chance to hide their (unrelated) log entries Hooks::run('Article::MissingArticleConditions', array(&$conds, $logTypes)); LogEventsList::showLogExtract($outputPage, $logTypes, $title, '', array('lim' => 10, 'conds' => $conds, 'showIfEmpty' => false, 'msgKey' => array($loggedIn ? 'moveddeleted-notice' : 'moveddeleted-notice-recent'))); } if (!$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage) { // If there's no backing content, send a 404 Not Found // for better machine handling of broken links. $this->getContext()->getRequest()->response()->statusHeader(404); } // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity) $policy = $this->getRobotPolicy('view'); $outputPage->setIndexPolicy($policy['index']); $outputPage->setFollowPolicy($policy['follow']); $hookResult = Hooks::run('BeforeDisplayNoArticleText', array($this)); if (!$hookResult) { return; } # Show error message $oldid = $this->getOldID(); if (!$oldid && $title->getNamespace() === NS_MEDIAWIKI && $title->hasSourceText()) { $outputPage->addParserOutput($this->getContentObject()->getParserOutput($title)); } else { if ($oldid) { $text = wfMessage('missing-revision', $oldid)->plain(); } elseif ($title->quickUserCan('create', $this->getContext()->getUser()) && $title->quickUserCan('edit', $this->getContext()->getUser())) { $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon'; $text = wfMessage($message)->plain(); } else { $text = wfMessage('noarticletext-nopermission')->plain(); } $dir = $this->getContext()->getLanguage()->getDir(); $lang = $this->getContext()->getLanguage()->getCode(); $outputPage->addWikiText(Xml::openElement('div', array('class' => "noarticletext mw-content-{$dir}", 'dir' => $dir, 'lang' => $lang)) . "\n{$text}\n</div>"); } }
/** * Prepares a list of links that have the purpose of discovery in the main navigation menu * @return array */ protected function getDiscoveryTools() { $config = $this->getMFConfig(); $items = array(); // Home link $items[] = array('name' => 'home', 'components' => array(array('text' => wfMessage('mobile-frontend-home-button')->escaped(), 'href' => Title::newMainPage()->getLocalUrl(), 'class' => MobileUI::iconClass('home', 'before'), 'data-event-name' => 'home'))); // Random link $items[] = array('name' => 'random', 'components' => array(array('text' => wfMessage('mobile-frontend-random-button')->escaped(), 'href' => SpecialPage::getTitleFor('Randompage', MWNamespace::getCanonicalName($config->get('MFContentNamespace')))->getLocalUrl() . '#/random', 'class' => MobileUI::iconClass('random', 'before'), 'id' => 'randomButton', 'data-event-name' => 'random'))); // Nearby link (if supported) if ($config->get('MFNearby') && ($config->get('MFNearbyEndpoint') || class_exists('GeoData'))) { $items[] = array('name' => 'nearby', 'components' => array(array('text' => wfMessage('mobile-frontend-main-menu-nearby')->escaped(), 'href' => SpecialPage::getTitleFor('Nearby')->getLocalURL(), 'class' => MobileUI::iconClass('nearby', 'before', 'nearby'), 'data-event-name' => 'nearby')), 'class' => 'jsonly'); } // Allow other extensions to add or override discovery tools Hooks::run('MinervaDiscoveryTools', array(&$items)); return $items; }
/** * @param $match * @return mixed */ protected static function formatLinksInCommentCallback($match) { global $wgContLang; $medians = '(?:' . preg_quote(MWNamespace::getCanonicalName(NS_MEDIA), '/') . '|'; $medians .= preg_quote($wgContLang->getNsText(NS_MEDIA), '/') . '):'; $comment = $match[0]; # fix up urlencoded title texts (copied from Parser::replaceInternalLinks) if (strpos($match[1], '%') !== false) { $match[1] = str_replace(array('<', '>'), array('<', '>'), rawurldecode($match[1])); } # Handle link renaming [[foo|text]] will show link as "text" if ($match[3] != "") { $text = $match[3]; } else { $text = $match[1]; } $submatch = array(); $thelink = null; if (preg_match('/^' . $medians . '(.*)$/i', $match[1], $submatch)) { # Media link; trail not supported. $linkRegexp = '/\\[\\[(.*?)\\]\\]/'; $title = Title::makeTitleSafe(NS_FILE, $submatch[1]); if ($title) { $thelink = self::makeMediaLinkObj($title, $text); } } else { # Other kind of link if (preg_match($wgContLang->linkTrail(), $match[4], $submatch)) { $trail = $submatch[1]; } else { $trail = ""; } $linkRegexp = '/\\[\\[(.*?)\\]\\]' . preg_quote($trail, '/') . '/'; if (isset($match[1][0]) && $match[1][0] == ':') { $match[1] = substr($match[1], 1); } list($inside, $trail) = self::splitTrail($trail); $linkText = $text; $linkTarget = self::normalizeSubpageLink(self::$commentContextTitle, $match[1], $linkText); $target = Title::newFromText($linkTarget); if ($target) { if ($target->getText() == '' && $target->getInterwiki() === '' && !self::$commentLocal && self::$commentContextTitle) { $newTarget = clone self::$commentContextTitle; $newTarget->setFragment('#' . $target->getFragment()); $target = $newTarget; } $thelink = self::link($target, $linkText . $inside) . $trail; } } if ($thelink) { // If the link is still valid, go ahead and replace it in! $comment = preg_replace($linkRegexp, StringUtils::escapeRegexReplacement($thelink), $comment, 1); } return $comment; }
/** * Returns geolocation button params */ private function getGeolocationButtonParams($refreshCache = false) { $sMemcKey = wfMemcKey($this->app->wg->title->getText(), $this->app->wg->title->getNamespace(), 'GeolocationButtonParams'); // use user default if (empty($iWidth)) { $wopt = $this->app->wg->user->getGlobalPreference('thumbsize'); if (!isset($this->app->wg->thumbLimits[$wopt])) { $wopt = User::getDefaultOption('thumbsize'); } $iWidth = $this->app->wg->thumbLimits[$wopt]; } $aResult = array('align' => 'right', 'width' => $iWidth); $aMemcResult = $this->app->wg->memc->get($sMemcKey); $refreshCache = true; // FIXME if ($refreshCache || empty($aMemcResult)) { $oArticle = new Article($this->app->wg->title); $sRawText = $oArticle->getRawText(); $aMatches = array(); $string = $this->app->wg->contLang->getNsText(NS_IMAGE) . '|' . MWNamespace::getCanonicalName(NS_IMAGE); $iFound = preg_match('#\\[\\[(' . $string . '):[^\\]]*|thumb[^\\]]*\\]\\]#', $sRawText, $aMatches); if (!empty($iFound)) { reset($aMatches); $sMatch = current($aMatches); $sMatch = str_replace('[[', '', $sMatch); $sMatch = str_replace(']]', '', $sMatch); $aMatch = explode('|', $sMatch); foreach ($aMatch as $element) { if ($element == 'left') { $aResult['align'] = $element; } if (substr($element, -2) == 'px' && (int) substr($element, 0, -2) > 0) { $aResult['width'] = (int) substr($element, 0, -2); } } } $iExpires = 60 * 60 * 24; $this->app->wg->memc->set($sMemcKey, $aResult, $iExpires); } else { $aResult['align'] = $aMemcResult['align']; if (!empty($aMemcResult['width'])) { $aResult['width'] = $aMemcResult['width']; } } // get default image width return $aResult; }
protected function appendNamespaces($property) { global $wgContLang; $data = array(); foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) { $data[$ns] = array('id' => intval($ns), 'case' => MWNamespace::isCapitalized($ns) ? 'first-letter' : 'case-sensitive'); ApiResult::setContent($data[$ns], $title); $canonical = MWNamespace::getCanonicalName($ns); if (MWNamespace::hasSubpages($ns)) { $data[$ns]['subpages'] = ''; } if ($canonical) { $data[$ns]['canonical'] = strtr($canonical, '_', ' '); } if (MWNamespace::isContent($ns)) { $data[$ns]['content'] = ''; } } $this->getResult()->setIndexedTagName($data, 'ns'); return $this->getResult()->addValue('query', $property, $data); }
function wfSajaxSearchArticleCKeditor($term) { global $wgContLang, $wgExtraNamespaces; $limit = 30; $ns = array(NS_MAIN, NS_CATEGORY, NS_IMAGE, NS_TEMPLATE, NS_USER); if (defined('SF_NS_FORM')) { $ns[] = SF_NS_FORM; } if (defined('SMW_NS_PROPERTY')) { $ns[] = SMW_NS_PROPERTY; } $term = $wgContLang->checkTitleEncoding($wgContLang->recodeInput(js_unescape($term))); $prefix = ""; if ($term[0] == ':') { $prefix = ':'; $term = substr($term, 1); } $pos = strpos($term, ':'); if ($pos !== false) { $nsName = strtolower(substr($term, 0, $pos)); foreach ($ns as $idx) { if (strtolower(MWNamespace::getCanonicalName($idx)) == $nsName) { $prefix .= MWNamespace::getCanonicalName($idx) . ':'; $term = substr($term, $pos + 1); $ns = array($idx); break; } } } if (strpos(strtolower($term), 'image:') === 0) { $ns = array(NS_IMAGE); $term = substr(strtolower($term), 6); $prefix .= 'Image:'; } else { if (strpos($term, ':') && is_array($wgExtraNamespaces)) { $pos = strpos($term, ':'); $find_ns = array_search(substr($term, 0, $pos), $wgExtraNamespaces); if ($find_ns) { $ns = array($find_ns); $prefix .= substr($term, 0, $pos + 1); $term = substr($term, $pos + 1); } } } $term1 = str_replace(' ', '_', $wgContLang->ucfirst($term)); $term2 = str_replace(' ', '_', $wgContLang->lc($term)); $term3 = str_replace(' ', '_', $wgContLang->uc($term)); $term4 = str_replace(' ', '_', $wgContLang->ucfirst($term2)); $term = $term1; if (strlen(str_replace('_', '', $term)) < 1 && count($ns) > 1) { return ''; } $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('page', 'page_title, page_namespace', array('page_namespace in (' . implode(',', $ns) . ') and ' . "( page_title LIKE '%" . $dbr->strencode($term1) . "%' " . "OR (LOWER(CONVERT(page_title, CHAR)) LIKE '%" . $dbr->strencode($term2) . "%') " . "OR (UPPER(CONVERT(page_title, CHAR)) LIKE '%" . $dbr->strencode($term3) . "%') " . "OR (page_title LIKE '%" . $dbr->strencode($term4) . "%') )"), __METHOD__, array('LIMIT' => $limit + 1)); $ret = array(); $i = 0; while (($row = $dbr->fetchObject($res)) && ++$i <= $limit) { $title = ''; if (isset($prefix) && !is_null($prefix)) { $title .= $prefix; } else { if ($row->page_namespace != NS_MAIN) { $title .= MWNamespace::getCanonicalName($row->page_namespace) . ':'; } } $title .= $row->page_title; $ret[] = $title; } // if we have not yet enough results, check the special pages if (count($ret) < $limit && $term2 != "") { global $wgSpecialPages; $specialPages = array_keys($wgSpecialPages); foreach ($specialPages as $page) { if (strpos(strtolower($page), $term2) !== FALSE || strpos(strtoupper($page), $term3) !== FALSE) { $ret[] = MWNamespace::getCanonicalName(NS_SPECIAL) . ':' . $page; } } } return join("\n", $ret); }
/** * Generate strings used for xml 'id' names in monobook tabs * * @param string $prepend Defaults to 'nstab-' * @return string XML 'id' name */ public function getNamespaceKey($prepend = 'nstab-') { global $wgContLang; // Gets the subject namespace if this title $namespace = MWNamespace::getSubject($this->getNamespace()); // Checks if canonical namespace name exists for namespace if (MWNamespace::exists($this->getNamespace())) { // Uses canonical namespace name $namespaceKey = MWNamespace::getCanonicalName($namespace); } else { // Uses text of namespace $namespaceKey = $this->getSubjectNsText(); } // Makes namespace key lowercase $namespaceKey = $wgContLang->lc($namespaceKey); // Uses main if ($namespaceKey == '') { $namespaceKey = 'main'; } // Changes file to image for backwards compatibility if ($namespaceKey == 'file') { $namespaceKey = 'image'; } return $prepend . $namespaceKey; }
/** * Generates the subheading with links * @param User $userObj User object for the target * @return string Appropriately-escaped HTML to be output literally * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. * Could be combined. */ protected function contributionsSub($userObj) { if ($userObj->isAnon()) { // Show a warning message that the user being searched for doesn't exists if (!User::isIP($userObj->getName())) { $this->getOutput()->wrapWikiMsg("<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>", ['contributions-userdoesnotexist', wfEscapeWikiText($userObj->getName())]); if (!$this->including()) { $this->getOutput()->setStatusCode(404); } } $user = htmlspecialchars($userObj->getName()); } else { $user = $this->getLinkRenderer()->makeLink($userObj->getUserPage(), $userObj->getName()); } $nt = $userObj->getUserPage(); $talk = $userObj->getTalkPage(); $links = ''; if ($talk) { $tools = self::getUserLinks($this, $userObj); $links = $this->getLanguage()->pipeList($tools); // Show a note if the user is blocked and display the last block log entry. // Do not expose the autoblocks, since that may lead to a leak of accounts' IPs, // and also this will display a totally irrelevant log entry as a current block. if (!$this->including()) { $block = Block::newFromTarget($userObj, $userObj); if (!is_null($block) && $block->getType() != Block::TYPE_AUTO) { if ($block->getType() == Block::TYPE_RANGE) { $nt = MWNamespace::getCanonicalName(NS_USER) . ':' . $block->getTarget(); } $out = $this->getOutput(); // showLogExtract() wants first parameter by reference LogEventsList::showLogExtract($out, 'block', $nt, '', ['lim' => 1, 'showIfEmpty' => false, 'msgKey' => [$userObj->isAnon() ? 'sp-contributions-blocked-notice-anon' : 'sp-contributions-blocked-notice', $userObj->getName()], 'offset' => '']); } } } return $this->msg('contribsub2')->rawParams($user, $links)->params($userObj->getName()); }
/** * Get an array containing the variables to be set in mw.config in JavaScript. * * Do not add things here which can be evaluated in ResourceLoaderStartUpModule * - in other words, page-independent/site-wide variables (without state). * You will only be adding bloat to the html page and causing page caches to * have to be purged on configuration changes. * @return array */ public function getJSVars() { global $wgContLang; $curRevisionId = 0; $articleId = 0; $canonicalSpecialPageName = false; # bug 21115 $title = $this->getTitle(); $ns = $title->getNamespace(); $canonicalNamespace = MWNamespace::exists($ns) ? MWNamespace::getCanonicalName($ns) : $title->getNsText(); $sk = $this->getSkin(); // Get the relevant title so that AJAX features can use the correct page name // when making API requests from certain special pages (bug 34972). $relevantTitle = $sk->getRelevantTitle(); $relevantUser = $sk->getRelevantUser(); if ($ns == NS_SPECIAL) { list($canonicalSpecialPageName, ) = SpecialPageFactory::resolveAlias($title->getDBkey()); } elseif ($this->canUseWikiPage()) { $wikiPage = $this->getWikiPage(); $curRevisionId = $wikiPage->getLatest(); $articleId = $wikiPage->getId(); } $lang = $title->getPageLanguage(); // Pre-process information $separatorTransTable = $lang->separatorTransformTable(); $separatorTransTable = $separatorTransTable ? $separatorTransTable : array(); $compactSeparatorTransTable = array(implode("\t", array_keys($separatorTransTable)), implode("\t", $separatorTransTable)); $digitTransTable = $lang->digitTransformTable(); $digitTransTable = $digitTransTable ? $digitTransTable : array(); $compactDigitTransTable = array(implode("\t", array_keys($digitTransTable)), implode("\t", $digitTransTable)); $user = $this->getUser(); $vars = array('wgCanonicalNamespace' => $canonicalNamespace, 'wgCanonicalSpecialPageName' => $canonicalSpecialPageName, 'wgNamespaceNumber' => $title->getNamespace(), 'wgPageName' => $title->getPrefixedDBkey(), 'wgTitle' => $title->getText(), 'wgCurRevisionId' => $curRevisionId, 'wgRevisionId' => (int) $this->getRevisionId(), 'wgArticleId' => $articleId, 'wgIsArticle' => $this->isArticle(), 'wgIsRedirect' => $title->isRedirect(), 'wgAction' => Action::getActionName($this->getContext()), 'wgUserName' => $user->isAnon() ? null : $user->getName(), 'wgUserGroups' => $user->getEffectiveGroups(), 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', 'wgPageContentLanguage' => $lang->getCode(), 'wgPageContentModel' => $title->getContentModel(), 'wgSeparatorTransformTable' => $compactSeparatorTransTable, 'wgDigitTransformTable' => $compactDigitTransTable, 'wgDefaultDateFormat' => $lang->getDefaultDateFormat(), 'wgMonthNames' => $lang->getMonthNamesArray(), 'wgMonthNamesShort' => $lang->getMonthAbbreviationsArray(), 'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey(), 'wgRelevantArticleId' => $relevantTitle->getArticleId()); if ($user->isLoggedIn()) { $vars['wgUserId'] = $user->getId(); $vars['wgUserEditCount'] = $user->getEditCount(); $userReg = wfTimestampOrNull(TS_UNIX, $user->getRegistration()); $vars['wgUserRegistration'] = $userReg !== null ? $userReg * 1000 : null; // Get the revision ID of the oldest new message on the user's talk // page. This can be used for constructing new message alerts on // the client side. $vars['wgUserNewMsgRevisionId'] = $user->getNewMessageRevisionId(); } if ($wgContLang->hasVariants()) { $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); } // Same test as SkinTemplate $vars['wgIsProbablyEditable'] = $title->quickUserCan('edit', $user) && ($title->exists() || $title->quickUserCan('create', $user)); foreach ($title->getRestrictionTypes() as $type) { $vars['wgRestriction' . ucfirst($type)] = $title->getRestrictions($type); } if ($title->isMainPage()) { $vars['wgIsMainPage'] = true; } if ($this->mRedirectedFrom) { $vars['wgRedirectedFrom'] = $this->mRedirectedFrom->getPrefixedDBkey(); } if ($relevantUser) { $vars['wgRelevantUserName'] = $relevantUser->getName(); } // Allow extensions to add their custom variables to the mw.config map. // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not // page-dependant but site-wide (without state). // Alternatively, you may want to use OutputPage->addJsConfigVars() instead. Hooks::run('MakeGlobalVariablesScript', array(&$vars, $this)); // Merge in variables from addJsConfigVars last return array_merge($vars, $this->getJsConfigVars()); }
protected function appendNamespaces($property) { global $wgContLang; $data = array(ApiResult::META_TYPE => 'assoc'); foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) { $data[$ns] = array('id' => intval($ns), 'case' => MWNamespace::isCapitalized($ns) ? 'first-letter' : 'case-sensitive'); ApiResult::setContentValue($data[$ns], 'name', $title); $canonical = MWNamespace::getCanonicalName($ns); $data[$ns]['subpages'] = MWNamespace::hasSubpages($ns); if ($canonical) { $data[$ns]['canonical'] = strtr($canonical, '_', ' '); } $data[$ns]['content'] = MWNamespace::isContent($ns); $data[$ns]['nonincludable'] = MWNamespace::isNonincludable($ns); $contentmodel = MWNamespace::getNamespaceContentModel($ns); if ($contentmodel) { $data[$ns]['defaultcontentmodel'] = $contentmodel; } } ApiResult::setIndexedTagName($data, 'ns'); return $this->getResult()->addValue('query', $property, $data); }