490 } |
490 } |
491 |
491 |
492 /** |
492 /** |
493 * Creates the page if it doesn't already exist. |
493 * Creates the page if it doesn't already exist. |
494 * @param string Optional page title. |
494 * @param string Optional page title. |
|
495 * @param bool Visibility (allow indexing) flag |
495 * @return bool True on success, false on failure. |
496 * @return bool True on success, false on failure. |
496 */ |
497 */ |
497 |
498 |
498 function create_page($title = false) |
499 function create_page($title = false, $visible = true) |
499 { |
500 { |
500 global $db, $session, $paths, $template, $plugins; // Common objects |
501 global $db, $session, $paths, $template, $plugins; // Common objects |
501 global $lang; |
502 global $lang; |
502 |
503 |
503 // Do we have permission to create the page? |
504 // Do we have permission to create the page? |
538 $metadata = array( |
539 $metadata = array( |
539 'urlname' => $this->page_id, |
540 'urlname' => $this->page_id, |
540 'namespace' => $this->namespace, |
541 'namespace' => $this->namespace, |
541 'name' => $name, |
542 'name' => $name, |
542 'special' => 0, |
543 'special' => 0, |
543 'visible' => 1, |
544 'visible' => $visible ? 1 : 0, |
544 'comments_on' => 1, |
545 'comments_on' => 1, |
545 'protected' => ( $this->namespace == 'System' ? 1 : 0 ), |
546 'protected' => ( $this->namespace == 'System' ? 1 : 0 ), |
546 'delvotes' => 0, |
547 'delvotes' => 0, |
547 'delvote_ips' => serialize(array()), |
548 'delvote_ips' => serialize(array()), |
548 'wiki_mode' => 2 |
549 'wiki_mode' => 2 |
555 $name = $db->escape($name); |
556 $name = $db->escape($name); |
556 $protect = ( $this->namespace == 'System' ) ? '1' : '0'; |
557 $protect = ( $this->namespace == 'System' ) ? '1' : '0'; |
557 $blank_array = $db->escape(serialize(array())); |
558 $blank_array = $db->escape(serialize(array())); |
558 |
559 |
559 // Query 1: Metadata entry |
560 // Query 1: Metadata entry |
560 $q = $db->sql_query('INSERT INTO ' . table_prefix . "pages(name, urlname, namespace, protected, delvotes, delvote_ips, wiki_mode)\n" |
561 $q = $db->sql_query('INSERT INTO ' . table_prefix . "pages(name, urlname, namespace, visible, protected, delvotes, delvote_ips, wiki_mode)\n" |
561 . "VALUES ( '$name', '$page_id', '$namespace', $protect, 0, '$blank_array', 2 );"); |
562 . " VALUES ( '$name', '$page_id', '$namespace', {$metadata['visible']}, $protect, 0, '$blank_array', 2 );"); |
562 if ( !$q ) |
563 if ( !$q ) |
563 $db->_die('PageProcessor page creation - metadata stage'); |
564 $db->_die('PageProcessor page creation - metadata stage'); |
564 |
565 |
565 // Query 2: Text insertion |
566 // Query 2: Text insertion |
566 $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text)\n" |
567 $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text)\n" |