502 } |
502 } |
503 |
503 |
504 /** |
504 /** |
505 * Creates the page if it doesn't already exist. |
505 * Creates the page if it doesn't already exist. |
506 * @param string Optional page title. |
506 * @param string Optional page title. |
|
507 * @param bool Visibility (allow indexing) flag |
507 * @return bool True on success, false on failure. |
508 * @return bool True on success, false on failure. |
508 */ |
509 */ |
509 |
510 |
510 function create_page($title = false) |
511 function create_page($title = false, $visible = true) |
511 { |
512 { |
512 global $db, $session, $paths, $template, $plugins; // Common objects |
513 global $db, $session, $paths, $template, $plugins; // Common objects |
513 global $lang; |
514 global $lang; |
514 |
515 |
515 // Do we have permission to create the page? |
516 // Do we have permission to create the page? |
550 $metadata = array( |
551 $metadata = array( |
551 'urlname' => $this->page_id, |
552 'urlname' => $this->page_id, |
552 'namespace' => $this->namespace, |
553 'namespace' => $this->namespace, |
553 'name' => $name, |
554 'name' => $name, |
554 'special' => 0, |
555 'special' => 0, |
555 'visible' => 1, |
556 'visible' => $visible ? 1 : 0, |
556 'comments_on' => 1, |
557 'comments_on' => 1, |
557 'protected' => ( $this->namespace == 'System' ? 1 : 0 ), |
558 'protected' => ( $this->namespace == 'System' ? 1 : 0 ), |
558 'delvotes' => 0, |
559 'delvotes' => 0, |
559 'delvote_ips' => serialize(array()), |
560 'delvote_ips' => serialize(array()), |
560 'wiki_mode' => 2 |
561 'wiki_mode' => 2 |
567 $name = $db->escape($name); |
568 $name = $db->escape($name); |
568 $protect = ( $this->namespace == 'System' ) ? '1' : '0'; |
569 $protect = ( $this->namespace == 'System' ) ? '1' : '0'; |
569 $blank_array = $db->escape(serialize(array())); |
570 $blank_array = $db->escape(serialize(array())); |
570 |
571 |
571 // Query 1: Metadata entry |
572 // Query 1: Metadata entry |
572 $q = $db->sql_query('INSERT INTO ' . table_prefix . "pages(name, urlname, namespace, protected, delvotes, delvote_ips, wiki_mode)\n" |
573 $q = $db->sql_query('INSERT INTO ' . table_prefix . "pages(name, urlname, namespace, visible, protected, delvotes, delvote_ips, wiki_mode)\n" |
573 . "VALUES ( '$name', '$page_id', '$namespace', $protect, 0, '$blank_array', 2 );"); |
574 . " VALUES ( '$name', '$page_id', '$namespace', {$metadata['visible']}, $protect, 0, '$blank_array', 2 );"); |
574 if ( !$q ) |
575 if ( !$q ) |
575 $db->_die('PageProcessor page creation - metadata stage'); |
576 $db->_die('PageProcessor page creation - metadata stage'); |
576 |
577 |
577 // Query 2: Text insertion |
578 // Query 2: Text insertion |
578 $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text)\n" |
579 $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text)\n" |