<?php

//
// Populate the hillary_pages table for the Hillary / Stubs feature
//
require_once 'commandLine.inc';
$fp = fopen('/home/reuben/hill_1-2.txt', 'r');
if (!$fp) {
    die("File reading problem!\n");
}
$ids = array();
while (($data = fgetcsv($fp)) !== false) {
    $id = intval($data[0]);
    if ($id) {
        $ids[] = $id;
    }
}
#$db = wfGetDB(DB_MASTER);
#$db->query('DELETE FROM hillary_pages', __FILE__);
#$db->query('DELETE FROM hillary_votes', __FILE__);
#$db->query('DELETE FROM hillary_votes_archive', __FILE__);
$added = Hillary::populatePages($ids);
print "Added {$added} articles to Hillary\n";
 public function execute($par)
 {
     global $wgOut, $wgRequest, $wgUser;
     global $wgCookiePrefix, $wgCookiePath, $wgCookieDomain, $wgCookieSecure;
     // get user ID
     $userid = $wgUser->getID();
     // if user is anon, assign them a cookie and give them
     // a random, negative user ID
     if ($userid <= 0) {
         $cookieName = $wgCookiePrefix . self::COOKIE_NAME;
         $cookieVal = intval(@$_COOKIE[$cookieName]);
         if ($cookieVal <= 0) {
             $newid = mt_rand(1, mt_getrandmax());
             $thirty_days = 90 * 24 * 60 * 60;
             setcookie($cookieName, $newid, time() + $thirty_days, $wgCookiePath, $wgCookieDomain, $wgCookieSecure);
             $userid = -$newid;
         } else {
             $userid = -$cookieVal;
         }
     }
     $action = $wgRequest->getVal('action');
     if ($action) {
         print json_encode(array('error' => 'This tool is not available'));
         exit;
         $pageid = $wgRequest->getInt('pageid');
         if (!$pageid) {
             exit;
         }
         $hillary = new Hillary($userid, $pageid);
         if ($action == 'fetch') {
             $result = $hillary->getPageDetails();
             if ($result) {
                 $result['pageid'] = $pageid;
             } else {
                 $result = array('pageid' => 0);
             }
             // find next article to show
             list($next_id, $next_url) = $hillary->getNextPage();
             $result['next_id'] = $next_id;
             $result['next_url'] = $next_url;
         } elseif ($action == 'vote') {
             $vote = $wgRequest->getInt('vote');
             $voted = $hillary->vote($vote);
             $result['voted'] = intval($voted);
         }
         $wgOut->setArticleBodyOnly(true);
         $json = json_encode($result);
         $wgOut->addHTML($json);
     } else {
         // If user has never voted with this tool before, show them
         // a splash page
         $hillary = new Hillary($userid);
         $votes = $hillary->getUserVotes();
         list($next_id, $next_url) = $hillary->getNextPage();
         $utmParamsStr = '';
         if (is_array($_GET)) {
             $utmParams = array();
             foreach ($_GET as $param => $val) {
                 if (preg_match('@^utm@', $param)) {
                     $utmParams[] = $param . '=' . $val;
                 }
             }
             if ($utmParams) {
                 $utmParamsStr = '?' . join('&', $utmParams);
             }
         }
         $toolURL = MobileWikihow::getMobileSite() . '/' . $next_url . $utmParamsStr . '#review';
         if (!$votes) {
             $wgOut->setArticleBodyOnly(true);
             $html = $hillary->getSplashPage($toolURL);
             $html = 'This tool is currently unavailable';
             $wgOut->addHTML($html);
         } else {
             $wgOut->redirect($toolURL);
         }
     }
 }
    ?>
			</div>
			<a href="<?php 
    echo $loginlink;
    ?>
" id="header_login"><?php 
    echo $logintext;
    ?>
</a>
		</div>

		<?php 
    if (class_exists('Hillary')) {
        ?>
			<?php 
        echo Hillary::getContainer();
        ?>
		<?php 
    }
    ?>

		<div class="search_static"></div>
	<?php 
}
?>

	<?php 
// Firefox? NO SEARCH FOR YOU!
?>
	<script type="text/javascript">
		var ua = navigator.userAgent;