public function execute() { global $wgUser, $wgTitle, $wgArticle; $userName = $this->getOption('u', 'Maintenance script'); $reason = $this->getOption('r', ''); $protection = "sysop"; if ($this->hasOption('semiprotect')) { $protection = "autoconfirmed"; } elseif ($this->hasOption('unprotect')) { $protection = ""; } $wgUser = User::newFromName($userName); $restrictions = array('edit' => $protection, 'move' => $protection); $wgTitle = Title::newFromText($this->getArg()); if (!$wgTitle) { $this->error("Invalid title", true); } $wgArticle = new Article($wgTitle); # un/protect the article $this->output("Updating protection status... "); $success = $wgArticle->updateRestrictions($restrictions, $reason); if ($success) { $this->output("done\n"); } else { $this->output("failed\n"); } }
public static function toggle($pagename) { global $wgUser; $title = Title::newFromDBkey($pagename); if (!$title) { return self::returnMsg(self::TITLE_INVALID, $protectState); } $aid = $title->getArticleID(); // title must exist! if ($aid == 0) { return self::returnMsg(self::TITLE_INVALID, $protectState); } // user must have the required clearance if (!$wgUser->isAllowed('protect')) { return self::returnMsg(self::USER_INSUFFICIENT_RIGHT, $protectState); } $protectState = $title->isProtected('edit'); // format the restriction // whilst inverting the state... $group = $protectState ? '' : 'sysop'; $restriction = array('edit' => $group); // update! $article = new Article($title); $code = $article->updateRestrictions($restriction); $msg = $code ? self::SUCCESS : self::FAILURE; // update protection status $protectState = $code ? !$protectState : $protectState; return self::returnMsg($msg, $protectState); }
public function execute() { global $wgUser, $wgRestrictionTypes, $wgRestrictionLevels; $params = $this->extractRequestParams(); $titleObj = NULL; if (!isset($params['title'])) { $this->dieUsageMsg(array('missingparam', 'title')); } if (!isset($params['token'])) { $this->dieUsageMsg(array('missingparam', 'token')); } if (empty($params['protections'])) { $this->dieUsageMsg(array('missingparam', 'protections')); } if (!$wgUser->matchEditToken($params['token'])) { $this->dieUsageMsg(array('sessionfailure')); } $titleObj = Title::newFromText($params['title']); if (!$titleObj) { $this->dieUsageMsg(array('invalidtitle', $params['title'])); } $errors = $titleObj->getUserPermissionsErrors('protect', $wgUser); if ($errors) { // We don't care about multiple errors, just report one of them $this->dieUsageMsg(reset($errors)); } $expiry = (array) $params['expiry']; if (count($expiry) != count($params['protections'])) { if (count($expiry) == 1) { $expiry = array_fill(0, count($params['protections']), $expiry[0]); } else { $this->dieUsageMsg(array('toofewexpiries', count($expiry), count($params['protections']))); } } $protections = array(); $expiryarray = array(); $resultProtections = array(); foreach ($params['protections'] as $i => $prot) { $p = explode('=', $prot); $protections[$p[0]] = $p[1] == 'all' ? '' : $p[1]; if ($titleObj->exists() && $p[0] == 'create') { $this->dieUsageMsg(array('create-titleexists')); } if (!$titleObj->exists() && $p[0] != 'create') { $this->dieUsageMsg(array('missingtitles-createonly')); } if (!in_array($p[0], $wgRestrictionTypes) && $p[0] != 'create') { $this->dieUsageMsg(array('protect-invalidaction', $p[0])); } if (!in_array($p[1], $wgRestrictionLevels) && $p[1] != 'all') { $this->dieUsageMsg(array('protect-invalidlevel', $p[1])); } if (in_array($expiry[$i], array('infinite', 'indefinite', 'never'))) { $expiryarray[$p[0]] = Block::infinity(); } else { $exp = strtotime($expiry[$i]); if ($exp < 0 || $exp == false) { $this->dieUsageMsg(array('invalidexpiry', $expiry[$i])); } $exp = wfTimestamp(TS_MW, $exp); if ($exp < wfTimestampNow()) { $this->dieUsageMsg(array('pastexpiry', $expiry[$i])); } $expiryarray[$p[0]] = $exp; } $resultProtections[] = array($p[0] => $protections[$p[0]], 'expiry' => $expiryarray[$p[0]] == Block::infinity() ? 'infinite' : wfTimestamp(TS_ISO_8601, $expiryarray[$p[0]])); } $cascade = $params['cascade']; $articleObj = new Article($titleObj); if ($params['watch']) { $articleObj->doWatch(); } if ($titleObj->exists()) { $ok = $articleObj->updateRestrictions($protections, $params['reason'], $cascade, $expiryarray); } else { $ok = $titleObj->updateTitleProtection($protections['create'], $params['reason'], $expiryarray['create']); } if (!$ok) { // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime? // Just throw an unknown error in this case, as it's very likely to be a race condition $this->dieUsageMsg(array()); } $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason']); if ($cascade) { $res['cascade'] = ''; } $res['protections'] = $resultProtections; $this->getResult()->setIndexedTagName($res['protections'], 'protection'); $this->getResult()->addValue(null, $this->getModuleName(), $res); }
function execute($par) { global $wgOut, $wgUser, $wgRequest; global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview; if ($wgUser->isBlocked()) { $wgOut->blockedPage(); return; } if ($wgUser->getID() == 0) { $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext'); return; } if (!in_array('staff', $wgUser->getGroups())) { $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext'); return; } $this->errorFile = ""; $this->errorTitle = ""; if ($wgRequest->getVal('delete')) { $wgOut->setArticleBodyOnly(true); $hpid = str_replace('delete_', '', $wgRequest->getVal('delete')); $html = self::deleteHPImage($hpid); $wgOut->addHTML($html); return; } $this->postSuccessful = true; if ($wgRequest->wasPosted()) { if ($wgRequest->getVal("updateActive")) { $dbw = wfGetDB(DB_MASTER); //first clear them all $dbw->update(WikihowHomepageAdmin::HP_TABLE, array('hp_active' => 0, 'hp_order' => 0), '*', __METHOD__); $images = $wgRequest->getArray("hp_images"); $count = 1; foreach ($images as $image) { if (!$image) { continue; } $dbw->update(WikihowHomepageAdmin::HP_TABLE, array('hp_active' => 1, 'hp_order' => $count), array('hp_id' => $image)); $count++; } } else { $title = WikiPhoto::getArticleTitleNoCheck($wgRequest->getVal('articleName')); if (!$title->exists()) { $this->postSuccessful = false; $this->errorTitle = "* That article does not exist."; } if ($this->postSuccessful) { //keep going $imageTitle = Title::newFromText($wgRequest->getVal('wpDestFile'), NS_IMAGE); $file = new LocalFile($imageTitle, RepoGroup::singleton()->getLocalRepo()); $file->upload($wgRequest->getFileTempName('wpUploadFile'), '', ''); $filesize = $file->getSize(); if ($filesize > 0) { $dbw = wfGetDB(DB_MASTER); $dbw->insert(WikihowHomepageAdmin::HP_TABLE, array('hp_page' => $title->getArticleID(), 'hp_image' => $imageTitle->getArticleID())); $article = new Article($imageTitle); $limit = array(); $limit['move'] = "sysop"; $limit['edit'] = "sysop"; $protectResult = $article->updateRestrictions($limit, "Used on homepage"); } else { $this->postSuccessful = false; $this->errorFile = "* We encountered an error uploading that file."; } } } } $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview; $adc = wfBoolToStr($useAjaxDestCheck); $alp = wfBoolToStr($useAjaxLicensePreview); $wgOut->setPageTitle('WikiHow Homepage Admin'); $wgOut->addScript("<script type=\"text/javascript\">\nwgAjaxUploadDestCheck = {$adc};\nwgAjaxLicensePreview = {$alp};\n</script>"); $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('jquery-ui-1.8.custom.min.js'), 'extensions/wikihow/common/ui/js', false)); $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('wikihowhomepageadmin.js'), 'extensions/wikihow/homepage', false)); $wgOut->addScript(HtmlSnips::makeUrlTags('css', array('wikihowhomepageadmin.css'), 'extensions/wikihow/homepage', false)); $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('upload.js'), 'skins/common', false)); $this->displayHomepageData(); $this->displayForm(); }
public function execute() { global $wgUser; $this->getMain()->requestWriteMode(); $params = $this->extractRequestParams(); $titleObj = NULL; if (!isset($params['title'])) { $this->dieUsageMsg(array('missingparam', 'title')); } if (!isset($params['token'])) { $this->dieUsageMsg(array('missingparam', 'token')); } if (!isset($params['protections']) || empty($params['protections'])) { $this->dieUsageMsg(array('missingparam', 'protections')); } if (!$wgUser->matchEditToken($params['token'])) { $this->dieUsageMsg(array('sessionfailure')); } $titleObj = Title::newFromText($params['title']); if (!$titleObj) { $this->dieUsageMsg(array('invalidtitle', $params['title'])); } $errors = $titleObj->getUserPermissionsErrors('protect', $wgUser); if (!empty($errors)) { // We don't care about multiple errors, just report one of them $this->dieUsageMsg(current($errors)); } if (in_array($params['expiry'], array('infinite', 'indefinite', 'never'))) { $expiry = Block::infinity(); } else { $expiry = strtotime($params['expiry']); if ($expiry < 0 || $expiry == false) { $this->dieUsageMsg(array('invalidexpiry')); } $expiry = wfTimestamp(TS_MW, $expiry); if ($expiry < wfTimestampNow()) { $this->dieUsageMsg(array('pastexpiry')); } } $protections = array(); foreach ($params['protections'] as $prot) { $p = explode('=', $prot); $protections[$p[0]] = $p[1] == 'all' ? '' : $p[1]; if ($titleObj->exists() && $p[0] == 'create') { $this->dieUsageMsg(array('create-titleexists')); } if (!$titleObj->exists() && $p[0] != 'create') { $this->dieUsageMsg(array('missingtitles-createonly')); } } $dbw = wfGetDb(DB_MASTER); $dbw->begin(); if ($titleObj->exists()) { $articleObj = new Article($titleObj); $ok = $articleObj->updateRestrictions($protections, $params['reason'], $params['cascade'], $expiry); } else { $ok = $titleObj->updateTitleProtection($protections['create'], $params['reason'], $expiry); } if (!$ok) { // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime? // Just throw an unknown error in this case, as it's very likely to be a race condition $this->dieUsageMsg(array()); } $dbw->commit(); $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason']); if ($expiry == Block::infinity()) { $res['expiry'] = 'infinity'; } else { $res['expiry'] = wfTimestamp(TS_ISO_8601, $expiry); } if ($params['cascade']) { $res['cascade'] = ''; } $res['protections'] = $protections; $this->getResult()->addValue(null, $this->getModuleName(), $res); }
} if (empty($wgWikiaKeyPages)) { $wgWikiaKeyPages = array('Image:Wiki.png', 'Image:Favicon.ico'); } #--- define restriction level and duration $restrictions['edit'] = 'sysop'; $restrictions['move'] = 'sysop'; $titleRestrictions = 'sysop'; $expiry = Block::infinity(); #--- define reason msg and fetch it $wgMessageCache->addMessages(array('createwiki-protect-reason' => 'Part of the official interface')); $reason = wfMsgForContent('createwiki-protect-reason'); $wgUser->addGroup('staff'); $wgUser->addGroup('bot'); foreach ($wgWikiaKeyPages as $pageName) { $title = Title::newFromText($pageName); $article = new Article($title); if ($article->exists()) { $ok = $article->updateRestrictions($restrictions, $reason, 0, $expiry); } else { $ok = $title->updateTitleProtection($titleRestrictions, $reason, $expiry); } if ($ok) { print "Protected key page: {$pageName}\n"; } else { print "Failed while trying to protect {$pageName}\n"; } } $wgUser->removeGroup('staff'); $wgUser->removeGroup('bot'); print "Done protecting pages.\n";
/** * protect key pages * * @author Lucas 'TOR' Garczewski <*****@*****.**> */ private function protectKeyPages() { global $wgUser, $wgWikiaKeyPages; $saveUser = $wgUser; $wgUser = \User::newFromName(self::WIKIA_USER); if (empty($wgWikiaKeyPages)) { $wgWikiaKeyPages = array('File:Wiki.png', 'File:Favicon.ico'); } /** * define restriction level and duration */ $restrictions["edit"] = 'sysop'; $restrictions["move"] = 'sysop'; $restrictions["create"] = 'sysop'; $titleRestrictions = 'sysop'; $expiry_string = \Block::infinity(); $expiry_array = array('edit' => $expiry_string, 'move' => $expiry_string); /** * define reason msg and fetch it */ $reason = wfMsgForContent('autocreatewiki-protect-reason'); foreach ($wgWikiaKeyPages as $pageName) { $title = \Title::newFromText($pageName); $article = new \Article($title); if ($article->exists()) { $cascade = 0; $ok = $article->updateRestrictions($restrictions, $reason, $cascade, $expiry_array); } else { $wikiPage = \WikiPage::factory($title); $ignored_reference = false; // doing this because MW1.19 doUpdateRestrictions() is weird, and has this passed by reference $status = $wikiPage->doUpdateRestrictions(array('create' => $titleRestrictions), array('create' => $expiry_string), $ignored_reference, $reason, $wgUser); $ok = $status->isOK(); } if ($ok) { $this->info('Protected key page', ['page_name' => $pageName]); } else { $this->warning('failed to protect key page', ['page_name' => $pageName]); } } $wgUser = $saveUser; }
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); }
${$svar}++; if (isset($options['dry'])) { echo "done.\n"; } else { if ($image->recordUpload($archive->value, $commentText, $license)) { # We're done! echo "done.\n"; if ($doProtect) { # Protect the file $article = new Article($title); echo "\nWaiting for slaves...\n"; // Wait for slaves. sleep(2.0); wfWaitForSlaves(1.0); echo "\nSetting image restrictions ... "; if ($article->updateRestrictions($restrictions)) { echo "done.\n"; } else { echo "failed.\n"; } } } else { echo "failed.\n"; } } } # Print out some statistics echo "\n"; foreach (array('count' => 'Found', 'added' => 'Added', 'skipped' => 'Skipped', 'overwritten' => 'Overwritten') as $var => $desc) { if (${$var} > 0) { echo "{$desc}: {${$var}}\n";
/** * protect key pages * * @author Lucas 'TOR' Garczewski <*****@*****.**> */ private function protectKeyPages() { global $wgUser, $wgWikiaKeyPages; $wgUser = User::newFromName("CreateWiki script"); if ($wgUser->isAnon()) { $wgUser->addToDatabase(); } if (empty($wgWikiaKeyPages)) { $wgWikiaKeyPages = array('File:Wiki.png', 'File:Favicon.ico'); } /** * define restriction level and duration */ $restrictions["edit"] = 'sysop'; $restrictions["move"] = 'sysop'; $restrictions["create"] = 'sysop'; $titleRestrictions = 'sysop'; $expiry_string = Block::infinity(); $expiry_array = array('edit' => $expiry_string, 'move' => $expiry_string); /** * define reason msg and fetch it */ $reason = wfMsgForContent('autocreatewiki-protect-reason'); $wgUser->addGroup('staff'); foreach ($wgWikiaKeyPages as $pageName) { $title = Title::newFromText($pageName); $article = new Article($title); if ($article->exists()) { $cascade = 0; $ok = $article->updateRestrictions($restrictions, $reason, $cascade, $expiry_array); } else { $wikiPage = WikiPage::factory($title); $ignored_reference = false; // doing this because MW1.19 doUpdateRestrictions() is weird, and has this passed by reference $status = $wikiPage->doUpdateRestrictions(array('create' => $titleRestrictions), array('create' => $expiry_string), $ignored_reference, $reason, $wgUser); $ok = $status->isOK(); } if ($ok) { Wikia::log(__METHOD__, "ok", "Protected key page: {$pageName}"); } else { Wikia::log(__METHOD__, "err", "Failed while trying to protect {$pageName}"); } } $wgUser->removeGroup("staff"); }
function doScrapeInsert() { foreach ($this->streams as &$stream) { if (!isset($stream->date_start_time)) { $stream->date_start_time = 0; } if ($stream->date_start_time == 0) { print 'error stream ' . $stream->name . ' missing time info' . "\n"; continue; } $hors = strpos($stream->name, 'house') !== false ? 'h' : 's'; $date_req = date('Y-m-d', $stream->date_start_time); if (strpos($stream->name, date('m-d-y', $stream->date_start_time)) === false) { $dTitle = Title::newFromText('Archive:Stream_DateMissMatch'); append_to_wiki_page($dTitle, 'DateMissMatch:[[Stream:' . $stream->stream_name . ']]:' . date('m-d-y', $stream->date_start_time) . "\n"); // use date from stream name: // house_da_01-01-07_ preg_match('/[0-9]+\\-[0-9]+\\-[0-9][0-9]/U', $stream->name, $matches); if (isset($matches[0])) { list($month, $day, $year) = explode('-', $matches[0]); $date_req = '20' . $year . '-' . $month . '-' . $day; } else { die('could not find date in stream name'); } } $cspan_url = $this->base_url . $this->base_query . '&date=' . $date_req . '&hors=' . $hors; echo $cspan_url . "\n"; $rawpage = $this->doRequest($cspan_url); // get the title and href if present: $patern = '/overlib\\(\'(.*)\\((Length: ([^\\)]*)).*CAPTION,\'<font size=2>(.*)<((.*href="([^"]*))|.*)>/'; preg_match_all($patern, $rawpage, $matches); $cspan_person_ary = array(); // format matches: foreach ($matches[0] as $k => $v) { $href = ''; $href_match = array(); preg_match('/href="(.*)"/', $matches[5][$k], $href_match); if (count($href_match) != 0) { $href = $href_match[1]; } $porg = str_replace('<br />', ' ', $matches[4][$k]); $porg = preg_replace('/[D|R|I]+\\-\\[.*\\]/', '', $porg); $pparts = explode(',', $porg); if (isset($pparts[1]) && isset($pparts[0])) { $pname = trim($pparts[1]) . '_' . trim($pparts[0]); if (mv_is_valid_person($pname)) { $cspan_person_ary[] = array('start_time' => strip_tags($matches[1][$k]), 'length' => $matches[3][$k], 'person_title' => str_replace('<br />', ' ', $matches[4][$k]), 'Spoken_by' => $pname, 'href' => $href); } } } // group people in page matches // $g_cspan_matches=array(); // $prev_person=null; // foreach($person_time_ary as $ptag){ // $g_cspan_matches[strtolower($ptag['Spoken_by'])][]=$ptag; // } // retrive db rows to find match: $dbr = wfGetDB(DB_SLAVE); // $mvd_res = MV_Index::getMVDInRange($stream->id, null, null, $mvd_type='ht_en',false,$smw_properties=array('Spoken_by'), ''); /*while ($row = $dbr->fetchObject($mvd_res)) { $db_person_ary=$g_row_matches=array(); //group peole in db matches: $cur_person = ''; $curKey=0; while ($row = $dbr->fetchObject($mvd_res)) { if(!isset($row->Spoken_by))continue; if($cur_person!=$row->Spoken_by){ $g_row_matches[]=get_object_vars($row); $curKey=count($g_row_matches)-1; $cur_person=$row->Spoken_by; }else{ $g_row_matches[$curKey]['end_wiki_title']=$row->wiki_title; $g_row_matches[$curKey]['end_time']+=($row->end_time-$row->start_time); } //print_r($g_row_matches); //if($curKey>2){ // die; //} } */ // get people from metavid table (and conform to mvd_res) $sql = 'SELECT (`people_time`.`time`-`streams`.`adj_start_time`) as `time`, `person_lookup`.`name_clean` as `Spoken_by`, `person_lookup`.`first` as `first`, `person_lookup`.`last` as `last` FROM `metavid`.`people_attr_stream_time` as `people_time` RIGHT JOIN `metavid`.`streams` as `streams` ON `streams`.`id`=`people_time`.`stream_fk` LEFT JOIN `metavid`.`people` as `person_lookup` ON `person_lookup`.`id` = `people_time`.`people_fk` WHERE `streams`.`name`=\'' . $stream->name . '\' ORDER BY `people_time`.`time` '; $people_res = $dbr->query($sql); $cur_person = ''; $curKey = 0; while ($row = $dbr->fetchObject($people_res)) { if (!isset($row->Spoken_by)) { continue; } $cur_row_person = $row->first . '_' . $row->last; if ($cur_person != $cur_row_person) { $db_person_ary[] = get_object_vars($row); $curKey = count($db_person_ary) - 1; $db_person_ary[$curKey]['Spoken_by'] = $row->first . '_' . $row->last; $db_person_ary[$curKey]['start_time'] = $row->time; // not on screen a long time if only one hit: $db_person_ary[$curKey]['end_time'] = $row->time + 10; $cur_person = $cur_row_person; } else { // update the end time: $db_person_ary[$curKey]['end_time'] = $row->time; } } // list on screen times for everyone: foreach ($db_person_ary as $row) { print $row['Spoken_by'] . ' on screen for ' . ($row['end_time'] - $row['start_time']) . "\n"; // $db_person_ary[]=$row; } // print_r($db_person_ary); // die; // count($cspan_person_ary) $cur_db_inx = 0; $cur_person = null; $fistValid = true; for ($i = 0; $i < count($cspan_person_ary); $i++) { // print "looking at: ". $cspan_person_ary[$i]['Spoken_by'] . "\n"; print "\tCSPAN: " . $cspan_person_ary[$i]['Spoken_by'] . ' on screen for ' . $cspan_person_ary[$i]['length'] . ' or:' . npt2seconds($cspan_person_ary[$i]['length']) . "\n"; // set up cur, the next and prev pointers: $cur_person = $cspan_person_ary[$i]['Spoken_by']; // make sure next is not the same as current: // note: we don't group above since the same person can give two subsequent different speeches $next_person = $cur_person; $k_person_inx = 1; $person_insert_set = array(); while ($next_person == $cur_person) { if (isset($cspan_person_ary[$i + $k_person_inx])) { $potential_next_person = mv_is_valid_person($cspan_person_ary[$i + $k_person_inx]['Spoken_by']) ? $cspan_person_ary[$i + $k_person_inx]['Spoken_by'] : null; if ($potential_next_person == null && $k_person_inx == 1) { $next_person = null; break; } elseif ($potential_next_person != null) { $next_person = $potential_next_person; } $k_person_inx++; } else { $next_person = null; } } // should be no need to make sure prev is not the same as current (as we do greedy look ahead below) // $prev_person = $cur_person; // $k=1; // while($prev_person==$cur_person){ if (isset($cspan_person_ary[$i - 1])) { $prev_person = mv_is_valid_person($cspan_person_ary[$i - 1]['Spoken_by']) ? $cspan_person_ary[$i - 1]['Spoken_by'] : null; } else { $prev_person = null; } // } if (mv_is_valid_person($cspan_person_ary[$i]['Spoken_by'])) { // print "\tis valid person looking for db sync\n"; // print "\t prev: $prev_person cur: $cur_person next: $next_person\n"; if ($prev_person == null && $next_person == null) { print "error both prev and next are null skiping person\n"; continue; } // check how long they where on screen (also check subquent) $cspan_on_screen_time = npt2seconds($cspan_person_ary[$i]['length']); // print "NOW STARTING AT: $cur_db_inx of " . count($db_person_ary) . "\n"; for ($j = $cur_db_inx; $j < count($db_person_ary); $j++) { // print "searchig db on: " . $db_person_ary[$j]['Spoken_by'] . "!=" . $cspan_person_ary[$i]['Spoken_by'] . " \n"; $prevMatch = $curMatch = $nextMatch = false; if ($cur_db_inx == 0 || $prev_person == null) { // no need to check prev in db_inx $prevMatch = true; // print "(no back check)"; } else { if ($db_person_ary[$j - 1]['Spoken_by'] == $prev_person) { // print "found prev match: $prev_person\n;"; $prevMatch = true; } } if (isset($db_person_ary[$j])) { if (isset($cspan_person_ary[$i])) { if ($db_person_ary[$j]['Spoken_by'] == $cspan_person_ary[$i]['Spoken_by']) { // print "found cur match:". $cspan_person_ary[$i]['Spoken_by']."\n"; $curMatch = true; } } } if ($next_person == null) { // no need to check next in db_inx $nextMatch = true; // print "(no next check)"; } else { if (isset($db_person_ary[$j + 1])) { if ($db_person_ary[$j + 1]['Spoken_by'] == $next_person) { // print "found next match:".$next_person."\n"; $nextMatch = true; } } } // if we have a match set do insert proc: if ($prevMatch && $curMatch && $nextMatch) { // print "FOUND Match on $j\n"; // print "\t prev: $prev_person cur: $cur_person next: $next_person\n"; $cur_db_inx = $j; // add all additional info we can from c-span: // also push forward for all of current (we should always hit the first series of the same person first ) $k = 0; // build insert set: $cur_start_time = $db_person_ary[$j]['start_time']; while ($cur_person == $cspan_person_ary[$i + $k]['Spoken_by']) { // use the last cspan_person for start case $cspan_person_ary[$i + $k]['wiki_start_time'] = $cur_start_time; if (npt2seconds($cspan_person_ary[$i + $k]['length']) > $db_person_ary[$j]['end_time'] - $cur_start_time) { $cspan_person_ary[$i + $k]['wiki_end_time'] = $db_person_ary[$j]['end_time']; // already used up our db_person_ary continue: print "a cspan insert sync " . ' ' . $cspan_person_ary[$i + $k]['wiki_start_time'] . " to " . $cspan_person_ary[$i + $k]['wiki_end_time'] . " of " . $db_person_ary[$j]['end_time'] . " for: " . $cspan_person_ary[$i]['Spoken_by'] . "\n"; break; } else { $cspan_person_ary[$i + $k]['wiki_end_time'] = $cur_start_time + npt2seconds($cspan_person_ary[$i + $k]['length']); // print "add " . npt2seconds($cspan_person_ary[$i+$k]['length']) . "\n"; $cur_start_time += npt2seconds($cspan_person_ary[$i + $k]['length']); } print "p cspan insert sync " . ' ' . $cspan_person_ary[$i + $k]['wiki_start_time'] . " to " . $cspan_person_ary[$i + $k]['wiki_end_time'] . " of " . $db_person_ary[$j]['end_time'] . " for: " . $cspan_person_ary[$i]['Spoken_by'] . "\n"; // print_r($db_person_ary[$j]); // print_r($cspan_person_ary[$i+$k]); $k++; if (!isset($cspan_person_ary[$i + $k])) { break; } } $k--; // extend the last property if within 100 seconds if (abs($cspan_person_ary[$i + $k]['wiki_end_time'] - $db_person_ary[$j]['end_time']) < 100) { $cspan_person_ary[$i + $k]['wiki_end_time'] = $db_person_ary[$j]['end_time']; print "updated cspan insert for: " . $cspan_person_ary[$i]['Spoken_by'] . ' ' . $cspan_person_ary[$i + $k]['wiki_start_time'] . " to " . $cspan_person_ary[$i + $k]['wiki_end_time'] . " of " . $db_person_ary[$j]['end_time'] . "\n"; } $k++; // /die; // move the index to the current: $i = $i + $k; continue; } } } else { // print $cspan_person_ary[$i]['Spoken_by'] . " is not valid person\n"; } } print "Get Additonal C-SPAN Data For \"synced\" Data:\n"; foreach ($cspan_person_ary as $pData) { if (isset($pData['wiki_start_time'])) { // init: $bill_categories = array(); $annotate_body = ''; $body = ''; $bill_key = null; $rawpage = $this->doRequest($this->base_url . $pData['href']); // $rawpage = $this->doRequest('http://www.c-spanarchives.org/congress/?q=node/77531&id=8330447'); preg_match('/<\\/td><th><center>([^<]*)<\\/center><\\/th><td>/U', $rawpage, $title_matches); preg_match('/<table width="400">\\n<tr><td>\\n(.*)<\\/tr><\\/td>/', $rawpage, $page_matches); if (isset($title_matches[1]) && isset($page_matches[1])) { $title = trim($title_matches[1]); $body = $page_matches[1]; // print_r($page_matches); } else { print "error can't find title or body\n"; print "skip..."; continue; } // do debate tag search: preg_match('/<td colspan="2">Debate:\\s*<[^>]*>([^<]*)/U', $rawpage, $debate_matches); if (isset($debate_matches[1])) { $bill_key = trim($debate_matches[1]); print "found debate: tag " . $bill_key . "\n"; // build gov-track-congress-session friendly debate url: if ($this->get_and_process_billid($bill_key, $stream->date_start_time) != null) { $bill_categories[$bill_key] = $bill_key; } } // title fix hack for C-span error motion to procceed // @@todo add in the rest of the motions: if (strpos($title, 'MOTION TO PROCEED') !== false) { $title = str_replace('MOTION TO PROCEED', '', $title); // $annotate_body.="[[Bill Motion:=MOTION TO PROCEED]]\n"; } // fix title case $title = ucwords(strtolower($title)); // don't Cap a Few of the Words: ' $title = str_replace(array(' And', ' Or', ' Of', ' A'), array(' and', ' or', ' of', ' a'), $title); // replace '' with `` $body = str_replace('\'\'', '``', $body); // replace bill names with [[Catgory:: bill name #]] // $bill_pattern = '/(H\.R\.\s[0-9]+)/'; $bill_pattern = '/'; $bill_pattern_ary = array(); $or = ''; foreach ($this->bill_types as $cspanT => $govtrakT) { $cspanT = str_replace('RES', '[\\s]?RES', $cspanT); // sometimes spaces before res in text $cspanT = str_replace('CON', '[\\s]?CON', $cspanT); // sometimes spaces before res in text // replace . with \.[\s]? $bill_pattern .= $or . '(' . str_replace('.', '\\.[\\s]?', $cspanT) . '\\s?[0-9]+)'; $bill_pattern_ary[] = '(' . str_replace('.', '\\.[\\s]?', $cspanT) . '\\s?[0-9]+)'; $or = '|'; } $bill_pattern .= '/i'; // case insensative // $body='bla bla H.R. 3453 test S. 3494 some more text'; // print "pattern:".$bill_pattern . "\n"; preg_match_all($bill_pattern, $body, $bill_matches); // print_r($bill_matches); // die; if (isset($bill_matches[1])) { foreach ($bill_matches as $k => $bill_type_ary) { if ($k != 0) { if (isset($bill_type_ary[0])) { $bill_name = $bill_type_ary[0]; } elseif (isset($bill_type_ary[1])) { $bill_name = $bill_type_ary[1]; } else { continue; } // if the first letter is lower case not likely a bill if (trim($bill_name) == '') { continue; } if (islower(substr($bill_name, 0, 1))) { continue; } // conform white space and case: $bill_name = str_replace(array('S. ', 'Con. ', 'Res. '), array('S.', 'CON.', 'RES. '), $bill_name); // make sure its not a false possitave and load bill data from govTrack: if ($this->get_and_process_billid($bill_name, $stream->date_start_time)) { $bill_categories[$bill_name] = $bill_name; } } } } // add speech by attribute to annotation body: $annotate_body .= 'Speech By: [[Speech by:=' . str_replace('_', ' ', $pData['Spoken_by']) . ']] '; // add speech by attribute to body as well? $body .= "\n\n" . 'Speech By: [[Speech by:=' . str_replace('_', ' ', $pData['Spoken_by']) . ']] '; // add any mentions of bills with linkback to full bill title: $body = preg_replace_callback($bill_pattern_ary, array('self', 'bill_pattern_cp'), $body); // source the doument: $body .= "\n\n" . 'Source: [[Data Source Name:=C-SPAN Congressional Chronicle]] [[Data Source URL:=' . $this->base_url . $pData['href'] . ']]'; $body .= "\n"; // add the title to the top of the page: $body = "==={$title}===\n" . $body; $cspan_title_str = $this->get_aligned_time_title($pData, 'Thomas_en', $stream); if (!$cspan_title_str) { $cspan_title_str = 'Thomas_en:' . $stream->name . '/' . seconds2npt($pData['wiki_start_time']) . '/' . seconds2npt($pData['wiki_end_time']); } $cspanTitle = Title::makeTitle(MV_NS_MVD, ucfirst($cspan_title_str)); // print "do edit ".$cspanTitle->getText()."\n"; do_update_wiki_page($cspanTitle, $body); // protect editing of the offical record (but allow moving for sync) $cspanTitle->loadRestrictions(); global $wgRestrictionTypes; foreach ($wgRestrictionTypes as $action) { // Fixme: this form currently requires individual selections, // but the db allows multiples separated by commas. $mRestrictions[$action] = implode('', $cspanTitle->getRestrictions($action)); } $article = new Article($cspanTitle); $mRestrictions['edit']['sysop'] = true; $expiry = Block::infinity(); $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $ok = $article->updateRestrictions($mRestrictions, wfMsg('mv_source_material'), false, $expiry); if ($ok) { print "updated permisions for " . $cspanTitle->getText() . "\n"; $dbw->commit(); } else { print "failed to update restrictions :(\n"; } // process each bill to the annotation body; $bcat = ''; $bill_lead_in = "\n\nBill "; // print_r($bill_categories); foreach ($bill_categories as $bill) { if (trim($bill) != '') { // use short title for category and long title for semantic link... (highly arbitrary) $annotate_body .= $bill_lead_in . '[[Bill:=' . $this->cur_bill_short_title . ']] '; $bill_lead_in = ' , '; $annotate_body .= "[[Category:{$bill}]] "; } } if (trim($title) != '') { $annotate_body .= "[[Category:{$title}]]\n"; } // see if we can align with an existing speech page: $anno_title_str = $this->get_aligned_time_title($pData, 'Anno_en', $stream); if (!$anno_title_str) { $anno_title_str = 'Anno_en:' . $stream->name . '/' . seconds2npt($pData['wiki_start_time']) . '/' . seconds2npt($pData['wiki_end_time']); } $annoTitle = Title::makeTitle(MV_NS_MVD, ucfirst($anno_title_str)); do_update_wiki_page($annoTitle, $annotate_body); // [Page: S14580] replaced with: [[Category:BillName]] // would be good to link into the official record for "pages" // [[Speech by:=name]] // [[category:=title]] // for documentation: // semantic qualities would be Aruging For:billX or Arguging Agaist billY // these pages are non-editable // maybe put the category info into annotations layer? (since it applies to both?) // do new page mvd:or_ } } // $inx_cspan_person_ary = array_keys($g_row_matches); // $inx_row_person_ary = array_keys($g_person_time_ary); // for($i=0;$i<5;$i++){ // } // find match person1->person2 // average switch time to get offset of stream // use offset to insert all $person_time_array data } }