function getDateCond($year, $month) { $year = intval($year); $month = intval($month); // Basic validity checks $this->mYear = $year > 0 ? $year : false; $this->mMonth = $month > 0 && $month < 13 ? $month : false; // Given an optional year and month, we need to generate a timestamp // to use as "WHERE rev_timestamp <= result" // Examples: year = 2006 equals < 20070101 (+000000) // year=2005, month=1 equals < 20050201 // year=2005, month=12 equals < 20060101 if (!$this->mYear && !$this->mMonth) { return; } if ($this->mYear) { $year = $this->mYear; } else { // If no year given, assume the current one $timestamp = MWTimestamp::getInstance(); $year = $timestamp->format('Y'); // If this month hasn't happened yet this year, go back to last year's month if ($this->mMonth > $timestamp->format('n')) { $year--; } } if ($this->mMonth) { $month = $this->mMonth + 1; // For December, we want January 1 of the next year if ($month > 12) { $month = 1; $year++; } } else { // No month implies we want up to the end of the year in question $month = 1; $year++; } // Y2K38 bug if ($year > 2032) { $year = 2032; } $ymd = (int) sprintf("%04d%02d01", $year, $month); if ($ymd > 20320101) { $ymd = 20320101; } $this->mOffset = $this->mDb->timestamp("{$ymd}000000"); }
/** * @covers ReverseChronologicalPager::getDateCond */ public function testGetDateCond() { $pager = $this->getMockForAbstractClass('ReverseChronologicalPager'); $timestamp = MWTimestamp::getInstance(); $db = wfGetDB(DB_MASTER); $currYear = $timestamp->format('Y'); $currMonth = $timestamp->format('n'); // Test that getDateCond sets and returns mOffset $this->assertEquals($pager->getDateCond(2006, 6), $pager->mOffset); // Test year and month $pager->getDateCond(2006, 6); $this->assertEquals($pager->mOffset, $db->timestamp('20060701000000')); // Test year, month, and day $pager->getDateCond(2006, 6, 5); $this->assertEquals($pager->mOffset, $db->timestamp('20060606000000')); // Test month overflow into the next year $pager->getDateCond(2006, 12); $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000')); // Test day overflow to the next month $pager->getDateCond(2006, 6, 30); $this->assertEquals($pager->mOffset, $db->timestamp('20060701000000')); // Test invalid month (should use end of year) $pager->getDateCond(2006, -1); $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000')); // Test invalid day (should use end of month) $pager->getDateCond(2006, 6, 1337); $this->assertEquals($pager->mOffset, $db->timestamp('20060701000000')); // Test last day of year $pager->getDateCond(2006, 12, 31); $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000')); // Test invalid day that overflows to next year $pager->getDateCond(2006, 12, 32); $this->assertEquals($pager->mOffset, $db->timestamp('20070101000000')); // Test month past current month (should use previous year) if ($currMonth < 5) { $pager->getDateCond(-1, 5); $this->assertEquals($pager->mOffset, $db->timestamp($currYear - 1 . '0601000000')); } if ($currMonth < 12) { $pager->getDateCond(-1, 12); $this->assertEquals($pager->mOffset, $db->timestamp($currYear . '0101000000')); } }
/** * @param int $year * @param int $month * @return string Formatted HTML */ public static function dateMenu($year, $month) { # Offset overrides year/month selection if ($month && $month !== -1) { $encMonth = intval($month); } else { $encMonth = ''; } if ($year) { $encYear = intval($year); } elseif ($encMonth) { $timestamp = MWTimestamp::getInstance(); $thisMonth = intval($timestamp->format('n')); $thisYear = intval($timestamp->format('Y')); if (intval($encMonth) > $thisMonth) { $thisYear--; } $encYear = $thisYear; } else { $encYear = ''; } $inputAttribs = array('id' => 'year', 'maxlength' => 4, 'size' => 7); return self::label(wfMessage('year')->text(), 'year') . ' ' . Html::input('year', $encYear, 'number', $inputAttribs) . ' ' . self::label(wfMessage('month')->text(), 'month') . ' ' . self::monthSelector($encMonth, -1); }
/** * Return value of a magic variable (like PAGENAME) * * @private * * @param $index integer * @param bool|\PPFrame $frame * * @throws MWException * @return string */ function getVariableValue($index, $frame = false) { global $wgContLang, $wgSitename, $wgServer; global $wgArticlePath, $wgScriptPath, $wgStylePath; if (is_null($this->mTitle)) { // If no title set, bad things are going to happen // later. Title should always be set since this // should only be called in the middle of a parse // operation (but the unit-tests do funky stuff) throw new MWException(__METHOD__ . ' Should only be ' . ' called while parsing (no title set)'); } /** * 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)); $pageLang = $this->getFunctionLang(); switch ($index) { case 'currentmonth': $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('m')); break; case 'currentmonth1': $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('n')); break; case 'currentmonthname': $value = $pageLang->getMonthName(MWTimestamp::getInstance($ts)->format('n')); break; case 'currentmonthnamegen': $value = $pageLang->getMonthNameGen(MWTimestamp::getInstance($ts)->format('n')); break; case 'currentmonthabbrev': $value = $pageLang->getMonthAbbreviation(MWTimestamp::getInstance($ts)->format('n')); break; case 'currentday': $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('j')); break; case 'currentday2': $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('d')); break; case 'localmonth': $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('m')); break; case 'localmonth1': $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('n')); break; case 'localmonthname': $value = $pageLang->getMonthName(MWTimestamp::getLocalInstance($ts)->format('n')); break; case 'localmonthnamegen': $value = $pageLang->getMonthNameGen(MWTimestamp::getLocalInstance($ts)->format('n')); break; case 'localmonthabbrev': $value = $pageLang->getMonthAbbreviation(MWTimestamp::getLocalInstance($ts)->format('n')); break; case 'localday': $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('j')); break; case 'localday2': $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('d')); break; case 'pagename': $value = wfEscapeWikiText($this->mTitle->getText()); break; case 'pagenamee': $value = wfEscapeWikiText($this->mTitle->getPartialURL()); break; case 'fullpagename': $value = wfEscapeWikiText($this->mTitle->getPrefixedText()); break; case 'fullpagenamee': $value = wfEscapeWikiText($this->mTitle->getPrefixedURL()); break; case 'subpagename': $value = wfEscapeWikiText($this->mTitle->getSubpageText()); break; case 'subpagenamee': $value = wfEscapeWikiText($this->mTitle->getSubpageUrlForm()); break; case 'rootpagename': $value = wfEscapeWikiText($this->mTitle->getRootText()); break; case 'rootpagenamee': $value = wfEscapeWikiText(wfUrlEncode(str_replace(' ', '_', $this->mTitle->getRootText()))); break; case 'basepagename': $value = wfEscapeWikiText($this->mTitle->getBaseText()); break; case 'basepagenamee': $value = wfEscapeWikiText(wfUrlEncode(str_replace(' ', '_', $this->mTitle->getBaseText()))); break; case 'talkpagename': if ($this->mTitle->canTalk()) { $talkPage = $this->mTitle->getTalkPage(); $value = wfEscapeWikiText($talkPage->getPrefixedText()); } else { $value = ''; } break; case 'talkpagenamee': if ($this->mTitle->canTalk()) { $talkPage = $this->mTitle->getTalkPage(); $value = wfEscapeWikiText($talkPage->getPrefixedURL()); } else { $value = ''; } break; case 'subjectpagename': $subjPage = $this->mTitle->getSubjectPage(); $value = wfEscapeWikiText($subjPage->getPrefixedText()); break; case 'subjectpagenamee': $subjPage = $this->mTitle->getSubjectPage(); $value = wfEscapeWikiText($subjPage->getPrefixedURL()); break; case 'pageid': // requested in bug 23427 $pageid = $this->getTitle()->getArticleID(); if ($pageid == 0) { # 0 means the page doesn't exist in the database, # which means the user is previewing a new page. # The vary-revision flag must be set, because the magic word # will have a different value once the page is saved. $this->mOutput->setFlag('vary-revision'); wfDebug(__METHOD__ . ": {{PAGEID}} used in a new page, setting vary-revision...\n"); } $value = $pageid ? $pageid : null; break; 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"); $value = $this->mRevisionId; break; 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"); $value = intval(substr($this->getRevisionTimestamp(), 6, 2)); break; 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"); $value = substr($this->getRevisionTimestamp(), 6, 2); break; 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"); $value = substr($this->getRevisionTimestamp(), 4, 2); break; case 'revisionmonth1': # 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__ . ": {{REVISIONMONTH1}} used, setting vary-revision...\n"); $value = intval(substr($this->getRevisionTimestamp(), 4, 2)); break; 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"); $value = substr($this->getRevisionTimestamp(), 0, 4); break; 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"); $value = $this->getRevisionTimestamp(); break; case 'revisionuser': # 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__ . ": {{REVISIONUSER}} used, setting vary-revision...\n"); $value = $this->getRevisionUser(); break; case 'revisionsize': # 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__ . ": {{REVISIONSIZE}} used, setting vary-revision...\n"); $value = $this->getRevisionSize(); break; case 'namespace': $value = str_replace('_', ' ', $wgContLang->getNsText($this->mTitle->getNamespace())); break; case 'namespacee': $value = wfUrlencode($wgContLang->getNsText($this->mTitle->getNamespace())); break; case 'namespacenumber': $value = $this->mTitle->getNamespace(); break; case 'talkspace': $value = $this->mTitle->canTalk() ? str_replace('_', ' ', $this->mTitle->getTalkNsText()) : ''; break; case 'talkspacee': $value = $this->mTitle->canTalk() ? wfUrlencode($this->mTitle->getTalkNsText()) : ''; break; case 'subjectspace': $value = str_replace('_', ' ', $this->mTitle->getSubjectNsText()); break; case 'subjectspacee': $value = wfUrlencode($this->mTitle->getSubjectNsText()); break; case 'currentdayname': $value = $pageLang->getWeekdayName((int) MWTimestamp::getInstance($ts)->format('w') + 1); break; case 'currentyear': $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('Y'), true); break; case 'currenttime': $value = $pageLang->time(wfTimestamp(TS_MW, $ts), false, false); break; case 'currenthour': $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('H'), true); break; case 'currentweek': # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to # int to remove the padding $value = $pageLang->formatNum((int) MWTimestamp::getInstance($ts)->format('W')); break; case 'currentdow': $value = $pageLang->formatNum(MWTimestamp::getInstance($ts)->format('w')); break; case 'localdayname': $value = $pageLang->getWeekdayName((int) MWTimestamp::getLocalInstance($ts)->format('w') + 1); break; case 'localyear': $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('Y'), true); break; case 'localtime': $value = $pageLang->time(MWTimestamp::getLocalInstance($ts)->format('YmdHis'), false, false); break; case 'localhour': $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('H'), true); break; case 'localweek': # @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to # int to remove the padding $value = $pageLang->formatNum((int) MWTimestamp::getLocalInstance($ts)->format('W')); break; case 'localdow': $value = $pageLang->formatNum(MWTimestamp::getLocalInstance($ts)->format('w')); break; case 'numberofarticles': $value = $pageLang->formatNum(SiteStats::articles()); break; case 'numberoffiles': $value = $pageLang->formatNum(SiteStats::images()); break; case 'numberofusers': $value = $pageLang->formatNum(SiteStats::users()); break; case 'numberofactiveusers': $value = $pageLang->formatNum(SiteStats::activeUsers()); break; case 'numberofpages': $value = $pageLang->formatNum(SiteStats::pages()); break; case 'numberofadmins': $value = $pageLang->formatNum(SiteStats::numberingroup('sysop')); break; case 'numberofedits': $value = $pageLang->formatNum(SiteStats::edits()); break; case 'numberofviews': global $wgDisableCounters; $value = !$wgDisableCounters ? $pageLang->formatNum(SiteStats::views()) : ''; break; case 'currenttimestamp': $value = wfTimestamp(TS_MW, $ts); break; case 'localtimestamp': $value = MWTimestamp::getLocalInstance($ts)->format('YmdHis'); break; case 'currentversion': $value = SpecialVersion::getVersion(); break; case 'articlepath': return $wgArticlePath; case 'sitename': return $wgSitename; case 'server': return $wgServer; case 'servername': $serverParts = wfParseUrl($wgServer); return $serverParts && isset($serverParts['host']) ? $serverParts['host'] : $wgServer; case 'scriptpath': return $wgScriptPath; case 'stylepath': return $wgStylePath; case 'directionmark': return $pageLang->getDirMark(); case 'contentlanguage': global $wgLanguageCode; return $wgLanguageCode; case 'cascadingsources': $value = CoreParserFunctions::cascadingsources($this); break; default: $ret = null; wfRunHooks('ParserGetVariableValueSwitch', array(&$this, &$this->mVarCache, &$index, &$ret, &$frame)); return $ret; } if ($index) { $this->mVarCache[$index] = $value; } return $value; }
/** * @param $year Integer * @param $month Integer * @return string Formatted HTML */ public static function dateMenu($year, $month) { # Offset overrides year/month selection if ($month && $month !== -1) { $encMonth = intval($month); } else { $encMonth = ''; } if ($year) { $encYear = intval($year); } elseif ($encMonth) { $timestamp = MWTimestamp::getInstance(); $thisMonth = intval($timestamp->format('n')); $thisYear = intval($timestamp->format('Y')); if (intval($encMonth) > $thisMonth) { $thisYear--; } $encYear = $thisYear; } else { $encYear = ''; } // JRS, upgrade 1.21: Add button classes to date menu $inputAttribs = array('id' => 'year', 'maxlength' => 4, 'size' => 7, 'class' => 'input_med'); return self::label(wfMessage('input-year')->text(), 'year', array('class' => 'input_med noborder')) . ' ' . Html::input('year', $encYear, 'number', $inputAttribs) . ' ' . self::label(wfMessage('input-month')->text(), 'month', array('class' => 'input_med noborder')) . ' ' . self::monthSelector($encMonth, -1); }
/** * Pick a random name in the temp zone and store a file to it. * Returns a FileRepoStatus object with the file Virtual URL in the value, * file can later be disposed using FileRepo::freeTemp(). * * @param string $originalName The base name of the file as specified * by the user. The file extension will be maintained. * @param string $srcPath The current location of the file. * @return FileRepoStatus Object with the URL in the value. */ public function storeTemp($originalName, $srcPath) { $this->assertWritableRepo(); // fail out if read-only $date = MWTimestamp::getInstance()->format('YmdHis'); $hashPath = $this->getHashPath($originalName); $dstUrlRel = $hashPath . $date . '!' . rawurlencode($originalName); $virtualUrl = $this->getVirtualUrl('temp') . '/' . $dstUrlRel; $result = $this->quickImport($srcPath, $virtualUrl); $result->value = $virtualUrl; return $result; }
/** * Generates the namespace selector form with hidden attributes. * @return string HTML fragment */ protected function getForm() { $this->opts['title'] = $this->getPageTitle()->getPrefixedText(); if (!isset($this->opts['target'])) { $this->opts['target'] = ''; } else { $this->opts['target'] = str_replace('_', ' ', $this->opts['target']); } if (!isset($this->opts['namespace'])) { $this->opts['namespace'] = ''; } if (!isset($this->opts['nsInvert'])) { $this->opts['nsInvert'] = ''; } if (!isset($this->opts['associated'])) { $this->opts['associated'] = false; } if (!isset($this->opts['contribs'])) { $this->opts['contribs'] = 'user'; } if (!isset($this->opts['year'])) { $this->opts['year'] = ''; } if (!isset($this->opts['month'])) { $this->opts['month'] = ''; } if ($this->opts['contribs'] == 'newbie') { $this->opts['target'] = ''; } if (!isset($this->opts['tagfilter'])) { $this->opts['tagfilter'] = ''; } if (!isset($this->opts['topOnly'])) { $this->opts['topOnly'] = false; } if (!isset($this->opts['newOnly'])) { $this->opts['newOnly'] = false; } if (!isset($this->opts['hideMinor'])) { $this->opts['hideMinor'] = false; } $form = Html::openElement('form', ['method' => 'get', 'action' => wfScript(), 'class' => 'mw-contributions-form']); # Add hidden params for tracking except for parameters in $skipParameters $skipParameters = ['namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly', 'newOnly', 'hideMinor', 'associated', 'tagfilter']; foreach ($this->opts as $name => $value) { if (in_array($name, $skipParameters)) { continue; } $form .= "\t" . Html::hidden($name, $value) . "\n"; } $tagFilter = ChangeTags::buildTagFilterSelector($this->opts['tagfilter']); if ($tagFilter) { $filterSelection = Html::rawElement('div', [], implode(' ', $tagFilter)); } else { $filterSelection = Html::rawElement('div', [], ''); } $this->getOutput()->addModules('mediawiki.userSuggest'); $labelNewbies = Xml::radioLabel($this->msg('sp-contributions-newbies')->text(), 'contribs', 'newbie', 'newbie', $this->opts['contribs'] == 'newbie', ['class' => 'mw-input']); $labelUsername = Xml::radioLabel($this->msg('sp-contributions-username')->text(), 'contribs', 'user', 'user', $this->opts['contribs'] == 'user', ['class' => 'mw-input']); $input = Html::input('target', $this->opts['target'], 'text', ['size' => '40', 'required' => '', 'class' => ['mw-input', 'mw-ui-input-inline', 'mw-autocomplete-user']] + ($this->opts['contribs'] === 'newbie' || $this->opts['target'] ? [] : ['autofocus' => true])); $targetSelection = Html::rawElement('div', [], $labelNewbies . '<br>' . $labelUsername . ' ' . $input . ' '); $namespaceSelection = Xml::tags('div', [], Xml::label($this->msg('namespace')->text(), 'namespace', '') . ' ' . Html::namespaceSelector(['selected' => $this->opts['namespace'], 'all' => ''], ['name' => 'namespace', 'id' => 'namespace', 'class' => 'namespaceselector']) . ' ' . Html::rawElement('span', ['class' => 'mw-input-with-label'], Xml::checkLabel($this->msg('invert')->text(), 'nsInvert', 'nsInvert', $this->opts['nsInvert'], ['title' => $this->msg('tooltip-invert')->text(), 'class' => 'mw-input']) . ' ') . Html::rawElement('span', ['class' => 'mw-input-with-label'], Xml::checkLabel($this->msg('namespace_association')->text(), 'associated', 'associated', $this->opts['associated'], ['title' => $this->msg('tooltip-namespace_association')->text(), 'class' => 'mw-input']) . ' ')); $filters = []; if ($this->getUser()->isAllowed('deletedhistory')) { $filters[] = Html::rawElement('span', ['class' => 'mw-input-with-label'], Xml::checkLabel($this->msg('history-show-deleted')->text(), 'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'], ['class' => 'mw-input'])); } $filters[] = Html::rawElement('span', ['class' => 'mw-input-with-label'], Xml::checkLabel($this->msg('sp-contributions-toponly')->text(), 'topOnly', 'mw-show-top-only', $this->opts['topOnly'], ['class' => 'mw-input'])); $filters[] = Html::rawElement('span', ['class' => 'mw-input-with-label'], Xml::checkLabel($this->msg('sp-contributions-newonly')->text(), 'newOnly', 'mw-show-new-only', $this->opts['newOnly'], ['class' => 'mw-input'])); $filters[] = Html::rawElement('span', ['class' => 'mw-input-with-label'], Xml::checkLabel($this->msg('sp-contributions-hideminor')->text(), 'hideMinor', 'mw-hide-minor-edits', $this->opts['hideMinor'], ['class' => 'mw-input'])); Hooks::run('SpecialContributions::getForm::filters', [$this, &$filters]); $extraOptions = Html::rawElement('div', [], implode('', $filters)); $dateSelectionAndSubmit = Xml::tags('div', [], Xml::dateMenu($this->opts['year'] === '' ? MWTimestamp::getInstance()->format('Y') : $this->opts['year'], $this->opts['month']) . ' ' . Html::submitButton($this->msg('sp-contributions-submit')->text(), ['class' => 'mw-submit'], ['mw-ui-progressive'])); $form .= Xml::fieldset($this->msg('sp-contributions-search')->text(), $targetSelection . $namespaceSelection . $filterSelection . $extraOptions . $dateSelectionAndSubmit, ['class' => 'mw-contributions-table']); $explain = $this->msg('sp-contributions-explain'); if (!$explain->isBlank()) { $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>"; } $form .= Xml::closeElement('form'); return $form; }
/** * Set and return the mOffset timestamp such that we can get all revisions with * a timestamp up to the specified parameters. * @param int $year Year up to which we want revisions * @param int $month Month up to which we want revisions * @param int $day [optional] Day up to which we want revisions. Default is end of month. * @return string|null Timestamp or null if year and month are false/invalid */ function getDateCond($year, $month, $day = -1) { $year = intval($year); $month = intval($month); $day = intval($day); // Basic validity checks for year and month $this->mYear = $year > 0 ? $year : false; $this->mMonth = $month > 0 && $month < 13 ? $month : false; // If year and month are false, don't update the mOffset if (!$this->mYear && !$this->mMonth) { return; } // Given an optional year, month, and day, we need to generate a timestamp // to use as "WHERE rev_timestamp <= result" // Examples: year = 2006 equals < 20070101 (+000000) // year=2005, month=1 equals < 20050201 // year=2005, month=12 equals < 20060101 // year=2005, month=12, day=5 equals < 20051206 if ($this->mYear) { $year = $this->mYear; } else { // If no year given, assume the current one $timestamp = MWTimestamp::getInstance(); $year = $timestamp->format('Y'); // If this month hasn't happened yet this year, go back to last year's month if ($this->mMonth > $timestamp->format('n')) { $year--; } } if ($this->mMonth) { $month = $this->mMonth; // Day validity check after we have month and year checked $this->mDay = checkdate($month, $day, $year) ? $day : false; if ($this->mDay) { // If we have a day, we want up to the day immediately afterward $day = $this->mDay + 1; // Did we overflow the current month? if (!checkdate($month, $day, $year)) { $day = 1; $month++; } } else { // If no day, assume beginning of next month $day = 1; $month++; } // Did we overflow the current year? if ($month > 12) { $month = 1; $year++; } } else { // No month implies we want up to the end of the year in question $month = 1; $day = 1; $year++; } // Y2K38 bug if ($year > 2032) { $year = 2032; } $ymd = (int) sprintf("%04d%02d%02d", $year, $month, $day); if ($ymd > 20320101) { $ymd = 20320101; } // Treat the given time in the wiki timezone and get a UTC timestamp for the database lookup $timestamp = MWTimestamp::getInstance("{$ymd}000000"); $timestamp->setTimezone($this->getConfig()->get('Localtimezone')); $this->mOffset = $this->mDb->timestamp($timestamp->getTimestamp()); return $this->mOffset; }
/** * Generates the namespace selector form with hidden attributes. * @return string HTML fragment */ protected function getForm() { $this->opts['title'] = $this->getPageTitle()->getPrefixedText(); if (!isset($this->opts['target'])) { $this->opts['target'] = ''; } else { $this->opts['target'] = str_replace('_', ' ', $this->opts['target']); } if (!isset($this->opts['namespace'])) { $this->opts['namespace'] = ''; } if (!isset($this->opts['nsInvert'])) { $this->opts['nsInvert'] = ''; } if (!isset($this->opts['associated'])) { $this->opts['associated'] = false; } if (!isset($this->opts['contribs'])) { $this->opts['contribs'] = 'user'; } if (!isset($this->opts['year'])) { $this->opts['year'] = ''; } if (!isset($this->opts['month'])) { $this->opts['month'] = ''; } if ($this->opts['contribs'] == 'newbie') { $this->opts['target'] = ''; } if (!isset($this->opts['tagfilter'])) { $this->opts['tagfilter'] = ''; } if (!isset($this->opts['topOnly'])) { $this->opts['topOnly'] = false; } if (!isset($this->opts['newOnly'])) { $this->opts['newOnly'] = false; } $form = Html::openElement('form', array('method' => 'get', 'action' => wfScript(), 'class' => 'mw-contributions-form')); # Add hidden params for tracking except for parameters in $skipParameters $skipParameters = array('namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly', 'newOnly', 'associated'); foreach ($this->opts as $name => $value) { if (in_array($name, $skipParameters)) { continue; } $form .= "\t" . Html::hidden($name, $value) . "\n"; } $tagFilter = ChangeTags::buildTagFilterSelector($this->opts['tagfilter']); if ($tagFilter) { $filterSelection = Html::rawElement('td', array('class' => 'mw-label'), array_shift($tagFilter)); $filterSelection .= Html::rawElement('td', array('class' => 'mw-input'), implode(' ', $tagFilter)); } else { $filterSelection = Html::rawElement('td', array('colspan' => 2), ''); } $labelNewbies = Xml::radioLabel($this->msg('sp-contributions-newbies')->text(), 'contribs', 'newbie', 'newbie', $this->opts['contribs'] == 'newbie', array('class' => 'mw-input')); $labelUsername = Xml::radioLabel($this->msg('sp-contributions-username')->text(), 'contribs', 'user', 'user', $this->opts['contribs'] == 'user', array('class' => 'mw-input')); $input = Html::input('target', $this->opts['target'], 'text', array('size' => '40', 'required' => '', 'class' => 'mw-input') + ($this->opts['target'] ? array() : array('autofocus'))); $targetSelection = Html::rawElement('td', array('colspan' => 2), $labelNewbies . '<br />' . $labelUsername . ' ' . $input . ' '); $namespaceSelection = Xml::tags('td', array('class' => 'mw-label'), Xml::label($this->msg('namespace')->text(), 'namespace', '')); $namespaceSelection .= Html::rawElement('td', null, Html::namespaceSelector(array('selected' => $this->opts['namespace'], 'all' => ''), array('name' => 'namespace', 'id' => 'namespace', 'class' => 'namespaceselector')) . ' ' . Html::rawElement('span', array('style' => 'white-space: nowrap'), Xml::checkLabel($this->msg('invert')->text(), 'nsInvert', 'nsInvert', $this->opts['nsInvert'], array('title' => $this->msg('tooltip-invert')->text(), 'class' => 'mw-input')) . ' ') . Html::rawElement('span', array('style' => 'white-space: nowrap'), Xml::checkLabel($this->msg('namespace_association')->text(), 'associated', 'associated', $this->opts['associated'], array('title' => $this->msg('tooltip-namespace_association')->text(), 'class' => 'mw-input')) . ' ')); if ($this->getUser()->isAllowed('deletedhistory')) { $deletedOnlyCheck = Html::rawElement('span', array('style' => 'white-space: nowrap'), Xml::checkLabel($this->msg('history-show-deleted')->text(), 'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'], array('class' => 'mw-input'))); } else { $deletedOnlyCheck = ''; } $checkLabelTopOnly = Html::rawElement('span', array('style' => 'white-space: nowrap'), Xml::checkLabel($this->msg('sp-contributions-toponly')->text(), 'topOnly', 'mw-show-top-only', $this->opts['topOnly'], array('class' => 'mw-input'))); $checkLabelNewOnly = Html::rawElement('span', array('style' => 'white-space: nowrap'), Xml::checkLabel($this->msg('sp-contributions-newonly')->text(), 'newOnly', 'mw-show-new-only', $this->opts['newOnly'], array('class' => 'mw-input'))); $extraOptions = Html::rawElement('td', array('colspan' => 2), $deletedOnlyCheck . $checkLabelTopOnly . $checkLabelNewOnly); $dateSelectionAndSubmit = Xml::tags('td', array('colspan' => 2), Xml::dateMenu($this->opts['year'] === '' ? MWTimestamp::getInstance()->format('Y') : $this->opts['year'], $this->opts['month']) . ' ' . Xml::submitButton($this->msg('sp-contributions-submit')->text(), array('class' => 'mw-submit'))); $form .= Xml::fieldset($this->msg('sp-contributions-search')->text()); $form .= Html::rawElement('table', array('class' => 'mw-contributions-table'), "\n" . Html::rawElement('tr', array(), $targetSelection) . "\n" . Html::rawElement('tr', array(), $namespaceSelection) . "\n" . Html::rawElement('tr', array(), $filterSelection) . "\n" . Html::rawElement('tr', array(), $extraOptions) . "\n" . Html::rawElement('tr', array(), $dateSelectionAndSubmit) . "\n"); $explain = $this->msg('sp-contributions-explain'); if (!$explain->isBlank()) { $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>"; } $form .= Xml::closeElement('fieldset') . Xml::closeElement('form'); return $form; }