Version select form. Main interface between selecting versions to view
and comparing multiple versions.

Because we can reload the page directly to a compare view (history/compare/1/2/3)
this form has to adapt to those parameters as well.

@return Form
348764
public function VersionsForm()
    {
        $id = $this->currentPageID();
        $page = $this->getRecord($id);
        $versionsHtml = '';

        $action = $this->getRequest()->param('Action');
        $versionID = $this->getRequest()->param('VersionID');
        $otherVersionID = $this->getRequest()->param('OtherVersionID');

        $showUnpublishedChecked = 0;
        $compareModeChecked = ($action == "compare");

        if ($page) {
            $versions = $page->allVersions();
            $versionID = (!$versionID) ? $page->Version : $versionID;

            if ($versions) {
                foreach ($versions as $k => $version) {
                    $active = false;

                    if ($version->Version == $versionID || $version->Version == $otherVersionID) {
                        $active = true;

                        if (!$version->WasPublished) {
                            $showUnpublishedChecked = 1;
                        }
                    }

                    $version->Active = ($active);
                }
            }

            $vd = new ViewableData();

            $versionsHtml = $vd->customise(array(
                'Versions' => $versions
            ))->renderWith($this->getTemplatesWithSuffix('_versions'));
        }

        $fields = new FieldList(
            new CheckboxField(
                'ShowUnpublished',
                _t('SilverStripe\\CMS\\Controllers\\CMSPageHistoryController.SHOWUNPUBLISHED', 'Show unpublished versions'),
                $showUnpublishedChecked
            ),
            new CheckboxField(
                'CompareMode',
                _t('SilverStripe\\CMS\\Controllers\\CMSPageHistoryController.COMPAREMODE', 'Compare mode (select two)'),
                $compareModeChecked
            ),
            new LiteralField('VersionsHtml', $versionsHtml),
            $hiddenID = new HiddenField('ID', false, "")
        );

        $form = Form::create(
            $this,
            'VersionsForm',
            $fields,
            new FieldList()
        )->setHTMLID('Form_VersionsForm');
        $form->loadDataFrom($this->getRequest()->requestVars());
        $hiddenID->setValue($id);
        $form->unsetValidator();

        $form
            ->addExtraClass('cms-versions-form') // placeholder, necessary for $.metadata() to work
            ->setAttribute('data-link-tmpl-compare', Controller::join_links($this->Link('compare'), '%s', '%s', '%s'))
            ->setAttribute('data-link-tmpl-show', Controller::join_links($this->Link('show'), '%s', '%s'));

        return $form;
    }
1202384
public function form()
    {
        $this->breadcrumb->onForm();
        $all  = $this->prepare();
        $this->roundRobin->build();
        $form = $this->form->of("antares.tester: test", function (FormGrid $form) use ($all) {
            $model = new Fluent([]);
            $form->setup($this, "antares::tools/tester/prepare", $model, ['id' => 'tester-form']);
            $form->name('Module tester');
            foreach ($all as $module => $tests) {
                $form->fieldset($module, function (Fieldset $fieldset) use ($tests) {
                    $fieldset->control('input:text', '', function($control) use($tests) {
                        $control->field = function() use($tests) {
                            return view('antares/tester::admin.partials._module', ['tests' => $tests]);
                        };
                    });
                });
            }
            $form->layout('antares/tester::admin.partials._form');
        });

        $form->grid->submit = trans('Start testing');
        return $form;
    }
1280227
public function actionChangePageVersionLayout()
    {
        $params =  Yii::$app->request->bodyParams;
        $pageItemId = $params['pageItemId'];
        $layoutId =  $params['layoutId'];
        $alias =  $params['alias'];

        $model = NavItemPage::findOne(['id' => $pageItemId]);
        
        if ($model) {
            $model->forceNavItem->updateTimestamp();
            return $model->updateAttributes(['layout_id' => $layoutId, 'version_alias' => $alias]);
        }
        
        return false;
    }
588039
public function rebuildForm()
    {
        $this->rebuilding = true;
        // If form is plain, buildForm method is empty, so we need to take
        // existing fields and add them again
        if (get_class($this) === 'Kris\LaravelFormBuilder\Form') {
            foreach ($this->fields as $name => $field) {
                // Remove any temp variables added in previous instance
                $options =  Arr::except($field->getOptions(), 'tmp');
                $this->add($name, $field->getType(), $options);
            }
        } else {
            $this->buildForm();
        }
        $this->rebuilding = false;

        return $this;
    }
1058424
public function Form() {
		// The editing form hasn't been put in place by the 'edit' action
		// so lets just show the status form
		$append = '';
		if (!$this->form) {
			if (WikiPage::$show_edit_button || $this->data()->canEdit()) {
				// create the information form 
				$this->form = $this->StatusForm();
			}
		} else {
			// if we have got an editing form, then we'll add a New Page
			// form if we have permissions to do so
			if (Permission::check(MANAGE_WIKI_PAGES)) {
				$append = $this->CreatePageForm()->forTemplate();
			}
		}

		return $this->form->forTemplate() . $append;
	}
720472
function getVersion()
    {
        if (empty($this->version))
            $this->version = self::Vx1_1;
        
        return $this->version;
    }
