本文整理汇总了PHP中Misc::getPagesFromURLs方法的典型用法代码示例。如果您正苦于以下问题:PHP Misc::getPagesFromURLs方法的具体用法?PHP Misc::getPagesFromURLs怎么用?PHP Misc::getPagesFromURLs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Misc
的用法示例。
在下文中一共展示了Misc::getPagesFromURLs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Execute special page. Only available to wikihow staff.
*/
function execute()
{
global $wgRequest, $wgOut, $wgUser, $wgLang;
$userGroups = $wgUser->getGroups();
if ($wgUser->isBlocked() || !in_array('staff', $userGroups)) {
$wgOut->setRobotpolicy('noindex,nofollow');
$wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
return;
}
if ($wgRequest->wasPosted()) {
set_time_limit(0);
$pageList = $wgRequest->getVal('pages-list', '');
$wgOut->setArticleBodyOnly(true);
if ($pageList) {
$pageList = urldecode($pageList);
}
$pageList = preg_split('@[\\r\\n]+@', $pageList);
$urls = array();
$partials = array();
foreach ($pageList as $url) {
$url = trim($url);
if (!empty($url)) {
$url = str_replace('%28', '(', $url);
$url = str_replace('%29', ')', $url);
$urls[] = $url;
if (preg_match('@^http://[^/]+/([^?]+)@', $url, $m)) {
$partials[$m[1]] = $url;
}
}
}
$results = Misc::getPagesFromURLs($urls, array('page_id', 'page_is_redirect'), true);
$lines = array();
foreach ($results as $url => $result) {
$details = 'Not a redirect';
if ($result['page_is_redirect']) {
$redir = self::getIntlRedirect($result['lang'], $result['page_id']);
if ($redir) {
$details = $redir;
}
}
$lines[] = array($url, $result['page_id'], $result['page_is_redirect'], $details);
unset($partials[$result['page_title']]);
}
foreach ($partials as $partial => $url) {
$lines[] = array($url, '', 0, 'Not found');
}
self::httpDownloadHeaders();
foreach ($lines as $line) {
print join("\t", $line) . "\n";
}
return;
}
$wgOut->setHTMLTitle('Admin - Lookup Redirects - wikiHow');
$tmpl = self::getGuts('AdminRedirects');
$wgOut->addHTML($tmpl);
}
示例2: execute
function execute($par)
{
global $wgOut, $wgUser, $wgRequest;
$userGroups = $wgUser->getGroups();
if ($wgUser->isBlocked() || !in_array('staff', $userGroups)) {
$wgOut->setRobotpolicy('noindex,nofollow');
$wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
return;
}
if ($wgRequest->wasPosted()) {
$wgOut->setArticleBodyOnly(true);
$urlList = $wgRequest->getVal("urls");
$urlArray = explode("\n", $urlList);
AdminImageRemoval::$imagesRemoved = array();
$urlArray = array_map("urldecode", $urlArray);
$pages = Misc::getPagesFromURLs($urlArray);
foreach ($pages as $page) {
if ($page['lang'] == "en") {
$this->removeImagesFromArticle($page['page_id']);
}
}
$errors = array();
foreach ($urlArray as $article) {
if (!array_key_exists($article, $pages)) {
$errors[] = $article;
}
}
if (count($errors) > 0) {
$result['success'] = false;
$result['errors'] = $errors;
} else {
$result['success'] = true;
}
echo json_encode($result);
$filePath = "/tmp/images-removal-" . date('Ymd') . ".txt";
$fo = fopen($filePath, 'a');
foreach (AdminImageRemoval::$imagesRemoved as $fileName) {
fwrite($fo, "Image:{$fileName}\n");
}
fclose($fo);
return;
}
$wgOut->addJScode('airj');
$s = Html::openElement('form', array('action' => '', 'id' => 'imageremoval')) . "\n";
$s .= Html::element('p', array(''), 'Input full URLs (e.g. http://www.wikihow.com/Kiss) for articles that should have images removed from them.');
$s .= Html::element('br');
$s .= Html::element('textarea', array('id' => 'urls', 'cols' => 55, 'rows' => 5)) . "\n";
$s .= Html::element('br');
$s .= Html::element('input', array('type' => 'submit', 'class' => "button primary", 'value' => 'Process articles')) . "\n";
$s .= Html::closeElement('form');
$s .= Html::element('div', array('id' => 'imageremoval_results'));
$wgOut->addHTML($s);
}
示例3: execute
public function execute($par)
{
global $wgRequest, $wgOut, $wgUser, $wgLang, $wgLanguageCode;
if ($wgUser->isBlocked()) {
$wgOut->blockedPage();
return;
}
$userGroups = $wgUser->getGroups();
if ($wgUser->getID() == 0 || !(in_array('sysop', $userGroups) || in_array('staff', $userGroups))) {
$wgOut->setRobotpolicy('noindex,nofollow');
$wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
return;
}
if (!$wgRequest->wasPosted()) {
EasyTemplate::set_path(dirname(__FILE__));
$tmpl = EasyTemplate::html("RevertTool.tmpl.php", array('msg' => wfMsg("mass-revert-message"), 'msgName' => "mass-revert-message"));
$wgOut->addHTML($tmpl);
return true;
} else {
set_time_limit(0);
$list = $wgRequest->getVal('page-list');
$revertUser = $wgRequest->getVal('revert-user');
$list = explode("\n", $list);
$urls = array();
if ($wgLanguageCode != "en") {
$pages = Misc::getPagesFromURLs($list);
foreach ($pages as $page) {
if ($page['lang'] == $wgLanguageCode) {
$urls[] = Misc::getLangBaseURL($page['lang']) . '/' . $page['page_title'];
} else {
$links = TranslationLink::getLinksTo($page['lang'], $page['page_id']);
foreach ($links as $link) {
if ($link->toLang == $wgLanguageCode) {
$urls[] = $link->toURL;
}
}
}
}
} else {
$urls = $list;
}
$results = $this->revertList($urls, $revertUser);
$wgOut->setArticleBodyOnly(true);
$wgOut->addHTML(json_encode($results));
return true;
}
}
示例4: addImages
/**
* Add a bunch of URLs to the database for adding their images to various languages
* @param urls New-line seperated list of URLs or Article ids from POST
* @param langs Comma-seperated list of languages to add the images on
*/
private function addImages($urls, $langs)
{
$urls = preg_split("@[\r\n]+@", Misc::getUrlDecodedData($urls));
$langs = preg_split("@,@", urldecode($langs));
$realUrls = array();
$langIds = array();
foreach ($urls as $url) {
if (is_numeric($url)) {
$langIds[] = array("lang" => "en", "id" => $url);
} else {
$realUrls[] = $url;
}
}
$pagesA = Misc::getPagesFromURLs($realUrls, array('page_id', 'page_title'));
$badURLs = array();
$results = array();
foreach ($realUrls as $url) {
if (!isset($pagesA[$url])) {
foreach ($langs as $lang) {
ImageTransfer::addBadURL($url, $lang, "URL not found");
}
$results[] = array('fromURL' => $url, 'toURL' => '', 'status' => 'Bad URL');
}
}
$pagesB = Misc::getPagesFromLangIds($langIds, array('page_id', 'page_title'));
$pages = array_merge($pagesA, $pagesB);
$fromIDs = array();
$urlLookup = array();
foreach ($pages as $page) {
$fromIDs[] = $page['page_id'];
$urlLookup[$page['page_id']] = Misc::getLangBaseURL('en') . '/' . $page['page_title'];
}
if (sizeof($fromIDs) == 0) {
return array();
}
// Fetch to cache the pages for later use in addImage
$this->batchFetchPages("en", $fromIDs);
$langTLs = array();
foreach ($langs as $lang) {
$langTLs[$lang] = TranslationLink::getLinks("en", $lang, array("tl_from_aid in (" . implode(',', $fromIDs) . ")"));
$newFromIds = array_map(function ($m) {
return $m->fromAID;
}, $langTLs[$lang]);
foreach ($fromIDs as $id) {
//Add error links
if (!in_array($id, $newFromIds)) {
$this->addImage($id, $lang, 0);
if (isset($urlLookup[$id])) {
$results[] = array('fromURL' => $urlLookup[$id], 'toURL' => '', 'status' => 'Could not find any translation link to ' . $lang);
}
}
}
TranslationLink::batchPopulateURLs($langTLs[$lang]);
// Cache the other language pages too in a batch
$langIds = array();
foreach ($langTLs[$lang] as $tl) {
$langIds[] = $tls->toAID;
}
$this->batchFetchPages($lang, $langIds);
}
foreach ($langs as $lang) {
foreach ($langTLs[$lang] as $tl) {
if (!$this->addImage($tl->fromAID, $tl->toLang, $tl->toAID)) {
$results[] = array('fromURL' => $tl->fromURL, 'toURL' => $tl->toURL, 'status' => 'Queued');
} else {
$results[] = array('fromURL' => $tl->fromURL, 'toURL' => $tl->toURL, 'status' => 'Failed to queue');
}
}
}
return $results;
}
示例5: checkUrl
/**
* Check if URL exists and is not a redirect
*/
static function checkUrl($url)
{
$pages = Misc::getPagesFromURLs(array($url));
foreach ($pages as $u => $p) {
if ($p['page_is_redirect'] == 0 && $p['page_namespace'] == NS_MAIN) {
return true;
}
}
return false;
}
示例6: execute
/**
* EXECUTE
**/
function execute($par)
{
global $wgRequest, $wgOut, $wgUser, $wgLanguageCode, $isDevHost, $wgActiveLanguages;
if ($wgUser->isBlocked()) {
$wgOut->blockedPage();
return;
}
$userGroups = $wgUser->getGroups();
if ($wgUser->getID() == 0 || !(in_array('sysop', $userGroups) || in_array('staff', $userGroups)) || !(IS_SPARE_HOST || $isDevHost)) {
$wgOut->setRobotpolicy('noindex,nofollow');
$wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
return;
}
$action = $wgRequest->getVal('action', NULL);
if ($wgRequest->wasPosted() && $_FILES['upload']) {
ini_set('memory_limit', '2048M');
$fileName = $_FILES['upload']['tmp_name'];
$list = file_get_contents($fileName);
set_time_limit(0);
$lines = self::parseURLlist($list);
self::httpDownloadHeaders();
$urls = array();
foreach ($lines as $line) {
$urls[] = $line['url1'];
$urls[] = $line['url2'];
}
$pageInfo = Misc::getPagesFromURLs($urls, array("page_title", "page_id"));
$links = array();
foreach ($lines as $line) {
$link = new TranslationLink();
$link->fromURL = $line['url1'];
$link->toURL = $line['url2'];
if (isset($pageInfo[$line['url1']]) && isset($pageInfo[$line['url2']])) {
$p1 = $pageInfo[$line['url1']];
$p2 = $pageInfo[$line['url2']];
$link->fromLang = $p1['lang'];
$link->fromAID = $p1['page_id'];
$link->toLang = $p2['lang'];
$link->toAID = $p2['page_id'];
}
$links[] = $link;
}
TranslationLink::batchUpdateTLStatus($links);
TranslationLink::batchAddTranslationLinks($links);
foreach ($links as $link) {
if ($link->fromLang != NULL && $link->fromAID != NULL && $link->toLang != NULL && $link->toAID != NULL) {
TranslationLink::writeLog(TranslationLink::ACTION_SAVE, $link->fromLang, NULL, $link->fromAID, $link->getFromPage(), $link->toLang, $link->getToPage(), $link->toAID, "TRANSLATION_OVERRIDE");
}
if ($link->tlStatus == TranslationLink::TL_STATUS_SAVED) {
if ($link->oldTlStatus == TranslationLink::TL_STATUS_UPDATEABLE) {
$message = "Updated existing link";
} elseif ($link->oldTlStatus == TranslationLink::TL_STATUS_SAVED) {
$message = "Already saved";
} elseif ($link->oldTlStatus == TranslationLink::TL_STATUS_NEW) {
$message = "Saved Link";
} else {
$message = "Already saved";
}
} elseif ($link->tlStatus == TranslationLink::TL_STATUS_NON_UPDATEABLE) {
$message = "Conflicting existings links, unable to save";
} else {
$message = "Unable to save, URLs invalid or not found";
}
print $link->fromURL . "\t" . $link->toURL . "\t" . $message . "\n";
}
// Hack to override MediaWiki functionality
exit;
return true;
} elseif ($action == null) {
EasyTemplate::set_path(dirname(__FILE__));
$tmpl = EasyTemplate::html("TranslationLinkOverride.tmpl.php");
$wgOut->addHTML($tmpl);
return true;
} elseif ($action == "fetchlinks") {
$id = $wgRequest->getVal('id', null);
$lang = $wgRequest->getVal('lang', null);
$this->fetchLinks($lang, $id);
return true;
} elseif ($action == "search") {
EasyTemplate::set_path(dirname(__FILE__));
$langs = $wgActiveLanguages;
$langs[] = 'en';
$tmpl = EasyTemplate::html("TranslationLinkOverride.delete.tmpl.php", array('langs' => $langs));
$wgOut->addHTML($tmpl);
return true;
} elseif ($action == "dodelete") {
$fromId = $wgRequest->getVal('fromId', null);
$fromLang = $wgRequest->getVal('fromLang', null);
$toId = $wgRequest->getVal('toId', null);
$toLang = $wgRequest->getVal('toLang', null);
$this->doDelete($fromLang, $fromId, $toLang, $toId);
}
return false;
}
示例7: processUrlListByLang
public function processUrlListByLang(&$urlList, $langCode)
{
$excludedKey = $this->getWAPConfig()->getExludedArticlesKeyName();
$excludeList = explode("\n", ConfigStorage::dbGetConfig($excludedKey));
$urlList = Misc::getUrlDecodedData($urlList);
$processedUrls = array(WAPArticle::STATE_INVALID => array(), WAPArticle::STATE_EXCLUDED => array(), WAPArticle::STATE_UNASSIGNED => array(), WAPArticle::STATE_ASSIGNED => array(), WAPArticle::STATE_COMPLETED => array(), WAPArticle::STATE_NEW => array());
$urls = $this->parseURLlist($urlList, $langCode);
foreach ($urls as $url) {
// If it's in the system, put it in the right bucket
$wa = $url['a'];
if ($wa->exists()) {
$url['aid'] = $aid = $wa->getArticleId();
if (in_array($aid, $excludeList)) {
$processedUrls[WAPArticle::STATE_EXCLUDED][] = $url;
} elseif ($wa->isCompleted()) {
$processedUrls[WAPArticle::STATE_COMPLETED][] = $url;
} elseif ($wa->isAssigned()) {
$processedUrls[WAPArticle::STATE_ASSIGNED][] = $url;
} elseif (!$wa->isAssigned()) {
$processedUrls[WAPArticle::STATE_UNASSIGNED][] = $url;
} else {
throw new Exception("Bad url: {$url['url']} {$url['lang']}. Report to your trusty wikiHow engineer.");
}
} else {
// If it's not in the system, see if it's even a valid title (exists and isn't a redirect)
// If it is then check to see if it's excluded.
// If it isn't excluded then it's considered a new article
$page = Misc::getPagesFromURLs(array($url['url']), array('page_id', 'page_is_redirect'), true);
$page = reset($page);
if (!empty($page) && $page['page_is_redirect'] != 1) {
$aid = $page['page_id'];
$url['aid'] = $aid;
if (in_array($aid, $excludeList)) {
$processedUrls[WAPArticle::STATE_EXCLUDED][] = $url;
} else {
$processedUrls[WAPArticle::STATE_NEW][] = $url;
}
} else {
$processedUrls[WAPArticle::STATE_INVALID][] = $url;
}
}
}
return $processedUrls;
}
示例8: addNewTitles
function addNewTitles($articles)
{
global $wgDBname;
$dbw = wfGetDB(DB_MASTER);
$errors = array();
$articles = array_map("urldecode", $articles);
$pages = Misc::getPagesFromURLs($articles);
foreach ($pages as $page) {
$languageCode = $page['lang'];
if ($languageCode == "en") {
//first add this article to the english db
$this->addIntlArticle($dbw, "en", $page['page_id']);
//now get all the translations
self::processTranslations($dbw, $page['page_id']);
} else {
self::addIntlArticle($dbw, $languageCode, $page['page_id']);
}
}
//Find ones that didn't work and tell user about them
foreach ($articles as $article) {
if (!array_key_exists($article, $pages)) {
$errors[] = $article;
}
}
$dbw->selectDB($wgDBname);
//reset memcache since we just changed a lot of values
wikihowAds::resetAllAdExclusionCaches();
return $errors;
}
示例9: fopen
<?php
include_once 'commandLine.inc';
if (sizeof($argv) != 2) {
print "Syntax: \n getLastFellow.php [input_file]";
exit;
}
$f = fopen($argv[1], "r");
$urls = array();
while ($row = fgets($f)) {
$urls[] = urldecode(chop($row));
}
$pages = Misc::getPagesFromURLs($urls, array('page_id'));
$dbr = wfGetDB(DB_SLAVE);
foreach ($urls as $url) {
$fellows = explode("\n", trim(wfMsg('wikifellows')));
$fellows = "'" . implode("','", $fellows) . "'";
$lastEdit = $dbr->selectField('revision', array('rev_user_text'), array('rev_page' => $pages[$url]['page_id'], "rev_user_text IN ({$fellows})"), __METHOD__, array('ORDER BY rev_id DESC', "LIMIT" => 1));
print "{$url}," . $lastEdit . "\n";
}