/** * @param $parser Parser * @param $frame PPFrame * @param $format string * @param $date string * @param $language string * @param $local string|bool * @return string */ public static function timeCommon($parser, $frame = null, $format = '', $date = '', $language = '', $local = false) { global $wgLocaltimezone; self::registerClearHook(); if ($date === '') { $cacheKey = $parser->getOptions()->getTimestamp(); $timestamp = new MWTimestamp($cacheKey); $date = $timestamp->getTimestamp(TS_ISO_8601); $useTTL = true; } else { $cacheKey = $date; $useTTL = false; } if (isset(self::$mTimeCache[$format][$cacheKey][$language][$local])) { $cachedVal = self::$mTimeCache[$format][$cacheKey][$language][$local]; if ($useTTL && $cachedVal[1] !== null && $frame && is_callable(array($frame, 'setTTL'))) { $frame->setTTL($cachedVal[1]); } return $cachedVal[0]; } # compute the timestamp string $ts # PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object $invalidTime = false; # the DateTime constructor must be used because it throws exceptions # when errors occur, whereas date_create appears to just output a warning # that can't really be detected from within the code try { # Default input timezone is UTC. $utc = new DateTimeZone('UTC'); # Correct for DateTime interpreting 'XXXX' as XX:XX o'clock if (preg_match('/^[0-9]{4}$/', $date)) { $date = '00:00 ' . $date; } # Parse date # UTC is a default input timezone. $dateObject = new DateTime($date, $utc); # Set output timezone. if ($local) { if (isset($wgLocaltimezone)) { $tz = new DateTimeZone($wgLocaltimezone); } else { $tz = new DateTimeZone(date_default_timezone_get()); } } else { $tz = $utc; } $dateObject->setTimezone($tz); # Generate timestamp $ts = $dateObject->format('YmdHis'); } catch (Exception $ex) { $invalidTime = true; } $ttl = null; # format the timestamp and return the result if ($invalidTime) { $result = '<strong class="error">' . wfMessage('pfunc_time_error')->inContentLanguage()->escaped() . '</strong>'; } else { self::$mTimeChars += strlen($format); if (self::$mTimeChars > self::$mMaxTimeChars) { return '<strong class="error">' . wfMessage('pfunc_time_too_long')->inContentLanguage()->escaped() . '</strong>'; } else { if ($ts < 0) { // Language can't deal with BC years return '<strong class="error">' . wfMessage('pfunc_time_too_small')->inContentLanguage()->escaped() . '</strong>'; } elseif ($ts < 100000000000000) { // Language can't deal with years after 9999 if ($language !== '' && Language::isValidBuiltInCode($language)) { // use whatever language is passed as a parameter $langObject = Language::factory($language); } else { // use wiki's content language $langObject = $parser->getFunctionLang(); StubObject::unstub($langObject); // $ttl is passed by reference, which doesn't work right on stub objects } $result = $langObject->sprintfDate($format, $ts, $tz, $ttl); } else { return '<strong class="error">' . wfMessage('pfunc_time_too_big')->inContentLanguage()->escaped() . '</strong>'; } } } self::$mTimeCache[$format][$cacheKey][$language][$local] = array($result, $ttl); if ($useTTL && $ttl !== null && $frame && is_callable(array($frame, 'setTTL'))) { $frame->setTTL($ttl); } return $result; }
/** * Check if user account is hidden * * @return bool True if hidden, false otherwise */ public function isHidden() { if ($this->mHideName !== null) { return $this->mHideName; } $this->getBlockedStatus(); if (!$this->mHideName) { global $wgAuth; StubObject::unstub($wgAuth); $authUser = $wgAuth->getUserInstance($this); $this->mHideName = (bool) $authUser->isHidden(); } return $this->mHideName; }
public function getSignature($user, $timestamp) { global $wgContLang, $wgParser; // Force unstub StubObject::unstub($wgParser); $timestamp = MWTimestamp::getLocalInstance($timestamp); $ts = $timestamp->format('YmdHis'); $tzMsg = $timestamp->format('T'); # might vary on DST changeover! # Allow translation of timezones through wiki. format() can return # whatever crap the system uses, localised or not, so we cannot # ship premade translations. $key = 'timezone-' . strtolower(trim($tzMsg)); $msg = wfMessage($key)->inContentLanguage(); if ($msg->exists()) { $tzMsg = $msg->text(); } $d = $wgContLang->timeanddate($ts, false, false) . " ({$tzMsg})"; if ($user) { return $wgParser->getUserSig($user, false, false) . ' ' . $d; } else { return "[Unknown user] {$d}"; } }