469 |
469 |
470 } |
470 } |
471 |
471 |
472 /** |
472 /** |
473 * Creates the page if it doesn't already exist. |
473 * Creates the page if it doesn't already exist. |
|
474 * @param string Optional page title. |
474 * @return bool True on success, false on failure. |
475 * @return bool True on success, false on failure. |
475 */ |
476 */ |
476 |
477 |
477 function create_page() |
478 function create_page($title = false) |
478 { |
479 { |
479 global $db, $session, $paths, $template, $plugins; // Common objects |
480 global $db, $session, $paths, $template, $plugins; // Common objects |
|
481 global $lang; |
480 |
482 |
481 // Do we have permission to create the page? |
483 // Do we have permission to create the page? |
482 if ( !$this->perms->get_permissions('create_page') ) |
484 if ( !$this->perms->get_permissions('create_page') ) |
483 { |
485 { |
484 $this->raise_error('You do not have permission to create this page.'); |
486 $this->raise_error($lang->get('pagetools_create_err_no_permission')); |
485 return false; |
487 return false; |
486 } |
488 } |
487 |
489 |
488 // Does it already exist? |
490 // Does it already exist? |
489 if ( $this->page_exists ) |
491 if ( $this->page_exists ) |
490 { |
492 { |
491 $this->raise_error('The page already exists.'); |
493 $this->raise_error($lang->get('pagetools_create_err_already_exists')); |
492 return false; |
494 return false; |
493 } |
495 } |
494 |
496 |
495 // It's not in there. Perform validation. |
497 // It's not in there. Perform validation. |
496 |
498 |
497 // We can't create special, admin, or external pages. |
499 // We can't create special, admin, or external pages. |
498 if ( $this->namespace == 'Special' || $this->namespace == 'Admin' || $this->namespace == 'Anonymous' ) |
500 if ( $this->namespace == 'Special' || $this->namespace == 'Admin' || $this->namespace == 'Anonymous' ) |
499 { |
501 { |
500 $this->raise_error('You cannot create Special or Admin pages - they can\'t be stored in the database.'); |
502 $this->raise_error($lang->get('pagetools_create_err_nodb_namespace')); |
501 return false; |
503 return false; |
502 } |
504 } |
503 |
505 |
504 // Guess the proper title |
506 // Guess the proper title |
505 $name = dirtify_page_id($this->page_id); |
507 $name = ( !empty($title) ) ? $title : dirtify_page_id($this->page_id); |
506 |
508 |
507 // Check for the restricted Project: prefix |
509 // Check for the restricted Project: prefix |
508 if ( substr($this->page_id, 0, 8) == 'Project:' ) |
510 if ( substr($this->page_id, 0, 8) == 'Project:' ) |
509 { |
511 { |
510 $this->raise_error('The prefix "Project:" is reserved for internal links and can\'t be used on a page name.'); |
512 $this->raise_error($lang->get('pagetools_create_err_reserved_prefix')); |
511 return false; |
513 return false; |
512 } |
514 } |
513 |
515 |
514 // Validation successful - insert the page |
516 // Validation successful - insert the page |
515 |
517 |
544 $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text)\n" |
546 $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text)\n" |
545 . "VALUES ( '$page_id', '$namespace', '' );"); |
547 . "VALUES ( '$page_id', '$namespace', '' );"); |
546 if ( !$q ) |
548 if ( !$q ) |
547 $db->_die('PageProcessor page creation - text stage'); |
549 $db->_die('PageProcessor page creation - text stage'); |
548 |
550 |
|
551 // Query 3: Log entry |
|
552 $db->sql_query('INSERT INTO ' . table_prefix."logs(time_id, date_string, log_type, action, author, page_id, namespace)\n" |
|
553 . " VALUES ( " . time() . ", '" . enano_date('d M Y h:i a') . "', 'page', 'create', \n" |
|
554 . " '" . $db->escape($session->username) . "', '" . $db->escape($this->page_id) . "', '" . $this->namespace . "');"); |
|
555 if ( !$q ) |
|
556 $db->_die('PageProcessor page creation - logging stage'); |
|
557 |
549 // Page created. We're good! |
558 // Page created. We're good! |
550 return true; |
559 return true; |
551 } |
560 } |
552 |
561 |
553 /** |
562 /** |
573 { |
582 { |
574 $fname = "page_Admin_{$this->page_id}"; |
583 $fname = "page_Admin_{$this->page_id}"; |
575 } |
584 } |
576 |
585 |
577 // Does the page "exist"? |
586 // Does the page "exist"? |
|
587 $pathskey = $paths->nslist[$namespace] . $page_id_cleaned; |
|
588 |
578 if ( $paths->page_id == $page_id && $paths->namespace == $namespace && !$paths->page_exists && ( $this->namespace != 'Admin' || ($this->namespace == 'Admin' && !function_exists($fname) ) ) ) |
589 if ( $paths->page_id == $page_id && $paths->namespace == $namespace && !$paths->page_exists && ( $this->namespace != 'Admin' || ($this->namespace == 'Admin' && !function_exists($fname) ) ) ) |
579 { |
590 { |
580 $this->page_exists = false; |
591 $this->page_exists = false; |
581 } |
592 } |
582 else if ( !isset( $paths->pages[ $paths->nslist[$namespace] . $page_id ] ) && ( $this->namespace == 'Admin' && !function_exists($fname) ) ) |
593 else if ( !isset( $paths->pages[ $pathskey ] ) && ( ( $this->namespace == 'Admin' && !function_exists($fname) ) || ( $this->namespace != 'Admin' ) ) ) |
583 { |
594 { |
584 $this->page_exists = false; |
595 $this->page_exists = false; |
585 } |
596 } |
586 else |
597 else |
587 { |
598 { |