/** * Displays a list of recently approved links if this feature is enabled in * $wgLinkPageDisplay. * * @return HTML */ function getNewLinks() { global $wgLinkPageDisplay; if (!$wgLinkPageDisplay['new_links']) { return ''; } $output = ''; $linkRedirect = SpecialPage::getTitleFor('LinkRedirect'); $l = new LinkList(); $links = $l->getLinkList(LINK_APPROVED_STATUS, '', 7, 0); foreach ($links as $link) { $output .= '<div class="link-recent"> <a href="' . $linkRedirect->escapeFullURL("url={$link['url']}") . "\" target=\"new\">{$link['title']}</a>\n\t\t</div>"; } $output = '<div class="link-container"> <h2>' . wfMsg('linkfilter-new-links-title') . '</h2> <div>' . $output . '</div> </div>'; return $output; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgOut, $wgRequest, $wgSupressPageTitle; $wgSupressPageTitle = true; // Add CSS & JS $wgOut->addModules('ext.linkFilter'); $per_page = 20; $page = $wgRequest->getInt('page', 1); $link_type = $wgRequest->getInt('link_type'); if ($link_type) { $type_name = Link::$link_types[$link_type]; $pageTitle = wfMsg('linkfilter-home-title', $type_name); } else { $type_name = 'All'; $pageTitle = wfMsg('linkfilter-home-title-all'); } $wgOut->setPageTitle($pageTitle); $output = '<div class="links-home-left">' . "\n\t"; $output .= '<h1 class="page-title">' . $pageTitle . '</h1>' . "\n\t"; $output .= '<div class="link-home-navigation"> <a href="' . Link::getSubmitLinkURL() . '">' . wfMsg('linkfilter-submit-title') . '</a>' . "\n"; if (Link::canAdmin()) { $output .= "\t\t" . '<a href="' . Link::getLinkAdminURL() . '">' . wfMsg('linkfilter-approve-links') . '</a>' . "\n"; } $output .= "\t\t" . '<div class="cleared"></div> </div>' . "\n"; $l = new LinkList(); $type = 0; // FIXME lazy hack --Jack on July 2, 2009 $total = $l->getLinkListCount(LINK_APPROVED_STATUS, $type); $links = $l->getLinkList(LINK_APPROVED_STATUS, $type, $per_page, $page, 'link_approved_date'); $linkRedirect = SpecialPage::getTitleFor('LinkRedirect'); $output .= '<div class="links-home-container">'; $link_count = count($links); $x = 1; // No links at all? Oh dear...show a message to the user about that! if ($link_count <= 0) { $wgOut->addWikiMsg('linkfilter-no-links-at-all'); } // Create RSS feed icon for special page $wgOut->setSyndicated(true); // Make feed (RSS/Atom) if requested $feedType = $wgRequest->getVal('feed'); if ($feedType != '') { return $this->makeFeed($feedType, $links); } foreach ($links as $link) { $border_fix = ''; if ($link_count == $x) { $border_fix = 'border-fix'; } $border_fix2 = ''; wfSuppressWarnings(); $date = date('l, F j, Y', $link['approved_timestamp']); if ($date != $last_date) { $border_fix2 = ' border-top-fix'; $output .= "<div class=\"links-home-date\">{$date}</div>"; #global $wgLang; #$unix = wfTimestamp( TS_MW, $link['approved_timestamp'] ); #$weekday = $wgLang->getWeekdayName( gmdate( 'w', $unix ) + 1 ); #$output .= '<div class="links-home-date">' . $weekday . # wfMsg( 'word-separator' ) . $wgLang->date( $unix, true ) . # '</div>'; } wfRestoreWarnings(); // okay, so suppressing E_NOTICEs is kinda bad practise, but... -Jack, January 21, 2010 $last_date = $date; $output .= "<div class=\"link-item-container{$border_fix2}\">\n\t\t\t\t\t<div class=\"link-item-type\">\n\t\t\t\t\t\t{$link['type_name']}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"link-item\">\n\t\t\t\t\t\t<div class=\"link-item-url\">\n\t\t\t\t\t\t\t<a href=\"" . $linkRedirect->escapeFullURL(array('link' => 'true', 'url' => $link['url'])) . '" target="new">' . $link['title'] . '</a> </div> <div class="link-item-desc">' . $link['description'] . '</div> </div> <div class="link-item-page"> <a href="' . $link['wiki_page'] . '">(' . wfMsgExt('linkfilter-comments', 'parsemag', $link['comments']) . ')</a> </div> <div class="cleared"></div>'; $output .= '</div>'; $x++; } $output .= '</div>'; /** * Build next/prev nav */ $numofpages = $total / $per_page; $pageLink = $this->getTitle(); if ($numofpages > 1) { $output .= '<div class="page-nav">'; if ($page > 1) { $output .= '<a href="' . $pageLink->escapeFullURL('page=' . ($page - 1)) . '">' . wfMsg('linkfilter-previous') . '</a> '; } if ($total % $per_page != 0) { $numofpages++; } if ($numofpages >= 9 && $page < $total) { $numofpages = 9 + $page; } if ($numofpages > $total / $per_page) { $numofpages = $total / $per_page + 1; } for ($i = 1; $i <= $numofpages; $i++) { if ($i == $page) { $output .= $i . ' '; } else { $output .= '<a href="' . $pageLink->escapeFullURL('page=' . $i) . "\">{$i}</a> "; } } if ($total - $per_page * $page > 0) { $output .= ' <a href="' . $pageLink->escapeFullURL('page=' . ($page + 1)) . '">' . wfMsg('linkfilter-next') . '</a>'; } $output .= '</div>'; } $output .= '</div>' . "\n"; // .links-home-left global $wgLinkPageDisplay; if ($wgLinkPageDisplay['rightcolumn']) { $output .= '<div class="links-home-right">'; $output .= '<div class="links-home-unit-container">'; $output .= $this->getPopularArticles(); $output .= $this->getInTheNews(); $output .= '</div>'; $output .= $this->getAdUnit(); $output .= '</div>'; } $output .= '<div class="cleared"></div>' . "\n"; $wgOut->addHTML($output); }
/** * Callback function for registerLinkFilterHook. */ public static function renderLinkFilterHook($input, $args, $parser) { global $wgMemc, $wgOut; $parser->disableCache(); // Add CSS (ParserOutput class only has addModules(), not // addModuleStyles() or addModuleScripts()...strange) $wgOut->addModuleStyles('ext.linkFilter'); if (isset($args['count'])) { $count = intval($args['count']); } else { $count = 10; } $key = wfMemcKey('linkfilter', $count); $data = $wgMemc->get($key); if ($data) { wfDebugLog('LinkFilter', "Loaded linkfilter hook from cache\n"); $links = $data; } else { wfDebugLog('LinkFilter', "Loaded linkfilter hook from DB\n"); $l = new LinkList(); $links = $l->getLinkList(LINK_APPROVED_STATUS, '', $count, 1, 'link_approved_date'); $wgMemc->set($key, $links, 60 * 5); } $link_submit = SpecialPage::getTitleFor('LinkSubmit'); $link_all = SpecialPage::getTitleFor('LinksHome'); $output = '<div> <div class="linkfilter-links"> <a href="' . $link_submit->escapeFullURL() . '">' . wfMsg('linkfilter-submit') . '</a> / <a href="' . $link_all->escapeFullURL() . '">' . wfMsg('linkfilter-all') . '</a>'; // Show a link to the link administration panel for privileged users if (Link::canAdmin()) { $output .= ' / <a href="' . Link::getLinkAdminURL() . '">' . wfMsg('linkfilter-approve-links') . '</a>'; } $output .= '</div> <div class="cleared"></div>'; foreach ($links as $link) { $output .= '<div class="link-item-hook"> <span class="link-item-hook-type">' . $link['type_name'] . '</span> <span class="link-item-hook-url"> <a href="' . $link['wiki_page'] . '" rel="nofollow">' . $link['title'] . '</a> </span> <span class="link-item-hook-page"> <a href="' . $link['wiki_page'] . '">(' . wfMsgExt('linkfilter-comments', 'parsemag', $link['comments']) . ')</a> </span> </div>'; } $output .= '</div>'; return $output; }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgUser, $wgOut, $wgRequest; // Check for linkadmin permission if (!$wgUser->isAllowed('linkadmin')) { throw new ErrorPageError('error', 'badaccess'); return false; } // Blocked through Special:Block? No access for you either! if ($wgUser->isBlocked()) { $wgOut->blockedPage(false); return false; } // Is the database locked or not? if (wfReadOnly()) { $wgOut->readOnlyPage(); return false; } // Set the page title $wgOut->setPageTitle(wfMsgHtml('linkfilter-approve-title')); // Add CSS & JS $wgOut->addModules('ext.linkFilter'); $output = ''; $output .= '<div class="lr-left">'; $l = new LinkList(); $links = $l->getLinkList(LINK_OPEN_STATUS, 0, 0, 0); $links_count = count($links); $x = 1; // The approval queue is empty? If so, show a message to the user about // that! if ($links_count <= 0) { $wgOut->addWikiMsg('linkfilter-nothing-to-approve'); } foreach ($links as $link) { $submitter = Title::makeTitle(NS_USER, $link['user_name']); $linkText = preg_replace_callback('/(<a[^>]*>)(.*?)(<\\/a>)/i', array('LinkApprove', 'cutLinkFilterLinkText'), "<a href=\"{$link['url']}\" target=\"new\">{$link['url']}</a>"); $border_fix = ''; if ($links_count == $x) { $border_fix = ' border-fix'; } $output .= "<div class=\"admin-link{$border_fix}\">\n\t\t\t\t\t<div class=\"admin-title\"><b>" . wfMsg('linkfilter-title') . '</b>: ' . htmlspecialchars($link['title']) . '</div> <div class="admin-desc"><b>' . wfMsg('linkfilter-description') . '</b>: ' . htmlspecialchars($link['description']) . '</div> <div class="admin-url"><b>' . wfMsg('linkfilter-url') . '</b>: <a href="' . $link['url'] . '" target="new">' . $linkText . '</a></div> <div class="admin-submitted"><b>' . wfMsg('linkfilter-submittedby') . "</b>: <a href=\"{$submitter->escapeFullURL()}\">{$link['user_name']}</a> " . wfMsg('linkfilter-ago', self::getLFTimeAgo($link['timestamp']), Link::getLinkType($link['type'])) . "</div>\n\t\t\t\t\t<div id=\"action-buttons-{$link['id']}\" class=\"action-buttons\">\n\t\t\t\t\t\t<a href=\"javascript:void(0);\" class=\"action-accept\" data-link-id=\"{$link['id']}\">" . wfMsgHtml('linkfilter-admin-accept') . "</a>\n\t\t\t\t\t\t<a href=\"javascript:void(0);\" class=\"action-reject\" data-link-id=\"{$link['id']}\">" . wfMsgHtml('linkfilter-admin-reject') . '</a> <div class="cleared"></div> </div>'; $output .= '</div>'; $x++; } // Admin instructions and the column of recently approved links $output .= '</div>'; $output .= '<div class="lr-right"> <div class="admin-link-instruction">' . wfMessage('linkfilter-admin-instructions')->inContentLanguage()->parse() . '</div> <div class="approved-link-container"> <h3>' . wfMsgHtml('linkfilter-admin-recent') . '</h3>'; $l = new LinkList(); $links = $l->getLinkList(LINK_APPROVED_STATUS, 0, 10, 0, 'link_approved_date'); // Nothing has been approved recently? Okay... if (count($links) <= 0) { $output .= wfMsg('linkfilter-no-recently-approved'); } else { // Yay, we have something! Let's build a list! foreach ($links as $link) { $output .= '<div class="approved-link"> <a href="' . $link['url'] . '" target="new">' . $link['title'] . '</a> <span class="approve-link-time">' . wfMsg('linkfilter-ago', self::getLFTimeAgo($link['approved_timestamp']), Link::getLinkType($link['type'])) . '</span> </div>'; } } $output .= '</div> </div> <div class="cleared"></div>'; $wgOut->addHTML($output); }