Exemplo n.º 1
0
 function getPinterestImage($title, $fromPad = true)
 {
     global $wgLanguageCode, $wgContLang;
     if (in_array($title->getNamespace(), array(NS_MAIN, NS_CATEGORY))) {
         if ($title->getNamespace() == NS_MAIN) {
             $file = Wikitext::getTitleImage($title);
             if ($file && isset($file)) {
                 $url = "/images/" . $file->getRel();
                 if ($fromPad) {
                     $url = wfGetPad($url);
                 }
                 return $url;
             }
         }
         $catmap = Categoryhelper::getIconMap();
         // still here? use default categoryimage
         // if page is a top category itself otherwise get top
         if (isset($catmap[urldecode($title->getPartialURL())])) {
             $cat = urldecode($title->getPartialURL());
         } else {
             $cat = Categoryhelper::getTopCategory($title);
             //INTL: Get the partial URL for the top category if it exists
             // For some reason only the english site returns the partial URL for getTopCategory
             if (isset($cat) && $wgLanguageCode != 'en') {
                 $title = Title::newFromText($cat);
                 if ($title != null) {
                     $cat = $title->getPartialURL();
                 }
             }
         }
         if (isset($catmap[$cat])) {
             $image = Title::newFromText($catmap[$cat]);
             $file = wfFindFile($image, false);
             if ($file) {
                 $url = "/images/" . $file->getRel();
                 if ($fromPad) {
                     $url = wfGetPad($url);
                 }
                 if ($url) {
                     return $url;
                 }
             } else {
                 $url = "/skins/WikiHow/images/wikihow_large.jpg";
                 if ($fromPad) {
                     $url = wfGetPad($url);
                 }
                 if ($url) {
                     return $url;
                 }
             }
         } else {
             $url = "/skins/WikiHow/images/wikihow_large.jpg";
             if ($fromPad) {
                 $url = wfGetPad($url);
             }
             if ($url) {
                 return $url;
             }
         }
     }
 }
Exemplo n.º 2
0
function wfGetTopCategory($title = null)
{
    $result = Categoryhelper::getTopCategory($title);
    return Title::makeTitle(NS_CATEGORY, $result);
}
Exemplo n.º 3
0
 static function getCategoryImageFile($title)
 {
     $catmap = Categoryhelper::getIconMap();
     // if page is a top category itself otherwise get top
     if (isset($catmap[urldecode($title->getPartialURL())])) {
         $cat = urldecode($title->getPartialURL());
     } else {
         $cat = Categoryhelper::getTopCategory($title);
         //INTL: Get the partial URL for the top category if it exists
         // For some reason only the english site returns the partial
         // URL for getTopCategory
         if (isset($cat) && $wgLanguageCode != 'en') {
             $title = Title::newFromText($cat);
             if ($title) {
                 $cat = $title->getPartialURL();
             }
         }
     }
     if (isset($catmap[$cat])) {
         $image = Title::newFromText($catmap[$cat]);
         $file = wfFindFile($image, false);
     } else {
         $image = Title::makeTitle(NS_IMAGE, "Book_266.png");
         $file = wfFindFile($image, false);
         if (!$file) {
             $file = wfFindFile("Book_266.png");
         }
     }
     return $file;
 }
