/** * @param ResourceLoaderContext $context * @return array */ protected function getConfigSettings($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgContLang; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } $conf = $this->getConfig(); // Build list of variables $vars = array('wgLoadScript' => wfScript('load'), 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $conf->get('StylePath'), 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $conf->get('ArticlePath'), 'wgScriptPath' => $conf->get('ScriptPath'), 'wgScriptExtension' => '.php', 'wgScript' => wfScript(), 'wgSearchType' => $conf->get('SearchType'), 'wgVariantArticlePath' => $conf->get('VariantArticlePath'), 'wgActionPaths' => (object) $conf->get('ActionPaths'), 'wgServer' => $conf->get('Server'), 'wgServerName' => $conf->get('ServerName'), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgTranslateNumerals' => $conf->get('TranslateNumerals'), 'wgVersion' => $conf->get('Version'), 'wgEnableAPI' => $conf->get('EnableAPI'), 'wgEnableWriteAPI' => $conf->get('EnableWriteAPI'), 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $conf->get('Sitename'), 'wgDBname' => $conf->get('DBname'), 'wgExtraSignatureNamespaces' => $conf->get('ExtraSignatureNamespaces'), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $conf->get('ExtensionAssetsPath'), 'wgCookiePrefix' => $conf->get('CookiePrefix'), 'wgCookieDomain' => $conf->get('CookieDomain'), 'wgCookiePath' => $conf->get('CookiePath'), 'wgCookieExpiration' => $conf->get('CookieExpiration'), 'wgResourceLoaderMaxQueryLength' => $conf->get('ResourceLoaderMaxQueryLength'), 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $conf->get('ResourceLoaderStorageVersion'), 'wgResourceLoaderStorageEnabled' => $conf->get('ResourceLoaderStorageEnabled'), 'wgResourceLoaderLegacyModules' => self::getLegacyModules(), 'wgForeignUploadTargets' => $conf->get('ForeignUploadTargets'), 'wgEnableUploads' => $conf->get('EnableUploads')); Hooks::run('ResourceLoaderGetConfigVars', array(&$vars)); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
/** * @param ResourceLoaderContext $context * @return array */ protected function getConfig($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength, $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion, $wgSearchType; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } // Build list of variables $vars = array('wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgSearchType' => $wgSearchType, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values(array_unique($wgFileExtensions)), 'wgDBname' => $wgDBname, 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $wgResourceLoaderStorageVersion, 'wgResourceLoaderStorageEnabled' => $wgResourceLoaderStorageEnabled); wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars)); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
function getQueryInfo() { $dbr = wfGetDB(DB_SLAVE); $dMsgText = wfMsgForContent('disambiguationspage'); $linkBatch = new LinkBatch(); # If the text can be treated as a title, use it verbatim. # Otherwise, pull the titles from the links table $dp = Title::newFromText($dMsgText); if ($dp) { if ($dp->getNamespace() != NS_TEMPLATE) { # @todo FIXME: We assume the disambiguation message is a template but # the page can potentially be from another namespace :/ wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n"); } $linkBatch->addObj($dp); } else { # Get all the templates linked from the Mediawiki:Disambiguationspage $disPageObj = Title::makeTitleSafe(NS_MEDIAWIKI, 'disambiguationspage'); $res = $dbr->select(array('pagelinks', 'page'), 'pl_title', array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE, 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()), __METHOD__); foreach ($res as $row) { $linkBatch->addObj(Title::makeTitle(NS_TEMPLATE, $row->pl_title)); } } $set = $linkBatch->constructSet('tl', $dbr); if ($set === false) { # We must always return a valid SQL query, but this way # the DB will always quickly return an empty result $set = 'FALSE'; wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n"); } // @todo FIXME: What are pagelinks and p2 doing here? return array('tables' => array('templatelinks', 'p1' => 'page', 'pagelinks', 'p2' => 'page'), 'fields' => array('p1.page_namespace AS namespace', 'p1.page_title AS title', 'pl_from AS value'), 'conds' => array($set, 'p1.page_id = tl_from', 'pl_namespace = p1.page_namespace', 'pl_title = p1.page_title', 'p2.page_id = pl_from', 'p2.page_namespace' => MWNamespace::getContentNamespaces())); }
function getOrderFields() { // For some crazy reason ordering by a constant // causes a filesort if ($this->requestedNamespace === false && count(MWNamespace::getContentNamespaces()) > 1) { return array('page_namespace', 'page_title'); } return array('page_title'); }
function getQueryInfo() { $query = array('tables' => array('page', 'langlinks'), 'fields' => array('namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'page_title'), 'conds' => array('ll_title IS NULL', 'page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0), 'join_conds' => array('langlinks' => array('LEFT JOIN', 'll_from = page_id'))); if ($this->prefix) { $dbr = wfGetDB(DB_SLAVE); $query['conds'][] = 'page_title ' . $dbr->buildLike($this->prefix, $dbr->anyString()); } return $query; }
function getOrderFields() { // For some crazy reason ordering by a constant // causes a filesort in MySQL 5 if (count(MWNamespace::getContentNamespaces()) > 1) { return array('page_namespace', 'page_title'); } else { return array('page_title'); } }
public function getQueryInfo() { $tables = array('page'); $conds = array('page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0); $joinConds = array(); $options = array('USE INDEX' => array('page' => 'page_redirect_namespace_len')); // Allow extensions to modify the query Hooks::run('ShortPagesQuery', array(&$tables, &$conds, &$joinConds, &$options)); return array('tables' => $tables, 'fields' => array('namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'page_len'), 'conds' => $conds, 'join_conds' => $joinConds, 'options' => $options); }
public function getQueryInfo() { $tables = ['page']; $conds = ['page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0]; $joinConds = []; $options = ['USE INDEX' => ['page' => 'page_redirect_namespace_len']]; // Allow extensions to modify the query Hooks::run('ShortPagesQuery', [&$tables, &$conds, &$joinConds, &$options]); return ['tables' => $tables, 'fields' => ['namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'page_len'], 'conds' => $conds, 'join_conds' => $joinConds, 'options' => $options]; }
/** * Note: Getting page_namespace only works if $this->isCached() is false */ function getQueryInfo() { return array('tables' => array('page', 'pagelinks'), 'fields' => array("'Withoutimages' as type", 'page_namespace as namespace', 'page_title as title', 'count(*) as value'), 'options' => array('GROUP BY' => 'page_title, page_namespace'), 'join_conds' => array('pagelinks' => array('JOIN', 'page_title = pl_title AND page_namespace = pl_namespace')), 'conds' => array('pl_from > 0', 'page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0, '( ( SELECT i1.il_to FROM imagelinks i1 WHERE 20 > ANY ( SELECT count(*) FROM imagelinks i2 WHERE i1.il_to = i2.il_to ) AND i1.il_from = page_id LIMIT 1 ) IS NULL )')); }
function getQueryInfo() { return array('tables' => array('langlinks', 'page'), 'fields' => array('namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'COUNT(*)'), 'conds' => array('page_namespace' => MWNamespace::getContentNamespaces()), 'options' => array('HAVING' => 'COUNT(*) > 1', 'GROUP BY' => array('page_namespace', 'page_title')), 'join_conds' => array('page' => array('LEFT JOIN', 'page_id = ll_from'))); }
/** * Whether the magic words __INDEX__ and __NOINDEX__ function for this page. * * @return bool */ public function canUseNoindex() { global $wgExemptFromUserRobotsControl; $bannedNamespaces = is_null($wgExemptFromUserRobotsControl) ? MWNamespace::getContentNamespaces() : $wgExemptFromUserRobotsControl; return !in_array($this->mNamespace, $bannedNamespaces); }
/** * @covers MWNamespace::getContentNamespaces */ public function testGetContentNamespaces() { global $wgContentNamespaces; $this->assertEquals(array(NS_MAIN), MWNamespace::getContentNamespaces(), '$wgContentNamespaces is an array with only NS_MAIN by default'); # test !is_array( $wgcontentNamespaces ) $wgContentNamespaces = ''; $this->assertEquals(array(NS_MAIN), MWNamespace::getContentNamespaces()); $wgContentNamespaces = false; $this->assertEquals(array(NS_MAIN), MWNamespace::getContentNamespaces()); $wgContentNamespaces = null; $this->assertEquals(array(NS_MAIN), MWNamespace::getContentNamespaces()); $wgContentNamespaces = 5; $this->assertEquals(array(NS_MAIN), MWNamespace::getContentNamespaces()); # test $wgContentNamespaces === array() $wgContentNamespaces = array(); $this->assertEquals(array(NS_MAIN), MWNamespace::getContentNamespaces()); # test !in_array( NS_MAIN, $wgContentNamespaces ) $wgContentNamespaces = array(NS_USER, NS_CATEGORY); $this->assertEquals(array(NS_MAIN, NS_USER, NS_CATEGORY), MWNamespace::getContentNamespaces(), 'NS_MAIN is forced in $wgContentNamespaces even if unwanted'); # test other cases, return $wgcontentNamespaces as is $wgContentNamespaces = array(NS_MAIN); $this->assertEquals(array(NS_MAIN), MWNamespace::getContentNamespaces()); $wgContentNamespaces = array(NS_MAIN, NS_USER, NS_CATEGORY); $this->assertEquals(array(NS_MAIN, NS_USER, NS_CATEGORY), MWNamespace::getContentNamespaces()); }
/** * Count pages in article space(s) * @return Integer */ public function articles() { global $wgArticleCountMethod; $tables = array('page'); $conds = array('page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0); if ($wgArticleCountMethod == 'link') { $tables[] = 'pagelinks'; $conds[] = 'pl_from=page_id'; } elseif ($wgArticleCountMethod == 'comma') { // To make a correct check for this, we would need, for each page, // to load the text, maybe uncompress it, maybe decode it and then // check if there's one comma. // But one thing we are sure is that if the page is empty, it can't // contain a comma :) $conds[] = 'page_len > 0'; } $this->mArticles = $this->db->selectField($tables, 'COUNT(DISTINCT page_id)', $conds, __METHOD__); return $this->mArticles; }
function getQueryInfo() { return array('tables' => array('page'), 'fields' => array('page_namespace AS namespace', 'page_title AS title', 'page_counter AS value'), 'conds' => array('page_is_redirect' => 0, 'page_namespace' => MWNamespace::getContentNamespaces())); }
function getQueryInfo() { return array('tables' => array('page', 'revision'), 'fields' => array('namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'rev_timestamp'), 'conds' => array('page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0, 'page_latest=rev_id')); }
public function getQueryInfo() { return ['tables' => ['revision', 'page'], 'fields' => ['namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'COUNT(*)', 'redirect' => 'page_is_redirect'], 'conds' => ['page_namespace' => MWNamespace::getContentNamespaces(), 'page_id = rev_page'], 'options' => ['HAVING' => 'COUNT(*) > 1', 'GROUP BY' => ['page_namespace', 'page_title', 'page_is_redirect']]]; }
public function getQueryInfo() { return ['tables' => ['page', 'revision'], 'fields' => ['namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'rev_timestamp'], 'conds' => ['page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0, 'page_latest=rev_id']]; }
function getQueryInfo() { // @todo FIXME: What are pagelinks and p2 doing here? return array('tables' => array('templatelinks', 'p1' => 'page', 'pagelinks', 'p2' => 'page'), 'fields' => array('namespace' => 'p1.page_namespace', 'title' => 'p1.page_title', 'value' => 'pl_from'), 'conds' => array($this->getQueryFromLinkBatch(), 'p1.page_id = tl_from', 'pl_namespace = p1.page_namespace', 'pl_title = p1.page_title', 'p2.page_id = pl_from', 'p2.page_namespace' => MWNamespace::getContentNamespaces())); }
function getQueryInfo() { return array('tables' => array('page'), 'fields' => array('namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'page_len'), 'conds' => array('page_namespace' => MWNamespace::getContentNamespaces(), 'page_is_redirect' => 0), 'options' => array('USE INDEX' => 'page_redirect_namespace_len')); }
/** * Returns the ID of a namespace that defaults to Wikitext. * * @throws MWException If there is none. * @return int The ID of the wikitext Namespace * @since 1.21 */ protected function getDefaultWikitextNS() { global $wgNamespaceContentModels; static $wikitextNS = null; // this is not going to change if ($wikitextNS !== null) { return $wikitextNS; } // quickly short out on most common case: if (!isset($wgNamespaceContentModels[NS_MAIN])) { return NS_MAIN; } // NOTE: prefer content namespaces $namespaces = array_unique(array_merge(MWNamespace::getContentNamespaces(), array(NS_MAIN, NS_HELP, NS_PROJECT), MWNamespace::getValidNamespaces())); $namespaces = array_diff($namespaces, array(NS_FILE, NS_CATEGORY, NS_MEDIAWIKI, NS_USER)); $talk = array_filter($namespaces, function ($ns) { return MWNamespace::isTalk($ns); }); // prefer non-talk pages $namespaces = array_diff($namespaces, $talk); $namespaces = array_merge($namespaces, $talk); // check default content model of each namespace foreach ($namespaces as $ns) { if (!isset($wgNamespaceContentModels[$ns]) || $wgNamespaceContentModels[$ns] === CONTENT_MODEL_WIKITEXT) { $wikitextNS = $ns; return $wikitextNS; } } // give up // @todo Inside a test, we could skip the test as incomplete. // But frequently, this is used in fixture setup. throw new MWException("No namespace defaults to wikitext!"); }
public function execute() { global $wgRequestTime; if (!$this->enabled) { $this->error("Nothing to do -- \$wgUseFileCache is disabled.", true); } $start = $this->getOption('start', "0"); if (!ctype_digit($start)) { $this->error("Invalid value for start parameter.", true); } $start = intval($start); $end = $this->getOption('end', "0"); if (!ctype_digit($end)) { $this->error("Invalid value for end parameter.", true); } $end = intval($end); $this->output("Building content page file cache from page {$start}!\n"); $dbr = $this->getDB(DB_REPLICA); $overwrite = $this->getOption('overwrite', false); $start = $start > 0 ? $start : $dbr->selectField('page', 'MIN(page_id)', false, __METHOD__); $end = $end > 0 ? $end : $dbr->selectField('page', 'MAX(page_id)', false, __METHOD__); if (!$start) { $this->error("Nothing to do.", true); } $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client # Do remaining chunk $end += $this->mBatchSize - 1; $blockStart = $start; $blockEnd = $start + $this->mBatchSize - 1; $dbw = $this->getDB(DB_MASTER); // Go through each page and save the output while ($blockEnd <= $end) { // Get the pages $res = $dbr->select('page', ['page_namespace', 'page_title', 'page_id'], ['page_namespace' => MWNamespace::getContentNamespaces(), "page_id BETWEEN {$blockStart} AND {$blockEnd}"], __METHOD__, ['ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY']); $this->beginTransaction($dbw, __METHOD__); // for any changes foreach ($res as $row) { $rebuilt = false; $title = Title::makeTitleSafe($row->page_namespace, $row->page_title); if (null == $title) { $this->output("Page {$row->page_id} has bad title\n"); continue; // broken title? } $context = new RequestContext(); $context->setTitle($title); $article = Article::newFromTitle($title, $context); $context->setWikiPage($article->getPage()); // If the article is cacheable, then load it if ($article->isFileCacheable(HTMLFileCache::MODE_REBUILD)) { $viewCache = new HTMLFileCache($title, 'view'); $historyCache = new HTMLFileCache($title, 'history'); if ($viewCache->isCacheGood() && $historyCache->isCacheGood()) { if ($overwrite) { $rebuilt = true; } else { $this->output("Page '{$title}' (id {$row->page_id}) already cached\n"); continue; // done already! } } MediaWiki\suppressWarnings(); // header notices // Cache ?action=view $wgRequestTime = microtime(true); # bug 22852 ob_start(); $article->view(); $context->getOutput()->output(); $context->getOutput()->clearHTML(); $viewHtml = ob_get_clean(); $viewCache->saveToFileCache($viewHtml); // Cache ?action=history $wgRequestTime = microtime(true); # bug 22852 ob_start(); Action::factory('history', $article, $context)->show(); $context->getOutput()->output(); $context->getOutput()->clearHTML(); $historyHtml = ob_get_clean(); $historyCache->saveToFileCache($historyHtml); MediaWiki\restoreWarnings(); if ($rebuilt) { $this->output("Re-cached page '{$title}' (id {$row->page_id})..."); } else { $this->output("Cached page '{$title}' (id {$row->page_id})..."); } $this->output("[view: " . strlen($viewHtml) . " bytes; " . "history: " . strlen($historyHtml) . " bytes]\n"); } else { $this->output("Page '{$title}' (id {$row->page_id}) not cacheable\n"); } } $this->commitTransaction($dbw, __METHOD__); // commit any changes (just for sanity) $blockStart += $this->mBatchSize; $blockEnd += $this->mBatchSize; } $this->output("Done!\n"); }
public function getQueryInfo() { return ['tables' => ['categorylinks', 'page'], 'fields' => ['namespace' => 'page_namespace', 'title' => 'page_title', 'value' => 'COUNT(*)'], 'conds' => ['page_namespace' => MWNamespace::getContentNamespaces()], 'options' => ['HAVING' => 'COUNT(*) > 1', 'GROUP BY' => ['page_namespace', 'page_title']], 'join_conds' => ['page' => ['LEFT JOIN', 'page_id = cl_from']]]; }
public function __construct($name = 'Randompage') { $this->namespaces = MWNamespace::getContentNamespaces(); parent::__construct($name); }
protected static function recentContentEditCount($uid, $seconds, $limit) { $dbr = wfGetDB(DB_SLAVE); # Get cutoff timestamp (edits that are too recent) $encCutoff = $dbr->addQuotes($dbr->timestamp(time() - $seconds)); # Check all recent content edits... $res = $dbr->select(array('revision', 'page'), '1', array('rev_user' => $uid, "rev_timestamp > {$encCutoff}", 'rev_page = page_id', 'page_namespace' => MWNamespace::getContentNamespaces()), __METHOD__, array('LIMIT' => $limit + 1, 'USE INDEX' => array('revision' => 'user_timestamp'))); return $dbr->numRows($res); }
function getQueryInfo() { return array('tables' => array('revision', 'page'), 'fields' => array('page_namespace AS namespace', 'page_title AS title', 'COUNT(*) AS value', 'page_is_redirect AS redirect'), 'conds' => array('page_namespace' => MWNamespace::getContentNamespaces(), 'page_id = rev_page'), 'options' => array('HAVING' => 'COUNT(*) > 1', 'GROUP BY' => 'page_namespace, page_title, page_is_redirect')); }