public function mobileSearch($q, $start, $limit = 20) { global $wgOut, $wgMemc; // Don't return more than 50 search results at a time to prevent abuse if ($limit > 50) { $limit = 50; } $key = wfMemcKey("MobileSearch", str_replace(" ", "-", $q), $start, $limit); if ($val = $wgMemc->get($key)) { return $val; } $contents = $this->googleSearchResultTitles($q, $start, $limit, 0, self::SEARCH_MOBILE); $results = array(); foreach ($contents as $t) { // Only return articles if ($t->getNamespace() != NS_MAIN) { continue; } $result = array(); $result['title'] = $t->getText(); $result['url'] = $t->getFullURL(); $result['imgurl'] = wfGetPad(SkinWikihowskin::getGalleryImage($t, 103, 80)); $result['intro'] = null; if ($r = Revision::newFromid($t->getLatestRevID())) { $intro = Wikitext::getIntro($r->getText()); $intro = trim(Wikitext::flatten($intro)); $result['intro'] = substr($intro, 0, 180); // Put an ellipsis on the end $len = strlen($result['intro']); $result['intro'] .= substr($result['intro'], $len - 1, $len) == '.' ? ".." : "..."; } if (!is_null($result['intro'])) { $results[] = array('article' => $result); } } $searchResults['results'] = $results; $json = json_encode($searchResults); $wgMemc->set($key, $json, 3600); // 1 hour header("Content-type: application/json"); $wgOut->disable(true); echo $json; }
public static function generateFeedItem() { $fname = "FeedGeneralActivities:generateFeedItem"; $dbr = wfGetDB(DB_SLAVE); $msg = null; $x = rand(0, 4); switch ($x) { case 0: $count = $dbr->selectField('imageadder', 'count(*)', array('imageadder_hasimage' => 0)); $count = number_format($count, 0, ".", ","); $msg = "There are {$count} articles with no image in the introduction, start adding images <a href='/Special:Introimageadder'>now.</a>"; $t = Title::makeTitle(NS_SPECIAL, "Introimageadder"); break; case 1: $count = $dbr->selectField('recentchanges', 'count(*)', array('rc_patrolled' => 0)); $count = number_format($count, 0, ".", ","); $msg = "There are {$count} unpatrolled edits in recent changes, start patrolling <a href='/Special:RCPatrol'>now.</a>"; $t = Title::makeTitle(NS_SPECIAL, "RCPatrol"); break; case 2: $count = $dbr->selectField('editfinder', 'count(*)', array()); $count = number_format($count, 0, ".", ","); $msg = "There are {$count} articles in the repair shop, start fixing them <a href='/Special:EditFinder'>now.</a>"; $t = Title::makeTitle(NS_SPECIAL, "EditFinder"); break; case 3: $count = $dbr->selectField('qc', 'count(*)', array('qc_patrolled' => 0)); $count = number_format($count, 0, ".", ","); $msg = "There are {$count} edits in the QG queue, start patrolling them <a href='/Special:QG'>now.</a>"; $t = Title::makeTitle(NS_SPECIAL, "QG"); break; case 4: $feeds = FeaturedArticles::getFeaturedArticles(1); if (sizeof($feeds > 0)) { $url = $feeds[0][0]; $url = preg_replace("@http://www.wikihow.com/@", "", $url); $t = Title::newFromURL(urldecode($url)); if ($t) { $img = SkinWikihowskin::getGalleryImage($t, 44, 33); $msg = "<img src='{$img}'/><a href='{$t->getFullURL()}'>{$t->getText()}</a> is today's Featured Article"; } } break; } $html = ""; if ($msg) { $html = "<div class='feeditem'>{$msg}<div class='actions'><a href='{$t->getFullURL()}'>Go there now</a></div></div>"; } wfProfileOut($fname); return $html; }
function formatRelated($t) { global $wgUser, $wgParser; $result = ''; if ($t && $t->exists()) { $r = Revision::newFromTitle($t); $intro = $wgParser->getSection($r->getText(), 0); $intro = Wikitext::flatten($intro); if (strlen($intro) > 250) { $intro = substr($intro, 0, 250) . '...'; } $sk = $wgUser->getSkin(); $img = SkinWikihowskin::getGalleryImage($t, 238, 139); $result .= "<div class='slide_related'>\n\t\t\t\t\t\t<a href='{$t->getFullURL()}'><img src='{$img}' alt='' width='238' height='139' class='gs_img' /></a>\n\t\t\t\t\t\t<h3><a href='{$t->getFullURL()}'>{$t->getText()}</a></h3>\n\t\t\t\t\t\t<p>{$intro}</p>\n\t\t\t\t\t\t</div>"; } return $result; }
function execute($par) { global $wgOut, $wgUser, $wgTitle, $wgLanguageCode, $wgHooks; if ($wgLanguageCode != 'en') { $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext'); $wgOut->setRobotPolicy('noindex,nofollow'); return; } require_once 'Leaderboard.body.php'; wfLoadExtensionMessages('RequestTopic'); $wgOut->addCSScode('suggc'); $wgOut->addJScode('suggj'); ListRequestedTopics::setActiveWidget(); ListRequestedTopics::setTopAuthorWidget(); ListRequestedTopics::getNewArticlesWidget(); $wgHooks["pageTabs"][] = array("wfRequestedTopicsTabs"); $wgOut->setHTMLTitle('Articles Started By You - wikiHow'); $wgOut->setRobotPolicy('noindex,nofollow'); //heading with link $request = '<a href="/Special:RequestTopic" class="editsection">' . wfMsg('requesttopic') . '</a>'; $heading = $request . '<h2>' . wfMsg('your_articles_header') . '</h2>'; //add surpise button $heading .= "<a href='/Special:RecommendedArticles?surprise=1' class='button buttonright secondary' id='suggested_surprise'>" . wfMsg('suggested_list_button_surprise') . "</a><br /><br /><br />"; $wgOut->addHTML($heading); if ($wgUser->getID() > 0) { $dbr = wfGetDB(DB_SLAVE); $res = $dbr->query("select * from firstedit left join page on fe_page=page_id\n\t\t\t\t\tleft join suggested_titles on page_title=st_title and page_namespace= 0 where fe_user={$wgUser->getID()} and page_id is not NULL order by st_category"); if ($dbr->numRows($res) == 0) { $wgOut->addHTML(wfMsg("yourarticles_none")); return; } $last_cat = "-"; // group it by categories // sometimes st_category is not set, so we have to grab the top category // from the title object of the target article $articles = array(); while ($row = $dbr->fetchObject($res)) { $t = Title::makeTitle(NS_MAIN, $row->page_title); $cat = $row->st_category; if ($cat == '') { $str = Categoryhelper::getTopCategory($t); if ($str != '') { $title = Title::makeTitle(NS_CATEGORY, $str); $cat = $title->getText(); } else { $cat = "Other"; } } if (!isset($articles[$cat])) { $articles[$cat] = array(); } $articles[$cat][] = $row; } foreach ($articles as $cat => $article_array) { $image = ListRequestedTopics::getCategoryImage($cat); $style = ""; if ($image == "") { $style = "style='padding-left:67px;'"; } $wgOut->addHTML('<h2>' . $cat . '</h2><div class="wh_block"><table class="suggested_titles_list">'); foreach ($article_array as $row) { $t = Title::makeTitle(NS_MAIN, $row->page_title); $ago = wfTimeAgo($row->page_touched); $authors = array_keys($this->getAuthors($t)); $a_out = array(); for ($i = 0; $i < 2 && sizeof($authors) > 0; $i++) { $a = array_shift($authors); if ($a == 'anonymous') { $a_out[] = "Anonymous"; // duh } else { $u = User::newFromName($a); if (!$u) { echo "{$a} broke"; exit; } $a_out[] = "<a href='{$u->getUserPage()->getFullURL()}'>{$u->getName()}</a>"; } } $skin = $wgUser->getSkin(); $img = SkinWikihowskin::getGalleryImage($t, 46, 35); $wgOut->addHTML("<tr><td class='article_image'><img src='{$img}' alt='' width='46' height='35' /></td>" . "<td><h3><a href='{$t->getFullURL()}' class='title'>" . wfMsg('howto', $t->getFullText()) . "</a></h3>" . "<p class='meta_info'>Authored by: <a href='{$wgUser->getUserPage()->getFullURL()}'>You</a></p>" . "<p class='meta_info'>Edits by: " . implode(", ", $a_out) . " (<a href='{$t->getFullURL()}?action=credits'>see all</a>)</p>" . "<p class='meta_info'>Last updated {$ago}</p>" . "</td>" . "<td class='view_count'>" . number_format($row->page_counter, 0, "", ",") . "</td></tr>"); } $wgOut->addHTML('</table></div>'); } } else { $rt = $wgTitle->getPrefixedURL(); $q = "returnto={$rt}"; $wgOut->addHTML(wfMsg('yourarticles_anon', $q)); } }
private function getFeatureArticleImage(&$title, $width, $height) { global $wgUser; $skin = $wgUser->getSkin(); // The next line was taken from: // SkinWikihowskin::featuredArticlesLineWide() $img = SkinWikihowskin::getGalleryImage($title, $width, $height); return wfGetPad($img); }
function getFoundInArticles($doc_name, $is_mobile) { $html = ''; $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('dv_links', 'dvl_page', array('dvl_doc' => $doc_name), __METHOD__); foreach ($res as $row) { $t = Title::newFromId($row->dvl_page); if ($t && $t->exists()) { global $wgUser; $sk = $wgUser->getSkin(); $img = SkinWikihowskin::getGalleryImage($t, 44, 33); if ($is_mobile) { $html .= $sk->featuredArticlesRow($t); } else { $html .= SkinWikihowskin::getArticleThumb($t, 127, 140); } //save for meta description if (!self::$firstRelated) { self::$firstRelated = ' ' . wfMessage('dv-meta-article-prefix')->text() . ' ' . htmlspecialchars($t->getText()); self::$firstRelatedTitle = $t; } } } return $html; }
private function getBoxBgImg($db, $quiz_name, $width, $height) { global $wgUser; $page = $db->selectField('quiz_links', 'ql_page', array('ql_name' => $quiz_name), __METHOD__, array('LIMIT' => 1)); $t = Title::newFromId($page); if ($t) { $sk = $wgUser->getSkin(); $img = SkinWikihowskin::getGalleryImage($t, $width, $height); $img = wfGetPad($img); } return $img; }