Exemplo n.º 4
0
 static function getGalleryImage($title, $width, $height, $skip_parser = false)
 {
     global $wgMemc, $wgLanguageCode, $wgContLang;
     $cachekey = wfMemcKey('gallery1', $title->getArticleID(), $width, $height);
     $val = $wgMemc->get($cachekey);
     if ($val) {
         return $val;
     }
     if ($title->getNamespace() == NS_MAIN || $title->getNamespace() == NS_CATEGORY) {
         if ($title->getNamespace() == NS_MAIN) {
             $file = Wikitext::getTitleImage($title, $skip_parser);
             if ($file && isset($file)) {
                 //need to figure out what size it will actually be able to create
                 //and put in that info. ImageMagick gives prefence to width, so
                 //we need to see if it's a landscape image and adjust the sizes
                 //accordingly
                 $sourceWidth = $file->getWidth();
                 $sourceHeight = $file->getHeight();
                 $heightPreference = false;
                 if ($width / $height < $sourceWidth / $sourceHeight) {
                     //desired image is portrait
                     $heightPreference = true;
                 }
                 $thumb = $file->getThumbnail($width, $height, true, true, $heightPreference);
                 if ($thumb instanceof MediaTransformError) {
                     // we got problems!
                     $thumbDump = print_r($thumb, true);
                     wfDebug("problem getting thumb for article '{$title->getText()}' of size {$width}x{$height}, image file: {$file->getTitle()->getText()}, path: {$file->getPath()}, thumb: {$thumbDump}\n");
                 } else {
                     $wgMemc->set($cachekey, wfGetPad($thumb->getUrl()), 2 * 3600);
                     // 2 hours
                     return wfGetPad($thumb->getUrl());
                 }
             }
         }
         $catmap = Categoryhelper::getIconMap();
         // if page is a top category itself otherwise get top
         if (isset($catmap[urldecode($title->getPartialURL())])) {
             $cat = urldecode($title->getPartialURL());
         } else {
             $cat = Categoryhelper::getTopCategory($title);
             //INTL: Get the partial URL for the top category if it exists
             // For some reason only the english site returns the partial
             // URL for getTopCategory
             if (isset($cat) && $wgLanguageCode != 'en') {
                 $title = Title::newFromText($cat);
                 if ($title) {
                     $cat = $title->getPartialURL();
                 }
             }
         }
         if (isset($catmap[$cat])) {
             $image = Title::newFromText($catmap[$cat]);
             $file = wfFindFile($image, false);
             if ($file) {
                 $sourceWidth = $file->getWidth();
                 $sourceHeight = $file->getHeight();
                 $heightPreference = false;
                 if ($width / $height < $sourceWidth / $sourceHeight) {
                     //desired image is portrait
                     $heightPreference = true;
                 }
                 $thumb = $file->getThumbnail($width, $height, true, true, $heightPreference);
                 if ($thumb) {
                     $wgMemc->set($cachekey, wfGetPad($thumb->getUrl()), 2 * 3600);
                     // 2 hours
                     return wfGetPad($thumb->getUrl());
                 }
             }
         } else {
             $image = Title::makeTitle(NS_IMAGE, "Book_266.png");
             $file = wfFindFile($image, false);
             if (!$file) {
                 $file = wfFindFile("Book_266.png");
             }
             $sourceWidth = $file->getWidth();
             $sourceHeight = $file->getHeight();
             $heightPreference = false;
             if ($width / $height < $sourceWidth / $sourceHeight) {
                 //desired image is portrait
                 $heightPreference = true;
             }
             $thumb = $file->getThumbnail($width, $height, true, true, $heightPreference);
             if ($thumb) {
                 $wgMemc->set($cachekey, wfGetPad($thumb->getUrl()), 2 * 3600);
                 // 2 hours
                 return wfGetPad($thumb->getUrl());
             }
         }
     }
 }
Exemplo n.º 5
0
 function execute($par)
 {
     global $wgOut, $wgUser, $wgTitle, $wgLanguageCode, $wgHooks;
     if ($wgLanguageCode != 'en') {
         $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
         $wgOut->setRobotPolicy('noindex,nofollow');
         return;
     }
     require_once 'Leaderboard.body.php';
     wfLoadExtensionMessages('RequestTopic');
     $wgOut->addHTML('<style type="text/css" media="all">/*<![CDATA[*/ @import "' . wfGetPad('/extensions/min/f/extensions/wikihow/suggestedtopics.css?rev=') . WH_SITEREV . '"; /*]]>*/</style>');
     $wgOut->addScript('<script type="text/javascript" src="' . wfGetPad('/extensions/min/f/extensions/wikihow/suggestedtopics.js?rev=') . WH_SITEREV . '"></script>');
     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="edit">' . 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 = $skin->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));
     }
 }