/** * @param int $ns The namespace to use for all pages */ public function __construct($ns) { if (!MWNamespace::exists($ns)) { throw new MWException("Namespace {$ns} doesn't exist on this wiki"); } $this->ns = $ns; }
private function checkNamespace($name, $argIdx, &$arg, $default = null) { global $wgContLang; if ($arg === null && $default !== null) { $arg = $default; } elseif (is_numeric($arg)) { $arg = (int) $arg; if (!MWNamespace::exists($arg)) { throw new Scribunto_LuaError("bad argument #{$argIdx} to '{$name}' (unrecognized namespace number '{$arg}')"); } } elseif (is_string($arg)) { $ns = $wgContLang->getNsIndex($arg); if ($ns === false) { throw new Scribunto_LuaError("bad argument #{$argIdx} to '{$name}' (unrecognized namespace name '{$arg}')"); } $arg = $ns; } else { $this->checkType($name, $argIdx, $arg, 'namespace number or name'); } }
/** * Determines which local title best corresponds to the given foreign title. * If such a title can't be found or would be locally invalid, null is * returned. * * @param ForeignTitle $foreignTitle The ForeignTitle to convert * @return Title|null */ public function createTitleFromForeignTitle(ForeignTitle $foreignTitle) { global $wgContLang; if ($foreignTitle->isNamespaceIdKnown()) { $foreignNs = $foreignTitle->getNamespaceId(); // For built-in namespaces (0 <= ID < 100), we try to find a local NS with // the same namespace ID if ($foreignNs < 100 && MWNamespace::exists($foreignNs)) { return Title::makeTitleSafe($foreignNs, $foreignTitle->getText()); } } // Do we have a local namespace by the same name as the foreign // namespace? $targetNs = $wgContLang->getNsIndex($foreignTitle->getNamespaceName()); if ($targetNs !== false) { return Title::makeTitleSafe($targetNs, $foreignTitle->getText()); } // Otherwise, just fall back to main namespace return Title::makeTitleSafe(0, $foreignTitle->getFullText()); }
public function execute() { global $wgTranslateMessageNamespaces; $namespace = $this->getOption('namespace', $wgTranslateMessageNamespaces); if (is_string($namespace)) { if (!MWNamespace::exists($namespace)) { $namespace = MWNamespace::getCanonicalIndex($namespace); if ($namespace === null) { $this->error('Bad namespace', true); } } } $db = wfGetDB(DB_MASTER); $tables = array('page', 'text', 'revision'); $fields = array('page_id', 'page_title', 'page_namespace', 'rev_id', 'old_text', 'old_flags'); $conds = array('page_latest = rev_id', 'old_id = rev_text_id', 'page_namespace' => $namespace); $limit = 100; $offset = 0; while (true) { $inserts = array(); $this->output('.', 0); $options = array('LIMIT' => $limit, 'OFFSET' => $offset); $res = $db->select($tables, $fields, $conds, __METHOD__, $options); if (!$res->numRows()) { break; } foreach ($res as $r) { $text = Revision::getRevisionText($r); if (strpos($text, TRANSLATE_FUZZY) !== false) { $inserts[] = array('rt_page' => $r->page_id, 'rt_revision' => $r->rev_id, 'rt_type' => RevTag::getType('fuzzy')); } } $offset += $limit; $db->replace('revtag', 'rt_type_page_revision', $inserts, __METHOD__); } }
/** * Set a target namespace to override the defaults * @param null|int $namespace * @return bool */ public function setTargetNamespace($namespace) { if (is_null($namespace)) { // Don't override namespaces $this->mTargetNamespace = null; $this->setImportTitleFactory(new NaiveImportTitleFactory()); return true; } elseif ($namespace >= 0 && MWNamespace::exists(intval($namespace))) { $namespace = intval($namespace); $this->mTargetNamespace = $namespace; $this->setImportTitleFactory(new NamespaceImportTitleFactory($namespace)); return true; } else { return false; } }
/** * @param object $row * @param Title $title */ protected function moveInconsistentPage($row, $title) { if ($title->exists() || $title->getInterwiki() || !$title->canExist()) { if ($title->getInterwiki() || !$title->canExist()) { $prior = $title->getPrefixedDBkey(); } else { $prior = $title->getDBkey(); } # Old cleanupTitles could move articles there. See bug 23147. $ns = $row->page_namespace; if ($ns < 0) { $ns = 0; } # Namespace which no longer exists. Put the page in the main namespace # since we don't have any idea of the old namespace name. See bug 68501. if (!MWNamespace::exists($ns)) { $ns = 0; } $clean = 'Broken/' . $prior; $verified = Title::makeTitleSafe($ns, $clean); if (!$verified || $verified->exists()) { $blah = "Broken/id:" . $row->page_id; $this->output("Couldn't legalize; form '{$clean}' exists; using '{$blah}'\n"); $verified = Title::makeTitleSafe($ns, $blah); } $title = $verified; } if (is_null($title)) { $this->error("Something awry; empty title.", true); } $ns = $title->getNamespace(); $dest = $title->getDBkey(); if ($this->dryrun) { $this->output("DRY RUN: would rename {$row->page_id} ({$row->page_namespace}," . "'{$row->page_title}') to ({$ns},'{$dest}')\n"); } else { $this->output("renaming {$row->page_id} ({$row->page_namespace}," . "'{$row->page_title}') to ({$ns},'{$dest}')\n"); $dbw = wfGetDB(DB_MASTER); $dbw->update('page', array('page_namespace' => $ns, 'page_title' => $dest), array('page_id' => $row->page_id), __METHOD__); LinkCache::singleton()->clear(); } }
/** * Get a message saying that an invalid title was encountered. * This should be called after a method like Title::makeTitleSafe() returned * a value indicating that the title object is invalid. * * @param $context IContextSource context to use to get the messages * @param $namespace int Namespace number * @param $title string Text of the title, without the namespace part */ public static function getInvalidTitleDescription(IContextSource $context, $namespace, $title) { global $wgContLang; // First we check whether the namespace exists or not. if (MWNamespace::exists($namespace)) { if ($namespace == NS_MAIN) { $name = $context->msg('blanknamespace')->text(); } else { $name = $wgContLang->getFormattedNsText($namespace); } return $context->msg('invalidtitle-knownnamespace', $namespace, $name, $title)->text(); } else { return $context->msg('invalidtitle-unknownnamespace', $namespace, $title)->text(); } }
/** * Decode the namespace URL parameter. * @param $ns String Either numeric NS number, NS name, or special value :all: * @return Mixed Integer or false Namespace number or false for no NS filtering. */ private function getNS($ns) { global $wgContLang; $nsNumb = $wgContLang->getNsIndex($ns); if ($nsNumb !== false) { // If they specified something like Talk or Image. return $nsNumb; } elseif (is_numeric($ns)) { // If they specified a number. $nsVal = intval($ns); if ($nsVal >= 0 && MWNamespace::exists($nsVal)) { return $nsVal; } else { wfDebug(__METHOD__ . ' Invalid numeric ns number. Using main.'); return 0; } } elseif ($ns === ':all:') { // Need someway to denote no namespace filtering, // This seems as good as any since a namespace can't // have colons in it. return false; } else { // Default of main only if user gives bad input. // Note, this branch is only reached on bad input. Omitting // the namespace parameter is like saying namespace=0. wfDebug(__METHOD__ . ' Invalid (non-numeric) ns. Using main.'); return 0; } }
/** * 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); }
/** * Make a <script> tag containing global variables * @param $skinName string Name of the skin * The odd calling convention is for backwards compatibility * @TODO @FIXME Make this not depend on $wgTitle! */ static function makeGlobalVariablesScript($skinName) { if (is_array($skinName)) { # Weird back-compat stuff. $skinName = $skinName['skinname']; } global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension; global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang; global $wgOut, $wgArticle; global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths; global $wgUseAjax, $wgAjaxWatch; global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI; global $wgRestrictionTypes; global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest; global $wgSitename; $ns = $wgTitle->getNamespace(); $nsname = MWNamespace::exists($ns) ? MWNamespace::getCanonicalName($ns) : $wgTitle->getNsText(); $separatorTransTable = $wgContLang->separatorTransformTable(); $separatorTransTable = $separatorTransTable ? $separatorTransTable : array(); $compactSeparatorTransTable = array(implode("\t", array_keys($separatorTransTable)), implode("\t", $separatorTransTable)); $digitTransTable = $wgContLang->digitTransformTable(); $digitTransTable = $digitTransTable ? $digitTransTable : array(); $compactDigitTransTable = array(implode("\t", array_keys($digitTransTable)), implode("\t", $digitTransTable)); $mainPage = Title::newFromText(wfMsgForContent('mainpage')); $vars = array('skin' => $skinName, 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ? SpecialPage::resolveAlias($wgTitle->getDBkey()) : false, 'wgNamespaceNumber' => $wgTitle->getNamespace(), 'wgPageName' => $wgTitle->getPrefixedDBKey(), 'wgTitle' => $wgTitle->getText(), 'wgAction' => $wgRequest->getText('action', 'view'), 'wgArticleId' => $wgTitle->getArticleId(), 'wgIsArticle' => $wgOut->isArticle(), 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(), 'wgUserGroups' => $wgUser->isAnon() ? null : $wgUser->getEffectiveGroups(), 'wgUserLanguage' => $wgLang->getCode(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgBreakFrames' => $wgBreakFrames, 'wgCurRevisionId' => isset($wgArticle) ? $wgArticle->getLatest() : 0, 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgSeparatorTransformTable' => $compactSeparatorTransTable, 'wgDigitTransformTable' => $compactDigitTransTable, 'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null, 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $wgContLang->getNamespaceIds(), 'wgSiteName' => $wgSitename, 'wgCategories' => $wgOut->getCategories()); if ($wgContLang->hasVariants()) { $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); } // if on upload page output the extension list & js_upload if (SpecialPage::resolveAlias($wgTitle->getDBkey()) == 'Upload') { global $wgFileExtensions, $wgAjaxUploadInterface; $vars['wgFileExtensions'] = $wgFileExtensions; } if ($wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption('disablesuggest', false)) { $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate(); $vars['wgDBname'] = $wgDBname; $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces($wgUser); $vars['wgMWSuggestMessages'] = array(wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled')); } foreach ($wgRestrictionTypes as $type) { $vars['wgRestriction' . ucfirst($type)] = $wgTitle->getRestrictions($type); } if ($wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn()) { $msgs = (object) array(); foreach (array('watch', 'unwatch', 'watching', 'unwatching', 'tooltip-ca-watch', 'tooltip-ca-unwatch') as $msgName) { $msgs->{$msgName . 'Msg'} = wfMsg($msgName); } $vars['wgAjaxWatch'] = $msgs; } // Allow extensions to add their custom variables to the global JS variables wfRunHooks('MakeGlobalVariablesScript', array(&$vars)); return self::makeVariablesScript($vars); }
/** * 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-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 $wgUseAjax, $wgEnableMWSuggest; $latestRevID = 0; $pageID = 0; $canonicalName = false; # bug 21115 $title = $this->getTitle(); $ns = $title->getNamespace(); $nsname = MWNamespace::exists($ns) ? MWNamespace::getCanonicalName($ns) : $title->getNsText(); // 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 = $this->getSkin()->getRelevantTitle(); if ($ns == NS_SPECIAL) { list($canonicalName, ) = SpecialPageFactory::resolveAlias($title->getDBkey()); } elseif ($this->canUseWikiPage()) { $wikiPage = $this->getWikiPage(); $latestRevID = $wikiPage->getLatest(); $pageID = $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)); $vars = array('wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => $canonicalName, 'wgNamespaceNumber' => $title->getNamespace(), 'wgPageName' => $title->getPrefixedDBKey(), 'wgTitle' => $title->getText(), 'wgCurRevisionId' => $latestRevID, 'wgArticleId' => $pageID, 'wgIsArticle' => $this->isArticle(), 'wgAction' => Action::getActionName($this->getContext()), 'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(), 'wgUserGroups' => $this->getUser()->getEffectiveGroups(), 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', 'wgPageContentLanguage' => $lang->getCode(), 'wgSeparatorTransformTable' => $compactSeparatorTransTable, 'wgDigitTransformTable' => $compactDigitTransTable, 'wgRelevantPageName' => $relevantTitle->getPrefixedDBKey()); if ($lang->hasVariants()) { $vars['wgUserVariant'] = $lang->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; } if ($this->mRedirectedFrom) { $vars['wgRedirectedFrom'] = $this->mRedirectedFrom->getPrefixedDBKey(); } // 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, $this)); // Merge in variables from addJsConfigVars last return array_merge($vars, $this->mJsConfigVars); }
public function execute($par = null) { global $wgOut, $wgRequest, $wgServer, $wgWikiFeedsSettings, $wgUser; $request = isset($par) ? $par : $wgRequest->getText('request'); if (!$request) { $wgOut->addWikiText(wfMsg('wikifeeds_mainpage')); // do special voodoo if private watchlist is enabled if ($wgWikiFeedsSettings['watchlistPrivate'] && $wgUser->isLoggedIn()) { if (!$wgUser->getOption('watchlistToken')) { $token = md5(microtime() . $wgUser->getID()); $wgUser->setOption('watchlistToken', $token); $wgUser->saveSettings(); } $token = $wgUser->getOption('watchlistToken'); $privateFeedUrl = Title::newFromText('WikiFeeds/atom/watchlist/user/' . $wgUser->getName() . '/token/' . $token, NS_SPECIAL); // and display blurb about token $wgOut->addWikiText(wfMsg('wikifeeds_tokeninfo', $token, $privateFeedUrl->getFullUrl())); } } else { $arr = explode('/', $request); //might have a valid request for a feed if (count($arr) >= 2) { $format = null; $feed = null; $count = self::DEFAULT_COUNT; $namespace = null; $params = array(); $areSane = true; if (strtolower($arr[0]) == 'atom') { $format = GenericXmlSyndicationFeed::FORMAT_ATOM10; } else { if (strtolower($arr[0]) == 'rss') { $format = GenericXmlSyndicationFeed::FORMAT_RSS20; } else { $wgOut->addWikiText(wfMsg('wikifeeds_unknownformat')); $areSane = false; } } switch (strtolower($arr[1])) { case 'newestarticles': $feed = self::FEED_NEWESTARTICLES; break; case 'recentarticlechanges': $feed = self::FEED_RECENTARTICLECHANGES; break; case 'recentuserchanges': $feed = self::FEED_RECENTUSERCHANGES; break; case 'newestuserarticles': $feed = self::FEED_NEWESTARTICLESBYUSER; break; case 'watchlist': $feed = self::FEED_USERWATCHLIST; break; case 'recentcategorychanges': $feed = self::FEED_RECENTCATEGORYCHANGES; break; case 'newestcategoryarticles': $feed = self::FEED_NEWESTCATEGORYARTICLES; break; case 'recentchangesnotincategory': $feed = self::FEED_RECENTCHANGESNOTINCATEGORY; break; case 'newestarticlesnotincategory': $feed = self::FEED_NEWESTARTICLESNOTINCATEGORY; break; default: $wgOut->addWikiText(wfMsg('wikifeeds_unknownfeed')); $areSane = false; } //now we look for additional parameters if (count($arr) > 3 && count($arr) % 2 == 0) { for ($i = 2; $i < count($arr); $i += 2) { $params[$arr[$i]] = $arr[$i + 1]; } } //if we are dealing with a category feed, we need a category specified if ($feed === self::FEED_RECENTCATEGORYCHANGES || $feed === self::FEED_NEWESTCATEGORYARTICLES || $feed === self::FEED_RECENTCHANGESNOTINCATEGORY || $feed === self::FEED_NEWESTARTICLESNOTINCATEGORY) { if (!array_key_exists('category', $params)) { $wgOut->addWikiText(wfMsg('wikifeeds_undefinedcategory')); $areSane = false; } else { //verify category is valid if (!$this->categoryExists($params['category'])) { $wgOut->addWikiText(wfMsg('wikifeeds_categorynoexist')); $areSane = false; } } } //if we are asking for a user feed, we need the user parameter if ($feed === self::FEED_RECENTUSERCHANGES || $feed === self::FEED_USERWATCHLIST || $feed === self::FEED_NEWESTARTICLESBYUSER) { if (!array_key_exists('user', $params)) { $wgOut->addWikiText(wfMsg('wikifeeds_undefineduser')); $areSane = false; } else { //verify the user exists $userId = User::idFromName($params['user']); if (is_null($userId) || $userId === 0) { $wgOut->addWikiText(wfMsg('wikifeeds_unknownuser')); $areSane = false; } else { if ($feed === self::FEED_USERWATCHLIST && $wgWikiFeedsSettings['watchlistPrivate']) { if (!array_key_exists('token', $params)) { $wgOut->addWikiText(wfMsg('wikifeeds_nowatchlisttoken')); $areSane = false; } else { $token = $params['token']; // verify token is sane $user = User::newFromId($userId); if ($token != $user->getOption('watchlistToken')) { $wgOut->addWikiText(wfMsg('wikifeeds_invalidwatchlisttoken')); $areSane = false; } } } } } } if (array_key_exists('count', $params) && ctype_digit($params['count']) && $params['count'] > 0) { $count = $params['count']; } if (array_key_exists('namespace', $params)) { $ns = $params['namespace']; if (ctype_digit($ns) && MWNamespace::exists($ns)) { // parameter is a number $namespace = $ns; } else { if (MWNamespace::exists(MWNamespace::getCanonicalIndex($ns))) { // parameter is a text $namespace = MWNamespace::getCanonicalIndex($ns); } else { if (strtolower($ns) == 'main' || $ns == '0') { // parameter is MAIN namespace (ns_id:0) $namespace = 0; } else { //namespace does not exist, show nothing $wgOut->addWikiText(wfMsg('wikifeeds_namespacenoexist')); $areSane = false; $namespace = "NULL"; } } } } if (array_key_exists('unique', $params) && $params['count'] != 'false') { $unique = true; } else { $unique = false; } //we are sane, so let's create a feed if ($areSane) { $wgOut->disable(); //if we successfully fetched a feed from the cache if ($this->_settings['cacheEnable'] && ($cached = $this->_cacheFetchFeed($feed, $format, $params))) { //$cached is an array containing feed text and some metadata header('Content-Type: ' . $cached['content-type']); print $cached['content']; } else { //no cache was hit, assemble the feed $Feed = new GenericXmlSyndicationFeed($format); switch ($feed) { case self::FEED_NEWESTARTICLES: $this->makeNewestArticles($Feed, $namespace, $count); break; case self::FEED_RECENTARTICLECHANGES: $this->makeRecentArticleChanges($Feed, $namespace, $count, $unique); break; case self::FEED_NEWESTARTICLESBYUSER: $this->makeNewestArticleByUser($Feed, $params['user'], $namespace, $count); break; case self::FEED_RECENTUSERCHANGES: $this->makeRecentUserChanges($Feed, $params['user'], $namespace, $count); break; case self::FEED_USERWATCHLIST: $this->makeUserWatchlist($Feed, $params['user'], $namespace, $count); break; case self::FEED_RECENTCATEGORYCHANGES: $this->makeRecentCategoryPageChanges($Feed, $params['category'], $namespace, $count); break; case self::FEED_NEWESTCATEGORYARTICLES: $this->makeNewestArticlesInCategory($Feed, $params['category'], $namespace, $count); break; case self::FEED_RECENTCHANGESNOTINCATEGORY: $this->makeRecentPageChangesNotInCategory($Feed, $params['category'], $namespace, $count); break; case self::FEED_NEWESTARTICLESNOTINCATEGORY: $this->makeNewestArticlesNotInCategory($Feed, $params['category'], $namespace, $count); break; default: echo 'unknown feed'; } $feedDate = 0; foreach ($Feed->items as $i) { if ($i->mArticle->mTimestamp > $feedDate) { $feedDate = $i->mArticle->mTimestamp; } } $Feed->lastUpdated = wfTimestamp(TS_UNIX, $feedDate); $Feed->linkSelf = $wgServer . $_SERVER['REQUEST_URI']; $Feed->sendOutput(); //finally, cache the feed if ($this->_settings['cacheEnable']) { $this->_cacheSaveFeed($Feed, $feed, $format, $params); } } } } } $this->setHeaders(); }
/** * initialize various variables and generate the template * * @param $out OutputPage */ function outputPage(OutputPage $out) { global $wgUser, $wgLang, $wgContLang; global $wgScript, $wgStylePath; global $wgMimeType, $wgJsMimeType, $wgRequest; global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version; global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments; global $wgArticlePath, $wgScriptPath, $wgServer; wfProfileIn(__METHOD__); Profiler::instance()->setTemplated(true); $oldid = $wgRequest->getVal('oldid'); $diff = $wgRequest->getVal('diff'); $action = $wgRequest->getVal('action', 'view'); wfProfileIn(__METHOD__ . '-init'); $this->initPage($out); $tpl = $this->setupTemplate($this->template, 'skins'); wfProfileOut(__METHOD__ . '-init'); wfProfileIn(__METHOD__ . '-stuff'); $this->thispage = $this->getTitle()->getPrefixedDBkey(); $this->userpage = $wgUser->getUserPage()->getPrefixedText(); $query = array(); if (!$wgRequest->wasPosted()) { $query = $wgRequest->getValues(); unset($query['title']); unset($query['returnto']); unset($query['returntoquery']); } $this->thisquery = wfArrayToCGI($query); $this->loggedin = $wgUser->isLoggedIn(); $this->iscontent = $this->getTitle()->getNamespace() != NS_SPECIAL; $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit')); $this->username = $wgUser->getName(); if ($wgUser->isLoggedIn() || $this->showIPinHeader()) { $this->userpageUrlDetails = self::makeUrlDetails($this->userpage); } else { # This won't be used in the standard skins, but we define it to preserve the interface # To save time, we check for existence $this->userpageUrlDetails = self::makeKnownUrlDetails($this->userpage); } $this->titletxt = $this->getTitle()->getPrefixedText(); wfProfileOut(__METHOD__ . '-stuff'); wfProfileIn(__METHOD__ . '-stuff-head'); if ($this->useHeadElement) { $pagecss = $this->setupPageCss(); if ($pagecss) { $out->addInlineStyle($pagecss); } } else { $this->setupUserCss($out); $tpl->set('pagecss', $this->setupPageCss()); $tpl->set('usercss', false); $this->userjs = $this->userjsprev = false; # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we # get rid of it? For that matter, why is any of this here at all? $this->setupUserJs($out->isUserJsAllowed()); $tpl->setRef('userjs', $this->userjs); $tpl->setRef('userjsprev', $this->userjsprev); if ($wgUseSiteJs) { $jsCache = $this->loggedin ? '&smaxage=0' : ''; $tpl->set('jsvarurl', self::makeUrl('-', "action=raw{$jsCache}&gen=js&useskin=" . urlencode($this->getSkinName()))); } else { $tpl->set('jsvarurl', false); } $tpl->setRef('xhtmldefaultnamespace', $wgXhtmlDefaultNamespace); $tpl->set('xhtmlnamespaces', $wgXhtmlNamespaces); $tpl->set('html5version', $wgHtml5Version); $tpl->set('headlinks', $out->getHeadLinks($this)); $tpl->set('csslinks', $out->buildCssLinks($this)); if ($wgUseTrackbacks && $out->isArticleRelated()) { $tpl->set('trackbackhtml', $out->getTitle()->trackbackRDF()); } else { $tpl->set('trackbackhtml', null); } } wfProfileOut(__METHOD__ . '-stuff-head'); wfProfileIn(__METHOD__ . '-stuff2'); $tpl->set('title', $out->getPageTitle()); $tpl->set('pagetitle', $out->getHTMLTitle()); $tpl->set('displaytitle', $out->mPageLinkTitle); $tpl->set('pageclass', $this->getPageClasses($this->getTitle())); $tpl->set('skinnameclass', 'skin-' . Sanitizer::escapeClass($this->getSkinName())); $nsname = MWNamespace::exists($this->getTitle()->getNamespace()) ? MWNamespace::getCanonicalName($this->getTitle()->getNamespace()) : $this->getTitle()->getNsText(); $tpl->set('nscanonical', $nsname); $tpl->set('nsnumber', $this->getTitle()->getNamespace()); $tpl->set('titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey()); $tpl->set('titletext', $this->getTitle()->getText()); $tpl->set('articleid', $this->getTitle()->getArticleId()); $tpl->set('currevisionid', $this->getTitle()->getLatestRevID()); $tpl->set('isarticle', $out->isArticle()); $tpl->setRef('thispage', $this->thispage); $subpagestr = $this->subPageSubtitle(); $tpl->set('subtitle', !empty($subpagestr) ? '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() : $out->getSubtitle()); $undelete = $this->getUndeleteLink(); $tpl->set('undelete', !empty($undelete) ? '<span class="subpages">' . $undelete . '</span>' : ''); $tpl->set('catlinks', $this->getCategories()); if ($out->isSyndicated()) { $feeds = array(); foreach ($out->getSyndicationLinks() as $format => $link) { $feeds[$format] = array('text' => wfMsg("feed-{$format}"), 'href' => $link); } $tpl->setRef('feeds', $feeds); } else { $tpl->set('feeds', false); } $tpl->setRef('mimetype', $wgMimeType); $tpl->setRef('jsmimetype', $wgJsMimeType); $tpl->set('charset', 'UTF-8'); $tpl->setRef('wgScript', $wgScript); $tpl->setRef('skinname', $this->skinname); $tpl->set('skinclass', get_class($this)); $tpl->setRef('stylename', $this->stylename); $tpl->set('printable', $out->isPrintable()); $tpl->set('handheld', $wgRequest->getBool('handheld')); $tpl->setRef('loggedin', $this->loggedin); $tpl->set('notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL); /* XXX currently unused, might get useful later $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) ); $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 ); $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' ); $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' ); $tpl->set( 'helppage', wfMsg( 'helppage' ) ); */ $tpl->set('searchaction', $this->escapeSearchLink()); $tpl->set('searchtitle', SpecialPage::getTitleFor('Search')->getPrefixedDBKey()); $tpl->set('search', trim($wgRequest->getVal('search'))); $tpl->setRef('stylepath', $wgStylePath); $tpl->setRef('articlepath', $wgArticlePath); $tpl->setRef('scriptpath', $wgScriptPath); $tpl->setRef('serverurl', $wgServer); $tpl->setRef('logopath', $wgLogo); $contentlang = $wgContLang->getCode(); $contentdir = $wgContLang->getDir(); $userlang = $wgLang->getCode(); $userdir = $wgLang->getDir(); $tpl->set('lang', $userlang); $tpl->set('dir', $userdir); $tpl->set('rtl', $wgLang->isRTL()); $tpl->set('capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : ''); $tpl->set('showjumplinks', $wgUser->getOption('showjumplinks')); $tpl->set('username', $wgUser->isAnon() ? null : $this->username); $tpl->setRef('userpage', $this->userpage); $tpl->setRef('userpageurl', $this->userpageUrlDetails['href']); $tpl->set('userlang', $userlang); // Users can have their language set differently than the // content of the wiki. For these users, tell the web browser // that interface elements are in a different language. $tpl->set('userlangattributes', ''); $tpl->set('specialpageattributes', ''); # obsolete if ($userlang !== $contentlang || $userdir !== $contentdir) { $attrs = " lang='{$userlang}' dir='{$userdir}'"; $tpl->set('userlangattributes', $attrs); } $newtalks = $this->getNewtalks($out); wfProfileOut(__METHOD__ . '-stuff2'); wfProfileIn(__METHOD__ . '-stuff3'); $tpl->setRef('newtalk', $newtalks); $tpl->setRef('skin', $this); $tpl->set('logo', $this->logoText()); if ($out->isArticle() && (!isset($oldid) || isset($diff)) && $this->getTitle()->exists()) { $article = new Article($this->getTitle(), 0); if (!$wgDisableCounters) { $viewcount = $wgLang->formatNum($article->getCount()); if ($viewcount) { $tpl->set('viewcount', wfMsgExt('viewcount', array('parseinline'), $viewcount)); } else { $tpl->set('viewcount', false); } } else { $tpl->set('viewcount', false); } if ($wgPageShowWatchingUsers) { $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('watchlist', array('COUNT(*) AS n'), array('wl_title' => $dbr->strencode($this->getTitle()->getDBkey()), 'wl_namespace' => $this->getTitle()->getNamespace()), __METHOD__); $x = $dbr->fetchObject($res); $numberofwatchingusers = $x->n; if ($numberofwatchingusers > 0) { $tpl->set('numberofwatchingusers', wfMsgExt('number_of_watching_users_pageview', array('parseinline'), $wgLang->formatNum($numberofwatchingusers))); } else { $tpl->set('numberofwatchingusers', false); } } else { $tpl->set('numberofwatchingusers', false); } $tpl->set('copyright', $this->getCopyright()); $this->credits = false; if ($wgMaxCredits != 0) { $this->credits = Action::factory('credits', $article)->getCredits($wgMaxCredits, $wgShowCreditsIfMax); } else { $tpl->set('lastmod', $this->lastModified($article)); } $tpl->setRef('credits', $this->credits); } elseif (isset($oldid) && !isset($diff)) { $tpl->set('copyright', $this->getCopyright()); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } else { $tpl->set('copyright', false); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } wfProfileOut(__METHOD__ . '-stuff3'); wfProfileIn(__METHOD__ . '-stuff4'); $tpl->set('copyrightico', $this->getCopyrightIcon()); $tpl->set('poweredbyico', $this->getPoweredBy()); $tpl->set('disclaimer', $this->disclaimerLink()); $tpl->set('privacy', $this->privacyLink()); $tpl->set('about', $this->aboutLink()); $tpl->set('footerlinks', array('info' => array('lastmod', 'viewcount', 'numberofwatchingusers', 'credits', 'copyright'), 'places' => array('privacy', 'about', 'disclaimer'))); global $wgFooterIcons; $tpl->set('footericons', $wgFooterIcons); foreach ($tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock) { if (count($footerIconsBlock) > 0) { foreach ($footerIconsBlock as &$footerIcon) { if (isset($footerIcon['src'])) { if (!isset($footerIcon['width'])) { $footerIcon['width'] = 88; } if (!isset($footerIcon['height'])) { $footerIcon['height'] = 31; } } } } else { unset($tpl->data['footericons'][$footerIconsKey]); } } if ($wgDebugComments) { $tpl->setRef('debug', $out->mDebugtext); } else { $tpl->set('debug', ''); } $tpl->set('reporttime', wfReportTime()); $tpl->set('sitenotice', $this->getSiteNotice()); $tpl->set('bottomscripts', $this->bottomScripts($out)); $tpl->set('printfooter', $this->printSource()); # Add a <div class="mw-content-ltr/rtl"> around the body text # not for special pages or file pages AND only when viewing AND if the page exists # (or is in MW namespace, because that has default content) if (!in_array($this->getTitle()->getNamespace(), array(NS_SPECIAL, NS_FILE)) && in_array($action, array('view', 'historysubmit')) && ($this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI)) { $pageLang = $this->getTitle()->getPageLanguage(); $realBodyAttribs = array('lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(), 'class' => 'mw-content-' . $pageLang->getDir()); $out->mBodytext = Html::rawElement('div', $realBodyAttribs, $out->mBodytext); } $tpl->setRef('bodytext', $out->mBodytext); # Language links $language_urls = array(); if (!$wgHideInterlanguageLinks) { foreach ($out->getLanguageLinks() as $l) { $tmp = explode(':', $l, 2); $class = 'interwiki-' . $tmp[0]; unset($tmp); $nt = Title::newFromText($l); if ($nt) { $language_urls[] = array('href' => $nt->getFullURL(), 'text' => $wgContLang->getLanguageName($nt->getInterwiki()) != '' ? $wgContLang->getLanguageName($nt->getInterwiki()) : $l, 'title' => $nt->getText(), 'class' => $class, 'lang' => $nt->getInterwiki(), 'hreflang' => $nt->getInterwiki()); } } } if (count($language_urls)) { $tpl->setRef('language_urls', $language_urls); } else { $tpl->set('language_urls', false); } wfProfileOut(__METHOD__ . '-stuff4'); wfProfileIn(__METHOD__ . '-stuff5'); # Personal toolbar $tpl->set('personal_urls', $this->buildPersonalUrls($out)); $content_navigation = $this->buildContentNavigationUrls($out); $content_actions = $this->buildContentActionUrls($content_navigation); $tpl->setRef('content_navigation', $content_navigation); $tpl->setRef('content_actions', $content_actions); $tpl->set('sidebar', $this->buildSidebar()); $tpl->set('nav_urls', $this->buildNavUrls($out)); // Set the head scripts near the end, in case the above actions resulted in added scripts if ($this->useHeadElement) { $tpl->set('headelement', $out->headElement($this)); } else { $tpl->set('headscripts', $out->getScript()); } $tpl->set('debughtml', $this->generateDebugHTML()); // original version by hansm if (!wfRunHooks('SkinTemplateOutputPageBeforeExec', array(&$this, &$tpl))) { wfDebug(__METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n"); } // Set the bodytext to another key so that skins can just output it on it's own // and output printfooter and debughtml separately $tpl->set('bodycontent', $tpl->data['bodytext']); // Append printfooter and debughtml onto bodytext so that skins that were already // using bodytext before they were split out don't suddenly start not outputting information $tpl->data['bodytext'] .= Html::rawElement('div', array('class' => 'printfooter'), "\n{$tpl->data['printfooter']}") . "\n"; $tpl->data['bodytext'] .= $tpl->data['debughtml']; // allow extensions adding stuff after the page content. // See Skin::afterContentHook() for further documentation. $tpl->set('dataAfterContent', $this->afterContentHook()); wfProfileOut(__METHOD__ . '-stuff5'); // execute template wfProfileIn(__METHOD__ . '-execute'); $res = $tpl->execute(); wfProfileOut(__METHOD__ . '-execute'); // result may be an error $this->printOrError($res); wfProfileOut(__METHOD__); }
/** * initialize various variables and generate the template * * @param $out OutputPage */ function outputPage(OutputPage $out) { global $wgArticle, $wgUser, $wgLang, $wgContLang; global $wgScript, $wgStylePath, $wgContLanguageCode; global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest; global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version; global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments; global $wgArticlePath, $wgScriptPath, $wgServer; wfProfileIn(__METHOD__); $oldid = $wgRequest->getVal('oldid'); $diff = $wgRequest->getVal('diff'); $action = $wgRequest->getVal('action', 'view'); wfProfileIn(__METHOD__ . '-init'); $this->initPage($out); $this->setMembers(); $tpl = $this->setupTemplate($this->template, 'skins'); #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText $tpl->setTranslator(new MediaWiki_I18N()); #} wfProfileOut(__METHOD__ . '-init'); wfProfileIn(__METHOD__ . '-stuff'); $this->thispage = $this->mTitle->getPrefixedDBkey(); $this->thisurl = $this->mTitle->getPrefixedURL(); $query = array(); if (!$wgRequest->wasPosted()) { $query = $wgRequest->getValues(); unset($query['title']); unset($query['returnto']); unset($query['returntoquery']); } $this->thisquery = wfUrlencode(wfArrayToCGI($query)); $this->loggedin = $wgUser->isLoggedIn(); $this->iscontent = $this->mTitle->getNamespace() != NS_SPECIAL; $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit')); $this->username = $wgUser->getName(); if ($wgUser->isLoggedIn() || $this->showIPinHeader()) { $this->userpageUrlDetails = self::makeUrlDetails($this->userpage); } else { # This won't be used in the standard skins, but we define it to preserve the interface # To save time, we check for existence $this->userpageUrlDetails = self::makeKnownUrlDetails($this->userpage); } $this->titletxt = $this->mTitle->getPrefixedText(); wfProfileOut(__METHOD__ . '-stuff'); wfProfileIn(__METHOD__ . '-stuff-head'); if ($this->useHeadElement) { $pagecss = $this->setupPageCss(); if ($pagecss) { $out->addInlineStyle($pagecss); } } else { $this->setupUserCss($out); $tpl->set('pagecss', $this->setupPageCss()); $tpl->setRef('usercss', $this->usercss); $this->userjs = $this->userjsprev = false; $this->setupUserJs($out->isUserJsAllowed()); $tpl->setRef('userjs', $this->userjs); $tpl->setRef('userjsprev', $this->userjsprev); if ($wgUseSiteJs) { $jsCache = $this->loggedin ? '&smaxage=0' : ''; $tpl->set('jsvarurl', self::makeUrl('-', "action=raw{$jsCache}&gen=js&useskin=" . urlencode($this->getSkinName()))); } else { $tpl->set('jsvarurl', false); } $tpl->setRef('xhtmldefaultnamespace', $wgXhtmlDefaultNamespace); $tpl->set('xhtmlnamespaces', $wgXhtmlNamespaces); $tpl->set('html5version', $wgHtml5Version); $tpl->set('headlinks', $out->getHeadLinks()); $tpl->set('csslinks', $out->buildCssLinks()); if ($wgUseTrackbacks && $out->isArticleRelated()) { $tpl->set('trackbackhtml', $out->getTitle()->trackbackRDF()); } else { $tpl->set('trackbackhtml', null); } } wfProfileOut(__METHOD__ . '-stuff-head'); wfProfileIn(__METHOD__ . '-stuff2'); $tpl->set('title', $out->getPageTitle()); $tpl->set('pagetitle', $out->getHTMLTitle()); $tpl->set('displaytitle', $out->mPageLinkTitle); $tpl->set('pageclass', $this->getPageClasses($this->mTitle)); $tpl->set('skinnameclass', 'skin-' . Sanitizer::escapeClass($this->getSkinName())); $nsname = MWNamespace::exists($this->mTitle->getNamespace()) ? MWNamespace::getCanonicalName($this->mTitle->getNamespace()) : $this->mTitle->getNsText(); $tpl->set('nscanonical', $nsname); $tpl->set('nsnumber', $this->mTitle->getNamespace()); $tpl->set('titleprefixeddbkey', $this->mTitle->getPrefixedDBKey()); $tpl->set('titletext', $this->mTitle->getText()); $tpl->set('articleid', $this->mTitle->getArticleId()); $tpl->set('currevisionid', isset($wgArticle) ? $wgArticle->getLatest() : 0); $tpl->set('isarticle', $out->isArticle()); $tpl->setRef('thispage', $this->thispage); $subpagestr = $this->subPageSubtitle(); $tpl->set('subtitle', !empty($subpagestr) ? '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() : $out->getSubtitle()); $undelete = $this->getUndeleteLink(); $tpl->set('undelete', !empty($undelete) ? '<span class="subpages">' . $undelete . '</span>' : ''); $tpl->set('catlinks', $this->getCategories()); if ($out->isSyndicated()) { $feeds = array(); foreach ($out->getSyndicationLinks() as $format => $link) { $feeds[$format] = array('text' => wfMsg("feed-{$format}"), 'href' => $link); } $tpl->setRef('feeds', $feeds); } else { $tpl->set('feeds', false); } $tpl->setRef('mimetype', $wgMimeType); $tpl->setRef('jsmimetype', $wgJsMimeType); $tpl->setRef('charset', $wgOutputEncoding); $tpl->setRef('wgScript', $wgScript); $tpl->setRef('skinname', $this->skinname); $tpl->set('skinclass', get_class($this)); $tpl->setRef('stylename', $this->stylename); $tpl->set('printable', $out->isPrintable()); $tpl->set('handheld', $wgRequest->getBool('handheld')); $tpl->setRef('loggedin', $this->loggedin); $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL); /* XXX currently unused, might get useful later $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) ); $tpl->set( "exists", $this->mTitle->getArticleID() != 0 ); $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" ); $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" ); $tpl->set( "helppage", wfMsg('helppage')); */ $tpl->set('searchaction', $this->escapeSearchLink()); $tpl->set('searchtitle', SpecialPage::getTitleFor('Search')->getPrefixedDBKey()); $tpl->set('search', trim($wgRequest->getVal('search'))); $tpl->setRef('stylepath', $wgStylePath); $tpl->setRef('articlepath', $wgArticlePath); $tpl->setRef('scriptpath', $wgScriptPath); $tpl->setRef('serverurl', $wgServer); $tpl->setRef('logopath', $wgLogo); $tpl->setRef('lang', $wgContLanguageCode); $tpl->set('dir', $wgContLang->getDir()); $tpl->set('rtl', $wgContLang->isRTL()); $tpl->set('capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : ''); $tpl->set('langname', $wgContLang->getLanguageName($wgContLanguageCode)); $tpl->set('showjumplinks', $wgUser->getOption('showjumplinks')); $tpl->set('username', $wgUser->isAnon() ? null : $this->username); $tpl->setRef('userpage', $this->userpage); $tpl->setRef('userpageurl', $this->userpageUrlDetails['href']); $tpl->set('userlang', $wgLang->getCode()); // Users can have their language set differently than the // content of the wiki. For these users, tell the web browser // that interface elements are in a different language. $tpl->set('userlangattributes', ''); $tpl->set('specialpageattributes', ''); $lang = $wgLang->getCode(); $dir = $wgLang->getDir(); if ($lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir()) { $attrs = " lang='{$lang}' dir='{$dir}'"; $tpl->set('userlangattributes', $attrs); // The content of SpecialPages should be presented in the // user's language. Content of regular pages should not be touched. if ($this->mTitle->isSpecialPage()) { $tpl->set('specialpageattributes', $attrs); } } $newtalks = $wgUser->getNewMessageLinks(); $ntl = ''; if (count($newtalks) == 1 && $newtalks[0]['wiki'] === wfWikiID()) { $usertitle = $this->mUser->getUserPage(); $usertalktitle = $usertitle->getTalkPage(); if (!$usertalktitle->equals($this->mTitle)) { $newmessageslink = $this->link($usertalktitle, wfMsgHtml('newmessageslink'), array(), array('redirect' => 'no'), array('known', 'noclasses')); $newmessagesdifflink = $this->link($usertalktitle, wfMsgHtml('newmessagesdifflink'), array(), array('diff' => 'cur'), array('known', 'noclasses')); $ntl = wfMsg('youhavenewmessages', $newmessageslink, $newmessagesdifflink); # Disable Cache $out->setSquidMaxage(0); } } else { if (count($newtalks)) { // _>" " for BC <= 1.16 $sep = str_replace('_', ' ', wfMsgHtml('newtalkseparator')); $msgs = array(); foreach ($newtalks as $newtalk) { $msgs[] = Xml::element('a', array('href' => $newtalk['link']), $newtalk['wiki']); } $parts = implode($sep, $msgs); $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts); $out->setSquidMaxage(0); } } wfProfileOut(__METHOD__ . '-stuff2'); wfProfileIn(__METHOD__ . '-stuff3'); $tpl->setRef('newtalk', $ntl); $tpl->setRef('skin', $this); $tpl->set('logo', $this->logoText()); if ($out->isArticle() and (!isset($oldid) or isset($diff)) and $wgArticle and 0 != $wgArticle->getID()) { if (!$wgDisableCounters) { $viewcount = $wgLang->formatNum($wgArticle->getCount()); if ($viewcount) { $tpl->set('viewcount', wfMsgExt('viewcount', array('parseinline'), $viewcount)); } else { $tpl->set('viewcount', false); } } else { $tpl->set('viewcount', false); } if ($wgPageShowWatchingUsers) { $dbr = wfGetDB(DB_SLAVE); $watchlist = $dbr->tableName('watchlist'); $res = $dbr->select('watchlist', array('COUNT(*) AS n'), array('wl_title' => $dbr->strencode($this->mTitle->getDBkey()), 'wl_namespace' => $this->mTitle->getNamespace()), __METHOD__); $x = $dbr->fetchObject($res); $numberofwatchingusers = $x->n; if ($numberofwatchingusers > 0) { $tpl->set('numberofwatchingusers', wfMsgExt('number_of_watching_users_pageview', array('parseinline'), $wgLang->formatNum($numberofwatchingusers))); } else { $tpl->set('numberofwatchingusers', false); } } else { $tpl->set('numberofwatchingusers', false); } $tpl->set('copyright', $this->getCopyright()); $this->credits = false; if ($wgMaxCredits != 0) { $this->credits = Credits::getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax); } else { $tpl->set('lastmod', $this->lastModified()); } $tpl->setRef('credits', $this->credits); } elseif (isset($oldid) && !isset($diff)) { $tpl->set('copyright', $this->getCopyright()); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } else { $tpl->set('copyright', false); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } wfProfileOut(__METHOD__ . '-stuff3'); wfProfileIn(__METHOD__ . '-stuff4'); $tpl->set('copyrightico', $this->getCopyrightIcon()); $tpl->set('poweredbyico', $this->getPoweredBy()); $tpl->set('disclaimer', $this->disclaimerLink()); $tpl->set('privacy', $this->privacyLink()); $tpl->set('about', $this->aboutLink()); if ($wgDebugComments) { $tpl->setRef('debug', $out->mDebugtext); } else { $tpl->set('debug', ''); } $tpl->set('reporttime', wfReportTime()); $tpl->set('sitenotice', wfGetSiteNotice()); $tpl->set('bottomscripts', $this->bottomScripts()); $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n"; $out->mBodytext .= $printfooter . $this->generateDebugHTML(); $tpl->setRef('bodytext', $out->mBodytext); # Language links $language_urls = array(); if (!$wgHideInterlanguageLinks) { foreach ($out->getLanguageLinks() as $l) { $tmp = explode(':', $l, 2); $class = 'interwiki-' . $tmp[0]; unset($tmp); $nt = Title::newFromText($l); if ($nt) { $language_urls[] = array('href' => $nt->getFullURL(), 'text' => $wgContLang->getLanguageName($nt->getInterwiki()) != '' ? $wgContLang->getLanguageName($nt->getInterwiki()) : $l, 'class' => $class); } } } if (count($language_urls)) { $tpl->setRef('language_urls', $language_urls); } else { $tpl->set('language_urls', false); } wfProfileOut(__METHOD__ . '-stuff4'); wfProfileIn(__METHOD__ . '-stuff5'); # Personal toolbar $tpl->set('personal_urls', $this->buildPersonalUrls()); $content_actions = $this->buildContentActionUrls(); $tpl->setRef('content_actions', $content_actions); $tpl->set('sidebar', $this->buildSidebar()); $tpl->set('nav_urls', $this->buildNavUrls()); // Set the head scripts near the end, in case the above actions resulted in added scripts if ($this->useHeadElement) { $tpl->set('headelement', $out->headElement($this)); } else { $tpl->set('headscripts', $out->getScript()); } // original version by hansm if (!wfRunHooks('SkinTemplateOutputPageBeforeExec', array(&$this, &$tpl))) { wfDebug(__METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n"); } // allow extensions adding stuff after the page content. // See Skin::afterContentHook() for further documentation. $tpl->set('dataAfterContent', $this->afterContentHook()); wfProfileOut(__METHOD__ . '-stuff5'); // execute template wfProfileIn(__METHOD__ . '-execute'); $res = $tpl->execute(); wfProfileOut(__METHOD__ . '-execute'); // result may be an error $this->printOrError($res); wfProfileOut(__METHOD__); }
/** * @brief Parse a namespace specification. * * @param int|string $param Namespace name or namespace index. * @return int Namespace index. * @throws Scribunto_LuaError */ public function parseNamespace($param) { if (is_numeric($param)) { /** A numeric parameter (including a numeric literal) is * interpreted as a namespace index. */ $index = intval($param); if (!MWNamespace::exists($index)) { throw new Scribunto_LuaError(wfMessage('dple-error-invalid-ns-index', $index)->text()); } return $index; } global $wgContLang; $index = $wgContLang->getNsIndex($param); if ($index === false) { return 0; } return $index; }
/** * 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; }
/** * 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()); }
/** * Make a <script> tag containing global variables * @param $skinName string Name of the skin * The odd calling convention is for backwards compatibility * @todo FIXME: Make this not depend on $wgTitle! * * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state. * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes. */ static function makeGlobalVariablesScript($skinName) { global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgUseAjax, $wgEnableMWSuggest; $ns = $wgTitle->getNamespace(); $nsname = MWNamespace::exists($ns) ? MWNamespace::getCanonicalName($ns) : $wgTitle->getNsText(); $vars = array('wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ? SpecialPage::resolveAlias($wgTitle->getDBkey()) : false, 'wgNamespaceNumber' => $wgTitle->getNamespace(), 'wgPageName' => $wgTitle->getPrefixedDBKey(), 'wgTitle' => $wgTitle->getText(), 'wgAction' => $wgRequest->getText('action', 'view'), 'wgArticleId' => $wgTitle->getArticleId(), 'wgIsArticle' => $wgOut->isArticle(), 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(), 'wgUserGroups' => $wgUser->getEffectiveGroups(), 'wgCurRevisionId' => isset($wgArticle) ? $wgArticle->getLatest() : 0, 'wgCategories' => $wgOut->getCategories(), 'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY'); foreach ($wgTitle->getRestrictionTypes() as $type) { $vars['wgRestriction' . ucfirst($type)] = $wgTitle->getRestrictions($type); } if ($wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption('disablesuggest', false)) { $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces($wgUser); } // Allow extensions to add their custom variables to the global JS variables wfRunHooks('MakeGlobalVariablesScript', array(&$vars)); return self::makeVariablesScript($vars); }