private function handleImageFeedback() { global $wgRequest, $wgOut, $wgName, $wgUser; $dbw = wfGetDB(DB_MASTER); $reason = $wgRequest->getVal('reason'); // Remove / chars from reason since this will be our delimeter in the ii_reason field $reason = $dbw->strencode(trim(str_replace("/", "", $reason))); // Add user who reported $reason = $wgUser->getName() . " says: {$reason}"; $voteTypePrefix = $wgRequest->getVal('voteType') == 'good' ? 'ii_good' : 'ii_bad'; $aid = $dbw->addQuotes($wgRequest->getVal('aid')); $imgUrl = substr(trim($wgRequest->getVal('imgUrl')), 1); $isWikiPhotoImg = 0; // Check if image is a wikiphoto image $t = Title::newFromUrl($imgUrl); if ($t && $t->exists()) { $r = Revision::newFromTitle($t); $userText = $r->getUserText(); if (strtolower($r->getUserText()) == self::WIKIPHOTO_USER_NAME) { $isWikiPhotoImg = 1; } $url = substr($t->getLocalUrl(), 1); $voteField = $voteTypePrefix . "_votes"; $reasonField = $voteTypePrefix . "_reasons"; $sql = "INSERT INTO image_feedback \n\t\t\t\t(ii_img_page_id, ii_wikiphoto_img, ii_page_id, ii_img_url, {$voteField}, {$reasonField}) VALUES \n\t\t\t\t({$t->getArticleId()}, {$isWikiPhotoImg}, {$aid}, '{$url}', 1, '{$reason}') \n\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t{$voteField} = {$voteField} + 1, {$reasonField} = CONCAT({$reasonField}, '/{$reason}')"; $dbw->query($sql, __METHOD__); $wgOut->setArticleBodyOnly(true); } }
static function urlFunction($func, $s = '', $arg = null) { $found = false; $title = Title::newFromText($s); # Due to order of execution of a lot of bits, the values might be encoded # before arriving here; if that's true, then the title can't be created # and the variable will fail. If we can't get a decent title from the first # attempt, url-decode and try for a second. if (is_null($title)) { $title = Title::newFromUrl(urldecode($s)); } if (!is_null($title)) { if (!is_null($arg)) { $text = $title->{$func}($arg); } else { $text = $title->{$func}(); } $found = true; } if ($found) { return $text; } else { return array('found' => false); } }
public function revertList($list, $revertUser) { global $wgServer, $wgLanguageCode; $results = array(); foreach ($list as $l) { if (preg_match('@^http://(.+)\\.wikihow\\.com/(.+)@', $l, $matches)) { if (!($wgLanguageCode == "en" && $matches[1] == "www" || $matches[1] == $wgLanguageCode)) { $results[] = array('url' => $l, 'success' => false, 'msg' => "Invalid URL for language"); } else { $link = $matches[2]; $title = Title::newFromUrl($link); $article = new Article($title); if ($article && $article->exists()) { $ret = $article->commitRollback($revertUser, wfMsg("mass-revert-message"), TRUE, $resultDetails); if (empty($ret)) { $results[] = array('url' => $l, 'success' => true); } else { $results[] = array('url' => $l, 'success' => false, 'msg' => $ret[0][0]); } } else { $results[] = array('url' => $l, 'success' => false, 'msg' => "Article not found"); } } } else { $results[] = array('url' => $l, 'success' => false, 'msg' => "Bad URL"); } } return $results; }
function execute($par) { global $wgUser, $wgRequest; $this->setHeaders(); if (!$this->userCanExecute($wgUser)) { $this->displayRestrictionError(); return; } $this->outputHeader(); // For live revisions $this->mRevisions = (array) $wgRequest->getIntArray('revision'); // For deleted/archived revisions $this->mTarget = Title::newFromUrl($wgRequest->getVal('target')); $this->mTimestamps = (array) $wgRequest->getArray('timestamp'); if (is_null($this->mTarget)) { // title and timestamps must go together $this->mTimestamps = array(); } $this->mPopulated = !empty($this->mRevisions) || !empty($this->mTimestamps); $this->mReason = $wgRequest->getText('wpReason'); $submitted = $wgRequest->wasPosted() && $wgRequest->getVal('action') == 'submit' && $wgUser->matchEditToken($wgRequest->getVal('wpEditToken')); if ($this->mPopulated && $submitted) { $this->submit(); } elseif ($this->mPopulated) { $this->showForm(); } else { $this->showEmpty(); } }
/** * @param Title $page * @param int $oldid */ function __construct($request) { global $wgUser; $target = $request->getVal('target'); $this->page = Title::newFromUrl($target); $this->revisions = $request->getIntArray('oldid', array()); $this->skin = $wgUser->getSkin(); $this->checks = array(array('revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT), array('revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT), array('revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER), array('revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED)); }
/** * Special page allowing users with the appropriate permissions to view * and hide revisions. Log items can also be hidden. * * @file * @ingroup SpecialPage */ function wfSpecialRevisiondelete($par = null) { global $wgOut, $wgRequest, $wgUser; # Handle our many different possible input types $target = $wgRequest->getText('target'); $oldid = $wgRequest->getArray('oldid'); $artimestamp = $wgRequest->getArray('artimestamp'); $logid = $wgRequest->getArray('logid'); $img = $wgRequest->getArray('oldimage'); $fileid = $wgRequest->getArray('fileid'); # For reviewing deleted files... $file = $wgRequest->getVal('file'); # If this is a revision, then we need a target page $page = Title::newFromUrl($target); if (is_null($page)) { $wgOut->addWikiMsg('undelete-header'); return; } # Only one target set at a time please! $i = (bool) $file + (bool) $oldid + (bool) $logid + (bool) $artimestamp + (bool) $fileid + (bool) $img; if ($i !== 1) { $wgOut->showErrorPage('revdelete-nooldid-title', 'revdelete-nooldid-text'); return; } # Logs must have a type given if ($logid && !strpos($page->getDBKey(), '/')) { $wgOut->showErrorPage('revdelete-nooldid-title', 'revdelete-nooldid-text'); return; } # Either submit or create our form $form = new RevisionDeleteForm($page, $oldid, $logid, $artimestamp, $fileid, $img, $file); if ($wgRequest->wasPosted()) { $form->submit($wgRequest); } else { if ($oldid || $artimestamp) { $form->showRevs(); } else { if ($fileid || $img) { $form->showImages(); } else { if ($logid) { $form->showLogItems(); } } } } # Show relevant lines from the deletion log. This will show even if said ID # does not exist...might be helpful $wgOut->addHTML("<h2>" . htmlspecialchars(LogPage::logName('delete')) . "</h2>\n"); LogEventsList::showLogExtract($wgOut, 'delete', $page->getPrefixedText()); if ($wgUser->isAllowed('suppressionlog')) { $wgOut->addHTML("<h2>" . htmlspecialchars(LogPage::logName('suppress')) . "</h2>\n"); LogEventsList::showLogExtract($wgOut, 'suppress', $page->getPrefixedText()); } }
function __construct() { global $wgRequest, $wgMiserMode; if ($wgRequest->getText('sort', 'img_date') == 'img_date') { $this->mDefaultDirection = true; } else { $this->mDefaultDirection = false; } $search = $wgRequest->getText('ilsearch'); if ($search != '' && !$wgMiserMode) { $nt = Title::newFromUrl($search); if ($nt) { $dbr = wfGetDB(DB_SLAVE); $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace("%", "\\%", $m); $m = str_replace("_", "\\_", $m); $this->mQueryConds = array("LOWER(img_name) LIKE '%{$m}%'"); } } parent::__construct(); }
function execute($par) { global $wgRequest, $wgOut, $wgTitle; $param = $wgRequest->getText('param'); $parcheck = $wgRequest->getText('parcheck'); $action = $wgTitle->getFullURL(); $description = wfMsgExt('checksite-description', array('parse')); $label = wfMsgExt('checksite-label', array('parseinline')); $submit = wfMsg('checksite-submit'); $post = "\n\t\t\t<form action=\"{$action}\" method=\"get\">\n\t\t\t{$description}\n\t\t\t{$label}\n\t\t\t<input type=\"text\" name=\"parcheck\" value=\"{$param}\" size=\"40\" maxlength=\"80\" />\n\t\t\t<input type=\"submit\" value=\"{$submit}\" />\n\t\t\t</form>"; $this->setHeaders(); if (!isset($parcheck) || strlen($parcheck) < 5) { $wgOut->addHTML($post); return; } $newdom = check_validate_domain($parcheck); if (!$newdom) { $parcheck = htmlspecialchars($parcheck); $wgOut->addWikiMsg('checksite-cant-check', $parcheck); return; } $newpage = $newdom; $newpage[0] = strtoupper($newpage[0]); $title = Title::newFromUrl($newpage); if (!is_object($title)) { $wgOut->addWikiMsg('checksite-not-found', $newpage); return; } if (!$title->exists()) { $wgOut->addWikiMsg('checksite-not-exist', $newpage); return; } $newhost = check_get_host($newdom); if (!$newhost) { $wgOut->addWikiMsg('checksite-url-not-found', $newdom); return; } if ($rob = @fopen("http://{$newhost}/robots.txt", 'r')) { $txt = fread($rob, 4096); while (!feof($rob)) { $txt .= fread($rob, 4096); if (strlen($txt) > 20000) { break; } } fclose($rob); if (eregi("User-agent:[ \t\n]*WebsiteWiki[ \t\r\n]*Disallow:[ \t\r\n]*/", $txt)) { global $wgUser; $output = wfMsg('checksite-robots', $newhost, $newpage); $orgUser = $wgUser; //TODO: should this hardcoded user be here? $wgUser = User::newFromName('Sysop'); $article = new Article($title); $restrict = array('edit' => 'sysop', 'move' => 'sysop'); $article->updateRestrictions($restrict, $output); $redirectUrl = wfMsg('checksite-redirect-url'); $redirectComment = wfMsg('checksite-redirect-comment'); $article->updateArticle("#REDIRECT [[{$redirectUrl}]]", $redirectComment, false, false); $wgUser = $orgUser; return; } } //TODO: check if this hardcoded URL should remain here if (stristr($newhost, 'duckshop.de')) { $wgOut->addWikiMsg('checksite-screenshot-error'); return; } $output = wfMsg('checksite-screenshot-updating', $newpage); /** * @todo -- lines below do nothing, so why they are there? * * $url = fopen("http://thumbs.websitewiki.de/newthumb.php?name=$newdom", 'r'); * fclose($url); */ # Output $wgOut->addHTML($output); }
function execute($par) { global $wgOut, $wgRequest, $wgParser, $wgUser, $wgFilterCallback, $wgCookiePath, $wgCookieDomain, $wgCookieSecure; $wgOut->disable(); // build the article which we are about to save $t = Title::newFromUrl($wgRequest->getVal('target')); $a = new Article($t); $action = $wgRequest->getVal('eaction'); wfDebug("Html5Editor::execute called with {$action}\n"); // process the edit update if ($action == 'get-vars') { $wgOut->disable(); $response = array('edittoken' => $wgUser->editToken(), 'edittime' => $a->getTimestamp(true), 'drafttoken' => wfGenerateToken(), 'olddraftid' => 0); // do they already have a draft saved? $drafts = Draft::getDrafts($t, $wgUser->getID()); if ($drafts) { // do we only select an html5 draft? probably not. // for loop here in case we want to display multiple drafts of same article $response['olddraftid'] = $drafts[0]->getID(); } print json_encode($response); return; } else { if ($action == 'load-draft') { $draftid = $wgRequest->getVal('draftid'); $draft = new Draft($draftid); if (!$draft->exists()) { wfLoadExtensionMessages("Html5editor"); $response = array('error' => wfMsg('h5e-draft-does-not-exist', $draftid), 'html' => ''); wfDebug("DRAFT: {$draftid} does not exist \n"); } else { $text = $draft->getText(); $html = $this->parse($t, $a, $text); $response = array(error => '', 'html' => $html); } print json_encode($response); return; } else { if ($action == 'save-draft') { $token = $wgRequest->getVal('edittoken'); if ($wgUser->matchEditToken($token)) { wfDebug("Html5Editor::execute save-draft edit token ok!\n"); $oldtext = $a->getContent(); $html = $wgRequest->getVal('html'); $newtext = $this->convertHTML2Wikitext($html, $oldtext); $draftid = $wgRequest->getVal('draftid', null); $draft = null; // 'null' apparently is what javascript is giving us. doh. if (!$draftid || preg_match("@[^0-9]@", $draftid)) { wfDebug("Html5Editor::execute getting draft id from title \n"); $draftid = self::getDraftIDFromTitle($t); } if (!$draftid || $draftid == 'null') { $draft = new Draft(); } else { $draft = Draft::newFromID($draftid); } wfDebug("Html5Editor::execute got draft id {$draftid} \n"); $draft->setTitle($t); //$draft->setStartTime( $wgRequest->getText( 'wpStarttime' ) ); $draft->setEditTime($wgRequest->getText('edittime')); $draft->setSaveTime(wfTimestampNow()); $draft->setText($newtext); $draft->setSummary($wgRequest->getText('editsummary')); $draft->setHtml5(true); //$draft->setMinorEdit( $wgRequest->getInt( 'wpMinoredit', 0 ) ); // Save draft $draft->save(); wfDebug("Html5Editor::execute saved draft with id {$draft->getID()} and text {$newtext} \n"); $response = array('draftid' => $draft->getID()); print json_encode($response); return; } else { wfDebug("Html5Editor::execute save-draft edit token BAD {$token} \n"); $response = array('error' => 'edit token bad'); print json_encode($response); return; } return; } else { if ($action == 'save-summary') { // this implementation could have a few problems // 1. if a user is editing the article in separate windows, it will // only update the last edit // 2. Could be easy to fake an edit summary save, but is limited to // edits made by the user /// 3. There's no real 'paper' trail of the saved summary // grab the cookie with the rev_id global $wgCookiePrefix; if (isset($_COOKIE["{$wgCookiePrefix}RevId" . $t->getArticleID()])) { $revid = $_COOKIE["{$wgCookiePrefix}RevId" . $t->getArticleID()]; wfDebug("AXX: updating revcomment {$revid} \n"); $dbw = wfGetDB(DB_MASTER); $summary = "updating from html5 editor, " . $wgRequest->getVal('summary'); $dbw->update('revision', array('rev_comment' => $summary), array('rev_id' => $revid, 'rev_user_text' => $wgUser->getName()), "Html5Editor::saveComment", array("LIMIT" => 1)); $dbw->update('recentchanges', array('rc_comment' => $summary), array('rc_this_oldid' => $revid, 'rc_user_text' => $wgUser->getName()), "Html5Editor::saveComment", array("LIMIT" => 1)); } else { wfDebug("AXX: NOT updating revcomment, why\n"); } return; } else { if ($action == 'publish-html') { // check the edit token $token = $wgRequest->getVal('edittoken'); if (!$wgUser->matchEditToken($token)) { $response = array('error' => wfMsg('sessionfailure')); print json_encode($response); return; } // check the edit time and check for a conflict $edittime = $wgRequest->getVal('edittime'); if (!preg_match('/^\\d{14}$/', $edittime)) { $edittime = null; } if (!$edittime) { $response = array('error' => 'missing or invalid edit time'); print json_encode($response); return; } if ($response = $this->getPermissionErrors($t)) { print json_encode($response); return; } $newArticle = !$t->exists(); $a = new Article($t); // check for edit conflict // if( $this->mArticle->getTimestamp() != $this->edittime ) { // $this->isConflict = true; // } // now ... let's convert the HTML back into wikitext... holy crap, we are nuts $oldtext = $a->getContent(); $html = $wgRequest->getVal('html'); $newtext = $this->convertHTML2Wikitext($html, $oldtext); // filter callback? if ($wgFilterCallback && $wgFilterCallback($t, $newtext, null)) { # Error messages or other handling should be performed by the filter function $response = array('error' => self::$spam_message, 'html' => $html); print json_encode($response); return; } // do the save // TODO: check for conflicts (obviously) if ($a->doEdit($newtext, $wgRequest->getVal('summary') . " (HTML5) ")) { //$alerts = new MailAddress("*****@*****.**"); //UserMailer::send($alerts, $alerts, "HTML5 Ouput for {$t->getText()}", "{$t->getFullURL()}?action=history \n HTML: " . trim($html) . "\n\nwikitext:\n $newtext\n\n\nUser: "******"\n\n\n\nPOST: " . print_r($_POST, true) ); $r = Revision::newFromTitle($t); $this->setRevCookie($t, $r); #$html = WikihowArticleHTML::postProcess($wgOut->parse($newtext)); $html = $this->parse($t, $a, $newtext); // Create an anon attribution cookie if ($newArticle && $wgUser->getId() == 0) { setcookie('aen_anon_newarticleid', $a->getId(), time() + 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure); } $response = array(error => '', 'html' => $html); print json_encode($response); return; } else { $response = array(error => 'Error saving', 'html' => ''); print json_encode($response); return; } } } } } } return; }
/** * */ function wfSpecialNewimages() { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest; $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr =& wfGetDB(DB_SLAVE); $sk = $wgUser->getSkin(); /** If we were clever, we'd use this to cache. */ $latestTimestamp = wfTimestamp(TS_MW, $dbr->selectField('image', 'img_timestamp', '', 'wfSpecialNewimages', array('ORDER BY' => 'img_timestamp DESC', 'LIMIT' => 1))); /** Hardcode this for now. */ $limit = 48; $where = array(); if ($wpIlMatch != '') { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace('%', "\\%", $m); $m = str_replace('_', "\\_", $m); $where[] = "LCASE(img_name) LIKE '%{$m}%'"; } } $invertSort = false; if ($until = $wgRequest->getVal('until')) { $where[] = 'img_timestamp < ' . $dbr->timestamp($until); } if ($from = $wgRequest->getVal('from')) { $where[] = 'img_timestamp >= ' . $dbr->timestamp($from); $invertSort = true; } $res = $dbr->select('image', array('img_size', 'img_name', 'img_user', 'img_user_text', 'img_description', 'img_timestamp'), $where, 'wfSpecialNewimages', array('LIMIT' => $limit + 1, 'ORDER BY' => 'img_timestamp' . ($invertSort ? '' : ' DESC'))); /** * We have to flip things around to get the last N after a certain date */ $images = array(); while ($s = $dbr->fetchObject($res)) { if ($invertSort) { array_unshift($images, $s); } else { array_push($images, $s); } } $dbr->freeResult($res); $gallery = new ImageGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; foreach ($images as $s) { if (++$shownImages > $limit) { # One extra just to test for whether to show a page link; # don't actually show it. break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText($name, NS_IMAGE); $img = Image::newFromTitle($nt); $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); $gallery->add($img, "{$ul}<br />\n<i>" . $wgLang->timeanddate($s->img_timestamp, true) . "</i><br />\n"); $timestamp = wfTimestamp(TS_MW, $s->img_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $bydate = wfMsg('bydate'); $lt = $wgLang->formatNum(min($shownImages, $limit)); $text = wfMsg("imagelisttext", "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>"); $wgOut->addHTML("<p>{$text}\n</p>"); $sub = wfMsg('ilsubmit'); $titleObj = Title::makeTitle(NS_SPECIAL, 'Newimages'); $action = $titleObj->escapeLocalURL("limit={$limit}"); $wgOut->addHTML("<form id=\"imagesearch\" method=\"post\" action=\"" . "{$action}\">" . "<input type='text' size='20' name=\"wpIlMatch\" value=\"" . htmlspecialchars($wpIlMatch) . "\" /> " . "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>"); $here = $wgContLang->specialPage('Newimages'); /** * Paging controls... */ $now = wfTimestampNow(); $date = $wgLang->timeanddate($now); $dateLink = $sk->makeKnownLinkObj($titleObj, wfMsg('rclistfrom', $date), 'from=' . $now); $prevLink = wfMsg('prevn', $wgLang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $prevLink = $sk->makeKnownLinkObj($titleObj, $prevLink, 'from=' . $firstTimestamp); } $nextLink = wfMsg('nextn', $wgLang->formatNum($limit)); if ($shownImages > $limit && $lastTimestamp) { $nextLink = $sk->makeKnownLinkObj($titleObj, $nextLink, 'until=' . $lastTimestamp); } $prevnext = '<p>' . wfMsg('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; $wgOut->addHTML($prevnext); if (count($images)) { $wgOut->addHTML($gallery->toHTML()); $wgOut->addHTML($prevnext); } else { $wgOut->addWikiText(wfMsg('noimages')); } }
function execute($par) { global $wgRequest, $wgUser, $wgOut, $wgLang, $wgServer; wfLoadExtensionMessages('UserTalkTool'); // CHECK FOR ADMIN STATUS if (!in_array('sysop', $wgUser->getGroups())) { $wgOut->setArticleRelated(false); $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext'); return; } // MAKE SURE USER IS NOT BLOCKED if ($wgUser->isBlocked()) { $wgOut->blockedPage(); return; } // CHECK FOR TARGET $target = isset($par) ? $par : $wgRequest->getVal('target'); if ($target == null || $target == "") { $wgOut->addHTML('No target specified'); return; } $dbw = wfGetDB(DB_MASTER); $dbr = wfGetDB(DB_SLAVE); $me = Title::makeTitle(NS_SPECIAL, "UserTalkTool"); // PROCESS FORM // // if ($wgRequest->wasPosted()) { $wgOut->setArticleBodyOnly(true); $utmsg = $wgRequest->getVal('utmessage'); if ($utmsg != "") { #$t = Title::newFromID($aid); $ts = wfTimestampNow(); $user = $wgUser->getName(); $real_name = User::whoIsReal($wgUser->getID()); if ($real_name == "") { $real_name = $user; } //User // // $utitem = $wgRequest->getVal('utuser'); wfDebug("UTT: posting user: {$utitem}\n"); wfDebug("UTT: by admin user: "******"\n"); if ($utitem != "") { // POST USER TALK PAGE // // $text = ""; $aid = ""; $a = ""; $formattedComment = ""; $u = new User(); $u->setName($utitem); $user_talk = $u->getTalkPage(); $dateStr = $wgLang->timeanddate(wfTimestampNow()); $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, mysql_real_escape_string($utmsg)); $aid = $user_talk->getArticleId(); if ($aid > 0) { $r = Revision::newFromTitle($user_talk); $text = $r->getText(); } $a = new Article($user_talk); $text .= "\n\n{$formattedComment}\n\n"; if ($aid > 0) { $a->updateArticle($text, "", true, false, false, '', true); } else { $a->insertNewArticle($text, "", true, false, true, false, false); } // MARK CHANGES PATROLLED // // $res = $dbr->select('recentchanges', 'max(rc_id) as rc_id', array('rc_title=\'' . mysql_real_escape_string($utitem) . '\'', 'rc_user='******'rc_cur_id=' . $aid, 'rc_patrolled=0')); while ($row = $dbr->fetchObject($res)) { wfDebug("UTT: mark patroll rcid: " . $row->rc_id . " \n"); RecentChange::markPatrolled($row->rc_id); PatrolLog::record($row->rc_id, false); } $dbr->freeResult($res); wfDebug("UTT: done\n"); wfDebug("UTT: Completed posting for [" . $utitem . "]\n"); $wgOut->addHTML("Completed posting for - " . $utitem); } else { wfDebug("UTT: No user\n"); $wgOut->addHTML("UT_MSG ERROR: No user specified. \n"); } } else { wfDebug("UTT: No message to post\n"); $wgOut->addHTML("UT_MSG ERROR: No message to post for - " . $utitem . "\n"); return; } $wgOut->redirect(''); } else { $sk = $wgUser->getSkin(); $wgOut->addHTML(' <script language="javascript" src="/extensions/wikihow/common/prototype1.8.2/prototype.js"></script> <script language="javascript" src="/extensions/wikihow/common/prototype1.8.2/effects.js"></script> <script language="javascript" src="/extensions/wikihow/common/prototype1.8.2/controls.js"></script> ' . "\n"); $wgOut->addHTML("\n\t\t\t<script type='text/javascript'>\n\t\t\t\tfunction utSend () {\n\n\t\t\t\t\t\$('formdiv').style.display = 'none';\n\t\t\t\t\t\$('resultdiv').innerHTML = 'Sending...<br />';\n\n\t\t\t\t\tliArray = document.getElementById('ut_ol').childNodes;\n\t\t\t\t\ti=0;\n\t\t\t\t\twhile(liArray[i]){\n\t\t\t\t\t\tif (document.getElementById(liArray[i].id)) {\n\t\t\t\t\t\t\tif (liArray[i].getAttribute('id').match(/^ut_li_/)) {\n\n\t\t\t\t\t\t\t\tdocument.forms['utForm'].utuser.value = liArray[i].getAttribute('id').replace('ut_li_','');\n\t\t\t\t\t\t\t\t\$('utForm').request({\n\t\t\t\t\t\t\t\t\tasynchronous: false,\n\t\t\t\t\t\t\t\t\tonComplete: function(transport) {\n\t\t\t\t\t\t\t\t\t\t\$('resultdiv').innerHTML += transport.responseText+'<br />';\n\t\t\t\t\t\t\t\t\t\tif (transport.responseText.match(/Completed posting for - /)){\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tvar u = transport.responseText.replace(/Completed posting for - /,'');\n\t\t\t\t\t\t\t\t\t\t\t//\$('resultdiv').innerHTML += 'UID: '+u+'<br />';\n\t\t\t\t\t\t\t\t\t\t\t\$('ut_li_'+u).innerHTML += ' <img src=\"/skins/WikiHow/light_green_check.png\" height=\"15\" width=\"15\" />';\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tonFailure: function(transport) {\n\t\t\t\t\t\t\t\t\t\t\$('resultdiv').innerHTML += 'Sending returned error for '+liArray[i].id+' <br />';\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t//\$('resultdiv').innerHTML += 'Sending '+liArray[i].id+'<br />';\n\t\t\t\t\t\t \t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ti++;\n\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t</script>\n\t\t\t\n\t\t\t"); // GET LIST OF RECIPIENTS // // if ($target) { $t = Title::newFromUrl($target); if ($t->getArticleId() <= 0) { $wgOut->addHTML("Target not a valid article."); return; } else { $r = Revision::newFromTitle($t); $text = $r->getText(); #$wgOut->addHTML( $text ); $utcount = preg_match_all('/\\[\\[User_talk:(.*?)[#\\]\\|]/', $text, $matches); #print_r($matches); $utlist = $matches[1]; } } // DISPLAY COUNT OF USER TALK PAGES FOUND // // if (count($utlist) == 0) { $wgOut->addHTML(wfMsg('notalkpagesfound')); return; } else { $wgOut->addHTML(count($utlist) . ' ' . wfMsg('talkpagesfound') . "<br />"); } // TEXTAREA and FORM // // $wgOut->addHTML(' <form id="utForm" method="post"> '); // DISPLAY LIST OF USER TALK PAGES // // $wgOut->addHTML('<div id="utlist" style="border: 1px grey solid;margin: 15px 0px 15px 0px;padding: 15px;height:215px;overflow:auto"><ol id="ut_ol">' . "\n"); foreach ($utlist as $utitem) { $wgOut->addHTML('<li id="ut_li_' . preg_replace('/\\s/m', '-', $utitem) . '"><a href="/User_talk:' . $utitem . '">' . $utitem . '</a></li>' . "\n"); } $wgOut->addHTML('</ol></div>' . "\n"); // TEXTAREA and FORM // // $wgOut->addHTML(' <div id="formdiv"> ' . wfMsg('sendbox') . '<br /> <textarea id="utmessage" name="utmessage" rows="6" style="margin: 5px 0px 5px 0px;"></textarea> <input id="utuser" type="hidden" name="utuser" value=""> <input tabindex="4" type="button" value="Send" cl1ass="btn" id="postcommentbutton" style="font-size: 110%; font-weight:bold" onclick="utSend(); return false;" /> </form> </div> <div id="resultdiv"></div>' . "\n"); } }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute($par) { global $wgGroupPermissions; $out = $this->getOutput(); $request = $this->getRequest(); $lang = $this->getLang(); $out->setPageTitle(wfMsgHtml('newvideos')); $wpIlMatch = $request->getText('wpIlMatch'); $dbr = wfGetDB(DB_SLAVE); $sk = $this->getSkin(); $shownav = !$this->including(); $hidebots = $request->getBool('hidebots', 1); $hidebotsql = ''; if ($hidebots) { /* * Make a list of group names which have the 'bot' flag * set. */ $botconds = array(); foreach ($wgGroupPermissions as $groupname => $perms) { if (array_key_exists('bot', $perms) && $perms['bot']) { $botconds[] = "ug_group='{$groupname}'"; } } /* If not bot groups, do not set $hidebotsql */ if ($botconds) { $isbotmember = $dbr->makeList($botconds, LIST_OR); /* * This join, in conjunction with WHERE ug_group * IS NULL, returns only those rows from IMAGE * where the uploading user is not a member of * a group which has the 'bot' permission set. */ $ug = $dbr->tableName('user_groups'); $hidebotsql = " LEFT OUTER JOIN {$ug} ON video_user_name=ug_user AND ({$isbotmember})"; } } $video = $dbr->tableName('video'); $sql = "SELECT video_timestamp FROM {$video}"; if ($hidebotsql) { $sql .= "{$hidebotsql} WHERE ug_group IS NULL"; } $sql .= ' ORDER BY video_timestamp DESC LIMIT 1'; $res = $dbr->query($sql, __METHOD__); $row = $dbr->fetchRow($res); if ($row !== false) { $ts = $row[0]; } else { $ts = false; } $sql = ''; /** If we were clever, we'd use this to cache. */ $latestTimestamp = wfTimestamp(TS_MW, $ts); /** Hardcode this for now. */ $limit = 48; if ($parval = intval($par)) { if ($parval <= $limit && $parval > 0) { $limit = $parval; } } $where = array(); $searchpar = array(); if ($wpIlMatch != '') { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace('%', "\\%", $m); $m = str_replace('_', "\\_", $m); $where[] = "LCASE(video_name) LIKE '%{$m}%'"; $searchpar['wpIlMatch'] = $wpIlMatch; } } $invertSort = false; if ($until = $request->getVal('until')) { $where[] = 'video_timestamp < ' . $dbr->timestamp($until); } if ($from = $request->getVal('from')) { $where[] = 'video_timestamp >= ' . $dbr->timestamp($from); $invertSort = true; } $sql = 'SELECT video_name, video_url, video_user_name, video_user_id, ' . " video_timestamp FROM {$video}"; if ($hidebotsql) { $sql .= $hidebotsql; $where[] = 'ug_group IS NULL'; } if (count($where)) { $sql .= ' WHERE ' . $dbr->makeList($where, LIST_AND); } $sql .= ' ORDER BY video_timestamp ' . ($invertSort ? '' : ' DESC'); $sql .= ' LIMIT ' . ($limit + 1); $res = $dbr->query($sql, __METHOD__); // We have to flip things around to get the last N after a certain date $videos = array(); foreach ($res as $s) { if ($invertSort) { array_unshift($videos, $s); } else { array_push($videos, $s); } } $gallery = new VideoGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownVideos = 0; foreach ($videos as $s) { if (++$shownVideos > $limit) { // One extra just to test for whether to show a page link; // don't actually show it. break; } $name = $s->video_name; $ut = $s->video_user_name; $nt = Title::newFromText($name, NS_VIDEO); $vid = new Video($nt, $this->getContext()); $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); $gallery->add($vid, "{$ul}<br />\n<i>" . $lang->timeanddate($s->video_timestamp, true) . "</i><br />\n"); $timestamp = wfTimestamp(TS_MW, $s->video_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $bydate = wfMsg('bydate'); $lt = $lang->formatNum(min($shownVideos, $limit)); if ($shownav) { $text = wfMsgExt('imagelisttext', 'parse', $lt, $bydate); $out->addHTML($text . "\n"); } $sub = wfMsg('ilsubmit'); $titleObj = SpecialPage::getTitleFor('NewVideos'); $action = $titleObj->escapeLocalURL($hidebots ? '' : 'hidebots=0'); if ($shownav) { $out->addHTML("<form id=\"imagesearch\" method=\"post\" action=\"{$action}\">" . Xml::input('wpIlMatch', 20, $wpIlMatch) . ' ' . Xml::submitButton($sub, array('name' => 'wpIlSubmit')) . '</form>'); } // Paging controls... # If we change bot visibility, this needs to be carried along. if (!$hidebots) { $botpar = array('hidebots' => 0); } else { $botpar = array(); } $now = wfTimestampNow(); $date = $lang->date($now, true); $time = $lang->time($now, true); $query = array_merge(array('from' => $now), $botpar, $searchpar); $dateLink = $sk->linkKnown($titleObj, htmlspecialchars(wfMsgHtml('sp-newimages-showfrom', $date, $time)), array(), $query); $query = array_merge(array('hidebots' => $hidebots ? 0 : 1), $searchpar); $showhide = $hidebots ? wfMsg('show') : wfMsg('hide'); $botLink = $sk->linkKnown($titleObj, htmlspecialchars(wfMsg('showhidebots', $showhide)), array(), $query); $opts = array('parsemag', 'escapenoentities'); $prevLink = wfMsgExt('pager-newer-n', $opts, $lang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $query = array_merge(array('from' => $firstTimestamp), $botpar, $searchpar); $prevLink = $sk->linkKnown($titleObj, $prevLink, array(), $query); } $nextLink = wfMsgExt('pager-older-n', $opts, $lang->formatNum($limit)); if ($shownVideos > $limit && $lastTimestamp) { $query = array_merge(array('until' => $lastTimestamp), $botpar, $searchpar); $nextLink = $sk->linkKnown($titleObj, $nextLink, array(), $query); } $prevnext = '<p>' . $botLink . ' ' . wfMsgHtml('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; if ($shownav) { $out->addHTML($prevnext); } if (count($videos)) { $out->addHTML($gallery->toHTML()); if ($shownav) { $out->addHTML($prevnext); } } else { $out->addWikiMsg('video-no-videos'); } }
function wfSpecialWikiaNewFiles($par, $specialPage) { global $wgOut, $wgLang, $wgRequest, $wgMiserMode; global $wmu, $wgOasisHD; $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr = wfGetDB(DB_SLAVE); $sk = RequestContext::getMain()->getSkin(); $shownav = !$specialPage->including(); $hidebots = $wgRequest->getBool('hidebots', 1); $hidebotsql = ''; if ($hidebots) { # Make a list of group names which have the 'bot' flag set. $botconds = array(); foreach (User::getGroupsWithPermission('bot') as $groupname) { $botconds[] = 'ug_group = ' . $dbr->addQuotes($groupname); } # If not bot groups, do not set $hidebotsql if ($botconds) { $isbotmember = $dbr->makeList($botconds, LIST_OR); # This join, in conjunction with WHERE ug_group IS NULL, returns # only those rows from IMAGE where the uploading user is not a mem- # ber of a group which has the 'bot' permission set. $ug = $dbr->tableName('user_groups'); $hidebotsql = " LEFT JOIN {$ug} ON img_user=ug_user AND ({$isbotmember})"; } } $image = $dbr->tableName('image'); $sql = "SELECT img_timestamp from {$image}"; if ($hidebotsql) { $sql .= "{$hidebotsql} WHERE ug_group IS NULL"; } $sql .= ' ORDER BY img_timestamp DESC LIMIT 1'; $res = $dbr->query($sql, __FUNCTION__); $row = $dbr->fetchRow($res); if ($row !== false) { $ts = $row[0]; } else { $ts = false; } $dbr->freeResult($res); $sql = ''; # If we were clever, we'd use this to cache. $latestTimestamp = wfTimestamp(TS_MW, $ts); # Hardcode this for now. $limit = 48; if ($parval = intval($par)) { if ($parval <= $limit && $parval > 0) { $limit = $parval; } } $where = array(); $searchpar = ''; if ($wpIlMatch != '' && !$wgMiserMode) { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->buildLike($dbr->anyString(), strtolower($nt->getDBkey()), $dbr->anyString()); $where[] = 'LOWER(img_name)' . $m; $searchpar = '&wpIlMatch=' . urlencode($wpIlMatch); } } $invertSort = false; if ($until = $wgRequest->getVal('until')) { $where[] = "img_timestamp < '" . $dbr->timestamp($until) . "'"; } if ($from = $wgRequest->getVal('from')) { $where[] = "img_timestamp >= '" . $dbr->timestamp($from) . "'"; $invertSort = true; } $sql = 'SELECT img_size, img_name, img_user, img_user_text,' . "img_description,img_timestamp FROM {$image}"; if ($hidebotsql) { $sql .= $hidebotsql; $where[] = 'ug_group IS NULL'; } // hook by Wikia, Bartek Lapinski 26.03.2009, for videos and stuff wfRunHooks('SpecialNewImages::beforeQuery', array(&$where)); if (count($where)) { $sql .= ' WHERE ' . $dbr->makeList($where, LIST_AND); } $sql .= ' ORDER BY img_timestamp ' . ($invertSort ? '' : ' DESC'); $sql .= ' LIMIT ' . ($limit + 1); $res = $dbr->query($sql, __FUNCTION__); /** * We have to flip things around to get the last N after a certain date */ $images = array(); while ($s = $dbr->fetchObject($res)) { if ($invertSort) { array_unshift($images, $s); } else { array_push($images, $s); } } $dbr->freeResult($res); $gallery = new WikiaPhotoGallery(); $gallery->parseParams(array("rowdivider" => true, "hideoverflow" => true)); //FB#1150 - make the images fit the whole horizontal space in Oasis and Oasis HD if (get_class($sk) == 'SkinOasis') { if ($wgOasisHD) { $gallery->setWidths(202); } else { $gallery->setWidths(212); } } $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; foreach ($images as $s) { $shownImages++; if ($shownImages > $limit) { # One extra just to test for whether to show a page link; # don't actually show it. break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText($name, NS_FILE); $ul = $sk->link(Title::makeTitle(NS_USER, $ut), $ut, array('class' => 'wikia-gallery-item-user')); $timeago = wfTimeFormatAgo($s->img_timestamp); $links = getLinkedFiles($s); // If there are more than two files, remove the 2nd and link to the // image page if (count($links) == 2) { array_splice($links, 1); $moreFiles = true; } else { $moreFiles = false; } $caption = wfMsgHtml('wikianewfiles-uploadby', $ul) . "<br />\n" . "<i>{$timeago}</i><br />\n"; if (count($links)) { $caption .= wfMsg('wikianewfiles-postedin') . " " . $links[0]; } if ($moreFiles) { $caption .= ", " . '<a href="' . $nt->getLocalUrl() . '#filelinks" class="wikia-gallery-item-more">' . wfMsgHtml('wikianewfiles-more') . '</a>'; } $gallery->add($nt, $caption); $timestamp = wfTimestamp(TS_MW, $s->img_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } wfRunHooks('SpecialNewImages::beforeDisplay', array(&$images, &$gallery, &$limit)); $titleObj = SpecialPage::getTitleFor('Newimages'); $action = $titleObj->getLocalURL($hidebots ? '' : 'hidebots=0'); if ($shownav && !$wgMiserMode) { $wgOut->addHTML(Xml::openElement('form', array('action' => $action, 'method' => 'post', 'id' => 'imagesearch')) . Xml::fieldset(wfMsg('newimages-legend')) . Xml::inputLabel(wfMsg('newimages-label'), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch) . ' ' . Xml::submitButton(wfMsg('ilsubmit'), array('name' => 'wpIlSubmit')) . Xml::closeElement('fieldset') . Xml::closeElement('form')); } /** * Paging controls... */ # If we change bot visibility, this needs to be carried along. if (!$hidebots) { $botpar = '&hidebots=0'; } else { $botpar = ''; } $now = wfTimestampNow(); $d = $wgLang->date($now, true); $t = $wgLang->time($now, true); $dateLink = $sk->link($titleObj, wfMsgHtml('sp-newimages-showfrom', $d, $t), array('class' => 'navigation-filesfrom'), 'from=' . $now . $botpar . $searchpar); $botLink = $sk->link($titleObj, wfMsgHtml('showhidebots', $hidebots ? wfMsgHtml('show') : wfMsgHtml('hide')), array('class' => 'navigation-' . ($hidebots ? 'showbots' : 'hidebots')), 'hidebots=' . ($hidebots ? '0' : '1') . $searchpar); $opts = array('parsemag', 'escapenoentities'); $prevLink = wfMsgExt('pager-newer-n', $opts, $wgLang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $wmu['prev'] = $firstTimestamp; $prevLink = $sk->link($titleObj, $prevLink, array('class' => 'navigation-newer'), 'from=' . $firstTimestamp . $botpar . $searchpar); } $nextLink = wfMsgExt('pager-older-n', $opts, $wgLang->formatNum($limit)); if ($shownImages > $limit && $lastTimestamp) { $wmu['next'] = $lastTimestamp; $nextLink = $sk->link($titleObj, $nextLink, array('class' => 'navigation-older'), 'until=' . $lastTimestamp . $botpar . $searchpar); } $prevnext = '<p id="newfiles-nav">' . $botLink . ' ' . wfMsgHtml('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; if (count($images)) { $wmu['gallery'] = $gallery; $wgOut->addHTML($gallery->toHTML()); if ($shownav) { $wgOut->addHTML($prevnext); } } else { $wgOut->addWikiMsg('noimages'); } }
/** * */ function wfSpecialImagelist() { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgMiserMode; $sort = $wgRequest->getVal('sort'); $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr =& wfGetDB(DB_SLAVE); $image = $dbr->tableName('image'); $sql = "SELECT img_size,img_name,img_user,img_user_text," . "img_description,img_timestamp FROM {$image}"; $byname = wfMsg("byname"); $bydate = wfMsg("bydate"); $bysize = wfMsg("bysize"); if (!$wgMiserMode && !empty($wpIlMatch)) { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace("%", "\\%", $m); $m = str_replace("_", "\\_", $m); $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'"; } } if ("bysize" == $sort) { $sql .= " ORDER BY img_size DESC"; $st = $bysize; } else { if ("byname" == $sort) { $sql .= " ORDER BY img_name"; $st = $byname; } else { $sort = "bydate"; $sql .= " ORDER BY img_timestamp DESC"; $st = $bydate; } } list($limit, $offset) = wfCheckLimits(50); if (0 == $limit) { $lt = wfMsg('imagelistall'); } else { $lt = $wgLang->formatNum("{$limit}"); $sql .= " LIMIT {$limit}"; } $wgOut->addHTML("<p>" . wfMsg("imglegend") . "</p>\n"); $text = wfMsg("imagelisttext", "<strong>{$lt}</strong>", "<strong>{$st}</strong>"); $wgOut->addHTML("<p>{$text}\n</p>"); $sk = $wgUser->getSkin(); $sub = wfMsg("ilsubmit"); $titleObj = Title::makeTitle(NS_SPECIAL, "Imagelist"); $action = $titleObj->escapeLocalURL("sort={$sort}&limit={$limit}"); if (!$wgMiserMode) { $wgOut->addHTML("<form id=\"imagesearch\" method=\"post\" action=\"" . "{$action}\">" . "<input type='text' size='20' name=\"wpIlMatch\" value=\"" . htmlspecialchars($wpIlMatch) . "\" /> " . "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>"); } $nums = array(50, 100, 250, 500); $here = Title::makeTitle(NS_SPECIAL, 'Imagelist'); $fill = ""; $first = true; foreach ($nums as $num) { if (!$first) { $fill .= " | "; } $first = false; $fill .= $sk->makeKnownLinkObj($here, $wgLang->formatNum($num), "sort=byname&limit={$num}&wpIlMatch=" . urlencode($wpIlMatch)); } $text = wfMsg("showlast", $fill, $byname); $wgOut->addHTML("<p>{$text}<br />\n"); $fill = ""; $first = true; foreach ($nums as $num) { if (!$first) { $fill .= " | "; } $first = false; $fill .= $sk->makeKnownLinkObj($here, $wgLang->formatNum($num), "sort=bysize&limit={$num}&wpIlMatch=" . urlencode($wpIlMatch)); } $text = wfMsg("showlast", $fill, $bysize); $wgOut->addHTML("{$text}<br />\n"); $fill = ""; $first = true; foreach ($nums as $num) { if (!$first) { $fill .= " | "; } $first = false; $fill .= $sk->makeKnownLinkObj($here, $wgLang->formatNum($num), "sort=bydate&limit={$num}&wpIlMatch=" . urlencode($wpIlMatch)); } $text = wfMsg("showlast", $fill, $bydate); $wgOut->addHTML("{$text}</p>\n<p>"); $res = $dbr->query($sql, "wfSpecialImagelist"); while ($s = $dbr->fetchObject($res)) { $name = $s->img_name; $ut = $s->img_user_text; if (0 == $s->img_user) { $ul = $ut; } else { $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); } $ilink = "<a href=\"" . htmlspecialchars(Image::imageUrl($name)) . "\">" . strtr(htmlspecialchars($name), '_', ' ') . "</a>"; $nb = wfMsg("nbytes", $wgLang->formatNum($s->img_size)); $l = "(" . $sk->makeKnownLinkObj(Title::makeTitle(NS_IMAGE, $name), wfMsg("imgdesc")) . ") {$ilink} . . {$nb} . . {$ul} . . " . $wgLang->timeanddate($s->img_timestamp, true); $l .= $sk->commentBlock($s->img_description); $wgOut->addHTML("{$l}<br />\n"); } $wgOut->addHTML("</p>"); $dbr->freeResult($res); }
/** * */ function wfSpecialImagelist() { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgMiserMode; $sort = $wgRequest->getVal('sort'); $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr =& wfGetDB(DB_SLAVE); $image = $dbr->tableName('image'); $sql = "SELECT img_size,img_name,img_user,img_user_text," . "img_description,img_timestamp FROM {$image}"; if (!$wgMiserMode && !empty($wpIlMatch)) { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace("%", "\\%", $m); $m = str_replace("_", "\\_", $m); $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'"; } } if ("bysize" == $sort) { $sql .= " ORDER BY img_size DESC"; } else { if ("byname" == $sort) { $sql .= " ORDER BY img_name"; } else { $sort = "bydate"; $sql .= " ORDER BY img_timestamp DESC"; } } list($limit, $offset) = wfCheckLimits(50); $lt = $wgLang->formatNum("{$limit}"); $sql .= " LIMIT {$limit}"; $wgOut->addWikiText(wfMsg('imglegend')); $wgOut->addHTML(wfMsgExt('imagelisttext', array('parse'), $lt, wfMsg($sort))); $sk = $wgUser->getSkin(); $titleObj = Title::makeTitle(NS_SPECIAL, "Imagelist"); $action = $titleObj->escapeLocalURL("sort={$sort}&limit={$limit}"); if (!$wgMiserMode) { $wgOut->addHTML("<form id=\"imagesearch\" method=\"post\" action=\"" . "{$action}\">" . wfElement('input', array('type' => 'text', 'size' => '20', 'name' => 'wpIlMatch', 'value' => $wpIlMatch)) . wfElement('input', array('type' => 'submit', 'name' => 'wpIlSubmit', 'value' => wfMsg('ilsubmit'))) . '</form>'); } $here = Title::makeTitle(NS_SPECIAL, 'Imagelist'); foreach (array('byname', 'bysize', 'bydate') as $sorttype) { $urls = null; foreach (array(50, 100, 250, 500) as $num) { $urls[] = $sk->makeKnownLinkObj($here, $wgLang->formatNum($num), "sort={$sorttype}&limit={$num}&wpIlMatch=" . urlencode($wpIlMatch)); } $sortlinks[] = wfMsgExt('showlast', array('parseinline', 'replaceafter'), implode($urls, ' | '), wfMsgExt($sorttype, array('escape'))); } $wgOut->addHTML(implode($sortlinks, "<br />\n") . "\n\n<hr />"); // lines $wgOut->addHTML('<p>'); $res = $dbr->query($sql, "wfSpecialImagelist"); while ($s = $dbr->fetchObject($res)) { $name = $s->img_name; $ut = $s->img_user_text; if (0 == $s->img_user) { $ul = $ut; } else { $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); } $dirmark = $wgContLang->getDirMark(); // to keep text in correct direction $ilink = "<a href=\"" . htmlspecialchars(Image::imageUrl($name)) . "\">" . strtr(htmlspecialchars($name), '_', ' ') . "</a>"; $nb = wfMsgExt('nbytes', array('parsemag', 'escape'), $wgLang->formatNum($s->img_size)); $desc = $sk->makeKnownLinkObj(Title::makeTitle(NS_IMAGE, $name), wfMsg('imgdesc')); $date = $wgLang->timeanddate($s->img_timestamp, true); $comment = $sk->commentBlock($s->img_description); $l = "({$desc}) {$dirmark}{$ilink} . . {$dirmark}{$nb} . . {$dirmark}{$ul}" . " . . {$dirmark}{$date} . . {$dirmark}{$comment}<br />\n"; $wgOut->addHTML($l); } $dbr->freeResult($res); $wgOut->addHTML('</p>'); }
* @package MediaWiki * @subpackage Maintenance * @author Rob Church <*****@*****.**> */ $options = array('help', 'nooverwrite'); $optionsWithArgs = array('title', 'user', 'comment'); require_once 'commandLine.inc'; echo "Import Text File\n\n"; if (isset($options['help'])) { showHelp(); } else { $filename = $args[0]; echo "Using {$filename}..."; if (is_file($filename)) { $title = isset($options['title']) ? $options['title'] : titleFromFilename($filename); $title = Title::newFromUrl($title); echo "\nUsing title '" . $title->getPrefixedText() . "'..."; if (is_object($title)) { if (!$title->exists() || !isset($options['nooverwrite'])) { $text = file_get_contents($filename); $user = isset($options['user']) ? $options['user'] : '******'; $user = User::newFromName($user); echo "\nUsing username '" . $user->getName() . "'..."; if (is_object($user)) { $wgUser =& $user; $comment = isset($options['comment']) ? $options['comment'] : 'Importing text file'; $comment = str_replace('_', ' ', $comment); echo "\nPerforming edit..."; $article = new Article($title); $article->doEdit($text, $comment); echo "done.\n";
foreach ($nodes as $node) { $links = $xpath->query(".//a[@class='l']", $node); foreach ($links as $link) { $href = $link->getAttribute("href"); #echo "$href\n"; #echo "+++{$doc->saveXML($link)}\n"; if ($href == $turl) { $found[] = $title; return $index; } $index++; } } #echo str_replace("<", "\n<", $doc->saveXML()); exit; $notfound[] = $title; return -1; } $check = wfTimestampNow(); foreach ($urls as $u) { $u = trim(urldecode($u)); if ($u == "") { continue; } $t = Title::newFromUrl($u); if (!$t) { echo "can't make t out of {$u}\n"; continue; } $result = search($t); echo "{$check},{$t->getText()},{$result}\n"; }
function doDelete($pages, $reason) { foreach ($pages as $page) { $title = Title::newFromUrl($page); $article = new Article($title); $article->doDelete($reason); } }
static function urlFunction($func, $s = '', $arg = null) { $title = Title::newFromText($s); # Due to order of execution of a lot of bits, the values might be encoded # before arriving here; if that's true, then the title can't be created # and the variable will fail. If we can't get a decent title from the first # attempt, url-decode and try for a second. if (is_null($title)) { $title = Title::newFromUrl(urldecode($s)); } if (!is_null($title)) { # Convert NS_MEDIA -> NS_FILE if ($title->getNamespace() == NS_MEDIA) { $title = Title::makeTitle(NS_FILE, $title->getDBKey()); } if (!is_null($arg)) { $text = $title->{$func}($arg); } else { $text = $title->{$func}(); } return $text; } else { return array('found' => false); } }
function execute($par) { global $wgRequest, $wgUser, $wgOut; $wgOut->setArticleBodyOnly(true); $wgOut->clearHTML(); $target = isset($par) ? $par : $wgRequest->getVal('target'); $title = Title::newFromUrl($target); if (!$title || !$title->exists()) { $wgOut->addHTML('Title no longer exists: ' . $target); return; } $article = new Article($title); $text = $article->getContent(true); $snippet = $article->getSection($text, 0) . "\n" . $article->getSection($text, 1); $html = $wgOut->parse($snippet); $wgOut->addHTML($html); }
public function execute($par) { global $wgOut, $wgUser, $wgRequest; if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } if (!$wgUser->isAllowed('deleterevision')) { $wgOut->permissionRequired('deleterevision'); return; } $this->skin =& $wgUser->getSkin(); # Set title and such $this->setHeaders(); $this->outputHeader(); $this->wasPosted = $wgRequest->wasPosted(); # Handle our many different possible input types $this->target = $wgRequest->getText('target'); $this->oldids = $wgRequest->getArray('oldid'); $this->artimestamps = $wgRequest->getArray('artimestamp'); $this->logids = $wgRequest->getArray('logid'); $this->oldimgs = $wgRequest->getArray('oldimage'); $this->fileids = $wgRequest->getArray('fileid'); # For reviewing deleted files... $this->file = $wgRequest->getVal('file'); # Only one target set at a time please! $i = (bool) $this->file + (bool) $this->oldids + (bool) $this->logids + (bool) $this->artimestamps + (bool) $this->fileids + (bool) $this->oldimgs; # No targets? if ($i == 0) { $wgOut->showErrorPage('notargettitle', 'notargettext'); return; } # Too many targets? if ($i !== 1) { $wgOut->showErrorPage('revdelete-toomanytargets-title', 'revdelete-toomanytargets-text'); return; } $this->page = Title::newFromUrl($this->target); # If we have revisions, get the title from the first one # since they should all be from the same page. This allows # for more flexibility with page moves... if (count($this->oldids) > 0) { $rev = Revision::newFromId($this->oldids[0]); $this->page = $rev ? $rev->getTitle() : $this->page; } # We need a target page! if (is_null($this->page)) { $wgOut->addWikiMsg('undelete-header'); return; } # Logs must have a type given if ($this->logids && !strpos($this->page->getDBKey(), '/')) { $wgOut->showErrorPage('revdelete-nologtype-title', 'revdelete-nologtype-text'); return; } # For reviewing deleted files...show it now if allowed if ($this->file) { $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($this->page, $this->file); $oimage->load(); // Check if user is allowed to see this file if (!$oimage->userCan(File::DELETED_FILE)) { $wgOut->permissionRequired('suppressrevision'); } else { $this->showFile($this->file); } return; } # Give a link to the logs/hist for this page if (!is_null($this->page) && $this->page->getNamespace() > -1) { $links = array(); $logtitle = SpecialPage::getTitleFor('Log'); $links[] = $this->skin->makeKnownLinkObj($logtitle, wfMsgHtml('viewpagelogs'), wfArrayToCGI(array('page' => $this->page->getPrefixedUrl()))); # Give a link to the page history $links[] = $this->skin->makeKnownLinkObj($this->page, wfMsgHtml('pagehist'), wfArrayToCGI(array('action' => 'history'))); # Link to deleted edits if ($wgUser->isAllowed('undelete')) { $undelete = SpecialPage::getTitleFor('Undelete'); $links[] = $this->skin->makeKnownLinkObj($undelete, wfMsgHtml('deletedhist'), wfArrayToCGI(array('target' => $this->page->getPrefixedDBkey()))); } # Logs themselves don't have histories or archived revisions $wgOut->setSubtitle('<p>' . implode($links, ' / ') . '</p>'); } # Lock the operation and the form context $this->secureOperation(); # Either submit or create our form if ($this->wasPosted) { $this->submit($wgRequest); } else { if ($this->deleteKey == 'oldid' || $this->deleteKey == 'artimestamp') { $this->showRevs(); } else { if ($this->deleteKey == 'fileid' || $this->deleteKey == 'oldimage') { $this->showImages(); } else { if ($this->deleteKey == 'logid') { $this->showLogItems(); } } } } # Show relevant lines from the deletion log. This will show even if said ID # does not exist...might be helpful $wgOut->addHTML("<h2>" . htmlspecialchars(LogPage::logName('delete')) . "</h2>\n"); LogEventsList::showLogExtract($wgOut, 'delete', $this->page->getPrefixedText()); if ($wgUser->isAllowed('suppressionlog')) { $wgOut->addHTML("<h2>" . htmlspecialchars(LogPage::logName('suppress')) . "</h2>\n"); LogEventsList::showLogExtract($wgOut, 'suppress', $this->page->getPrefixedText()); } }
/** * */ function wfSpecialNewimages($par, $specialPage) { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgGroupPermissions; $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr =& wfGetDB(DB_SLAVE); $sk = $wgUser->getSkin(); $shownav = !$specialPage->including(); $hidebots = $wgRequest->getBool('hidebots', 1); if ($hidebots) { /** Make a list of group names which have the 'bot' flag set. */ $botconds = array(); foreach ($wgGroupPermissions as $groupname => $perms) { if (array_key_exists('bot', $perms) && $perms['bot']) { $botconds[] = "ug_group='{$groupname}'"; } } $isbotmember = $dbr->makeList($botconds, LIST_OR); /** This join, in conjunction with WHERE ug_group IS NULL, returns only those rows from IMAGE where the uploading user is not a member of a group which has the 'bot' permission set. */ $ug = $dbr->tableName('user_groups'); $joinsql = " LEFT OUTER JOIN {$ug} ON img_user=ug_user AND (" . $isbotmember . ')'; } $image = $dbr->tableName('image'); $sql = "SELECT img_timestamp from {$image}"; if ($hidebots) { $sql .= $joinsql . ' WHERE ug_group IS NULL'; } $sql .= ' ORDER BY img_timestamp DESC LIMIT 1'; $res = $dbr->query($sql, 'wfSpecialNewImages'); $row = $dbr->fetchRow($res); if ($row !== false) { $ts = $row[0]; } else { $ts = false; } $dbr->freeResult($res); $sql = ''; /** If we were clever, we'd use this to cache. */ $latestTimestamp = wfTimestamp(TS_MW, $ts); /** Hardcode this for now. */ $limit = 48; if ($parval = intval($par)) { if ($parval <= $limit && $parval > 0) { $limit = $parval; } } $where = array(); $searchpar = ''; if ($wpIlMatch != '') { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace('%', "\\%", $m); $m = str_replace('_', "\\_", $m); $where[] = "LCASE(img_name) LIKE '%{$m}%'"; $searchpar = '&wpIlMatch=' . urlencode($wpIlMatch); } } $invertSort = false; if ($until = $wgRequest->getVal('until')) { $where[] = 'img_timestamp < ' . $dbr->timestamp($until); } if ($from = $wgRequest->getVal('from')) { $where[] = 'img_timestamp >= ' . $dbr->timestamp($from); $invertSort = true; } $sql = 'SELECT img_size, img_name, img_user, img_user_text,' . "img_description,img_timestamp FROM {$image}"; if ($hidebots) { $sql .= $joinsql; $where[] = 'ug_group IS NULL'; } if (count($where)) { $sql .= ' WHERE ' . $dbr->makeList($where, LIST_AND); } $sql .= ' ORDER BY img_timestamp ' . ($invertSort ? '' : ' DESC'); $sql .= ' LIMIT ' . ($limit + 1); $res = $dbr->query($sql, 'wfSpecialNewImages'); /** * We have to flip things around to get the last N after a certain date */ $images = array(); while ($s = $dbr->fetchObject($res)) { if ($invertSort) { array_unshift($images, $s); } else { array_push($images, $s); } } $dbr->freeResult($res); $gallery = new ImageGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; foreach ($images as $s) { if (++$shownImages > $limit) { # One extra just to test for whether to show a page link; # don't actually show it. break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText($name, NS_IMAGE); $img = Image::newFromTitle($nt); $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); $gallery->add($img, "{$ul}<br />\n<i>" . $wgLang->timeanddate($s->img_timestamp, true) . "</i><br />\n"); $timestamp = wfTimestamp(TS_MW, $s->img_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $bydate = wfMsg('bydate'); $lt = $wgLang->formatNum(min($shownImages, $limit)); if ($shownav) { $text = wfMsgExt('imagelisttext', array('parse'), $lt, $bydate); $wgOut->addHTML($text . "\n"); } $sub = wfMsg('ilsubmit'); $titleObj = Title::makeTitle(NS_SPECIAL, 'Newimages'); $action = $titleObj->escapeLocalURL($hidebots ? '' : 'hidebots=0'); if ($shownav) { $wgOut->addHTML("<form id=\"imagesearch\" method=\"post\" action=\"" . "{$action}\">" . "<input type='text' size='20' name=\"wpIlMatch\" value=\"" . htmlspecialchars($wpIlMatch) . "\" /> " . "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>"); } $here = $wgContLang->specialPage('Newimages'); /** * Paging controls... */ # If we change bot visibility, this needs to be carried along. if (!$hidebots) { $botpar = '&hidebots=0'; } else { $botpar = ''; } $now = wfTimestampNow(); $date = $wgLang->timeanddate($now, true); $dateLink = $sk->makeKnownLinkObj($titleObj, wfMsg('sp-newimages-showfrom', $date), 'from=' . $now . $botpar . $searchpar); $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg('showhidebots', $hidebots ? wfMsg('show') : wfMsg('hide')), 'hidebots=' . ($hidebots ? '0' : '1') . $searchpar); $prevLink = wfMsg('prevn', $wgLang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $prevLink = $sk->makeKnownLinkObj($titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar); } $nextLink = wfMsg('nextn', $wgLang->formatNum($limit)); if ($shownImages > $limit && $lastTimestamp) { $nextLink = $sk->makeKnownLinkObj($titleObj, $nextLink, 'until=' . $lastTimestamp . $botpar . $searchpar); } $prevnext = '<p>' . $botLink . ' ' . wfMsg('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; if ($shownav) { $wgOut->addHTML($prevnext); } if (count($images)) { $wgOut->addHTML($gallery->toHTML()); if ($shownav) { $wgOut->addHTML($prevnext); } } else { $wgOut->addWikiText(wfMsg('noimages')); } }
/** * @file * @ingroup SpecialPage * FIXME: this code is crap, should use Pager and Database::select(). */ function wfSpecialNewimages($par, $specialPage) { global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMiserMode; $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr = wfGetDB(DB_SLAVE); $sk = $wgUser->getSkin(); $shownav = !$specialPage->including(); $hidebots = $wgRequest->getBool('hidebots', 1); $hidebotsql = ''; if ($hidebots) { # Make a list of group names which have the 'bot' flag set. $botconds = array(); foreach (User::getGroupsWithPermission('bot') as $groupname) { $botconds[] = 'ug_group = ' . $dbr->addQuotes($groupname); } # If not bot groups, do not set $hidebotsql if ($botconds) { $isbotmember = $dbr->makeList($botconds, LIST_OR); # This join, in conjunction with WHERE ug_group IS NULL, returns # only those rows from IMAGE where the uploading user is not a mem- # ber of a group which has the 'bot' permission set. $ug = $dbr->tableName('user_groups'); $hidebotsql = " LEFT JOIN {$ug} ON img_user=ug_user AND ({$isbotmember})"; } } $image = $dbr->tableName('image'); $sql = "SELECT img_timestamp from {$image}"; if ($hidebotsql) { $sql .= "{$hidebotsql} WHERE ug_group IS NULL"; } $sql .= ' ORDER BY img_timestamp DESC LIMIT 1'; $res = $dbr->query($sql, __FUNCTION__); $row = $dbr->fetchRow($res); if ($row !== false) { $ts = $row[0]; } else { $ts = false; } $dbr->freeResult($res); $sql = ''; # If we were clever, we'd use this to cache. $latestTimestamp = wfTimestamp(TS_MW, $ts); # Hardcode this for now. $limit = 48; if ($parval = intval($par)) { if ($parval <= $limit && $parval > 0) { $limit = $parval; } } $where = array(); $searchpar = ''; if ($wpIlMatch != '' && !$wgMiserMode) { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->escapeLike(strtolower($nt->getDBkey())); $where[] = "LOWER(img_name) LIKE '%{$m}%'"; $searchpar = '&wpIlMatch=' . urlencode($wpIlMatch); } } $invertSort = false; if ($until = $wgRequest->getVal('until')) { $where[] = "img_timestamp < '" . $dbr->timestamp($until) . "'"; } if ($from = $wgRequest->getVal('from')) { $where[] = "img_timestamp >= '" . $dbr->timestamp($from) . "'"; $invertSort = true; } $sql = 'SELECT img_size, img_name, img_user, img_user_text,' . "img_description,img_timestamp FROM {$image}"; if ($hidebotsql) { $sql .= $hidebotsql; $where[] = 'ug_group IS NULL'; } if (count($where)) { $sql .= ' WHERE ' . $dbr->makeList($where, LIST_AND); } $sql .= ' ORDER BY img_timestamp ' . ($invertSort ? '' : ' DESC'); $sql .= ' LIMIT ' . ($limit + 1); $res = $dbr->query($sql, __FUNCTION__); /** * We have to flip things around to get the last N after a certain date */ $images = array(); while ($s = $dbr->fetchObject($res)) { if ($invertSort) { array_unshift($images, $s); } else { array_push($images, $s); } } $dbr->freeResult($res); $gallery = new ImageGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; foreach ($images as $s) { $shownImages++; if ($shownImages > $limit) { # One extra just to test for whether to show a page link; # don't actually show it. break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText($name, NS_FILE); $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); $gallery->add($nt, "{$ul}<br />\n<i>" . $wgLang->timeanddate($s->img_timestamp, true) . "</i><br />\n"); $timestamp = wfTimestamp(TS_MW, $s->img_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $titleObj = SpecialPage::getTitleFor('Newimages'); $action = $titleObj->getLocalURL($hidebots ? '' : 'hidebots=0'); if ($shownav && !$wgMiserMode) { $wgOut->addHTML(Xml::openElement('form', array('action' => $action, 'method' => 'post', 'id' => 'imagesearch')) . Xml::fieldset(wfMsg('newimages-legend')) . Xml::inputLabel(wfMsg('newimages-label'), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch) . ' ' . Xml::submitButton(wfMsg('ilsubmit'), array('name' => 'wpIlSubmit')) . Xml::closeElement('fieldset') . Xml::closeElement('form')); } $bydate = wfMsg('bydate'); $lt = $wgLang->formatNum(min($shownImages, $limit)); if ($shownav) { $text = wfMsgExt('imagelisttext', array('parse'), $lt, $bydate); $wgOut->addHTML($text . "\n"); } /** * Paging controls... */ # If we change bot visibility, this needs to be carried along. if (!$hidebots) { $botpar = '&hidebots=0'; } else { $botpar = ''; } $now = wfTimestampNow(); $d = $wgLang->date($now, true); $t = $wgLang->time($now, true); $dateLink = $sk->makeKnownLinkObj($titleObj, wfMsgHtml('sp-newimages-showfrom', $d, $t), 'from=' . $now . $botpar . $searchpar); $botLink = $sk->makeKnownLinkObj($titleObj, wfMsgHtml('showhidebots', $hidebots ? wfMsgHtml('show') : wfMsgHtml('hide')), 'hidebots=' . ($hidebots ? '0' : '1') . $searchpar); $opts = array('parsemag', 'escapenoentities'); $prevLink = wfMsgExt('pager-newer-n', $opts, $wgLang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $prevLink = $sk->makeKnownLinkObj($titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar); } $nextLink = wfMsgExt('pager-older-n', $opts, $wgLang->formatNum($limit)); if ($shownImages > $limit && $lastTimestamp) { $nextLink = $sk->makeKnownLinkObj($titleObj, $nextLink, 'until=' . $lastTimestamp . $botpar . $searchpar); } $prevnext = '<p>' . $botLink . ' ' . wfMsgHtml('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; if ($shownav) { $wgOut->addHTML($prevnext); } if (count($images)) { $wgOut->addHTML($gallery->toHTML()); if ($shownav) { $wgOut->addHTML($prevnext); } } else { $wgOut->addWikiMsg('noimages'); } }
function do_people_insert($doInterestLookup = false, $forcePerson = '', $force = false) { global $valid_attributes, $states_ary; $dbr = wfGetDB(DB_SLAVE); include_once 'scrape_and_insert.inc.php'; $mvScrape = new MV_BaseScraper(); //do people query: if ($forcePerson != '') { $res = $dbr->query("SELECT * FROM `metavid`.`people` WHERE `name_clean` LIKE '{$forcePerson}'"); } else { $res = $dbr->query("SELECT * FROM `metavid`.`people`"); } if ($dbr->numRows($res) == 0) { die('could not find people: ' . "\n"); } $person_ary = array(); while ($person = $dbr->fetchObject($res)) { $person_ary[] = $person; } foreach ($person_ary as $person) { $person_title = Title::newFromUrl($person->name_clean); //semantic data via template: $mapk = null; $page_body = '{{Congress Person|' . "\n"; foreach ($valid_attributes as $dbKey => $attr) { list($name, $desc) = $attr; if ($dbKey == 'district') { //special case for district: if ($person->district) { if ($person->district != 0) { $page_body .= "{$name}=" . text_number($person->district) . ' District' . "|\n"; } } } else { if ($dbKey == 'total_received') { if (!$mapk) { print 'no mapkey for total_received' . "\n"; } else { $raw_results = $mvScrape->doRequest('http://www.maplight.org/map/us/legislator/' . $mapk); preg_match('/Contributions\\sReceived\\:\\s\\$([^<]*)/', $raw_results, $matches); if (isset($matches[1])) { $page_body .= "{$name}=\$" . $matches[1] . "|\n"; } } } else { if ($dbKey == 'contribution_date_range') { if (!$mapk) { print 'out of order attr proccess missing mapk' . "\n"; } else { $raw_results = $mvScrape->doRequest('http://www.maplight.org/map/us/legislator/' . $mapk); preg_match('/Showing\\scontributions<\\/dt><dd>([^<]*)</', $raw_results, $matches); if (isset($matches[1])) { $page_body .= "{$name}=" . $matches[1] . "|\n"; } } } else { if ($dbKey == 'maplight_id') { if (!$person->{$dbKey}) { //print 'do_maplight_id'."\n"; //try to grab the maplight id $raw_results = $mvScrape->doRequest('http://maplight.org/map/us/legislator/search/' . $person->last . '+' . $person->first); preg_match_all('/map\\/us\\/legislator\\/([^"]*)">(.*)<\\/a>.*<td>([^<]*)<.*<td>([^<]*)<.*<td>([^<]*)<.*<td>([^<]*)</U', $raw_results, $matches); //do point system for match $point = array(); $title_lookup = array('Rep.' => 'House', 'Sen.' => 'Senate'); if (isset($matches['2'][0])) { foreach ($matches['2'] as $k => $name_html) { if (!isset($point[$k])) { $point[$k] = 0; } list($lname, $fname) = explode(',', trim(strip_tags($name_html))); if (strtolower($person->first) == strtolower($fname)) { $point[$k] += 2; } if (strtolower($person->last) == strtolower($lname)) { $point[$k] += 2; } if ($person->state == $matches['3'][$k]) { $point[$k]++; } if ($person->district == $matches['4'][$k]) { $point[$k]++; } if ($person->party == $matches['5'][$k]) { $point[$k]++; } if (isset($title_lookup[$person->title])) { if ($title_lookup[$person->title] == $matches['6']) { $point[$k]++; } } } $max = 0; $mapk = null; //print_r($point); foreach ($point as $k => $v) { if ($v > $max) { $mapk = $matches[1][$k]; $max = $v; } } } } else { $mapk = $person->{$dbKey}; } $page_body .= "{$name}=" . $mapk . "|\n"; } else { if (trim($person->{$dbKey}) != '') { if ($dbKey == 'state') { $person->state = $states_ary[$person->state]; } $page_body .= "{$name}={$person->{$dbKey}}| \n"; } } } } } } //if we have the maplight key add in all contributions and procces contributers if (!$mapk) { print 'missing mapkey' . "\n"; } else { $raw_results = $mvScrape->doRequest('http://www.maplight.org/map/us/legislator/' . $mapk); preg_match_all('/\\/map\\/us\\/interest\\/([^"]*)">([^<]*)<.*\\$([^\\<]*)</U', $raw_results, $matches); if (isset($matches[1])) { foreach ($matches[1] as $k => $val) { $hr_inx = $k + 1; $page_body .= "Funding Interest {$hr_inx}=" . html_entity_decode($matches[2][$k]) . "|\n"; $page_body .= "Funding Amount {$hr_inx}=\$" . $matches[3][$k] . "|\n"; if ($doInterestLookup) { //make sure the intrest has been proccessed: do_proc_interest($matches[1][$k], html_entity_decode($matches[2][$k])); } //do_proc_interest('G1100','Chambers of commerce'); } } } //add in the full name attribute: $page_body .= "Full Name=" . $person->title . ' ' . $person->first . ' ' . $person->middle . ' ' . $person->last . "| \n"; $page_body .= '}}'; //add in basic info to be overwitten by tranclude (from $full_name = $person->title . ' ' . $person->first . ' ' . $person->middle . ' ' . $person->last; if (trim($full_name) == '') { $full_name = $person->name_clean; } $page_body .= "\n" . 'Person page For <b>' . $full_name . "</b><br />\n"; // "Text Spoken By [[Special:MediaSearch/person/{$person->name_clean}|$full_name]] "; do_update_wiki_page($person_title, $page_body, '', $force); //die('only run on first person'."\n"); } foreach ($person_ary as $person) { //download/upload all the photos: $imgTitle = Title::makeTitle(NS_IMAGE, $person->name_clean . '.jpg'); //if(!$imgTitle->exists()){ global $wgTmpDirectory; $url = 'http://www.opensecrets.org/politicians/img/pix/' . $person->osid . '.jpg'; //print $wgTmpDirectory . "\n"; $local_file = tempnam($wgTmpDirectory, 'WEBUPLOAD'); //copy file: # Check if already there existence $image = wfLocalFile($imgTitle); if ($image->exists()) { echo $imgTitle->getDBkey() . " already in the wiki\n"; continue; } for ($ct = 0; $ct < 10; $ct++) { if (!@copy($url, $local_file)) { print "failed to copy {$url} to local_file (tring again) \n"; } else { print "copy success\n"; $ct = 10; } if ($ct == 9) { print 'complete failure' . "\n"; } } # Stash the file echo "Saving " . $imgTitle->getDBkey() . "..."; $image = wfLocalFile($imgTitle); $archive = $image->publish($local_file); if (WikiError::isError($archive)) { echo "failed.\n"; continue; } echo "importing..."; $comment = 'Image file for [[' . $person->name_clean . ']]'; $license = ''; if ($image->recordUpload($archive, $comment, $license)) { # We're done! echo "done.\n"; } else { echo "failed.\n"; } //} } }