if (!$r) {
        continue;
    }
    $text = $r->getText();
    preg_match("@\\|youtube\\|[^\\|]+\\|@U", $text, $matches);
    if (sizeof($matches) > 0) {
        $id = $matches[0];
        $id = str_replace("|", "", $id);
        $id = str_replace("youtube", "", $id);
        $vids[] = array('id' => $id, 'text' => $t->getText(), 'full-text' => $t->getFullText());
    }
}
// Pull from the youtube API to figure out whether the video is "noembed"
foreach ($vids as &$vid) {
    $url = "http://gdata.youtube.com/feeds/api/videos/" . $vid['id'];
    $results = Importvideo::getResults($url);
    $vid['noembed'] = intval(strpos($results, "<yt:noembed/>") !== false);
}
// Remove all embedable videos from the list
$vids = array_filter($vids, function ($item) {
    return $item['noembed'];
});
// Sometimes DB connection goes away at this point. To reconnect using
// Mediawiki's abstraction of the mysql database, the only way I found
// is to "close" the non-existent connection then request another.
$db->close();
$db = wfGetDB(DB_SLAVE);
$db->ping();
// Check if any of these noembed vids have links on the site
$start = microtime(true);
foreach ($vids as $i => $vid) {