/** * Check by name if a page exists. * * @author {@link http://wikkawiki.org/JavaWoman JavaWoman} * @copyright Copyright © 2004, Marjolein Katsma * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @version 1.1 * * NOTE: v. 1.0 -> 1.1 * - name changed from ExistsPage() to existsPage() !!! * - added $prefix param so it can be used from installer * - added $current param so it checks by default for a current page only * * @access public * @uses Query() * * @param string $page page name to check * @param string $prefix optional: table prefix to use * pass NULL if you need to override the $active parameter * default: prefix as in configuration file * @param mixed $dblink optional: connection resource, or NULL to get * object's connection * @param string $active optional: if TRUE, check for actgive page only * default: TRUE * @return boolean TRUE if page exists, FALSE otherwise */ function existsPage($page, $prefix = '', $dblink = NULL, $active = TRUE) { // Always replace '_' with ws $page = preg_replace('/_+/', ' ', $page); // init $count = 0; $table_prefix = empty($prefix) && isset($this) ? $this->GetConfigValue('table_prefix') : $prefix; if (is_null($dblink)) { $dblink = $this->dblink; } // build query $query = "SELECT COUNT(tag)\n\t\t\t\tFROM " . $table_prefix . "pages\n\t\t\t\tWHERE tag='" . mysql_real_escape_string($page) . "'"; if ($active) { $query .= "\t\tAND latest='Y'"; } // do query if ($r = Wakka::Query($query, $dblink)) { $count = mysql_result($r, 0); mysql_free_result($r); } // report return $count > 0 ? TRUE : FALSE; }