/** * initialize various variables and generate the template * @return QuickTemplate */ protected function prepareQuickTemplate() { $appleTouchIcon = $this->getConfig()->get('AppleTouchIcon'); $out = $this->getOutput(); // add head items if ($appleTouchIcon !== false) { $out->addHeadItem('touchicon', Html::element('link', array('rel' => 'apple-touch-icon', 'href' => $appleTouchIcon))); } $out->addHeadItem('viewport', Html::element('meta', array('name' => 'viewport', 'content' => 'initial-scale=1.0, user-scalable=yes, minimum-scale=0.25, ' . 'maximum-scale=5.0, width=device-width'))); // Generate skin template $tpl = parent::prepareQuickTemplate(); // Set whether or not the page content should be wrapped in div.content (for // example, on a special page) $tpl->set('unstyledContent', $out->getProperty('unstyledContent')); // Set the links for the main menu $tpl->set('menu_data', $this->getMenuData()); // Set the links for page secondary actions $tpl->set('secondary_actions', $this->getSecondaryActions($tpl)); // Construct various Minerva-specific interface elements $this->preparePageContent($tpl); $this->prepareHeaderAndFooter($tpl); $this->prepareMenuButton($tpl); $this->prepareBanners($tpl); $this->prepareWarnings($tpl); $this->preparePageActions($tpl); $this->prepareUserButton($tpl); $this->prepareLanguages($tpl); if ($this->isMenuEnabled) { $templateParser = new TemplateParser(__DIR__ . '/../../resources/skins.minerva.scripts/'); $tpl->set('menuhtml', $templateParser->processTemplate('menu', $tpl->data['menu_data'])); } else { $tpl->set('menuhtml', ''); } return $tpl; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUploadPath, $wgUser, $wgHuijiPrefix; $templateParser = new TemplateParser(__DIR__ . '/pages'); $out = $this->getOutput(); $user = $this->getUser(); if (!$user->isAllowed('AdminDashboard')) { $out->permissionRequired('AdminDashboard'); return; } // Set the page title, robot policies, etc. $this->setHeaders(); // Add CSS $out->addModules('ext.socialprofile.userprofile.css'); $out->addModules('ext.socialprofile.admindashboard.css'); // Add js and message // $out->addModules( 'skin.bootstrapmediawiki.huiji.getRecordsInterface.js' ); $out->addModules('ext.socialprofile.admindashboard.js'); $out->addModules('ext.socialprofile.userprofile.js'); $output = ''; // Prevent E_NOTICE $yesterday = date("Y-m-d", strtotime("-1 day")); $totaledit = SiteStats::edits(); $ueb = new UserEditBox(); $rankInfo = AllSitesInfo::getAllSitesRankData($wgHuijiPrefix, $yesterday); $usf = new UserSiteFollow(); $follows = $usf->getSiteFollowers('', $wgHuijiPrefix); // print_r($follows); $followCount = count($follows); if ($followCount >= 8) { $follows = array_slice($follows, 0, 8); $display = ''; } else { $display = 'none'; } $newFollow = array(); foreach ($follows as $value) { $arr['user_name'] = $value['user_name']; $userPage = Title::makeTitle(NS_USER, $value['user_name']); $arr['user_url'] = htmlspecialchars($userPage->getFullURL()); $arr['follow_date'] = wfMessage('comments-time-ago', HuijiFunctions::getTimeAgo(strtotime($value['follow_date'])))->text(); $newFollow[] = $arr; } $sentToAll = SpecialPage::getTitleFor('SendToFollowers')->getFullURL(); $showMore = SpecialPage::getTitleFor('EditRank')->getFullURL(); $rightsManage = SpecialPage::getTitleFor('用户权限')->getFullURL(); $blockUsers = SpecialPage::getTitleFor('封禁')->getFullURL(); $freezeUsers = SpecialPage::getTitleFor('解除封禁')->getFullURL(); $replaceText = SpecialPage::getTitleFor('替换文本')->getFullURL(); $siteRankPage = SpecialPage::getTitleFor('SiteRank')->getFullURL(); $allSpecial = SpecialPage::getTitleFor('特殊页面')->getFullURL(); $siteAvatar = (new wSiteAvatar($wgHuijiPrefix, 'l'))->getAvatarHtml(); $token = $user->getEditToken(); if (is_null($newFollow)) { $newFollow = false; } $output .= $templateParser->processTemplate('admin_index', array('siteRank' => isset($rankInfo[0]['site_rank']) ? $rankInfo[0]['site_rank'] : '暂无', 'siteScore' => isset($rankInfo[0]['site_score']) ? $rankInfo[0]['site_score'] : '暂无', 'yesterdayCount' => UserSiteFollow::getFollowerCountOneday($wgHuijiPrefix, $yesterday), 'totalCount' => UserSiteFollow::getFollowerCount($wgHuijiPrefix), 'yesterdayEdit' => $ueb->getSiteEditCount('', $wgHuijiPrefix, $yesterday, $yesterday), 'totalEdit' => $totaledit, 'totalView' => $ueb->getSiteViewCount(-1, $wgHuijiPrefix, '', ''), 'yesterdayView' => $ueb->getSiteViewCount(-1, $wgHuijiPrefix, $yesterday, $yesterday), 'newFollow' => $newFollow, 'sendToAll' => $sentToAll, 'showMore' => $showMore, 'display' => $display, 'rightsManage' => $rightsManage, 'blockUsers' => $blockUsers, 'freezeUsers' => $freezeUsers, 'replaceText' => $replaceText, 'siteRankPage' => $siteRankPage, 'allSpecial' => $allSpecial, 'siteAvatar' => $siteAvatar, 'token' => $token)); $out->addHtml($output); }
/** * @dataProvider provideProcessTemplate * @covers TemplateParser::processTemplate * @covers TemplateParser::getTemplate * @covers TemplateParser::getTemplateFilename */ public function testProcessTemplate($name, $args, $result, $exception = false) { if ($exception) { $this->setExpectedException($exception); } $tp = new TemplateParser($this->templateDir); $this->assertEquals($result, $tp->processTemplate($name, $args)); }
/** * Get a common dropdown for all ranking pages */ public static function getRankingDropdown($activeList) { global $wgUser; $templateParser = new TemplateParser(__DIR__); $followed = UserSiteFollow::getTopFollowedSitesWithDetails($wgUser->getId(), $wgUser->getId()); $output = $templateParser->processTemplate('dropdown', array('activeList' => $activeList, 'followed' => $followed, 'hasFollowed' => count($followed) > 0)); return $output; }
/** * @inheritdoc * Renders a search link and branding. */ protected function makeChromeHeaderContent($data) { $templateParser = new TemplateParser(__DIR__ . '/../../templates'); $args = array('siteName' => SkinMinerva::getSitename(), 'showSearchForm' => $this->isSpecialMobileMenuPage, 'showTitle' => !$this->isSpecialMobileMenuPage); if ($this->isSpecialMobileMenuPage) { $args += array('mobileMenuClass' => 'js-only back ' . MobileUI::iconClass('back'), 'mobileMenuLink' => '#back', 'mobileMenuTitle' => wfMessage('mobile-frontend-main-menu-back')->parse(), 'searchForm' => $this->makeSearchForm($data)); } else { $args += array('mobileMenuClass' => MobileUI::iconClass('search'), 'mobileMenuLink' => SpecialPage::getTitleFor('MobileMenu')->getLocalUrl(), 'mobileMenuTitle' => wfMessage('mobile-frontend-main-menu')->parse(), 'searchInputClass' => 'hidden'); } echo $templateParser->processTemplate('header', $args); }
/** * Generate user page content for non-existent user pages * * @param OutputPage $output * @param User $pageUser owner of the user page * @return string */ public static function getUserPageContent($output, $pageUser) { $context = MobileContext::singleton(); $pageUsername = $pageUser->getName(); // Is the current user viewing their own page? $isCurrentUser = $output->getUser()->getName() === $pageUsername; $data['ctaHeading'] = $isCurrentUser ? $context->msg('mobile-frontend-user-page-no-owner-page-yet')->text() : $context->msg('mobile-frontend-user-page-no-page-yet', $pageUsername)->parse(); $data['ctaDescription'] = $isCurrentUser ? $context->msg('mobile-frontend-user-page-describe-yourself', $context->msg('mobile-frontend-user-page-describe-yourself-editors')->text())->text() : $context->msg('mobile-frontend-user-page-desired-action', $pageUsername)->parse(); $data['createPageLinkLabel'] = $isCurrentUser ? $context->msg('mobile-frontend-user-page-create-owner-page-link-label')->text() : $context->msg('mobile-frontend-user-page-create-user-page-link-label', $pageUser->getUserPage()->getBaseTitle())->parse(); $data['createPageLinkAdditionalClasses'] = $isCurrentUser ? 'mw-ui-button' : ''; $templateParser = new TemplateParser(__DIR__); return $templateParser->processTemplate('user_page_cta', $data); }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUploadPath, $wgUser, $wgHuijiPrefix; $templateParser = new TemplateParser(__DIR__ . '/pages'); $out = $this->getOutput(); $user = $this->getUser(); // Set the page title, robot policies, etc. $this->setHeaders(); // Add Less $out->addModuleStyles('ext.socialprofile.admindashboard.less'); // Add CSS $out->addModuleStyles('ext.socialprofile.admindashboard.css'); // Add js and messages $out->addModules('ext.socialprofile.admindashboard.js'); $output = ''; // Prevent E_NOTICE $yesterday = date("Y-m-d", strtotime("-1 day")); $dbr = wfGetDB(DB_SLAVE); $counter = new SiteStatsInit($dbr); $totaledit = $counter->edits(); $ueb = new UserEditBox(); $output .= $templateParser->processTemplate('admin_index', array('yesterdayCount' => UserSiteFollow::getSiteCountOnedayDB($wgHuijiPrefix, $yesterday), 'totalCount' => UserSiteFollow::getSiteCount($wgHuijiPrefix), 'yesterdayEdit' => $ueb->getSiteEditCountOneday($wgHuijiPrefix, $yesterday), 'totalEdit' => $totaledit, 'totalView' => $ueb->getSiteViewCountTotal($wgHuijiPrefix), 'yesterdayView' => $ueb->getSiteViewCountOneday($wgHuijiPrefix, $yesterday))); $out->addHtml($output); }
/** * Renders the tags assigned to the page as part of the Browse experiment. * * @param array $data The data used to build the page * @return string The HTML representing the tags section */ protected function renderBrowseTags($data) { if (!isset($data['browse_tags']) || !$data['browse_tags']) { return ''; } $browseTags = $this->getSkin()->getMFConfig()->get('MFBrowseTags'); $baseLink = SpecialPage::getTitleFor('TopicTag')->getLinkURL(); // TODO: Create tag entity and view. $tags = array_map(function ($rawTag) use($browseTags, $baseLink) { return array('msg' => $rawTag, 'link' => $baseLink . '/' . str_replace(' ', '_', $rawTag)); }, $data['browse_tags']); // FIXME: This should be in MinervaTemplate#getTemplateParser. $templateParser = new TemplateParser(__DIR__ . '/../../resources'); return $templateParser->processTemplate('mobile.browse/tags', array('headerMsg' => wfMessage('mobile-frontend-browse-tags-header')->text(), 'tags' => $tags)); }
# bug 30219 : can not use pathinfo() on URLs since slashes do not match $matches = []; $ext = 'php'; $path = '/'; foreach (array_filter(explode('/', $_SERVER['PHP_SELF'])) as $part) { if (!preg_match('/\\.(php5?)$/', $part, $matches)) { $path .= "{$part}/"; } else { $ext = $matches[1] == 'php5' ? 'php5' : 'php'; break; } } # Check to see if the installer is running if (!function_exists('session_name')) { $installerStarted = false; } else { if (!wfIniGetBool('session.auto_start')) { session_name('mw_installer_session'); } $oldReporting = error_reporting(E_ALL & ~E_NOTICE); $success = session_start(); error_reporting($oldReporting); $installerStarted = $success && isset($_SESSION['installData']); } $templateParser = new TemplateParser(); # Render error page if no LocalSettings file can be found try { echo $templateParser->processTemplate('NoLocalSettings', ['wgVersion' => isset($wgVersion) ? $wgVersion : 'VERSION', 'path' => $path, 'ext' => $ext, 'localSettingsExists' => file_exists(MW_CONFIG_FILE), 'installerStarted' => $installerStarted]); } catch (Exception $e) { echo 'Error: ' . htmlspecialchars($e->getMessage()); }
/** * Generates each row in the contributions list. * * Contributions which are marked "top" are currently on top of the history. * For these contributions, a [rollback] link is shown for users with roll- * back privileges. The rollback link restores the most recent version that * was not written by the target user. * * @todo This would probably look a lot nicer in a table. * @param object $row * @return string */ function formatRow($row) { $ret = ''; $classes = []; /* * There may be more than just revision rows. To make sure that we'll only be processing * revisions here, let's _try_ to build a revision out of our row (without displaying * notices though) and then trying to grab data from the built object. If we succeed, * we're definitely dealing with revision data and we may proceed, if not, we'll leave it * to extensions to subscribe to the hook to parse the row. */ MediaWiki\suppressWarnings(); try { $rev = new Revision($row); $validRevision = (bool) $rev->getId(); } catch (Exception $e) { $validRevision = false; } MediaWiki\restoreWarnings(); if ($validRevision) { $classes = []; $page = Title::newFromRow($row); $link = Linker::link($page, htmlspecialchars($page->getPrefixedText()), ['class' => 'mw-contributions-title'], $page->isRedirect() ? ['redirect' => 'no'] : []); # Mark current revisions $topmarktext = ''; $user = $this->getUser(); if ($row->rev_id === $row->page_latest) { $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>'; $classes[] = 'mw-contributions-current'; # Add rollback link if (!$row->page_is_new && $page->quickUserCan('rollback', $user) && $page->quickUserCan('edit', $user)) { $this->preventClickjacking(); $topmarktext .= ' ' . Linker::generateRollback($rev, $this->getContext()); } } # Is there a visible previous revision? if ($rev->userCan(Revision::DELETED_TEXT, $user) && $rev->getParentId() !== 0) { $difftext = Linker::linkKnown($page, $this->messages['diff'], [], ['diff' => 'prev', 'oldid' => $row->rev_id]); } else { $difftext = $this->messages['diff']; } $histlink = Linker::linkKnown($page, $this->messages['hist'], [], ['action' => 'history']); if ($row->rev_parent_id === null) { // For some reason rev_parent_id isn't populated for this row. // Its rumoured this is true on wikipedia for some revisions (bug 34922). // Next best thing is to have the total number of bytes. $chardiff = ' <span class="mw-changeslist-separator">. .</span> '; $chardiff .= Linker::formatRevisionSize($row->rev_len); $chardiff .= ' <span class="mw-changeslist-separator">. .</span> '; } else { $parentLen = 0; if (isset($this->mParentLens[$row->rev_parent_id])) { $parentLen = $this->mParentLens[$row->rev_parent_id]; } $chardiff = ' <span class="mw-changeslist-separator">. .</span> '; $chardiff .= ChangesList::showCharacterDifference($parentLen, $row->rev_len, $this->getContext()); $chardiff .= ' <span class="mw-changeslist-separator">. .</span> '; } $lang = $this->getLanguage(); $comment = $lang->getDirMark() . Linker::revComment($rev, false, true); $date = $lang->userTimeAndDate($row->rev_timestamp, $user); if ($rev->userCan(Revision::DELETED_TEXT, $user)) { $d = Linker::linkKnown($page, htmlspecialchars($date), ['class' => 'mw-changeslist-date'], ['oldid' => intval($row->rev_id)]); } else { $d = htmlspecialchars($date); } if ($rev->isDeleted(Revision::DELETED_TEXT)) { $d = '<span class="history-deleted">' . $d . '</span>'; } # Show user names for /newbies as there may be different users. # Note that we already excluded rows with hidden user names. if ($this->contribs == 'newbie') { $userlink = ' . . ' . $lang->getDirMark() . Linker::userLink($rev->getUser(), $rev->getUserText()); $userlink .= ' ' . $this->msg('parentheses')->rawParams(Linker::userTalkLink($rev->getUser(), $rev->getUserText()))->escaped() . ' '; } else { $userlink = ''; } $flags = []; if ($rev->getParentId() === 0) { $flags[] = ChangesList::flag('newpage'); } if ($rev->isMinor()) { $flags[] = ChangesList::flag('minor'); } $del = Linker::getRevDeleteLink($user, $rev, $page); if ($del !== '') { $del .= ' '; } $diffHistLinks = $this->msg('parentheses')->rawParams($difftext . $this->messages['pipe-separator'] . $histlink)->escaped(); # Tags, if any. list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow($row->ts_tags, 'contributions', $this->getContext()); $classes = array_merge($classes, $newClasses); Hooks::run('SpecialContributions::formatRow::flags', [$this->getContext(), $row, &$flags]); $templateParams = ['del' => $del, 'timestamp' => $d, 'diffHistLinks' => $diffHistLinks, 'charDifference' => $chardiff, 'flags' => $flags, 'articleLink' => $link, 'userlink' => $userlink, 'logText' => $comment, 'topmarktext' => $topmarktext, 'tagSummary' => $tagSummary]; # Denote if username is redacted for this edit if ($rev->isDeleted(Revision::DELETED_USER)) { $templateParams['rev-deleted-user-contribs'] = $this->msg('rev-deleted-user-contribs')->escaped(); } $templateParser = new TemplateParser(); $ret = $templateParser->processTemplate('SpecialContributionsLine', $templateParams); } // Let extensions add data Hooks::run('ContributionsLineEnding', [$this, &$ret, $row, &$classes]); // TODO: Handle exceptions in the catch block above. Do any extensions rely on // receiving empty rows? if ($classes === [] && $ret === '') { wfDebug("Dropping Special:Contribution row that could not be formatted\n"); return "<!-- Could not format Special:Contribution row. -->\n"; } // FIXME: The signature of the ContributionsLineEnding hook makes it // very awkward to move this LI wrapper into the template. return Html::rawElement('li', ['class' => $classes], $ret) . "\n"; }
/** * Return a message box. * @param string $html of contents of box * @param string $className corresponding to box * @return string of html representing a box. */ public static function messageBox($html, $className) { $templateParser = new TemplateParser(__DIR__ . '/../resources/mobile.messageBox/'); return $templateParser->processTemplate('MessageBox', array('className' => $className, 'msg' => $html)); }
public function renderError($args) { $templateParser = new TemplateParser(__DIR__ . '/../../../resources'); $message = $templateParser->processTemplate('mobile.browse/special/gather_error', $args); $this->renderUnavailableBanner($message); }
static function showPage() { global $wgUser, $wgParser; $templateParser = new TemplateParser(__DIR__ . '/View'); $output = ''; // Prevent E_NOTICE //user login if ($wgUser->isLoggedIn()) { $login = true; } else { $login = false; $register = Linker::linkKnown(SpecialPage::getTitleFor('Userlogin'), '注册', array(), array('type' => 'signup')); $active = 'active'; $inactive = 'in active'; } // check mobile device $mobile = mobiledetect(); $mobileUser = $mobile && $login; if (!$mobileUser) { //right data $fileCount = AllSitesInfo::getAllUploadFileCount(); $siteCount = AllSitesInfo::getSiteCountNum(); $userCount = AllSitesInfo::getUsreCountNum(); $editCount = AllSitesInfo::getAllSiteEditCount(); $pageCount = AllSitesInfo::getAllPageCount(); $userName = $wgUser->getName(); $usreId = $wgUser->getId(); $avatar = new wAvatar($usreId, 'l'); $userAvatar = $avatar->getAvatarURL(); //level $stats = new UserStats($usreId, $userName); $stats_data = $stats->getUserStats(); $user_level = new UserLevel($stats_data['points']); $level_link = Title::makeTitle(NS_HELP, wfMessage('user-profile-userlevels-link')->inContentLanguage()->text()); $levelUrl = htmlspecialchars($level_link->getFullURL()); $userLevel = $user_level->getLevelName(); //user info $notice = SpecialPage::getTitleFor('ViewFollows'); $contributions = SpecialPage::getTitleFor('Contributions'); $userEdit = Linker::link($contributions, $stats_data['edits'], array(), array('target' => $userName, 'contribs' => 'user')); $follower = Linker::link($notice, UserUserFollow::getFollowingCount($wgUser), array('id' => 'user-following-count'), array('user' => $userName, 'rel_type' => 1)); $followee = Linker::link($notice, UserUserFollow::getFollowerCount($wgUser), array('id' => 'user-follower-count'), array('user' => $userName, 'rel_type' => 2)); //siterank $yesterday = date('Y-m-d', strtotime('-1 days')); $allSiteRank = AllSitesInfo::getAllSitesRankData('', $yesterday); $siteRank = array_slice($allSiteRank, 0, 10); $siteInfo = array(); foreach ($siteRank as $key => $value) { $siteRank[$key]['site_prefix'] = HuijiPrefix::prefixToSiteName($value['site_prefix']); $siteRank[$key]['site_url'] = HuijiPrefix::prefixToUrl($value['site_prefix']); $siteInfo = AllSitesInfo::getPageInfoByPrefix($value['site_prefix']); $siteRank[$key]['totalEdits'] = $siteInfo['totalEdits']; $siteRank[$key]['totalArticles'] = $siteInfo['totalArticles']; $siteRank[$key]['totalPages'] = $siteInfo['totalPages']; $siteRank[$key]['totalUsers'] = $siteInfo['totalUsers']; } //userrank $weekRank = UserStats::getUserRank(10, 'week'); $monthRank = UserStats::getUserRank(20, 'month'); $totalRank = UserStats::getUserRank(20, 'total'); //小蓝格 $ueb = new UserEditBox(); $editBox = $editData = array(); $userEditInfo = $ueb->getUserEditInfo($usreId); $maxlen = $currentMaxlen = 0; //init variables. foreach ($userEditInfo as $value) { if (is_object($value) && !empty($value->_id) && $value->value > 0) { $editBox[$value->_id] = $value->value; $editData[] = $value->_id; } } $today = date("Y-m-d"); $yesterday = date("Y-m-d", strtotime("-1 day")); $editBox[$today] = UserEditBox::getTodayEdit($usreId); if (!empty($editBox[$today])) { $editData[] = $today; } $totalEdit = count($editData); if ($totalEdit > 0) { $resArr[] = strtotime($editData[0]); $maxlen = 1; } for ($k = 1; $k < count($editData); $k++) { if (in_array(strtotime($editData[$k]) - 86400, $resArr)) { $resArr[] = strtotime($editData[$k]); if (count($resArr) > $maxlen) { $maxlen = count($resArr); } } else { $resArr = array(); $resArr[] = strtotime($editData[$k]); } if ($resArr[count($resArr) - 1] == strtotime($today) || $resArr[count($resArr) - 1] == strtotime($yesterday)) { $currentMaxlen = count($resArr); } else { $currentMaxlen = 0; } } $lange = '<svg width="710" height="110" class=" "> <g transform="translate(20, 20)">'; $n = 676 / 13; $dateArr = array(); for ($k = 0; $k < 365; $k++) { $dateArr[] = date('Y-m-d', strtotime("-{$k} day")); } $desdateArr = array_reverse($dateArr); $translate = array(); for ($i = 0; $i <= $n; $i++) { $trani = $i * 13; $lange .= '<g transform="translate(' . $trani . ', 0)">'; $dayofweek = date('w', strtotime($desdateArr[0])); if ($i == 0) { $j = $dayofweek; $start = 0; $m = 7 - $dayofweek; } else { $j = 0; $m = 7; $start = $i * 7 - $dayofweek; } $zoneDate = array_slice($desdateArr, $start, $m); foreach ($zoneDate as $val) { $arrDate[$j] = $val; $y = $j * 13; $dataCount = isset($editBox[$val]) ? $editBox[$val] : 0; if ($dataCount == 0) { $color = '#eee'; } elseif ($dataCount > 0 && $dataCount <= 8) { $color = '#86beee'; } elseif ($dataCount > 8 && $dataCount <= 21) { $color = '#5ea2de'; } elseif ($dataCount > 21 && $dataCount <= 55) { $color = '#256fb1'; } else { $color = '#0d5493'; } $lange .= '<rect class="day" width="11" height="11" y="' . $y . '" fill="' . $color . '" data-count="' . $dataCount . '" data-date="' . $val . '" title="' . $val . ' 编辑' . $dataCount . '次"></rect>'; $j = $j >= 7 ? 0 : $j + 1; } if (!empty($arrDate[0])) { $translate[$arrDate[0]] = $trani; } $lange .= '</g>'; } $moninit = 1; for ($p = 0; $p < 12; $p++) { $year = date('Y') - 1; $mon = date('m') + $p + 1; if ($mon > 12) { $mon = $moninit++; $year = date('Y'); } $sunDay = UserEditBox::getSunday($mon, $year); $Stime = strtotime($sunDay); $sunDay = date('Y-m-d', $Stime); if (!isset($translate[$sunDay])) { $Suntime = strtotime($sunDay); $Sundate = date('Y', $Suntime) - 1; $sunDay = UserEditBox::getSunday($mon, $Sundate); } foreach ($translate as $key => $value) { if (strtotime($key) == strtotime($sunDay)) { $x = $value; } } $lange .= '<text x="' . $x . '" y="-5" class="' . $year . '">' . $mon . '月</text>'; } $lange .= ' <text text-anchor="middle" class="wday" dx="-10" dy="9" style="display: none;">S</text> <text text-anchor="middle" class="wday" dx="-10" dy="22">M</text> <text text-anchor="middle" class="wday" dx="-10" dy="35" style="display: none;">T</text> <text text-anchor="middle" class="wday" dx="-10" dy="48">W</text> <text text-anchor="middle" class="wday" dx="-10" dy="61" style="display: none;">T</text> <text text-anchor="middle" class="wday" dx="-10" dy="74">F</text> <text text-anchor="middle" class="wday" dx="-10" dy="87" style="display: none;">S</text> </g> </svg>'; //url helpManual huijitramac $helpManual = 'http://www.huiji.wiki/wiki/%E5%B8%AE%E5%8A%A9:%E7%BC%96%E8%BE%91%E6%89%8B%E5%86%8C'; $tarmac = 'http://www.huiji.wiki/wiki/%E7%81%B0%E6%9C%BAwiki:%E7%81%B0%E6%9C%BA%E5%81%9C%E6%9C%BA%E5%9D%AA'; $contact = 'http://www.huiji.wiki/wiki/%E7%81%B0%E6%9C%BAwiki:%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC'; } if ($login) { // follow $followUserCount = UserUserFollow::getFollowingCount($wgUser); if ($followUserCount >= 5) { $userHidden = true; } else { $userHidden = false; } $followSiteCount = UserSiteFollow::getFollowingCount($wgUser); if ($followSiteCount >= 5) { $siteHidden = true; } else { $siteHidden = false; } //recommend user $weekRank $monthRank $totalRank $uuf = new UserUserFollow(); if (count($weekRank) >= 8) { $recommend = UserStats::getUserRank(10, 'week'); } elseif (count($monthRank) >= 8) { $recommend = UserStats::getUserRank(20, 'month'); } else { $recommend = UserStats::getUserRank(20, 'total'); } $recommendRes = array(); $flres = array(); foreach ($recommend as $value) { $tuser = User::newFromName($value['user_name']); $isFollow = $uuf->checkUserUserFollow($wgUser, $tuser); if (!$isFollow && $value['user_name'] != $userName) { $flres['avatar'] = $value['avatarImage']; $flres['username'] = $value['user_name']; $flres['userurl'] = $value['user_url']; $recommendRes[] = $flres; } } $recommendRes = array_slice($recommendRes, 0, 5); //recommend site $usf = new UserSiteFollow(); // $recSite = array_slice($allSiteRank,0 ,5); $recommendSite = array(); foreach ($allSiteRank as $value) { $isFollowSite = $usf->checkUserSiteFollow($wgUser, $value['site_prefix']); if ($isFollowSite == false) { $fsres['s_name'] = HuijiPrefix::prefixToSiteName($value['site_prefix']); $fsres['s_url'] = HuijiPrefix::prefixToUrl($value['site_prefix']); $fsres['s_prefix'] = $value['site_prefix']; $fsres['s_avatar'] = (new wSiteAvatar($value['site_prefix'], 'l'))->getAvatarHtml(); $recommendSite[] = $fsres; } } $recommendSite = array_slice($recommendSite, 0, 5); if ($login && !$mobile) { $infoHeader = wfMessage('info-header-user')->parseAsBlock(); } elseif (!$login) { $infoHeader = wfMessage('info-header-anon')->parseAsBlock(); } else { $infoHeader = ''; } } $output .= $templateParser->processTemplate('frontpage', array('mobileUser' => $mobileUser, 'infoHeader' => $infoHeader, 'fileCount' => $fileCount, 'siteCount' => $siteCount, 'userCount' => $userCount, 'editCount' => $editCount, 'pageCount' => $pageCount, 'userName' => $userName, 'userAvatar' => $userAvatar, 'levelUrl' => $levelUrl, 'userLevel' => $userLevel, 'userEdit' => $userEdit, 'follower' => $follower, 'followee' => $followee, 'siteRank' => $siteRank, 'weekRank' => $weekRank, 'monthRank' => $monthRank, 'totalRank' => $totalRank, 'lange' => $lange, 'login' => $login, 'register' => $register, 'userHidden' => $userHidden, 'siteHidden' => $siteHidden, 'active' => $active, 'inactive' => $inactive, 'recommendSite' => $recommendSite, 'recContent' => $recContent, 'followUserCount' => $followUserCount, 'followSiteCount' => $followSiteCount, 'helpManual' => $helpManual, 'tarmac' => $tarmac, 'contact' => $contact)); return $output; }
public static function getCarousel($input, $args, $parser) { // global $wgUser; // $parser->disableCache(); $id = isset($args['id']) ? $args['id'] : 'carousel-generic' . self::$nextId++; $interval = isset($args['interval']) ? $args['interval'] : '5000'; $width = isset($args['width']) ? $args['width'] : null; // $button = isset( $args['button'] ) ? $args['button'] : '下拉菜单'; // $id = isset( $args['id'] ) ? $args['id']: hash('sha1', $button, false); $arr = explode(PHP_EOL, $input); $li = array(); $i = 0; foreach ($arr as $line) { if (trim($line) == '') { // $i++; continue; } $group = array(); $temp = explode('|', $line); // $options = ParserOptions::newFromUser($wgUser); $group['id'] = $id; $group['image'] = $parser->recursiveTagParse('[[' . $temp[0] . ($width != null ? "|{$width}" : "") . ']]'); $group['caption'] = isset($temp[1]) ? $parser->recursiveTagParse($temp[1]) : ''; $group['i'] = $i; if ($i == 0) { $group['active'] = 'active'; } else { $group['active'] = ''; } // $group['caption'] = $parser->recursiveTagParse($temp[0]); // $group['body'] = $parser->recursiveTagParse($temp[1]); // $group['hid'] = hash('sha1', $group['title'].$i, false); // $group['id'] = hash('sha1', $group['body'].$i, false); $i++; $li[] = $group; } $templateParser = new TemplateParser(__DIR__ . '/View'); $output = $templateParser->processTemplate('carousel', array('id' => $id, 'li' => $li)); return $output; }
/** * Enhanced RC group * @param RCCacheEntry[] $block * @return string * @throws DomainException */ protected function recentChangesBlockGroup($block) { $recentChangesFlags = $this->getConfig()->get('RecentChangesFlags'); # Add the namespace and title of the block as part of the class $tableClasses = ['mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc']; if ($block[0]->mAttribs['rc_log_type']) { # Log entry $tableClasses[] = Sanitizer::escapeClass('mw-changeslist-log-' . $block[0]->mAttribs['rc_log_type']); } else { $tableClasses[] = Sanitizer::escapeClass('mw-changeslist-ns' . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title']); } if ($block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched) { $tableClasses[] = 'mw-changeslist-line-watched'; } else { $tableClasses[] = 'mw-changeslist-line-not-watched'; } # Collate list of users $userlinks = []; # Other properties $curId = 0; # Some catalyst variables... $namehidden = true; $allLogs = true; $RCShowChangedSize = $this->getConfig()->get('RCShowChangedSize'); # Default values for RC flags $collectedRcFlags = []; foreach ($recentChangesFlags as $key => $value) { $flagGrouping = isset($recentChangesFlags[$key]['grouping']) ? $recentChangesFlags[$key]['grouping'] : 'any'; switch ($flagGrouping) { case 'all': $collectedRcFlags[$key] = true; break; case 'any': $collectedRcFlags[$key] = false; break; default: throw new DomainException("Unknown grouping type \"{$flagGrouping}\""); } } foreach ($block as $rcObj) { // If all log actions to this page were hidden, then don't // give the name of the affected page for this block! if (!$this->isDeleted($rcObj, LogPage::DELETED_ACTION)) { $namehidden = false; } $u = $rcObj->userlink; if (!isset($userlinks[$u])) { $userlinks[$u] = 0; } if ($rcObj->mAttribs['rc_type'] != RC_LOG) { $allLogs = false; } # Get the latest entry with a page_id and oldid # since logs may not have these. if (!$curId && $rcObj->mAttribs['rc_cur_id']) { $curId = $rcObj->mAttribs['rc_cur_id']; } $userlinks[$u]++; } # Sort the list and convert to text krsort($userlinks); asort($userlinks); $users = []; foreach ($userlinks as $userlink => $count) { $text = $userlink; $text .= $this->getLanguage()->getDirMark(); if ($count > 1) { // @todo FIXME: Hardcoded '×'. Should be a message. $formattedCount = $this->getLanguage()->formatNum($count) . '×'; $text .= ' ' . $this->msg('parentheses')->rawParams($formattedCount)->escaped(); } array_push($users, $text); } # Article link $articleLink = ''; $revDeletedMsg = false; if ($namehidden) { $revDeletedMsg = $this->msg('rev-deleted-event')->escaped(); } elseif ($allLogs) { $articleLink = $this->maybeWatchedLink($block[0]->link, $block[0]->watched); } else { $articleLink = $this->getArticleLink($block[0], $block[0]->unpatrolled, $block[0]->watched); } $queryParams['curid'] = $curId; # Sub-entries $lines = []; foreach ($block as $i => $rcObj) { $line = $this->getLineData($block, $rcObj, $queryParams); if (!$line) { // completely ignore this RC entry if we don't want to render it unset($block[$i]); continue; } // Roll up flags foreach ($line['recentChangesFlagsRaw'] as $key => $value) { $flagGrouping = isset($recentChangesFlags[$key]['grouping']) ? $recentChangesFlags[$key]['grouping'] : 'any'; switch ($flagGrouping) { case 'all': if (!$value) { $collectedRcFlags[$key] = false; } break; case 'any': if ($value) { $collectedRcFlags[$key] = true; } break; default: throw new DomainException("Unknown grouping type \"{$flagGrouping}\""); } } $lines[] = $line; } // Further down are some assumptions that $block is a 0-indexed array // with (count-1) as last key. Let's make sure it is. $block = array_values($block); if (empty($block) || !$lines) { // if we can't show anything, don't display this block altogether return ''; } $logText = $this->getLogText($block, $queryParams, $allLogs, $collectedRcFlags['newpage'], $namehidden); # Character difference (does not apply if only log items) $charDifference = false; if ($RCShowChangedSize && !$allLogs) { $last = 0; $first = count($block) - 1; # Some events (like logs and category changes) have an "empty" size, so we need to skip those... while ($last < $first && $block[$last]->mAttribs['rc_new_len'] === null) { $last++; } while ($last < $first && $block[$first]->mAttribs['rc_old_len'] === null) { $first--; } # Get net change $charDifference = $this->formatCharacterDifference($block[$first], $block[$last]); } $numberofWatchingusers = $this->numberofWatchingusers($block[0]->numberofWatchingusers); $usersList = $this->msg('brackets')->rawParams(implode($this->message['semicolon-separator'], $users))->escaped(); $templateParams = ['articleLink' => $articleLink, 'charDifference' => $charDifference, 'collectedRcFlags' => $this->recentChangesFlags($collectedRcFlags), 'languageDirMark' => $this->getLanguage()->getDirMark(), 'lines' => $lines, 'logText' => $logText, 'numberofWatchingusers' => $numberofWatchingusers, 'rev-deleted-event' => $revDeletedMsg, 'tableClasses' => $tableClasses, 'timestamp' => $block[0]->timestamp, 'users' => $usersList]; $this->rcCacheIndex++; $templateParser = new TemplateParser(); return $templateParser->processTemplate('EnhancedChangesListGroup', $templateParams); }
/** * Add talk, contributions, and uploads links at the top of the user page. * * @inheritdoc * @param BaseTemplate $tpl */ protected function prepareHeaderAndFooter(BaseTemplate $tpl) { parent::prepareHeaderAndFooter($tpl); if ($this->isUserPage) { $talkPage = $this->pageUser->getTalkPage(); $data = array('talkPageTitle' => $talkPage->getPrefixedURL(), 'talkPageLink' => $talkPage->getLocalUrl(), 'talkPageLinkTitle' => $this->msg('mobile-frontend-user-page-talk')->escaped(), 'contributionsPageLink' => SpecialPage::getTitleFor('Contributions', $this->pageUser)->getLocalURL(), 'contributionsPageTitle' => $this->msg('mobile-frontend-user-page-contributions')->escaped(), 'uploadsPageLink' => SpecialPage::getTitleFor('Uploads', $this->pageUser)->getLocalURL(), 'uploadsPageTitle' => $this->msg('mobile-frontend-user-page-uploads')->escaped()); $templateParser = new TemplateParser(__DIR__); $tpl->set('postheadinghtml', $templateParser->processTemplate('user_page_links', $data)); } }
/** * In addition to the main menu, this function renders the search form on top of the menu * @inheritdoc */ protected function getMainMenuHtml($data) { $templateParser = new TemplateParser(__DIR__); $args = array('searchForm' => $this->getSearchForm($data)); return $templateParser->processTemplate('searchForm', $args) . parent::getMainMenuHtml($data); }
/** * Create and prepare header and footer content * @param BaseTemplate $tpl */ protected function prepareHeaderAndFooter(BaseTemplate $tpl) { $title = $this->getTitle(); $user = $this->getUser(); $out = $this->getOutput(); if ($this->isUserPage) { $talkPage = $this->pageUser->getTalkPage(); $data = array('talkPageTitle' => $talkPage->getPrefixedURL(), 'talkPageLink' => $talkPage->getLocalUrl(), 'talkPageLinkTitle' => $this->msg('mobile-frontend-user-page-talk')->escaped(), 'contributionsPageLink' => SpecialPage::getTitleFor('Contributions', $this->pageUser)->getLocalURL(), 'contributionsPageTitle' => $this->msg('mobile-frontend-user-page-contributions')->escaped(), 'uploadsPageLink' => SpecialPage::getTitleFor('Uploads', $this->pageUser)->getLocalURL(), 'uploadsPageTitle' => $this->msg('mobile-frontend-user-page-uploads')->escaped()); $templateParser = new TemplateParser(__DIR__); $tpl->set('postheadinghtml', $templateParser->processTemplate('user_page_links', $data)); } elseif ($title->isMainPage()) { if ($user->isLoggedIn()) { $pageTitle = wfMessage('mobile-frontend-logged-in-homepage-notification', $user->getName())->text(); } else { $pageTitle = ''; } $out->setPageTitle($pageTitle); } if ($this->canUseWikiPage()) { // If it's a page that exists, add last edited timestamp if ($this->getWikiPage()->exists()) { $tpl->set('historyLink', $this->getHistoryLink($title)); } } $tpl->set('headinghtml', $this->getHeaderHtml()); // set defaults if (!isset($tpl->data['postbodytext'])) { $tpl->set('postbodytext', ''); // not currently set in desktop skin } }
/** * Render the entire page * @param array $data Data used to build the page * @todo replace with template engines */ protected function render($data) { $templateParser = new TemplateParser(__DIR__); // begin rendering echo $data['headelement']; ?> <div id="mw-mf-viewport"> <nav id="mw-mf-page-left" class="navigation-drawer view-border-box"> <?php echo $this->getMainMenuHtml($data); ?> </nav> <div id="mw-mf-page-center"> <div class="banner-container"> <?php echo $templateParser->processTemplate('banners', $data); ?> </div> <div class="header"> <?php echo $this->getHeaderHtml($data); ?> </div> <div id="content" class="mw-body"> <?php $this->renderContentWrapper($data); ?> </div> <?php $this->renderFooter($data); ?> </div> </div> <?php $this->printTrail(); ?> </body> </html> <?php }
/** * Render the page * @param string $par The username of the user to display */ public function executeWhenAvailable($par) { $out = $this->getOutput(); $this->setHeaders(); $out->addJsConfigVars(array('wgMFMaxDescriptionChars' => self::MAX_DESCRIPTION_CHARS)); if ($par) { $this->targetUser = User::newFromName($par); $pageTitle = $this->targetUser ? $this->targetUser->getName() : $par; $out->setPageTitle($pageTitle); // Make sure this is a valid registered user and not an invalid username (e.g. ip see bug 56822) if ($this->targetUser && $this->targetUser->getId()) { // Prepare content $templateParser = new TemplateParser(__DIR__); $this->userInfo = new MobileUserInfo($this->targetUser); $html = $templateParser->processTemplate('userprofile', $this->getTemplateData($templateParser)); $out->addHtml($html); } else { $this->displayNoUserError('mobile-frontend-profile-nouser'); } } else { $out->setPageTitle($this->msg('mobile-frontend-profile-title')); $this->displayNoUserError('mobile-frontend-profile-noargs'); } }
/** * Render the settings form (with actual set settings) to display to user */ private function getSettingsForm() { $out = $this->getOutput(); $context = MobileContext::singleton(); $user = $this->getUser(); $out->setPageTitle($this->msg('mobile-frontend-main-menu-settings-heading')); if ($this->getRequest()->getCheck('success')) { $out->wrapWikiMsg("<div class=\"successbox\"><strong>\n\$1\n</strong></div><div id=\"mw-pref-clear\"></div>", 'savedprefs'); } $betaEnabled = $context->isBetaGroupMember(); $imagesChecked = $context->imagesDisabled() ? '' : 'checked'; // images are off when disabled $imagesBeta = $betaEnabled ? 'checked' : ''; $imagesDescriptionMsg = $this->msg('mobile-frontend-settings-images-explain')->parse(); $disableMsg = $this->msg('mobile-frontend-images-status')->parse(); $betaEnableMsg = $this->msg('mobile-frontend-settings-beta')->parse(); $betaDescriptionMsg = $this->msg('mobile-frontend-opt-in-explain')->parse(); $saveSettings = $this->msg('mobile-frontend-save-settings')->escaped(); $action = $this->getPageTitle()->getLocalURL(); $html = Html::openElement('form', array('class' => 'mw-mf-settings', 'method' => 'POST', 'action' => $action)); $token = $user->isLoggedIn() ? Html::hidden('token', $user->getEditToken()) : ''; $returnto = Html::hidden('returnto', $this->returnToTitle->getFullText()); // array to save the data of options, which should be displayed here $options = array(); // image settings $options['images'] = array('checked' => $imagesChecked, 'label' => $disableMsg, 'description' => $imagesDescriptionMsg, 'name' => 'enableImages', 'id' => 'enable-images-toggle'); // beta settings if ($this->getMFConfig()->get('MFEnableBeta')) { $options['beta'] = array('checked' => $imagesBeta, 'label' => $betaEnableMsg, 'description' => $betaDescriptionMsg, 'name' => 'enableBeta', 'id' => 'enable-beta-toggle'); } $templateParser = new TemplateParser(__DIR__ . '/../../resources/mobile.special.mobileoptions.scripts'); // @codingStandardsIgnoreStart Long line foreach ($options as $key => $data) { if (isset($data['type']) && $data['type'] === 'hidden') { $html .= Html::element('input', array('type' => 'hidden', 'name' => $data['name'], 'value' => $data['checked'])); } else { $html .= $templateParser->processTemplate('checkbox', $data); } } $className = MobileUI::buttonClass('constructive'); $html .= <<<HTML \t\t<input type="submit" class="{$className}" id="mw-mf-settings-save" value="{$saveSettings}"> \t\t{$token} \t\t{$returnto} \t</form> HTML; // @codingStandardsIgnoreEnd $out->addHTML($html); }
/** * Render the entire page * @param array $data Data used to build the page * @todo replace with template engines */ protected function render($data) { $templateParser = new TemplateParser(__DIR__); $internalBanner = $data['internalBanner']; $preBodyText = isset($data['prebodyhtml']) ? $data['prebodyhtml'] : ''; $data = array_merge($data, array('hasHistory' => isset($data['historyLink']), 'hasSubjectPage' => isset($data['subject-page']), 'isSpecialPage' => $this->isSpecialPage, 'hasPageActions' => count($this->getPageActions()), 'hasPreBodyText' => $internalBanner || $preBodyText || isset($data['page_actions']), 'footerRows' => $this->getFooterRows($data), 'debug' => MWDebug::getDebugHTML($this->getSkin()->getContext()), 'pageactionshtml' => $this->getPageActionsHtml($data), 'secondaryactionshtml' => $this->getSecondaryActionsHtml(), 'searchhtml' => $this->getSearchForm($data))); echo $templateParser->processTemplate('minervaNeue', $data); }