function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser;
     if (!in_array('newarticlepatrol', $wgUser->getRights())) {
         $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     $wgOut->addHTML("  <script type=\"text/javascript\" src=\"" . wfGetPad('/extensions/min/f/skins/common/clientscript.js,/skins/common/ac.js,/extensions/wikihow/managerssfeed.js&rev=') . WH_SITEREV . "\"></script> ");
     $wgOut->addHTML('<link rel="stylesheet" type="text/css" href="' . wfGetPad('/extensions/min/f/extensions/wikihow/managerssfeed.css') . '" />');
     $wgOut->addScript('<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>');
     $month = $wgRequest->getVal('month', gmdate("n"));
     // build the month tab
     $wgOut->addHTML("<center>");
     for ($i = 1; $i <= 12; $i++) {
         $link = "<a href='/Special:Managerssfeed?month={$i}'>";
         if ($i < 10) {
             $now = wfTimestamp(TS_UNIX, date("Y") . "0" . $i . "01000000");
         } else {
             $now = wfTimestamp(TS_UNIX, date("Y") . $i . "01000000");
         }
         if ($i == $month) {
             $wgOut->addHTML("<div class='month selected'>" . gmdate("M", $now) . "</div>");
         } else {
             $wgOut->addHTML("<div class='month'>{$link}" . gmdate("M", $now) . "</a></div>");
         }
     }
     $now = wfTimestamp(TS_UNIX, gmdate("Y") . ($month < 10 ? "0" . $month : $month) . "01000000");
     // get the feeds
     $dbr = wfGetDB(DB_SLAVE);
     $ts1 = wfTimestamp(TS_MW, $now);
     $tsunix = wfTimestamp(TS_UNIX, $now) + 31 * 3600 * 24;
     // jump ahead 31 days
     $ts2 = wfTimestamp(TS_MW, date("Y", $tsunix) . date("m", $tsunix) . "01000000");
     $res = $dbr->select(array('rssfeed', 'page'), array('page_namespace', 'page_title', 'rss_timestamp', 'rss_approved'), array("rss_timestamp >= '{$ts1}'", "rss_timestamp < '{$ts2}'", 'page_id=rss_page'));
     $map = array();
     while ($row = $dbr->fetchObject($res)) {
         $day = substr($row->rss_timestamp, 0, 8);
         $t = Title::makeTitle($row->page_namespace, $row->page_title);
         if (!isset($map[$day])) {
             $map[$day] = array();
         }
         $map[$day][] = array($t, $row->rss_approved);
     }
     $wgOut->addHTML("</center><br clear='all'><table class='days'>");
     $index = 0;
     while (gmdate("n", $now) == $month) {
         $t = Randomizer::getRandomTitle();
         $d = gmdate("j", $now);
         $wgOut->addHTML("<tr class='day'>\n\t\t\t\t<td class='date'><span class='dow'>" . gmdate("D", $now) . "</span><br/>" . gmdate("d", $now) . "\n\t\t\t\t<table class='addicon'><tr><td>\t<input type='image' src='" . wfGetPad('/extensions/wikihow/plus.png') . "' height='24px' onclick='add({$d})'/></tr></td></table>\n\t\t\t\t</td>\n\t\t\t\t<td class='feeditem'>\n\t\t\t\t<table width='100%' class='feeditem' id='feed_{$d}'>\n\t\t\t");
         if (isset($map[gmdate("Ymd", $now)])) {
             foreach ($map[gmdate("Ymd", $now)] as $tmap) {
                 $t = $tmap[0];
                 $approved = $tmap[1] == 1;
                 $wgOut->addHTML($this->getRow($tmap[0], $t->getArticleID(), $approved));
             }
         }
         $wgOut->addHTML("</table>\n\t\t\t\t\t</td>");
         $wgOut->addHTML("</tr>");
         $now += 3600 * 24;
         $index++;
     }
     $wgOut->addHTML("</table>");
 }
Exemple #2
0
 function execute()
 {
     // Get the parameters
     $params = $this->extractRequestParams();
     $command = $params['subcmd'];
     $result = $this->getResult();
     $module = $this->getModuleName();
     $error = '';
     // try to catch fatal errors to not break app
     ini_set('display_errors', 0);
     register_shutdown_function(function () {
         $error = error_get_last();
         if ($error !== null && ($error['type'] == E_ERROR || $error['type'] == E_CORE_ERROR)) {
             header('Content-Type: application/json');
             $result = array('app' => array('error' => print_r($error, true)));
             print json_encode($result);
             exit;
         }
     });
     switch ($command) {
         case 'article':
             $id = $params['id'];
             $name = $params['name'];
             $random = in_array(strtolower($params['random']), array('1', 't', 'y', 'true'));
             $title = null;
             if ($random) {
                 $title = Randomizer::getRandomTitle();
             } elseif ($id) {
                 $title = Title::newFromID($id);
             } elseif ($name) {
                 $title = Title::newFromURL($name);
             }
             if (!$title || !$title->exists()) {
                 $error = 'Title not found';
             } else {
                 $revid = !$random ? $params['oldid'] : 0;
                 if (!$revid) {
                     $title = WikihowArticleEditor::resolveRedirects($title);
                     if (!$title) {
                         $error = 'Could not find redirect';
                     }
                 }
                 if (!$error) {
                     $articleResult = AppDataFormatter::parseArticle($title, $revid);
                     $creditsResult = AppDataFormatter::getArticleCredits($title, &$articleResult);
                     $articleResult['random'] = $random;
                     //print_r($articleResult);exit;
                     $result->addValue(null, $module, $articleResult);
                     $result->addValue(null, $module, $creditsResult);
                 }
             }
             break;
         case 'credits':
             $id = $params['id'];
             $name = $params['name'];
             $title = null;
             if ($id) {
                 $title = Title::newFromID($id);
             } elseif ($name) {
                 $title = Title::newFromURL($name);
             }
             if (!$title || !$title->exists()) {
                 $error = 'Title not found';
             } else {
                 $creditsResult = AppDataFormatter::getArticleCredits($title);
                 $result->addValue(null, $module, $creditsResult);
             }
             break;
         case 'featured':
             $num = $params['num'];
             $results = AppDataFormatter::featuredArticles($num);
             $result->addValue(null, $module, array('articles' => $results));
             break;
         case 'search':
             $first = $params['first'];
             $num = $params['num'];
             $q = $params['q'];
             $qp = $params['qp'];
             $noCache = $params['nocache'];
             $results = null;
             if ($q) {
                 $results = AppDataFormatter::search($q, $first, $num);
             } elseif ($qp) {
                 $results = AppDataFormatter::searchPartial($qp, $num, $noCache);
             } else {
                 $error = 'Either q (query) or qp (query prefix) param is required';
             }
             if ($results) {
                 $result->addValue(null, $module, array('articles' => $results));
             }
             break;
         case 'psearch':
             $q = $params['q'];
             $wt = $params['wt'];
             $rows = $params['rows'] ?: 10;
             $contents = self::websolrSearch($q, $wt, $rows);
             echo $contents;
             exit;
             break;
         case 'langs':
             $langs = AppDataFormatter::getLangEndpoints();
             $result->addValue(null, $module, array('langs' => $langs));
             break;
         default:
             $error = 'no subcmd specified';
             break;
     }
     if ($error) {
         $result->addValue(null, $module, array('error' => $error));
     }
     return true;
 }