196521
public function getVersions()
    {
        if (!isset($this->_versions)) {
            $versions = array();

            foreach ($this->getMethods() as $method) {
                $matches = array();

                if (preg_match('/(up)(\d+)/', $method, $matches)) {
                    $versions[] = $matches[2];
                }
            }

            $path = dirname($this->getIdentifier()->filepath);

            if (file_exists($path)) {
                if (file_exists($path.'/migrations')) {
                    $files = new DirectoryIterator($path.'/migrations');
                    foreach ($files as $file) {
                        $matches = array();
                        if (preg_match('/(\d+)\.sql/', (string) $file, $matches)) {
                            $versions[] = $matches[1];
                        } elseif (preg_match('/(\d+)\.php/', (string) $file, $matches)) {
                            $versions[] = $matches[1];
                        }
                    }
                }
            }
            sort($versions);
            $this->_versions = array_unique($versions);
            $this->_max_version = array_pop($versions);
        }

        return $this->_versions;
    }
1324109
public function getChangeInfoForm()
    {

        if (! $this->changeInfoForm) {
            $this->setChangeInfoForm($this->getServiceLocator()->get('playgrounduser_change_info_form'));
        }

        return $this->changeInfoForm;
    }
282460
protected function getVersion()
    {
        if ($this->version === null) {
            $info = $this->client->info();
            $this->version = $info['redis_version'];
        }

        return $this->version;
    }
1305794
public function getServerVersion()
    {
        if (!$this->serverVersion) {
            $this->method = 'getServerVersion';
            $this->sendRequest();
            $this->method = null;
        }

        return $this->serverVersion;
    }
1242552
protected function whyCantCopyVersion()
    {
        $originalPage = $this->getSingleOriginalPage();
        if ($originalPage === null) {
            return t("It's possible to copy just one page version at a time.");
        }
        if ($originalPage->isExternalLink()) {
            return t("It's not possible to copy the page version of an external URL.");
        }
        if ($originalPage->isAliasPage()) {
            return t("It's not possible to copy the page version of aliases.");
        }
        $destinationPage = $this->getDestinationPage();
        if ($destinationPage->getCollectionID() == $originalPage->getCollectionID()) {
            return t("It's not possible to copy the page version of a page to the page itself.");
        }
        $pc = new Checker($destinationPage);
        if (!$pc->canWrite()) {
            return t('You don\'t have the permission to edit the contents of "%s".', $destinationPage->getCollectionName());
        }

        return '';
    }
480093
public function Form()
    {
        $form = new Form(
            $this,
            'SilverStripe\\Forms\\Form',
            new FieldList($root = new TabSet('Root', new Tab('Main'))),
            new FieldList()
        );

        if ($this->getTopLevelController() instanceof LeftAndMain) {
            $form->setTemplate('LeftAndMain_EditForm');
            $form->addExtraClass('cms-content cms-edit-form cms-tabset center');
            $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');

            $root->setTemplate('CMSTabSet');
            $form->Backlink = $this->getBackLink();
        }

        return $form;
    }
449431
public function getVersionToModify()
    {
        $u = new User();
        $vObj = $this->getVersionObject();
        if ($this->isMasterCollection() || ($vObj->isNew())) {
            return $this;
        } else {
            $nc = $this->cloneVersion(null);

            return $nc;
        }
    }
672157
public function getVersionNumber() {
        if (!isset($this->versionNumber)) {
            if (!$this->isConnected())
                $this->connect();
            $this->versionNumber = $this->sqlite->version()['versionNumber'];
        }
        return $this->versionNumber;
    }
185245
public function changes()
    {
        // Check viewability of changes
        if (!Config::inst()->get(VersionFeed::class, 'changes_enabled')
            || !$this->owner->PublicHistory
            || $this->owner->Version == ''
        ) {
            return $this->owner->httpError(404, 'Page history not viewable');
        }

        // Cache the diffs to remove DOS possibility.
        $target = $this->owner;
        $key = implode('_', array('changes', $target->ID, $target->Version));
        $entries = $this->filterContent($key, function () use ($target) {
            return $target->getDiffList(null, Config::inst()->get(VersionFeed::class, 'changes_limit'));
        });

        // Generate the output.
        $title = _t(
            'SilverStripe\\VersionFeed\\VersionFeed.SINGLEPAGEFEEDTITLE',
            'Updates to {title} page',
            ['title' => $this->owner->Title]
        );
        $rss = new RSSFeed($entries, $this->owner->request->getURL(), $title, '', 'Title', '', null);
        $rss->setTemplate('Page_changes_rss');
        return $rss->outputToBrowser();
    }
877518
public function versionAction()
    {
        $this->assign('version', Samurai::getVersion());
        $this->assign('state', Samurai::getState());
        return self::VIEW_TEMPLATE;
    }
1097
protected function compareVersion()
    {
        $manifest = $this->getManifest();
        $extensionEntity = $this->getExtensionEntity();

        if (isset($extensionEntity)) {
            $comparedVersion = version_compare($manifest['version'], $extensionEntity->get('version'), '>=');
            if ($comparedVersion <= 0) {
                $this->throwErrorAndRemovePackage('You cannot install an older version of this extension.');
            }
        }
    }