static function admins() { if (!isset(self::$admins)) { $dbr =& wfGetDB(DB_SLAVE); self::$admins = $dbr->selectField('user_groups', 'COUNT(*)', array('ug_group' => 'sysop'), __METHOD__); } return self::$admins; }
/** * Show the special page * * @param mixed $par (not used) */ function wfSpecialStatistics($par = '') { global $wgOut, $wgLang, $wgRequest; $dbr = wfGetDB(DB_SLAVE); $views = SiteStats::views(); $edits = SiteStats::edits(); $good = SiteStats::articles(); $images = SiteStats::images(); $total = SiteStats::pages(); $users = SiteStats::users(); $admins = SiteStats::admins(); $numJobs = SiteStats::jobs(); if ($wgRequest->getVal('action') == 'raw') { $wgOut->disable(); header('Pragma: nocache'); echo "total={$total};good={$good};views={$views};edits={$edits};users={$users};admins={$admins};images={$images};jobs={$numJobs}\n"; return; } else { $text = "__NOTOC__\n"; $text .= '==' . wfMsg('sitestats') . "==\n"; $text .= wfMsgExt('sitestatstext', array('parsemag'), $wgLang->formatNum($total), $wgLang->formatNum($good), $wgLang->formatNum($views), $wgLang->formatNum($edits), $wgLang->formatNum(sprintf('%.2f', $total ? $edits / $total : 0)), $wgLang->formatNum(sprintf('%.2f', $edits ? $views / $edits : 0)), $wgLang->formatNum($numJobs), $wgLang->formatNum($images)) . "\n"; $text .= "==" . wfMsg('userstats') . "==\n"; $text .= wfMsgExt('userstatstext', array('parsemag'), $wgLang->formatNum($users), $wgLang->formatNum($admins), '[[' . wfMsgForContent('grouppage-sysop') . ']]', $wgLang->formatNum(sprintf('%.2f', $admins / $users * 100)), User::makeGroupLinkWiki('sysop')) . "\n"; global $wgDisableCounters, $wgMiserMode, $wgUser, $wgLang, $wgContLang; if (!$wgDisableCounters && !$wgMiserMode) { $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_counter'), array('page_is_redirect' => 0, 'page_counter > 0'), __METHOD__, array('ORDER BY' => 'page_counter DESC', 'LIMIT' => 10)); if ($res->numRows() > 0) { $text .= "==" . wfMsg('statistics-mostpopular') . "==\n"; while ($row = $res->fetchObject()) { $title = Title::makeTitleSafe($row->page_namespace, $row->page_title); if ($title instanceof Title) { $text .= '* [[:' . $title->getPrefixedText() . ']] (' . $wgLang->formatNum($row->page_counter) . ")\n"; } } $res->free(); } } $footer = wfMsg('statistics-footer'); if (!wfEmptyMsg('statistics-footer', $footer) && $footer != '') { $text .= "\n" . $footer; } $wgOut->addWikiText($text); } }
protected function appendStatistics($property) { $data = array(); $data['pages'] = intval(SiteStats::pages()); $data['articles'] = intval(SiteStats::articles()); $data['views'] = intval(SiteStats::views()); $data['edits'] = intval(SiteStats::edits()); $data['images'] = intval(SiteStats::images()); $data['users'] = intval(SiteStats::users()); $data['admins'] = intval(SiteStats::admins()); $data['jobs'] = intval(SiteStats::jobs()); $this->getResult()->addValue('query', $property, $data); }
/** * Return value of a magic variable (like PAGENAME) * * @private */ function getVariableValue($index) { global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath; /** * Some of these require message or data lookups and can be * expensive to check many times. */ if (wfRunHooks('ParserGetVariableValueVarCache', array(&$this, &$this->mVarCache))) { if (isset($this->mVarCache[$index])) { return $this->mVarCache[$index]; } } $ts = wfTimestamp(TS_UNIX, $this->mOptions->getTimestamp()); wfRunHooks('ParserGetVariableValueTs', array(&$this, &$ts)); # Use the time zone global $wgLocaltimezone; if (isset($wgLocaltimezone)) { $oldtz = getenv('TZ'); putenv('TZ=' . $wgLocaltimezone); } wfSuppressWarnings(); // E_STRICT system time bitching $localTimestamp = date('YmdHis', $ts); $localMonth = date('m', $ts); $localMonthName = date('n', $ts); $localDay = date('j', $ts); $localDay2 = date('d', $ts); $localDayOfWeek = date('w', $ts); $localWeek = date('W', $ts); $localYear = date('Y', $ts); $localHour = date('H', $ts); if (isset($wgLocaltimezone)) { putenv('TZ=' . $oldtz); } wfRestoreWarnings(); switch ($index) { case 'currentmonth': return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('m', $ts)); case 'currentmonthname': return $this->mVarCache[$index] = $wgContLang->getMonthName(gmdate('n', $ts)); case 'currentmonthnamegen': return $this->mVarCache[$index] = $wgContLang->getMonthNameGen(gmdate('n', $ts)); case 'currentmonthabbrev': return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation(gmdate('n', $ts)); case 'currentday': return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('j', $ts)); case 'currentday2': return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('d', $ts)); case 'localmonth': return $this->mVarCache[$index] = $wgContLang->formatNum($localMonth); case 'localmonthname': return $this->mVarCache[$index] = $wgContLang->getMonthName($localMonthName); case 'localmonthnamegen': return $this->mVarCache[$index] = $wgContLang->getMonthNameGen($localMonthName); case 'localmonthabbrev': return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation($localMonthName); case 'localday': return $this->mVarCache[$index] = $wgContLang->formatNum($localDay); case 'localday2': return $this->mVarCache[$index] = $wgContLang->formatNum($localDay2); case 'pagename': return wfEscapeWikiText($this->mTitle->getText()); case 'pagenamee': return $this->mTitle->getPartialURL(); case 'fullpagename': return wfEscapeWikiText($this->mTitle->getPrefixedText()); case 'fullpagenamee': return $this->mTitle->getPrefixedURL(); case 'subpagename': return wfEscapeWikiText($this->mTitle->getSubpageText()); case 'subpagenamee': return $this->mTitle->getSubpageUrlForm(); case 'basepagename': return wfEscapeWikiText($this->mTitle->getBaseText()); case 'basepagenamee': return wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText())); case 'talkpagename': if ($this->mTitle->canTalk()) { $talkPage = $this->mTitle->getTalkPage(); return wfEscapeWikiText($talkPage->getPrefixedText()); } else { return ''; } case 'talkpagenamee': if ($this->mTitle->canTalk()) { $talkPage = $this->mTitle->getTalkPage(); return $talkPage->getPrefixedUrl(); } else { return ''; } case 'subjectpagename': $subjPage = $this->mTitle->getSubjectPage(); return wfEscapeWikiText($subjPage->getPrefixedText()); case 'subjectpagenamee': $subjPage = $this->mTitle->getSubjectPage(); return $subjPage->getPrefixedUrl(); case 'revisionid': // Let the edit saving system know we should parse the page // *after* a revision ID has been assigned. $this->mOutput->setFlag('vary-revision'); wfDebug(__METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n"); return $this->mRevisionId; case 'revisionday': // Let the edit saving system know we should parse the page // *after* a revision ID has been assigned. This is for null edits. $this->mOutput->setFlag('vary-revision'); wfDebug(__METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n"); return intval(substr($this->getRevisionTimestamp(), 6, 2)); case 'revisionday2': // Let the edit saving system know we should parse the page // *after* a revision ID has been assigned. This is for null edits. $this->mOutput->setFlag('vary-revision'); wfDebug(__METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n"); return substr($this->getRevisionTimestamp(), 6, 2); case 'revisionmonth': // Let the edit saving system know we should parse the page // *after* a revision ID has been assigned. This is for null edits. $this->mOutput->setFlag('vary-revision'); wfDebug(__METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n"); return intval(substr($this->getRevisionTimestamp(), 4, 2)); case 'revisionyear': // Let the edit saving system know we should parse the page // *after* a revision ID has been assigned. This is for null edits. $this->mOutput->setFlag('vary-revision'); wfDebug(__METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n"); return substr($this->getRevisionTimestamp(), 0, 4); case 'revisiontimestamp': // Let the edit saving system know we should parse the page // *after* a revision ID has been assigned. This is for null edits. $this->mOutput->setFlag('vary-revision'); wfDebug(__METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n"); return $this->getRevisionTimestamp(); case 'namespace': return str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace())); case 'namespacee': return wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace())); case 'talkspace': return $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : ''; case 'talkspacee': return $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : ''; case 'subjectspace': return $this->mTitle->getSubjectNsText(); case 'subjectspacee': return wfUrlencode($this->mTitle->getSubjectNsText()); case 'currentdayname': return $this->mVarCache[$index] = $wgContLang->getWeekdayName(gmdate('w', $ts) + 1); case 'currentyear': return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('Y', $ts), true); case 'currenttime': return $this->mVarCache[$index] = $wgContLang->time(wfTimestamp(TS_MW, $ts), false, false); case 'currenthour': return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('H', $ts), true); case 'currentweek': // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to // int to remove the padding return $this->mVarCache[$index] = $wgContLang->formatNum((int) gmdate('W', $ts)); case 'currentdow': return $this->mVarCache[$index] = $wgContLang->formatNum(gmdate('w', $ts)); case 'localdayname': return $this->mVarCache[$index] = $wgContLang->getWeekdayName($localDayOfWeek + 1); case 'localyear': return $this->mVarCache[$index] = $wgContLang->formatNum($localYear, true); case 'localtime': return $this->mVarCache[$index] = $wgContLang->time($localTimestamp, false, false); case 'localhour': return $this->mVarCache[$index] = $wgContLang->formatNum($localHour, true); case 'localweek': // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to // int to remove the padding return $this->mVarCache[$index] = $wgContLang->formatNum((int) $localWeek); case 'localdow': return $this->mVarCache[$index] = $wgContLang->formatNum($localDayOfWeek); case 'numberofarticles': return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::articles()); case 'numberoffiles': return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::images()); case 'numberofusers': return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::users()); case 'numberofpages': return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::pages()); case 'numberofadmins': return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::admins()); case 'numberofedits': return $this->mVarCache[$index] = $wgContLang->formatNum(SiteStats::edits()); case 'currenttimestamp': return $this->mVarCache[$index] = wfTimestamp(TS_MW, $ts); case 'localtimestamp': return $this->mVarCache[$index] = $localTimestamp; case 'currentversion': return $this->mVarCache[$index] = SpecialVersion::getVersion(); case 'sitename': return $wgSitename; case 'server': return $wgServer; case 'servername': return $wgServerName; case 'scriptpath': return $wgScriptPath; case 'directionmark': return $wgContLang->getDirMark(); case 'contentlanguage': global $wgContLanguageCode; return $wgContLanguageCode; default: $ret = null; if (wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$this->mVarCache, &$index, &$ret))) { return $ret; } else { return null; } } }
/** * Return value of a magic variable (like PAGENAME) * * @private */ function getVariableValue($index) { global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath; /** * Some of these require message or data lookups and can be * expensive to check many times. */ static $varCache = array(); if (wfRunHooks('ParserGetVariableValueVarCache', array(&$this, &$varCache))) { if (isset($varCache[$index])) { return $varCache[$index]; } } $ts = time(); wfRunHooks('ParserGetVariableValueTs', array(&$this, &$ts)); # Use the time zone global $wgLocaltimezone; if (isset($wgLocaltimezone)) { $oldtz = getenv('TZ'); putenv('TZ=' . $wgLocaltimezone); } $localTimestamp = date('YmdHis', $ts); $localMonth = date('m', $ts); $localMonthName = date('n', $ts); $localDay = date('j', $ts); $localDay2 = date('d', $ts); $localDayOfWeek = date('w', $ts); $localWeek = date('W', $ts); $localYear = date('Y', $ts); $localHour = date('H', $ts); if (isset($wgLocaltimezone)) { putenv('TZ=' . $oldtz); } switch ($index) { case 'currentmonth': return $varCache[$index] = $wgContLang->formatNum(date('m', $ts)); case 'currentmonthname': return $varCache[$index] = $wgContLang->getMonthName(date('n', $ts)); case 'currentmonthnamegen': return $varCache[$index] = $wgContLang->getMonthNameGen(date('n', $ts)); case 'currentmonthabbrev': return $varCache[$index] = $wgContLang->getMonthAbbreviation(date('n', $ts)); case 'currentday': return $varCache[$index] = $wgContLang->formatNum(date('j', $ts)); case 'currentday2': return $varCache[$index] = $wgContLang->formatNum(date('d', $ts)); case 'localmonth': return $varCache[$index] = $wgContLang->formatNum($localMonth); case 'localmonthname': return $varCache[$index] = $wgContLang->getMonthName($localMonthName); case 'localmonthnamegen': return $varCache[$index] = $wgContLang->getMonthNameGen($localMonthName); case 'localmonthabbrev': return $varCache[$index] = $wgContLang->getMonthAbbreviation($localMonthName); case 'localday': return $varCache[$index] = $wgContLang->formatNum($localDay); case 'localday2': return $varCache[$index] = $wgContLang->formatNum($localDay2); case 'pagename': return $this->mTitle->getText(); case 'pagenamee': return $this->mTitle->getPartialURL(); case 'fullpagename': return $this->mTitle->getPrefixedText(); case 'fullpagenamee': return $this->mTitle->getPrefixedURL(); case 'subpagename': return $this->mTitle->getSubpageText(); case 'subpagenamee': return $this->mTitle->getSubpageUrlForm(); case 'basepagename': return $this->mTitle->getBaseText(); case 'basepagenamee': return wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText())); case 'talkpagename': if ($this->mTitle->canTalk()) { $talkPage = $this->mTitle->getTalkPage(); return $talkPage->getPrefixedText(); } else { return ''; } case 'talkpagenamee': if ($this->mTitle->canTalk()) { $talkPage = $this->mTitle->getTalkPage(); return $talkPage->getPrefixedUrl(); } else { return ''; } case 'subjectpagename': $subjPage = $this->mTitle->getSubjectPage(); return $subjPage->getPrefixedText(); case 'subjectpagenamee': $subjPage = $this->mTitle->getSubjectPage(); return $subjPage->getPrefixedUrl(); case 'revisionid': return $this->mRevisionId; case 'revisionday': return intval(substr($this->getRevisionTimestamp(), 6, 2)); case 'revisionday2': return substr($this->getRevisionTimestamp(), 6, 2); case 'revisionmonth': return intval(substr($this->getRevisionTimestamp(), 4, 2)); case 'revisionyear': return substr($this->getRevisionTimestamp(), 0, 4); case 'revisiontimestamp': return $this->getRevisionTimestamp(); case 'namespace': return str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace())); case 'namespacee': return wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace())); case 'talkspace': return $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : ''; case 'talkspacee': return $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : ''; case 'subjectspace': return $this->mTitle->getSubjectNsText(); case 'subjectspacee': return wfUrlencode($this->mTitle->getSubjectNsText()); case 'currentdayname': return $varCache[$index] = $wgContLang->getWeekdayName(date('w', $ts) + 1); case 'currentyear': return $varCache[$index] = $wgContLang->formatNum(date('Y', $ts), true); case 'currenttime': return $varCache[$index] = $wgContLang->time(wfTimestamp(TS_MW, $ts), false, false); case 'currenthour': return $varCache[$index] = $wgContLang->formatNum(date('H', $ts), true); case 'currentweek': // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to // int to remove the padding return $varCache[$index] = $wgContLang->formatNum((int) date('W', $ts)); case 'currentdow': return $varCache[$index] = $wgContLang->formatNum(date('w', $ts)); case 'localdayname': return $varCache[$index] = $wgContLang->getWeekdayName($localDayOfWeek + 1); case 'localyear': return $varCache[$index] = $wgContLang->formatNum($localYear, true); case 'localtime': return $varCache[$index] = $wgContLang->time($localTimestamp, false, false); case 'localhour': return $varCache[$index] = $wgContLang->formatNum($localHour, true); case 'localweek': // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to // int to remove the padding return $varCache[$index] = $wgContLang->formatNum((int) $localWeek); case 'localdow': return $varCache[$index] = $wgContLang->formatNum($localDayOfWeek); case 'numberofarticles': return $varCache[$index] = $wgContLang->formatNum(SiteStats::articles()); case 'numberoffiles': return $varCache[$index] = $wgContLang->formatNum(SiteStats::images()); case 'numberofusers': return $varCache[$index] = $wgContLang->formatNum(SiteStats::users()); case 'numberofpages': return $varCache[$index] = $wgContLang->formatNum(SiteStats::pages()); case 'numberofadmins': return $varCache[$index] = $wgContLang->formatNum(SiteStats::admins()); case 'currenttimestamp': return $varCache[$index] = wfTimestampNow(); case 'localtimestamp': return $varCache[$index] = $localTimestamp; case 'currentversion': return $varCache[$index] = SpecialVersion::getVersion(); case 'sitename': return $wgSitename; case 'server': return $wgServer; case 'servername': return $wgServerName; case 'scriptpath': return $wgScriptPath; case 'directionmark': return $wgContLang->getDirMark(); case 'contentlanguage': global $wgContLanguageCode; return $wgContLanguageCode; default: $ret = null; if (wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$varCache, &$index, &$ret))) { return $ret; } else { return null; } } }