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; }