/** * WARNING: This function makes an API request and is therefore slow. * * This function is intended only for use to test if not-yet-created pages are blocked * (so that we can prevent their creation). If calling-code just needs to check if an * already-existing page is blocked, check the page properties using * GetWikiaPageProp(WPP_LYRICFIND_MARKED_FOR_REMOVAL) instead. */ public static function isPageBlockedViaApi($amgId = "", $gracenoteId = "", $pageTitleText = "") { wfProfileIn(__METHOD__); $isBlocked = false; $app = F::app(); $service = new LyricFindTrackingService(); // format trackid parameter $trackId = $service->formatTrackId(['amg' => $amgId, 'gracenote' => $gracenoteId, 'title' => $pageTitleText]); $url = $app->wg->LyricFindApiUrl . '/lyric.do'; $data = ['apikey' => $app->wg->LyricFindApiKeys['display'], 'reqtype' => 'offlineviews', 'count' => 1, 'trackid' => $trackId, 'output' => 'json', 'useragent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : self::DEFAULT_USER_AGENT]; wfDebug(__METHOD__ . ': ' . json_encode($data) . "\n"); $resp = Http::post($url, ['postData' => $data]); if ($resp !== false) { wfDebug(__METHOD__ . ": API response - {$resp}\n"); } // get the code from API response if ($resp !== false) { $json = json_decode($resp, true); $code = !empty($json['response']['code']) ? intval($json['response']['code']) : false; switch ($code) { case self::CODE_LYRIC_IS_BLOCKED: $isBlocked = true; break; case self::CODE_SUCCESS_NO_LYRICS: case self::CODE_LRC_IS_AVAILABLE: case self::CODE_LYRIC_IS_INSTRUMENTAL: case self::CODE_LYRIC_IS_AVAILABLE: break; default: self::log(__METHOD__, "got #{$code} response code from API (track amg#{$amgId} / gn#{$gracenoteId} / '{$pageTitleText}')"); } } else { self::log(__METHOD__, "LyricFind API request failed in isPageBlockedViaApi()!"); } wfProfileOut(__METHOD__); return $isBlocked; }