function execute($par)
 {
     global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc, $wgDBname;
     global $wgServer, $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
     global $wgFeedClasses, $wgUseRCPatrol;
     global $wgScriptPath, $wgServer;
     global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
     $wgOut->setArticleBodyOnly(true);
     $type = $wgRequest->getVal("type");
     $ndisplay = $wgRequest->getVal("ndisplay");
     $DEBUG = 1;
     require_once 'IGGadgetTMPL.php';
     global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
     global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
     $wgOut->setSquidMaxage(3600);
     // extract the number of days
     $days = 6;
     if ($ndisplay != "" && is_numeric($ndisplay) && $ndisplay < 10) {
         $numitems = $ndisplay;
     } else {
         $numitems = 3;
     }
     date_default_timezone_set("UTC");
     $days = FeaturedArticles::getNumberOfDays($days);
     $feeds = FeaturedArticles::getFeaturedArticles($days);
     if ($type == "home") {
         $now = time();
         $count = 0;
         $mainTitle = "";
         $relatedArticles = "";
         $featuredArticles = "";
         $ggtmpl = new GoogleGadgetHome2();
         $ggtmpl->outHeader();
         $itemnum = 1;
         $itemmax = 3;
         foreach ($feeds as $f) {
             $url = $f[0];
             $d = $f[1];
             if ($d > $now) {
                 continue;
             }
             $url = str_replace("http://wiki.ehow.com/", "", $url);
             $url = str_replace("http://www.wikihow.com/", "", $url);
             $url = str_replace($wgServer . $wgScriptPath . "/", "", $url);
             $title = Title::newFromURL(urldecode($url));
             $title_text = $title->getPrefixedText();
             if (isset($f[2]) && $f[2] != null && trim($f[2]) != '') {
                 $title_text = $f[2];
             } else {
                 $title_text = wfMsg('howto', $title_text);
             }
             $mainTitle = $title;
             $summary = "";
             $a = "";
             if ($title == null) {
                 echo "title is null for {$url}";
                 exit;
             }
             if ($title->getArticleID() > 0) {
                 $a = GoodRevision::newArticleFromLatest($title);
                 $summary = $a->getContent(true);
                 $summary = preg_replace('/\\{\\{fa\\}\\}/', '', $summary);
                 global $wgParser;
                 $output = $wgParser->parse($summary, $title, new ParserOptions());
                 $relatedArticles = $this->getRelatedWikihowsFromSource($title, 4);
                 $summary = $this->addTargetBlank($output->getText());
                 $summary = preg_replace('/href="\\//', 'href="' . $wgServer . '/', $summary);
                 $summary = preg_replace('/src="\\//', 'src="' . $wgServer . '/', $summary);
                 $summary = preg_replace('/<span id="gatEditSection" class="editsection1">(.*?)<\\/span>/', '', $summary);
                 $linkEmail = $wgServer . '/index.php?title=Special:EmailLink&target=' . $title->getPrefixedURL();
                 $backlinks = "\n<div id='articletools'><div class='SecL'></div><div class='SecR'></div><a name='articletools'></a><h2> <span>Article Tools</span></h2> </div>";
                 $backlinks .= "<ul style='list-style: none;margin-left:0;padding-left:4em;text-indent:-1em;'>";
                 $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/images/logo_small.png' height=12 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $wgServer . "/" . $title->getPrefixedURL() . "'>Read on wikiHow</a></li>";
                 $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/sharetab/ShareTab_Email.gif' height=15 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $linkEmail . "'>Email this Article</a></li>";
                 $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/images/pencil_benji_park_01.png' height=15 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $wgServer . $title->getEditURL() . "'>Edit</a></li>";
                 $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/images/speech_ballon.png' height=15 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $wgServer . "/Discussion:" . $title->getPrefixedURL() . "'>Discuss</a></li>";
                 $backlinks .= "<ul>\n";
                 $summary .= $backlinks;
                 $ggtmpl->outMain($title_text, $summary, $url, $itemnum);
                 $itemnum++;
             } else {
                 echo '<!-- no article found for articleid:' . $title->getArticleID() . ' title:' . $title_text . ' -->';
             }
             if ($itemnum > $itemmax) {
                 break;
             }
         }
         $relatedArticles = preg_replace('/href="\\//', 'href="' . $wgServer . '/', $relatedArticles);
         $ggtmpl->outFooter();
     } else {
         if ($type == "canvas") {
             $now = time();
             $count = 0;
             $mainTitle = "";
             $relatedArticles = "";
             $featuredArticles = "";
             $maxShow = 7;
             $ggtmpl = new GoogleGadgetCanvas();
             $ggtmpl->outHeader();
             foreach ($feeds as $f) {
                 $url = $f[0];
                 $d = $f[1];
                 if ($d > $now) {
                     continue;
                 }
                 $url = str_replace("http://wiki.ehow.com/", "", $url);
                 $url = str_replace("http://www.wikihow.com/", "", $url);
                 $url = str_replace($wgServer . $wgScriptPath . "/", "", $url);
                 $title = Title::newFromURL(urldecode($url));
                 $title_text = $title->getPrefixedText();
                 if (isset($f[2]) && $f[2] != null && trim($f[2]) != '') {
                     $title_text = $f[2];
                 } else {
                     $title_text = wfMsg('howto', $title_text);
                 }
                 if ($count < $maxShow) {
                     $mainTitle = $title;
                     $summary = "";
                     $a = "";
                     if ($title == null) {
                         echo "title is null for {$url}";
                         exit;
                     }
                     if ($title->getArticleID() > 0) {
                         $a = GoodRevision::newArticleFromLatest($title);
                         $summary = $a->getContent(true);
                         $summary = preg_replace('/\\{\\{.*\\}\\}/', '', $summary);
                         global $wgParser;
                         $output = $wgParser->parse($summary, $title, new ParserOptions());
                         $relatedArticles = $this->getRelatedWikihowsFromSource($title, 4);
                         $summary = $this->addTargetBlank($output->getText());
                         $summary = preg_replace('/href="\\//', 'href="' . $wgServer . '/', $summary);
                         $summary = preg_replace('/src="\\//', 'src="' . $wgServer . '/', $summary);
                         $summary = preg_replace('/<span id="gatEditSection" class="editsection1">(.*?)<\\/span>/', '', $summary);
                         $linkEmail = $wgServer . '/index.php?title=Special:EmailLink&target=' . $title->getPrefixedURL();
                         $backlinks = "\n<div id='articletools'><div class='SecL'></div><div class='SecR'></div><a name='articletools'></a><h2> <span>Article Tools</span></h2> </div>";
                         $backlinks .= "<ul style='list-style: none;margin-left:0;padding-left:4em;text-indent:-1em;'>";
                         $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/images/logo_small.png' height=12 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $wgServer . "/" . $title->getPrefixedURL() . "'>Read on wikiHow</a></li>";
                         $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/sharetab/ShareTab_Email.gif' height=15 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $linkEmail . "'>Email this Article</a></li>";
                         $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/images/pencil_benji_park_01.png' height=15 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $wgServer . $title->getEditURL() . "'>Edit</a></li>";
                         $backlinks .= "<li style='list-style-type: none;'><img src='" . $wgServer . "/skins/WikiHow/images/speech_ballon.png' height=15 width=15>&nbsp;&nbsp;<a target='_blank' href='" . $wgServer . "/Discussion:" . $title->getPrefixedURL() . "'>Discuss</a></li>";
                         $backlinks .= "<ul>\n";
                         $summary .= $backlinks;
                         $ggtmpl->outMain($title_text, $summary, $url);
                     } else {
                         echo '<!-- no article found for articleid:' . $title->getArticleID() . ' title:' . $title_text . ' -->';
                     }
                 }
                 $featuredArticles .= '<li><a href="' . $wgServer . '/' . $url . '" target="_blank">' . $title_text . '</a></li>' . "\n";
                 $count++;
             }
             $relatedArticles = preg_replace('/href="\\//', 'href="' . $wgServer . '/', $relatedArticles);
             $ggtmpl->outFeaturedArticles($featuredArticles);
             $ggtmpl->outRelatedArticles($relatedArticles);
             $ggtmpl->outFooter();
         } else {
             $ggtmpl = new GoogleGadgetModule($wgServer);
             $ggtmpl->outModulePrefs();
             exit;
         }
     }
 }
 function execute($par)
 {
     global $wgOut, $wgTitle, $wgMemc, $wgServer;
     global $wgScriptPath, $wgServer, $wgRequest;
     require_once 'NVGadgetTMPL.php';
     header("Content-Type: text/html");
     $wgOut->setSquidMaxage(3600);
     $nvtmpl = new NetVibes();
     $nvtmpl->outHeader();
     // extract the number of days
     $days = 6;
     $numitems = 5;
     date_default_timezone_set("UTC");
     $days = FeaturedArticles::getNumberOfDays($days);
     $feeds = FeaturedArticles::getFeaturedArticles($days);
     if (count($feeds) > 2) {
         $spotlight = rand(0, 3);
     } else {
         $spotlight = rand(0, count($feeds));
     }
     if ($getSpotlight = $wgRequest->getVal('spotlight')) {
         $spotlight = $getSpotlight;
     }
     $now = time();
     $count = 0;
     $itemsshown = 0;
     $itemlist = "";
     foreach ($feeds as $f) {
         $url = $f[0];
         $d = $f[1];
         if ($d > $now) {
             continue;
         }
         $url = str_replace("http://wiki.ehow.com/", "", $url);
         $url = str_replace("http://www.wikihow.com/", "", $url);
         $url = str_replace($wgServer . $wgScriptPath . "/", "", $url);
         $title = Title::newFromURL(urldecode($url));
         $summary = "";
         $image = "";
         $mtext = "";
         $a = "";
         if ($title == null) {
             echo "title is null for {$url}";
             exit;
         }
         if ($title->getArticleID() > 0) {
             $a = $this->getLastPatrolledRevision($title);
             $summary = Article::getSection($a->getContent(true), 0);
             global $wgParser;
             $summary = ereg_replace("\\{\\{.*\\}\\}", "", $summary);
             $output = $wgParser->parse($summary, $title, new ParserOptions());
             $title_text = $title->getPrefixedText();
             if (isset($f[2]) && $f[2] != null && trim($f[2]) != '') {
                 $title_text = $f[2];
             } else {
                 $title_text = wfMsg('howto', $title_text);
             }
             $artbloblen = 480;
             if ($count == $spotlight) {
                 $summary = $output->getText();
                 // REMOVE MAGNIFY IMAGE
                 $summary = preg_replace('/<img src="\\/skins\\/common\\/images\\/magnify-clip\\.png" width="15" height="11" alt="" \\/>/', '', $summary);
                 // REBUILD IMAGE TAG. RESIZE IMAGE AND SET ABSOLUTE PATH.
                 if (preg_match('/<img alt=".*?" src="(.*?)" width="(\\d+)" height="(\\d+)"/', $summary, $match)) {
                     if ($match[3] != "") {
                         if ($match[3] > 100) {
                             $hrat = 100 / $match[3];
                         } else {
                             $hrat = 1;
                         }
                         $width = number_format($match[2] * $hrat, 0, '.', '');
                         $height = number_format($match[3] * $hrat, 0, '.', '');
                     }
                     $summary = preg_replace('/width="' . $match[2] . '"/', 'width="' . $width . '"', $summary);
                     $summary = preg_replace('/height="' . $match[3] . '"/', 'height="' . $height . '"', $summary);
                     $p = preg_replace('/\\//', '\\/', $match[1]);
                     $p = '/src="' . $p . '"/';
                     $rval = 'src="' . $wgServer . $match[1] . '"';
                     $summary = preg_replace($p, $rval, $summary);
                 }
                 // REMOVE ALL TAGS EXCEPT IMG AND SETUP IMAGE DIV
                 $summary = strip_tags($summary, '<img>');
                 if (preg_match('/<img(.*?)>/', $summary, $match)) {
                     $m = preg_replace('/\\//', '\\/', $match[1]);
                     $pat = '/<img' . $m . '>/';
                     $rval = '<div class="floatright"><span>' . '<a href="' . $wgServer . '/' . $url . '" target="_blank">' . '<img' . $match[1] . '></a></span></div>';
                     $summary = preg_replace($pat, $rval, $summary);
                 }
                 // TRUNCATE ARTICLE
                 if (strlen($summary) > $artbloblen) {
                     $summary = substr($summary, 0, $artbloblen);
                     $summary .= '... <a href="' . $wgServer . '/' . $url . '" target="_blank">[Read More]</a>' . "\n";
                 } else {
                     $summary .= ' <a href="' . $wgServer . '/' . $url . '" target="_blank">[Read More]</a>' . "\n";
                 }
                 $nvtmpl->outMain($title_text, $summary, $url);
             } else {
                 if ($itemsshown < $numitems) {
                     $itemlist .= $nvtmpl->outItem($title_text, $summary, $url, $count);
                     $itemsshown++;
                 }
             }
             $count++;
         }
     }
     $nvtmpl->outItemList($itemlist);
     $nvtmpl->outFooter();
 }
 public function execute($par)
 {
     global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc;
     global $IP, $wgDBname, $wgParser;
     global $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
     global $wgFeedClasses, $wgUseRCPatrol;
     global $wgScriptPath, $wgServer;
     global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
     global $messageMemc, $wgDBname, $wgFeedCacheTimeout;
     global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode, $wgLanguageCode;
     $fname = 'wfSpecialGeneratefeed';
     $fullfeed = 0;
     $mrss = 0;
     if ($par == 'fullfeed') {
         $fullfeed = 1;
     } else {
         if ($par == 'mrss') {
             $mrss = 1;
         }
     }
     require_once "{$IP}/extensions/wikihow/FeaturedRSSFeed.php";
     header('Content-Type: text/xml');
     $wgOut->setSquidMaxage(60);
     $feedFormat = 'rss';
     $timekey = "{$wgDBname}:rcfeed:{$feedFormat}:timestamp";
     $key = "{$wgDBname}:rcfeed:{$feedFormat}:limit:{$limit}:minor:{$hideminor}";
     $feedTitle = wfMsg('Rss-feedtitle');
     $feedBlurb = wfMsg('Rss-feedblurb');
     $feed = new FeaturedRSSFeed($feedTitle, $feedBlurb, "{$wgServer}{$wgScriptPath}/Main-Page");
     if ($mrss) {
         $feed->outHeaderMRSS();
     } else {
         // Replace to get back to raw feed (not full and without mrss)
         //$feed->outHeader();
         $feed->outHeaderFullFeed();
     }
     // extract the number of days below -- this is default
     $days = 6;
     date_default_timezone_set('UTC');
     if ($wgRequest->getVal('micro', null) == 1) {
         $days = FeaturedArticles::getNumberOfDays($days, 'RSS-Microblog-Feed');
         $feeds = FeaturedArticles::getFeaturedArticles($days, 'RSS-Microblog-Feed');
     } else {
         $days = FeaturedArticles::getNumberOfDays($days);
         $feeds = FeaturedArticles::getFeaturedArticles($days);
     }
     $now = time();
     $itemcount = 0;
     $itemcountmax = 6;
     foreach ($feeds as $f) {
         $url = trim($f[0]);
         $d = $f[1];
         if ($d > $now) {
             continue;
         }
         if (!$url) {
             continue;
         }
         $url = str_replace('http://wiki.ehow.com/', '', $url);
         $url = str_replace('http://www.wikihow.com/', '', $url);
         $url = str_replace($wgServer . $wgScriptPath . '/', '', $url);
         $title = Title::newFromURL(urldecode($url));
         $summary = '';
         $content = '';
         if ($title == null) {
             echo "title is null for {$url}";
             exit;
         }
         //from the Featured Articles
         if ($title->getArticleID() > 0) {
             $article = GoodRevision::newArticleFromLatest($title);
             $summary = self::getArticleSummary($article, $title);
             $images = self::getImages($article, $title);
             //XXFULL FEED
             if (!$mrss) {
                 $content = $article->getContent(true);
                 $content = preg_replace('/\\{\\{[^}]*\\}\\}/', '', $content);
                 $output = $wgParser->parse($content, $title, new ParserOptions());
                 $content = self::addTargetBlank($output->getText());
                 $content = preg_replace('/href="\\//', 'href="' . $wgServer . '/', $content);
                 $content = preg_replace('/src="\\//', 'src="' . $wgServer . '/', $content);
                 $content = preg_replace('/<span id="gatEditSection" class="editsection1">(.*?)<\\/span>/', '', $content);
                 $content = preg_replace('/<h2> <a target="_blank" href="(.*?)>edit<\\/a>/', '<h2>', $content);
                 $content = preg_replace('/<img src="(.*?)\\/skins\\/common\\/images\\/magnify-clip.png"(.*?)\\/>/', '', $content);
                 $linkEmail = $wgServer . '/index.php?title=Special:EmailLink&target=' . $title->getPrefixedURL();
                 $backlinks = "\n<div id='articletools'><div class='SecL'></div><div class='SecR'></div><a name='articletools'></a><h2> <span>" . wfMsg('RSS-fullfeed-articletools') . "</span></h2> </div>";
                 $backlinks .= "<ul>\n";
                 $backlinks .= "<li type='square'><a target='_blank' href='" . $wgServer . "/" . $title->getPrefixedURL() . "'>" . wfMsg('RSS-fullfeed-articletools-read') . "</a></li>\n";
                 $backlinks .= "<li type='square'><a target='_blank' href='" . $linkEmail . "'>" . wfMsg('RSS-fullfeed-articletools-email') . "</a></li>\n";
                 $backlinks .= "<li type='square'><a target='_blank' href='" . $wgServer . $title->getEditURL() . "'>" . wfMsg('RSS-fullfeed-articletools-edit') . "</a></li>\n";
                 $backlinks .= "<li type='square'><a target='_blank' href='" . $wgServer . "/" . $title->getTalkPage() . "'>" . wfMsg('RSS-fullfeed-articletools-discuss') . "</a></li>\n";
                 $backlinks .= "<ul>\n";
                 $content .= $backlinks;
             }
         } else {
             continue;
         }
         $talkpage = $title->getTalkPage();
         $title_text = $title->getPrefixedText();
         if (isset($f[2]) && $f[2] != null && trim($f[2]) != '') {
             $title_text = $f[2];
         } else {
             $title_text = wfMsg('howto', $title_text);
         }
         $item = new FeedItem($title_text, $summary, $title->getFullURL(), $d, null, $talkpage->getFullURL());
         if ($mrss) {
             $feed->outItemMRSS($item, $images);
         } else {
             // Replace to get back to raw feed (not full and without mrss)
             $feed->outItemFullFeed($item, $content, $images);
         }
         $itemcount++;
     }
     $feed->outFooter();
 }