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) {
function execute($par) { global $wgOut, $wgRequest, $wgUser, $wgParser; if ($wgUser->isBlocked()) { $wgOut->blockedPage(); return; } if ($wgUser->getID() == 0) { $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext'); return; } if (class_exists('WikihowCSSDisplay')) { WikihowCSSDisplay::setSpecialBackground(true); } if ($wgRequest->getVal('fetchReviewersTable')) { $wgOut->setArticleBodyOnly(true); echo $this->getReviewersTable(); return; } wfLoadExtensionMessages('Importvideo'); wfLoadExtensionMessages("Videoadder"); $target = isset($par) ? $par : $wgRequest->getVal('target'); $cat = htmlspecialchars($wgRequest->getVal('cat')); // get just the HTML for the Ajax call for the next video // used even on the initial page load if ($target == 'getnext') { $wgOut->setArticleBodyOnly(true); // process any skipped videos if ($wgRequest->getVal('va_page_id') && !preg_match("@[^0-9]@", $wgRequest->getVal('va_page_id'))) { $dbw = wfGetDB(DB_MASTER); $vals = array('va_vid_id' => $wgRequest->getVal('va_vid_id'), 'va_user' => $wgUser->getID(), 'va_user_text' => $wgUser->getName(), 'va_timestamp' => wfTimestampNow(), 'va_inuse' => null, 'va_src' => 'youtube'); $va_skip = $wgRequest->getVal('va_skip'); if ($va_skip < 2) { $vals['va_skipped_accepted'] = $va_skip; } $dbw->update('videoadder', $vals, array('va_page' => $wgRequest->getVal('va_page_id'))); if ($wgRequest->getVal('va_skip') == 0) { // import the video $tx = Title::newFromID($wgRequest->getVal('va_page_id')); $ipv = new ImportvideoYoutube(); $text = $ipv->loadVideoText($wgRequest->getVal('va_vid_id')); $vid = Title::makeTitle(NS_VIDEO, $tx->getText()); Importvideo::updateVideoArticle($vid, $text, wfMessage('va_addingvideo')->text()); Importvideo::updateMainArticle($tx, wfMessage('va_addingvideo')->text()); wfRunHooks("VAdone", array()); $wgOut->redirect(''); } else { if ($wgRequest->getVal('va_skip') == 2) { // the user has skipped it and not rejected this one, don't show it to them again self::skipArticle($wgRequest->getVal('va_page_id')); wfRunHooks("VAskipped", array()); } } } $results = self::getNext(); if (empty($results)) { $wgOut->addHTML("Something went wrong. Refresh."); return; } $title = $results[0]; $vid = $results[1]; $id = str_replace("http://gdata.youtube.com/feeds/api/videos/", "", $vid['ID']); if (!$title) { $wgOut->addHTML("Something went wrong. Refresh."); return; } $revision = Revision::newFromTitle($title); $popts = $wgOut->parserOptions(); $popts->setTidy(true); $parserOutput = $wgOut->parse($revision->getText(), $title, $popts); $magic = WikihowArticleHTML::grabTheMagic($revision->getText()); $html = WikihowArticleHTML::processArticleHTML($parserOutput, array('no-ads' => true, 'ns' => NS_MAIN, 'magic-word' => $magic)); $result['guts'] = "<div id='va_buttons'><a href='#' onclick='va_skip(); return false;' class='button secondary ' style='float:left;'>Skip</a>\n<a id='va_yes' href='#' class='button primary disabled buttonright'>Yes, it does</a>\n<a id='va_no' href='#' class='button secondary buttonright'>No, it doesn't</a><div class='clearall'></div></div>\n<div id='va_title'><a href='{$title->getFullURL()}' target='new'>" . wfMsg("howto", $title->getText()) . "</a></div>\n\t\t\t\t\t<div id='va_video' class='section_text'>\n\t<p id='va_notice'>" . wfMsg('va_notice') . "</p>\n<object width='480' height='385'><param name='movie' value='http://www.youtube.com/v/{$id}&hl=en_US&fs=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/{$id}&hl=en_US&fs=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='385'></embed></object>\n\t\t\t\t\t<input type='hidden' id='va_vid_id' value='{$id}'/>\n\t\t\t\t\t<input type='hidden' id='va_page_id' value='{$title->getArticleID()}'/>\n\t\t\t\t\t<input type='hidden' id='va_page_title' value='" . htmlspecialchars($title->getText()) . "'/>\n\t\t\t\t\t<input type='hidden' id='va_page_url' value='" . htmlspecialchars($title->getFullURL()) . "'/>\n\t\t\t\t\t<input type='hidden' id='va_skip' value='0'/>\n\t\t\t\t\t<input type='hidden' id='va_src' value='youtube'/>\n\t\t\t\t\t</div>\n\n\t\t\t</div>\n\t\t\t"; $result['article'] = $html; $dropdown = wfMsg('va_browsemsg') . " " . self::getCategoryDropDown(); $result['options'] = "<div id='va_browsecat'>" . $dropdown . "</div>"; $result['cat'] = $cat; print_r(json_encode($result)); return; } // add the layer of the page $this->setHeaders(); $this->setSideWidgets(); $wgOut->addJScode('vcooj'); $wgOut->addJScode('vaddj'); $wgOut->addCSScode('vaddc'); $wgOut->addHTML("<div class='tool_header tool'><h1>" . wfMessage('va_question') . "<span id='va_instructions'>" . wfMessage('va_instructions') . "</span></h1>"); $wgOut->addHTML("<div id='va_guts'>\n\t\t\t\t\t<center><img src='/extensions/wikihow/rotate.gif'/></center>\n\t\t\t\t</div>"); $wgOut->addHTML("</div>"); $wgOut->addHTML("<input type='hidden' id='va_cat' value='{$cat}' />"); $wgOut->addHTML("<div id='va_article'></div>"); $langKeys = array('va_congrats', 'va_check'); $js = Wikihow_i18n::genJSMsgs($langKeys); $wgOut->addHTML($js); return; }