code/pages/WikiPage.php
public function addpage($args) {
		if (!Permission::check(MANAGE_WIKI_PAGES)) {
			return Security::permissionFailure($this);
		}

		$pageName = trim($args['NewPageName']);
		$createType = $args['CreateType'] ? $args['CreateType'] : 'child';
		if (!strlen($pageName)) {
			throw new Exception("Invalid page name");
		}

		$createContext = $this->data();

		if ($args['CreateContext']) {
			$createContext = DataObject::get_by_id('WikiPage', $args['CreateContext']);
		}

		if (!$createContext instanceof WikiPage) {
			throw new Exception("You must select an existing wiki page.");
		}

		// now see whether to add the new page above, below or as a child
		$page = new WikiPage();
		$page->Title = $pageName;
		$page->MenuTitle = $pageName;

		switch ($createType) {
			case 'sibling': {
					$page->ParentID = $createContext->ParentID;
					break;
				}
			case 'child':
			default: {
					$page->ParentID = $createContext->ID;
					break;
				}
		}

		$page->writeToStage('Stage');

		// publish if we're on autopublish
		if (WikiPage::$auto_publish) {
			$page->doPublish();
		}

		return $this->redirect($page->Link('edit') . '?stage=Stage');
	}
public function addpage($args) {
		if (!Permission::check(MANAGE_WIKI_PAGES)) {
			return Security::permissionFailure($this);
		}

		$pageName = trim($args['NewPageName']);
		$createType = $args['CreateType'] ? $args['CreateType'] : 'child';
		if (!strlen($pageName)) {
			throw new Exception("Invalid page name");
		}

		$createContext = $this->data();

		if ($args['CreateContext']) {
			$createContext = DataObject::get_by_id('WikiPage', $args['CreateContext']);
		}

		if (!$createContext instanceof WikiPage) {
			throw new Exception("You must select an existing wiki page.");
		}

		// now see whether to add the new page above, below or as a child
		$page = new WikiPage();
		$page->Title = $pageName;
		$page->MenuTitle = $pageName;

		switch ($createType) {
			case 'sibling': {
					$page->ParentID = $createContext->ParentID;
					break;
				}
			case 'child':
			default: {
					$page->ParentID = $createContext->ID;
					break;
				}
		}

		$page->writeToStage('Stage');

		// publish if we're on autopublish
		if (WikiPage::$auto_publish) {
			$page->doPublish();
		}

		return $this->redirect($page->Link('edit') . '?stage=Stage');
	}
public function addpage ( $ args ) { if ( ! Permission :: check ( MANAGE_WIKI_PAGES ) ) { return Security :: permissionFailure ( $ this ) ; } $ pageName = trim ( $ args [ 'NewPageName' ] ) ; $ createType = $ args [ 'CreateType' ] ? $ args [ 'CreateType' ] : 'child' ; if ( ! strlen ( $ pageName ) ) { throw new Exception ( "Invalid page name" ) ; } $ createContext = $ this -> data ( ) ; if ( $ args [ 'CreateContext' ] ) { $ createContext = DataObject :: get_by_id ( 'WikiPage' , $ args [ 'CreateContext' ] ) ; } if ( ! $ createContext instanceof WikiPage ) { throw new Exception ( "You must select an existing wiki page." ) ; } // now see whether to add the new page above, below or as a child $ page = new WikiPage ( ) ; $ page -> Title = $ pageName ; $ page -> MenuTitle = $ pageName ; switch ( $ createType ) { case 'sibling' : { $ page -> ParentID = $ createContext -> ParentID ; break ; } case 'child' : default : { $ page -> ParentID = $ createContext -> ID ; break ; } } $ page -> writeToStage ( 'Stage' ) ; // publish if we're on autopublish if ( WikiPage :: $ auto_publish ) { $ page -> doPublish ( ) ; } return $ this -> redirect ( $ page -> Link ( 'edit' ) . '?stage=Stage' ) ; }
Creates an entirely new page as a child of the current page, or
'after' a selected page.
Creates an entirely new page as a child of the current page or after a selected page .