includes/pageprocess.php
changeset 827 2c20563245b2
parent 825 9d5c04c1414f
parent 821 a64c56a1a6a4
child 832 7152ca0a0ce9
equal deleted inserted replaced
826:dcf5381ce8ba 827:2c20563245b2
   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"
   587     if ( !$q )
   588     if ( !$q )
   588       $db->_die('PageProcessor page creation - logging stage');
   589       $db->_die('PageProcessor page creation - logging stage');
   589     
   590     
   590     // Update the cache
   591     // Update the cache
   591     $paths->update_metadata_cache();
   592     $paths->update_metadata_cache();
       
   593     
       
   594     // Make sure that when/if we save the page later in this instance it doesn't get re-created
       
   595     $this->page_exists = true;
   592     
   596     
   593     // Page created. We're good!
   597     // Page created. We're good!
   594     return true;
   598     return true;
   595   }
   599   }
   596   
   600