public function tryToTestBlogs(WebGuy $I, $scenario) { $I->am('simple user'); $I->amOnPage(\BlogPage::BLOGS_URL); $I->seeInTitle('Блоги'); $I->seeLink('Опубликованный блог'); $I->see('Опубликованный блог описание'); $I->dontSeeLink('Удаленный блог'); $I->amGoingTo('test blog show page'); $I->expectTo('see blog page'); $I->amOnPage(\BlogPage::getBlogRoute(\BlogPage::PUBLIC_BLOG_SLUG)); $I->seeLink('Опубликованный блог'); $I->see('Опубликованный блог описание'); $I->see('Участников нет =('); $I->seeLink('Первая публичная запись в опубликованном блоге'); $tags = ['тег', 'тег2', 'тег3']; foreach ($tags as $tag) { $I->seeLink($tag); } $I->dontSeeLink('Черновик в опубликованном блоге'); $I->amGoingTo('test blog page with deleted blog'); $I->expectTo('see http exception'); $I->amOnPage(\BlogPage::getBlogRoute(\BlogPage::DELETED_BLOG_SLUG)); $I->see('Страница которую вы запросили не найдена.'); }
public function tryToTestFrontend(WebGuy $I, $scenario) { $I->amGoingTo('test main modules on frontend'); $I->amOnPage('/ru/'); $I->see('Поздравляем!', 'h1'); //blogs $I->amOnPage(\BlogPage::BLOGS_URL); $I->seeInTitle('Блоги'); $I->seeLink('Опубликованный блог'); $I->see('Опубликованный блог описание'); $I->amGoingTo('test blog show page'); $I->expectTo('see blog page'); $I->amOnPage(\BlogPage::getBlogRoute(\BlogPage::PUBLIC_BLOG_SLUG)); $I->seeLink('Опубликованный блог'); $I->see('Опубликованный блог описание'); $I->see('Участников нет =('); //feedback $I->amGoingTo('test contacts page'); $I->amOnPage(\FeedBackPage::CONTACTS_URL); $I->seeInTitle('Контакты'); $I->see('Контакты', 'h1'); $I->amOnPage(\FeedBackPage::FAQ_URL); $I->see('Вопросы и ответы', 'h1'); $I->see('Задайте вопрос ?!', '.btn'); //news $I->am('simple user'); $I->amGoingTo('test news list page...'); $I->amOnPage(\NewsPage::URL); $I->see('Новости', 'h1'); $I->seeLink('Первая опубликованная новость'); $I->am('anonymous user'); $I->amGoingTo('test show news page...'); $I->amOnPage(\NewsPage::route('pervaja-opublikovannaja-novost')); $I->expectTo('see published news...'); $I->see('Первая опубликованная новость', 'h4'); $I->see('Первая опубликованная текст'); $I->seeInTitle('Первая опубликованная новость'); //page $I->wantToTest('show published page...'); $I->amOnPage('/pages/opublikovannaja-starnica'); $I->seeInTitle('Опубликованная страница'); $I->see('Опубликованная страница', 'h3'); $I->see('Опубликованная страница текст'); //users $I->amOnPage('/users/'); $I->see('Пользователи', 'h1'); $I->seeLink('yupe'); //gallery $I->amOnPage(\GalleryPage::ALBUMS_URL); $I->see('Галереи изображений'); $I->seeLink('Первая галерея'); $I->amOnPage('/en/'); $I->see('Congratulations!', 'h1'); $I->amOnPage('/ru/'); $I->see('Поздравляем!', 'h1'); $I->amOnPage('/en/'); $I->see('Congratulations!', 'h1'); $I->amOnPage('/ru/'); $I->see('Поздравляем!', 'h1'); }
public function onLoad($param) { parent::onLoad($param); if (!$this->IsPostBack) { $this->bindData(); } }
public function onLoad($param) { parent::onLoad($param); if (!$this->IsPostBack) { $this->CategoryName->Text = $this->_category->Name; $this->CategoryDescription->Text = $this->_category->Description; } }
public function onLoad($param) { parent::onLoad($param); if (!$this->IsPostBack) { $this->Categories->DataSource = $this->DataAccess->queryCategories(); $this->Categories->dataBind(); } }
public function onLoad($param) { parent::onLoad($param); $this->Status->Visible = $this->_post->Status !== PostRecord::STATUS_PUBLISHED && $this->_post->Status !== PostRecord::STATUS_STICKY; $this->CategoryList->DataSource = $this->DataAccess->queryCategoriesByPostID($this->_post->ID); $this->CategoryList->dataBind(); $this->CommentList->DataSource = $this->DataAccess->queryCommentsByPostID($this->_post->ID); $this->CommentList->dataBind(); }
public function onLoad($param) { parent::onLoad($param); if (!$this->IsPostBack) { $userRecord = $this->_userRecord; $this->Username->Text = $userRecord->Name; $this->FullName->Text = $userRecord->FullName; $this->Email->Text = $userRecord->Email; $this->Website->Text = $userRecord->Website; } }
public function onInit($param) { parent::onInit($param); if (($id = $this->Request['id']) !== null) { $id = TPropertyValue::ensureInteger($id); } else { $id = $this->User->ID; } if (($this->_userRecord = $this->DataAccess->queryUserByID($id)) === null) { throw new BlogException(500, 'profile_id_invalid', $id); } $this->_userRecord->Email = strtr(strtoupper($this->_userRecord->Email), array('@' => ' at ', '.' => ' dot ')); }
/** * Create a page using the pagetype */ public function initPage() { $this->setPageType(); $page = null; switch ($this->pageType) { case 'menu': $page = new Page($this->param); break; case 'content': $page = new ContentPage($this->param); break; case 'contact': $page = new ContactPage($this->param); break; case 'news': $page = new NewsPage($this->param); break; case 'blog': $page = new BlogPage($this->param); break; } $page->showPage(); }
public function NavigationLink($direction) { switch ($direction) { case 'next': $sort = 'Sort:GreaterThan'; break; case 'prev': $sort = 'Sort:LessThan'; break; default: return false; } $page = BlogPage::get()->filter(array('ParentID' => $this->ParentID, $sort => $this->Sort))->sort('Sort ASC')->first(); return $page; }
public function onLoad($param) { parent::onLoad($param); $this->PostList->DataSource = $this->_posts; $this->PostList->dataBind(); if ($this->getPageOffset() > 0) { if (($offset = $this->getPageOffset() - $this->getPageSize()) < 0) { $offset = 0; } $this->PrevPage->NavigateUrl = $this->formUrl($offset); $this->PrevPage->Visible = true; } if (count($this->_posts) === $this->getPageSize()) { $this->NextPage->NavigateUrl = $this->formUrl($this->getPageOffset() + $this->getPageSize()); $this->NextPage->Visible = true; } }
public function onLoad($param) { parent::onLoad($param); if (!$this->IsPostBack) { $postRecord = $this->_postRecord; $this->Title->Text = $postRecord->Title; $this->Content->Text = $postRecord->Content; $this->DraftMode->Checked = $postRecord->Status === PostRecord::STATUS_DRAFT; $this->Categories->DataSource = $this->DataAccess->queryCategories(); $this->Categories->dataBind(); $cats = $this->DataAccess->queryCategoriesByPostID($postRecord->ID); $catIDs = array(); foreach ($cats as $cat) { $catIDs[] = $cat->ID; } $this->Categories->SelectedValues = $catIDs; } }
public function onLoad($param) { parent::onLoad($param); if (!$this->IsPostBack) { $parameters = $this->Application->Parameters; $this->SiteTitle->Text = $parameters['SiteTitle']; $this->SiteSubtitle->Text = $parameters['SiteSubtitle']; $this->SiteOwner->Text = $parameters['SiteOwner']; $this->AdminEmail->Text = $parameters['AdminEmail']; $this->MultipleUser->Checked = TPropertyValue::ensureBoolean($parameters['MultipleUser']); $this->AccountApproval->Checked = TPropertyValue::ensureBoolean($parameters['AccountApproval']); $this->PostPerPage->Text = $parameters['PostPerPage']; $this->RecentComments->Text = $parameters['RecentComments']; $this->PostApproval->Checked = TPropertyValue::ensureBoolean($parameters['PostApproval']); $themes = $this->Service->ThemeManager->AvailableThemes; $this->ThemeName->DataSource = $themes; $this->ThemeName->dataBind(); $this->ThemeName->SelectedValue = array_search($parameters['ThemeName'], $themes); } }
public function run($request) { $this->removeInitialPages(); $this->deleteAll(BlogPage::get()); // $this->deleteAll(ContactPage::get()); $pages = ['Home' => new HomePage(), 'Blog' => new BlogPage()]; // $homepage = HomePage::get()->first(); // $homepage->IntroText = "WELL CRAFTED INTRO"; // $homepage->PromoText = "PARTNERSHIP PROMOTION"; // $introImg = new Image(); // $imgFile = 'themes/Default/assets/images/doof.jpg'; // var_dump($imgFile); // $introImg->Filename = $imgFile; // $introImg->Title = 'Intro background image'; // $introImg->write(); // $homepage->IntroImageID = $introImg->ID; foreach ($pages as $name => $class) { $this->findOrCreatePage($name, $class); } }
public function run($request) { $this->deleteAll(ArticlePage::get()); $faker = Faker\Factory::create(); $blogPage = BlogPage::get()->first(); $img = new Image(); $imgFile = 'themes/Helix/assets/images/doof.jpg'; // var_dump($imgFile); $img->Filename = $imgFile; $img->Title = 'Template image'; $img->write(); for ($articles = 0; $articles < 20; $articles++) { $articlePage = new ArticlePage(); $articlePage->Title = "Article " . $articles; $articlePage->Content = $faker->text(400); // $articlePage->summarySize = rand(1,3); $articlePage->summarySize = 1; $articlePage->SummaryImageID = $img->ID; $articlePage->setParent($blogPage); $articlePage->write(); $articlePage->publish("Stage", "Live"); $articlePage->flushCache(); } }
/** * Show the new special page * * @param $limit Integer: show this many entries (LIMIT for SQL) */ public function execute($limit) { global $wgMemc, $wgOut, $wgScriptPath; $wgOut->setPageTitle(wfMsg('ah-new-articles')); if (empty($limit)) { $limit = 25; } elseif (!empty($limit)) { $limit = intval($limit); } // Add some CSS for ListPages // @todo FIXME: this should be loaded when including the special page, // too, but if ( $this->including() ) does nothing, prolly because of // the parser cache $wgOut->addModules('ext.blogPage.articlesHome'); $imgPath = $wgScriptPath . '/extensions/BlogPage/images/'; $output = '<div class="left-articles">'; if (!$this->including()) { $output .= '<h2>' . wfMsg('ah-new-articles') . '</h2>'; } // Try cache first $key = wfMemcKey('blog', 'new', 'twentyfive'); $data = $wgMemc->get($key); if ($data != '') { wfDebugLog('BlogPage', 'Got new articles in ArticleLists from cache'); $newBlogPosts = $data; } else { wfDebugLog('BlogPage', 'Got new articles in ArticleLists from DB'); $dbr = wfGetDB(DB_SLAVE); // Code sporked from Rob Church's NewestPages extension // You rock, dude! $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_is_redirect', 'page_id'), array('page_namespace' => NS_BLOG, 'page_is_redirect' => 0), __METHOD__, array('ORDER BY' => 'page_id DESC', 'LIMIT' => $limit)); $newBlogPosts = array(); foreach ($res as $row) { $newBlogPosts[] = array('title' => $row->page_title, 'ns' => $row->page_namespace, 'id' => $row->page_id); } // Cache in memcached for 15 minutes $wgMemc->set($key, $newBlogPosts, 60 * 15); } $output .= '<div class="listpages-container">' . "\n"; if (empty($newBlogPosts)) { $output .= wfMsg('ah-no-results'); } else { foreach ($newBlogPosts as $newBlogPost) { $titleObj = Title::makeTitle(NS_BLOG, $newBlogPost['title']); $output .= "\t\t\t\t" . '<div class="listpages-item">'; $pageImage = BlogPage::getPageImage($newBlogPost['id']); if ($pageImage) { // Load MediaWiki image object to get thumbnail tag $img = wfFindFile($pageImage); $imgTag = ''; if (is_object($img)) { $thumb = $img->transform(array('width' => 65, 'height' => 0)); $imgTag = $thumb->toHtml(); } $output .= "<div class=\"listpages-image\">{$imgTag}</div>\n"; } $output .= '<a href="' . $titleObj->escapeFullURL() . '">' . $titleObj->getText() . "</a>\n\t\t\t\t\t\t<div class=\"listpages-blurb\">\n" . BlogPage::getBlurb($newBlogPost['title'], $newBlogPost['ns'], 300) . '</div><!-- .listpages-blurb --> <div class="listpages-stats">' . "\n"; $output .= "<img src=\"{$imgPath}voteIcon.gif\" alt=\"\" border=\"0\" /> " . wfMsgExt('blog-author-votes', 'parsemag', BlogPage::getVotesForPage($newBlogPost['id'])); $output .= " <img src=\"{$imgPath}comment.gif\" alt=\"\" border=\"0\" /> " . wfMsgExt('blog-author-comments', 'parsemag', BlogPage::getCommentsForPage($newBlogPost['id'])) . '</div><!-- . listpages-stats --> </div><!-- .listpages-item --> <div class="cleared"></div>' . "\n"; } } $output .= '</div>' . "\n"; // .listpages-container $output .= '</div>' . "\n"; // .left-articles $wgOut->addHTML($output); }
/** * Save page into DB */ function save() { $plugin =& $this->plugin; $journalId = $this->journalId; $plugin->import('BlogPage'); $blogPagesDao =& DAORegistry::getDAO('BlogPagesDAO'); if (isset($this->blogPageId)) { $blogPage =& $blogPagesDao->getBlogPage($this->blogPageId); } if (!isset($blogPage)) { $blogPage = new BlogPage(); } $blogPage->setJournalId($journalId); $blogPage->setPath($this->getData('pagePath')); $blogPage->setTitle($this->getData('title'), null); // Localized $blogPage->setContent($this->getData('content'), null); // Localized if (isset($this->blogPageId)) { $blogPagesDao->updateBlogPage($blogPage); } else { $blogPagesDao->insertBlogPage($blogPage); } }
/** * Show a list of this user's blog articles in their user profile page. * * @param $userProfile Object: instance of UserProfilePage * @return Boolean: true */ public static function getArticles($userProfile) { global $wgUserProfileDisplay, $wgMemc, $wgOut; if (!$wgUserProfileDisplay['articles']) { return ''; } $user_name = $userProfile->user_name; $output = ''; // Try cache first $key = wfMemcKey('user', 'profile', 'articles', $userProfile->user_id); $data = $wgMemc->get($key); $articles = array(); if ($data != '') { wfDebugLog('BlogPage', "Got UserProfile articles for user {$user_name} from cache\n"); $articles = $data; } else { wfDebugLog('BlogPage', "Got UserProfile articles for user {$user_name} from DB\n"); $categoryTitle = Title::newFromText(wfMsgForContent('blog-by-user-category', wfMsgForContent('blog-category')) . " {$user_name}"); $dbr = wfGetDB(DB_SLAVE); /** * I changed the original query a bit, since it wasn't returning * what it should've. * I added the DISTINCT to prevent one page being listed five times * and added the page_namespace to the WHERE clause to get only * blog pages and the cl_from = page_id to the WHERE clause so that * the cl_to stuff actually, y'know, works :) */ $res = $dbr->select(array('page', 'categorylinks'), array('DISTINCT page_id', 'page_title', 'page_namespace'), array('cl_from = page_id', 'cl_to' => array($categoryTitle->getDBkey()), 'page_namespace' => NS_BLOG), __METHOD__, array('ORDER BY' => 'page_id DESC', 'LIMIT' => 5)); foreach ($res as $row) { $articles[] = array('page_title' => $row->page_title, 'page_namespace' => $row->page_namespace, 'page_id' => $row->page_id); } $wgMemc->set($key, $articles, 60); } // Load opinion count via user stats; $stats = new UserStats($userProfile->user_id, $user_name); $stats_data = $stats->getUserStats(); $articleCount = $stats_data['opinions_created']; $articleLink = Title::makeTitle(NS_CATEGORY, wfMsgForContent('blog-by-user-category', wfMsgForContent('blog-category')) . " {$user_name}"); if (count($articles) > 0) { $output .= '<div class="user-section-heading"> <div class="user-section-title">' . wfMsg('blog-user-articles-title') . '</div> <div class="user-section-actions"> <div class="action-right">'; if ($articleCount > 5) { $output .= '<a href="' . $articleLink->escapeFullURL() . '" rel="nofollow">' . wfMsg('user-view-all') . '</a>'; } $output .= '</div> <div class="action-left">' . wfMsgExt('user-count-separator', 'parsemag', count($articles), $articleCount) . '</div> <div class="cleared"></div> </div> </div> <div class="cleared"></div> <div class="user-articles-container">'; $x = 1; foreach ($articles as $article) { $articleTitle = Title::makeTitle($article['page_namespace'], $article['page_title']); $voteCount = BlogPage::getVotesForPage($article['page_id']); $commentCount = BlogPage::getCommentsForPage($article['page_id']); if ($x == 1) { $divClass = 'article-item-top'; } else { $divClass = 'article-item'; } $output .= '<div class="' . $divClass . "\">\n\t\t\t\t\t<div class=\"number-of-votes\">\n\t\t\t\t\t\t<div class=\"vote-number\">{$voteCount}</div>\n\t\t\t\t\t\t<div class=\"vote-text\">" . wfMsgExt('blog-user-articles-votes', 'parsemag', $voteCount) . '</div> </div> <div class="article-title"> <a href="' . $articleTitle->escapeFullURL() . "\">{$articleTitle->getText()}</a>\n\t\t\t\t\t\t<span class=\"item-small\">" . wfMsgExt('blog-user-article-comment', 'parsemag', $commentCount) . '</span> </div> <div class="cleared"></div> </div>'; $x++; } $output .= '</div>'; } $wgOut->addHTML($output); return true; }
function &_returnBlogPageFromRow(&$row) { $blogPagesPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName); $blogPagesPlugin->import('BlogPage'); $blogPage = new BlogPage(); $blogPage->setId($row['blog_page_id']); $blogPage->setPath($row['path']); $blogPage->setJournalId($row['journal_id']); $this->getDataObjectSettings('blog_page_settings', 'blog_page_id', $row['blog_page_id'], $blogPage); return $blogPage; }
public function LatestNews($count) { return BlogPage::get()->filter('ParentID', '18')->sort('Created', 'ASC')->limit($count); }
public function index() { $P = PVars::getObj('page'); $vw = new ViewWrap($this->_view); $cw = new ViewWrap($this); // index is called when http request = ./blog if (PPostHandler::isHandling()) { return; } $request = PRequest::get()->request; $member = $this->_model->getLoggedInMember(); //$User = A PP_User::login(); if (!isset($request[1])) { $request[1] = ''; } // user bar // show the userbar always for now: /*if ($User && $request[1] != 'tags') { */ // $P->newBar .= $vw->userbar(); /*} */ $bloguser = 0; $RSS = false; switch ($request[1]) { case 'ajax': if (!isset($request[2])) { PPHP::PExit(); } switch ($request[2]) { case 'post': $this->ajaxPost(); break; } break; case 'suggestTags': // ignore current request, so we can use the last request PRequest::ignoreCurrentRequest(); if (!isset($request[2])) { PPHP::PExit(); } $new_tags = $this->_model->suggestTags($request[2]); echo $this->_view->generateClickableTagSuggestions($new_tags); PPHP::PExit(); break; case 'suggestLocation': // ignore current request, so we can use the last request PRequest::ignoreCurrentRequest(); if (!isset($request[2])) { PPHP::PExit(); } $locations = $this->_model->suggestLocation($request[2]); echo $this->_view->generateLocationOverview($locations); PPHP::PExit(); break; case 'create': if (!$member) { PRequest::home(); } if (isset($request[2]) && $request[2] == 'finish' && isset($request[3]) && $this->_model->isPostId($request[3])) { $page = new BlogSinglePostPage($this->_model); $page->member = $member; $page->post = $this->_model->getPost($request[3]); } else { $page = new BlogCreatePage($this->_model); } return $page; case 'del': if (!$member || !isset($request[2]) || !$this->_model->isUserPost($member->id, $request[2])) { PRequest::home(); } $post = $this->_model->getPost($request[2]); $p = new BlogDeletePage($this->_model); $p->member = $member; $p->post = $post; return $p; case 'edit': if (!$member || !isset($request[2]) || !$this->_model->isUserPost($member->id, $request[2])) { PRequest::home(); } if (isset($request[3]) && $request[3] == 'finish') { $p = new BlogSinglePostPage($this->_model); $p->member = $member; $p->post = $this->_model->getPost($request[2]); return $p; } else { //$callbackId = $this->editProcess((int)$request[2]); //$vars =& PPostHandler::getVars($callbackId); if (!isset($vars['errors']) || !is_array($vars['errors'])) { $vars['errors'] = array(); } $this->_editFill($request[2], $vars); $p = new BlogEditPage($this->_model); $p->post = $this->_model->getPost($request[2]); $p->member = $member; $p->vars = $vars; return $p; $P->content .= $vw->editForm((int) $request[2], $callbackId); } break; case 'search': if (!empty($this->args_vars->get['s']) && strlen($this->args_vars->get['s']) >= 3) { $search = $this->args_vars->get['s']; $tagsposts = $this->_model->getTaggedPostsIt($search); $posts = $this->_model->searchPosts($search); } else { $error = 'To few arguments'; $posts = false; $tagsposts = false; $search = ''; } $p = new BlogSearchPage($this->_model); $p->posts = $posts; $p->tagged_posts = $tagsposts; $p->search = $search; return $p; $P->content .= $vw->searchPage($posts, $tagsposts); break; /* removed - references user app case 'settings': $p = new BlogSettingsPage($this->_model); return $p; $P->content .= $vw->settingsForm(); break; */ /* removed - references user app case 'settings': $p = new BlogSettingsPage($this->_model); return $p; $P->content .= $vw->settingsForm(); break; */ case 'tags': $p = new BlogTagsPage($this->_model); $p->tag = isset($request[2]) ? $request[2] : false; return $p; $P->content .= $vw->tags(isset($request[2]) ? $request[2] : false); break; case 'cat': $p = new BlogCategoriesPage($this->_model); return $p; break; default: $page = isset($this->args_vars->get['page']) && intval($this->args_vars->get['page']) ? intval($this->args_vars->get['page']) : 1; // display blogs of user $request[1] $memberBlog = $this->_model->getMemberByUsername($request[1]); if ($memberBlog) { if (!isset($request[2])) { $request[2] = ''; } switch ($request[2]) { case 'cat': if (isset($request[3])) { $p = new BlogPage($this->_model); $p->page = $page; $p->category = $request[3]; $p->member = $memberBlog; $p->initPager($this->_model->countRecentPosts($memberBlog->id, $request[3]), $page); $p->posts = $this->_model->getRecentPostsArray($memberBlog->id, $request[3], $page); break; } // if we're not dealing with a category, fall through and hit the default // if we're not dealing with a category, fall through and hit the default case '': default: // show different blog layout for public visitors if ($post = $this->_model->getPost($request[2])) { $p = new BlogSinglePostPage($this->_model); $p->member = $memberBlog; $p->post = $post; } else { $p = new BlogPage($this->_model); $p->page = $page; $p->member = $memberBlog; $p->initPager($this->_model->countRecentPosts($memberBlog->id, false), $page); $p->posts = $this->_model->getRecentPostsArray($memberBlog->id, false, $page); } break; } } else { $p = new BlogPage($this->_model); $p->page = $page; $p->initPager($this->_model->countRecentPosts(false, false), $page); $p->posts = $this->_model->getRecentPostsArray(false, false, $page); } return $p; } }
public function onLoad($param) { parent::onLoad($param); $this->ErrorMessage->Text = $this->Application->SecurityManager->validateData(urldecode($this->Request['msg'])); }
function getAuthorArticles($author_index) { global $wgOut, $wgBlogPageDisplay, $wgMemc; if ($wgBlogPageDisplay['author_articles'] == false) { return ''; } $user_name = $this->authors[$author_index]['user_name']; $user_id = $this->authors[$author_index]['user_id']; $blogCat = wfMsgForContent('blog-category'); $archiveLink = Title::makeTitle(NS_CATEGORY, wfMsg('blog-by-user-category', $blogCat) . " {$user_name}"); $articles = array(); // Try cache first $key = wfMemcKey('blog', 'author', 'articles', $user_id); $data = $wgMemc->get($key); if ($data != '') { wfDebugLog('BlogPage', "Got blog author articles for user {$user_name} from cache"); $articles = $data; } else { wfDebugLog('BlogPage', "Got blog author articles for user {$user_name} from DB"); $dbr = wfGetDB(DB_SLAVE); $categoryTitle = Title::newFromText(wfMsg('blog-by-user-category', $blogCat) . " {$user_name}"); $res = $dbr->select(array('page', 'categorylinks'), array('DISTINCT(page_id) AS page_id', 'page_title'), array('cl_to' => array($categoryTitle->getDBkey()), 'page_namespace' => NS_BLOG), __METHOD__, array('ORDER BY' => 'page_id DESC', 'LIMIT' => 4), array('categorylinks' => array('INNER JOIN', 'cl_from = page_id'))); $array_count = 0; foreach ($res as $row) { if ($row->page_id != $this->getId() && $array_count < 3) { $articles[] = array('page_title' => $row->page_title, 'page_id' => $row->page_id); $array_count++; } } // Cache for half an hour $wgMemc->set($key, $articles, 60 * 30); } $output = ''; if (count($articles) > 0) { $css_fix = ''; if (count($this->getVotersList()) == 0 && count($this->getEditorsList()) == 0) { $css_fix = ' more-container-fix'; } $output .= "<div class=\"more-container{$css_fix}\">\n\t\t\t<h3>" . wfMsg('blog-author-more-by', $user_name) . '</h3>'; $x = 1; foreach ($articles as $article) { $articleTitle = Title::makeTitle(NS_BLOG, $article['page_title']); $output .= '<div class="author-article-item"> <a href="' . $articleTitle->escapeFullURL() . "\">{$articleTitle->getText()}</a>\n\t\t\t\t\t<div class=\"author-item-small\">" . wfMsgExt('blog-author-votes', 'parsemag', BlogPage::getVotesForPage($article['page_id'])) . ', ' . wfMsgExt('blog-author-comments', 'parsemag', BlogPage::getCommentsForPage($article['page_id'])) . '</div> </div>'; $x++; } $output .= '<div class="author-archive-link"> <a href="' . $archiveLink->escapeFullURL() . '">' . wfMsg('blog-view-archive-link') . '</a> </div> </div>'; } return $output; }
/** * Get the 25 most popular blog posts from the database and then cache them * in memcached for 15 minutes. * The definition of 'popular' is very arbitrary at the moment. * * Fork of the original getPopularPosts() method, the only thing changed * here is the HTML output which was toned down and count changed from 25 * to 10. * * @return String: HTML */ public function getPopularPostsForRightSide() { global $wgMemc; // Try cache first $key = wfMemcKey('blog', 'popular', 'ten'); $data = $wgMemc->get($key); if ($data != '') { wfDebugLog('BlogPage', 'Got popular posts in ArticlesHome from cache'); $popularBlogPosts = $data; } else { wfDebugLog('BlogPage', 'Got popular posts in ArticlesHome from DB'); $dbr = wfGetDB(DB_SLAVE); $commentsTable = $dbr->tableName('Comments'); $voteTable = $dbr->tableName('Vote'); // Code sporked from Rob Church's NewestPages extension $res = $dbr->select(array('page', 'Comments', 'Vote'), array('DISTINCT page_id', 'page_namespace', 'page_title', 'page_is_redirect'), array('page_namespace' => NS_BLOG, 'page_is_redirect' => 0, 'page_id = Comment_Page_ID', 'page_id = vote_page_id', "((SELECT COUNT(*) FROM {$voteTable} WHERE vote_page_id = page_id) >= 5 OR\n\t\t\t\t\t(SELECT COUNT(*) FROM {$commentsTable} WHERE Comment_Page_ID = page_id) >= 5)"), __METHOD__, array('ORDER BY' => 'page_id DESC', 'LIMIT' => 10), array('Comments' => array('INNER JOIN', 'page_id = Comment_Page_ID'), 'Vote' => array('INNER JOIN', 'page_id = vote_page_id'))); $popularBlogPosts = array(); foreach ($res as $row) { $popularBlogPosts[] = array('title' => $row->page_title, 'ns' => $row->page_namespace, 'id' => $row->page_id); } // Cache in memcached for 15 minutes $wgMemc->set($key, $popularBlogPosts, 60 * 15); } $output = '<div class="listpages-container">'; if (empty($popularBlogPosts)) { $output .= wfMsg('ah-no-results'); } else { foreach ($popularBlogPosts as $popularBlogPost) { $titleObj = Title::makeTitle(NS_BLOG, $popularBlogPost['title']); $votes = BlogPage::getVotesForPage($popularBlogPost['id']); $output .= '<div class="listpages-item">'; $output .= '<div class="listpages-votebox">' . "\n"; $output .= '<div class="listpages-votebox-number">' . $votes . "</div>\n"; $output .= '<div class="listpages-votebox-text">' . wfMsgExt('blog-author-votes', 'parsemag', $votes) . "</div>\n"; // .listpages-votebox-text $output .= '</div>' . "\n"; // .listpages-votebox $output .= '<a href="' . $titleObj->escapeFullURL() . '">' . $titleObj->getText() . '</a> </div><!-- .listpages-item --> <div class="cleared"></div>' . "\n"; } } $output .= '</div>' . "\n"; // .listpages-container return $output; }