function hash() { return wikihash($this->_prefs); }
function main() { if (!USE_DB_SESSION) { validateSessionPath(); } global $request; if (DEBUG & _DEBUG_APD and extension_loaded("apd")) { apd_set_session_trace(9); } // Postpone warnings global $ErrorManager; if (defined('E_STRICT')) { // and (E_ALL & E_STRICT)) // strict php5? $ErrorManager->setPostponedErrorMask(E_NOTICE | E_USER_NOTICE | E_USER_WARNING | E_WARNING | E_STRICT); } else { $ErrorManager->setPostponedErrorMask(E_NOTICE | E_USER_NOTICE | E_USER_WARNING | E_WARNING); } $request = new WikiRequest(); $action = $request->getArg('action'); if (substr($action, 0, 3) != 'zip') { if ($action == 'pdf') { $ErrorManager->setPostponedErrorMask(-1); } // everything //else // reject postponing of warnings // $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE); } /* * Allow for disabling of markup cache. * (Mostly for debugging ... hopefully.) * * See also <?plugin WikiAdminUtils action=purge-cache ?> */ if (!defined('WIKIDB_NOCACHE_MARKUP')) { if ($request->getArg('nocache')) { // 1 or purge define('WIKIDB_NOCACHE_MARKUP', $request->getArg('nocache')); } else { define('WIKIDB_NOCACHE_MARKUP', false); } // redundant, but explicit } // Initialize with system defaults in case user not logged in. // Should this go into constructor? $request->initializeTheme(); $request->updateAuthAndPrefs(); $request->initializeLang(); //FIXME: //if ($user->is_authenticated()) // $LogEntry->user = $user->getId(); // Memory optimization: // http://www.procata.com/blog/archives/2004/05/27/rephlux-and-php-memory-usage/ // kill the global PEAR _PEAR_destructor_object_list if (!empty($_PEAR_destructor_object_list)) { $_PEAR_destructor_object_list = array(); } $request->possiblyDeflowerVirginWiki(); // hack! define proper actions for these. if (defined('WIKI_XMLRPC') and WIKI_XMLRPC) { return; } if (defined('WIKI_SOAP') and WIKI_SOAP) { return; } $validators = array('wikiname' => WIKI_NAME, 'args' => wikihash($request->getArgs()), 'prefs' => wikihash($request->getPrefs())); if (CACHE_CONTROL == 'STRICT') { $dbi = $request->getDbh(); $timestamp = $dbi->getTimestamp(); $validators['mtime'] = $timestamp; $validators['%mtime'] = (int) $timestamp; } // FIXME: we should try to generate strong validators when possible, // but for now, our validator is weak, since equal validators do not // indicate byte-level equality of content. (Due to DEBUG timing output, etc...) // // (If DEBUG if off, this may be a strong validator, but I'm going // to go the paranoid route here pending further study and testing.) // $validators['%weak'] = true; $request->setValidators($validators); $request->handleAction(); if (DEBUG and DEBUG & _DEBUG_INFO) { phpinfo(INFO_VARIABLES | INFO_MODULES); } $request->finish(); }
function HTTP_ETag($val, $is_weak = false) { $this->_val = wikihash($val); $this->_weak = $is_weak; }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; //$this->_request = & $request; //$this->_dbi = & $dbi; $user = $request->getUser(); //FIXME: fails on test with DumpHtml:RateIt if (!is_object($user)) { return HTML(); } $this->userid = $user->getId(); $args = $this->getArgs($argstr, $request); $this->dimension = $args['dimension']; $this->imgPrefix = $args['imgPrefix']; if ($this->dimension == '') { $this->dimension = 0; $args['dimension'] = 0; } if ($args['pagename']) { // Expand relative page names. $page = new WikiPageName($args['pagename'], $basepage); $args['pagename'] = $page->name; } if (empty($args['pagename'])) { return $this->error(_("no page specified")); } $this->pagename = $args['pagename']; $rdbi = RatingsDb::getTheRatingsDb(); $this->_rdbi =& $rdbi; if ($args['mode'] === 'add') { //if (!$user->isSignedIn()) return $this->error(_("You must sign in")); $actionImg = $WikiTheme->_path . $this->actionImgPath(); $rdbi->addRating($request->getArg('rating'), $this->userid, $this->pagename, $this->dimension); if (!empty($request->_is_buffering_output)) { ob_end_clean(); } // discard any previous output // delete the cache $page = $request->getPage(); //$page->set('_cached_html', false); $request->cacheControl('MUST-REVALIDATE'); $dbi->touch(); //fake validators without args $request->appendValidators(array('wikiname' => WIKI_NAME, 'args' => wikihash(''))); header('Content-type: image/png'); readfile($actionImg); exit; } elseif ($args['mode'] === 'delete') { //if (!$user->isSignedIn()) return $this->error(_("You must sign in")); $actionImg = $WikiTheme->_path . $this->actionImgPath(); $rdbi->deleteRating($this->userid, $this->pagename, $this->dimension); if (!empty($request->_is_buffering_output)) { ob_end_clean(); } // discard any previous output // delete the cache $page = $request->getPage(); //$page->set('_cached_html', false); $request->cacheControl('MUST-REVALIDATE'); $dbi->touch(); //fake validators without args $request->appendValidators(array('wikiname' => WIKI_NAME, 'args' => wikihash(''))); header('Content-type: image/png'); readfile($actionImg); exit; } elseif (!$args['show']) { return $this->RatingWidgetHtml($args['pagename'], $args['version'], $args['imgPrefix'], $args['dimension'], $args['small']); } else { //if (!$user->isSignedIn()) return $this->error(_("You must sign in")); //extract($args); $rating = $rdbi->getRating(); $html = HTML::p($this->pagename . ": " . sprintf(_("Rated by %d users | Average rating %.1f stars"), $rdbi->getNumUsers($this->pagename, $this->dimension), $rdbi->getAvg($this->pagename, $this->dimension)), HTML::br()); if ($rating) { $html->pushContent(sprintf(_("Your rating was %.1f"), $rating)); } else { $pred = $rdbi->getPrediction($this->userid, $this->pagename, $this->dimension); if (is_string($pred)) { $html->pushContent(sprintf(_("%s prediction for you is %s stars"), WIKI_NAME, $pred)); } elseif ($pred) { $html->pushContent(sprintf(_("%s prediction for you is %.1f stars"), WIKI_NAME, $pred)); } } //$html->pushContent(HTML::p()); //$html->pushContent(HTML::em("(Experimental: This might be entirely bogus data)")); return $html; } }
function displayActionImg($mode) { global $WikiTheme, $request; if (!empty($request->_is_buffering_output)) { ob_end_clean(); } // discard any previous output // delete the cache $page = $request->getPage(); //$page->set('_cached_html', false); $request->cacheControl('MUST-REVALIDATE'); $dbi = $request->getDbh(); $dbi->touch(); //fake validators without args $request->appendValidators(array('wikiname' => WIKI_NAME, 'args' => wikihash(''))); $request->discardOutput(); $actionImg = $WikiTheme->_path . $this->actionImgPath(); if (file_exists($actionImg)) { header('Content-type: image/png'); readfile($actionImg); } else { header('Content-type: image/png'); echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQMAAABIeJ9nAAAAA1BMVEX///' . '+nxBvIAAAAAXRSTlMAQObYZgAAABNJREFUeF4NwAEBAAAAgJD+r5YGAAQAAXHhfPAAAAAASUVORK5CYII='); } exit; }