<commit_before><?php
namespace wcf\acp\form;
use wcf\data\page\Page;
use wcf\data\page\PageAction;
use wcf\form\AbstractForm;
use wcf\system\acl\simple\SimpleAclHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\UserInputException;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;

/**
 * Shows the page add form.
 * 
 * @author	<NAME>
 * @copyright	2001-2016 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\Acp\Form
 * @since	3.0
 */
class PageEditForm extends PageAddForm {
	/**
	 * @inheritDoc
	 */
	public $activeMenuItem = 'wcf.acp.menu.link.cms.page.list';
	
	/**
	 * page id
	 * @var	integer
	 */
	public $pageID = 0;
	
	/**
	 * page object
	 * @var	Page
	 */
	public $page;
	
	/**
	 * @inheritDoc
	 * 
	 * @throws	IllegalLinkException
	 */
	public function readParameters() {
		parent::readParameters();
	
		if (isset($_REQUEST['id'])) $this->pageID = intval($_REQUEST['id']);
		$this->page = new Page($this->pageID);
		if (!$this->page->pageID) {
			throw new IllegalLinkException();
		}
		if ($this->page->isMultilingual) $this->isMultilingual = 1;
	}
	
	/**
	 * @inheritDoc
	 */
	protected function readPageType() {
		// not required for editing
	}
	
	/**
	 * @inheritDoc
	 */
	public function readFormParameters() {
		parent::readFormParameters();
		
		$this->pageType = $this->page->pageType;
		if ($this->page->originIsSystem) {
			$this->applicationPackageID = $this->page->applicationPackageID;
			
			if ($this->page->hasFixedParent) {
				$this->parentPageID = $this->page->parentPageID;
			}
		}
		
		if ($this->page->requireObjectID) {
			// pages that require an object id can never be set as landing page
			$this->isLandingPage = 0;
		}
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validateName() {
		if (mb_strtolower($this->name) != mb_strtolower($this->page->name)) {
			parent::validateName();
		}
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validatePageType() {
		// type is immutable
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validateParentPageID() {
		if ($this->page->hasFixedParent) {
			if ($this->parentPageID != $this->page->parentPageID) {
				throw new UserInputException('parentPageID', 'invalid');
			}
		}
		else {
			parent::validateParentPageID();
		}
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validateCustomUrl($languageID, $customURL) {
		if ($this->pageType == 'system') {
			if ($customURL != $this->page->controllerCustomURL) {
				parent::validateCustomUrl($languageID, $customURL);
			}
		}
		else {
			if (mb_strtolower($customURL) != mb_strtolower($this->page->getPageContents()[$languageID]->customURL)) {
				parent::validateCustomUrl($languageID, $customURL);
			}
		}
	}
	
	/**
	 * @inheritDoc
	 */
	public function save() {
		AbstractForm::save();
		
		$data = [
			'name' => $this->name,
			'isDisabled' => $this->isDisabled ? 1 : 0,
			'lastUpdateTime' => TIME_NOW,
			'parentPageID' => $this->parentPageID ?: null,
			'applicationPackageID' => $this->applicationPackageID
		];
		
		if ($this->pageType == 'system') {
			$content = [];<commit_msg>Fixed potential issue when creating new language versions of a page<commit_after><?php
namespace wcf\acp\form;
use wcf\data\page\Page;
use wcf\data\page\PageAction;
use wcf\form\AbstractForm;
use wcf\system\acl\simple\SimpleAclHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\UserInputException;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;

/**
 * Shows the page add form.
 * 
 * @author	<NAME>
 * @copyright	2001-2016 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\Acp\Form
 * @since	3.0
 */
class PageEditForm extends PageAddForm {
	/**
	 * @inheritDoc
	 */
	public $activeMenuItem = 'wcf.acp.menu.link.cms.page.list';
	
	/**
	 * page id
	 * @var	integer
	 */
	public $pageID = 0;
	
	/**
	 * page object
	 * @var	Page
	 */
	public $page;
	
	/**
	 * @inheritDoc
	 * 
	 * @throws	IllegalLinkException
	 */
	public function readParameters() {
		parent::readParameters();
	
		if (isset($_REQUEST['id'])) $this->pageID = intval($_REQUEST['id']);
		$this->page = new Page($this->pageID);
		if (!$this->page->pageID) {
			throw new IllegalLinkException();
		}
		if ($this->page->isMultilingual) $this->isMultilingual = 1;
	}
	
	/**
	 * @inheritDoc
	 */
	protected function readPageType() {
		// not required for editing
	}
	
	/**
	 * @inheritDoc
	 */
	public function readFormParameters() {
		parent::readFormParameters();
		
		$this->pageType = $this->page->pageType;
		if ($this->page->originIsSystem) {
			$this->applicationPackageID = $this->page->applicationPackageID;
			
			if ($this->page->hasFixedParent) {
				$this->parentPageID = $this->page->parentPageID;
			}
		}
		
		if ($this->page->requireObjectID) {
			// pages that require an object id can never be set as landing page
			$this->isLandingPage = 0;
		}
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validateName() {
		if (mb_strtolower($this->name) != mb_strtolower($this->page->name)) {
			parent::validateName();
		}
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validatePageType() {
		// type is immutable
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validateParentPageID() {
		if ($this->page->hasFixedParent) {
			if ($this->parentPageID != $this->page->parentPageID) {
				throw new UserInputException('parentPageID', 'invalid');
			}
		}
		else {
			parent::validateParentPageID();
		}
	}
	
	/**
	 * @inheritDoc
	 */
	protected function validateCustomUrl($languageID, $customURL) {
		if ($this->pageType == 'system') {
			if ($customURL != $this->page->controllerCustomURL) {
				parent::validateCustomUrl($languageID, $customURL);
			}
		}
		else {
			if (isset($this->page->getPageContents()[$languageID]) && mb_strtolower($customURL) != mb_strtolower($this->page->getPageContents()[$languageID]->customURL)) {
				parent::validateCustomUrl($languageID, $customURL);
			}
		}
	}
	
	/**
	 * @inheritDoc
	 */
	public function save() {
		AbstractForm::save();
		
		$data = [
			'name' => $this->name,
			'isDisabled' => $this->isDisabled ? 1 : 0,
			'lastUpdateTime' => TIME_NOW,
			'parentPageID' => $this->parentPageID ?: null,
			'applicationPackageID' => $this->applicationPackageID
		];
		
		if ($this->pageType == 'system') {
			$content = [];
{'fraction_non_alphanumeric': 0.16692522494570275, 'fraction_numerical': 0.004654049022649705, 'mean_word_length': 3.601713062098501, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5105105', 'n_tokens_mistral': 2452, 'n_tokens_neox': 2127, 'n_words': 405}