function execute($par) { $this->setHeaders(); $this->outputHeader(); $this->getOutput()->addModuleStyles('mediawiki.special.pagesWithProp'); $request = $this->getRequest(); $propname = $request->getVal('propname', $par); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('page_props', 'pp_propname', '', __METHOD__, array('DISTINCT', 'ORDER BY' => 'pp_propname')); $propnames = array(); foreach ($res as $row) { $propnames[$row->pp_propname] = $row->pp_propname; } $form = new HTMLForm(array('propname' => array('type' => 'selectorother', 'name' => 'propname', 'options' => $propnames, 'default' => $propname, 'label-message' => 'pageswithprop-prop', 'required' => true)), $this->getContext()); $form->setMethod('get'); $form->setSubmitCallback(array($this, 'onSubmit')); $form->setWrapperLegendMsg('pageswithprop-legend'); $form->addHeaderText($this->msg('pageswithprop-text')->parseAsBlock()); $form->setSubmitTextMsg('pageswithprop-submit'); $form->prepareForm(); $form->displayForm(false); if ($propname !== '' && $propname !== null) { $form->trySubmit(); } }
public function execute($par) { $this->setHeaders(); $this->outputHeader(); $this->getOutput()->addModuleStyles('mediawiki.special.pagesWithProp'); $request = $this->getRequest(); $propname = $request->getVal('propname', $par); $propnames = $this->getExistingPropNames(); $form = new HTMLForm(array('propname' => array('type' => 'selectorother', 'name' => 'propname', 'options' => $propnames, 'default' => $propname, 'label-message' => 'pageswithprop-prop', 'required' => true)), $this->getContext()); $form->setMethod('get'); $form->setSubmitCallback(array($this, 'onSubmit')); $form->setWrapperLegendMsg('pageswithprop-legend'); $form->addHeaderText($this->msg('pageswithprop-text')->parseAsBlock()); $form->setSubmitTextMsg('pageswithprop-submit'); $form->prepareForm(); $form->displayForm(false); if ($propname !== '' && $propname !== null) { $form->trySubmit(); } }
/** * Get a form for editing the watchlist in "raw" mode * * @return HTMLForm */ protected function getRawForm() { $titles = implode($this->getWatchlist(), "\n"); $fields = array('Titles' => array('type' => 'textarea', 'label-message' => 'watchlistedit-raw-titles', 'default' => $titles)); $form = new HTMLForm($fields, $this->getContext()); $form->setTitle($this->getTitle('raw')); $form->setSubmitTextMsg('watchlistedit-raw-submit'); # Used message keys: 'accesskey-watchlistedit-raw-submit', 'tooltip-watchlistedit-raw-submit' $form->setSubmitTooltip('watchlistedit-raw-submit'); $form->setWrapperLegendMsg('watchlistedit-raw-legend'); $form->addHeaderText($this->msg('watchlistedit-raw-explain')->parse()); $form->setSubmitCallback(array($this, 'submitRaw')); return $form; }
/** * Get a form for clearing the watchlist * * @return HTMLForm */ protected function getClearForm() { $context = new DerivativeContext($this->getContext()); $context->setTitle($this->getPageTitle('clear')); // Reset subpage $form = new HTMLForm(array(), $context); $form->setSubmitTextMsg('watchlistedit-clear-submit'); # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit' $form->setSubmitTooltip('watchlistedit-clear-submit'); $form->setWrapperLegendMsg('watchlistedit-clear-legend'); $form->addHeaderText($this->msg('watchlistedit-clear-explain')->parse()); $form->setSubmitCallback(array($this, 'submitClear')); $form->setSubmitDestructive(); return $form; }
/** * Customizes the HTMLForm a bit * * @param $form HTMLForm */ protected function alterForm(HTMLForm $form) { $form->setWrapperLegendMsg('blockip-legend'); $form->setHeaderText(''); $form->setSubmitCallback(array(__CLASS__, 'processUIForm')); $msg = $this->alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit'; $form->setSubmitTextMsg($msg); # Don't need to do anything if the form has been posted if (!$this->getRequest()->wasPosted() && $this->preErrors) { $s = HTMLForm::formatErrors($this->preErrors); if ($s) { $form->addHeaderText(Html::rawElement('div', array('class' => 'error'), $s)); } } }
/** * @return bool */ function addRule() { $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-addrule')); $project = $this->getRequest()->getText('project'); $region = $this->getRequest()->getText('region'); $groupid = $this->getRequest()->getText('groupid'); if (!$this->userLDAP->inRole('projectadmin', $project)) { $this->notInRole('projectadmin', $project); return false; } $securitygroup = $this->userNova->getSecurityGroup($groupid); if (!$securitygroup) { $this->getOutput()->addWikiMsg('openstackmanager-nonexistantsecuritygroup'); return false; } $group_keys = array('' => ''); $securityGroups = $this->userNova->getSecurityGroups(); foreach ($securityGroups as $securityGroup) { $securityGroupName = $securityGroup->getGroupName(); $group_keys[$securityGroupName] = $securityGroupName; } $securityGroupInfo = array(); $securityGroupInfo['groupid'] = array('type' => 'hidden', 'default' => $groupid, 'name' => 'groupid'); $securityGroupInfo['project'] = array('type' => 'hidden', 'default' => $project, 'section' => 'rule/singlerule', 'name' => 'project'); $securityGroupInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region'); $securityGroupInfo['fromport'] = array('type' => 'text', 'label-message' => 'openstackmanager-securitygrouprule-fromport', 'default' => '', 'section' => 'rule/singlerule', 'name' => 'fromport'); $securityGroupInfo['toport'] = array('type' => 'text', 'label-message' => 'openstackmanager-securitygrouprule-toport', 'default' => '', 'section' => 'rule/singlerule', 'name' => 'toport'); $securityGroupInfo['protocol'] = array('type' => 'select', 'label-message' => 'openstackmanager-securitygrouprule-protocol', 'options' => array('' => '', 'icmp' => 'icmp', 'tcp' => 'tcp', 'udp' => 'udp'), 'section' => 'rule/singlerule', 'name' => 'protocol'); $securityGroupInfo['range'] = array('type' => 'text', 'label-message' => 'openstackmanager-securitygrouprule-ranges', 'help-message' => 'openstackmanager-securitygrouprule-ranges-help', 'default' => '', 'section' => 'rule/singlerule', 'name' => 'range'); $securityGroupInfo['group'] = array('type' => 'select', 'label-message' => 'openstackmanager-securitygrouprule-groups', 'help-message' => 'openstackmanager-securitygrouprule-groups-help', 'options' => $group_keys, 'section' => 'rule/group', 'name' => 'group'); $securityGroupInfo['action'] = array('type' => 'hidden', 'default' => 'addrule', 'name' => 'action'); $securityGroupForm = new HTMLForm($securityGroupInfo, $this->getContext(), 'openstackmanager-novasecuritygroup'); $securityGroupForm->addHeaderText($this->msg('openstackmanager-securitygrouprule-group-exclusive')->text(), 'rule'); $securityGroupForm->setSubmitID('novainstance-form-removerulesubmit'); $securityGroupForm->setSubmitCallback(array($this, 'tryAddRuleSubmit')); $securityGroupForm->show(); return true; }
/** * Customizes the HTMLForm a bit * * @param HTMLForm $form */ protected function alterForm(HTMLForm $form) { $form->setWrapperLegendMsg('blockip-legend'); $form->setHeaderText(''); $form->setSubmitDestructive(); $msg = $this->alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit'; $form->setSubmitTextMsg($msg); $this->addHelpLink('Help:Blocking users'); # Don't need to do anything if the form has been posted if (!$this->getRequest()->wasPosted() && $this->preErrors) { $s = $form->formatErrors($this->preErrors); if ($s) { $form->addHeaderText(Html::rawElement('div', array('class' => 'error'), $s)); } } }
/** * Get the HTMLForm to control behaviour * @return HTMLForm|null */ protected function getForm() { $this->fields = $this->getFormFields(); $form = new HTMLForm($this->fields, $this->getContext()); $form->setSubmitCallback(array($this, 'onSubmit')); $form->setWrapperLegend($this->msg(strtolower($this->getName()) . '-legend')); $form->addHeaderText($this->msg(strtolower($this->getName()) . '-text')->parseAsBlock()); // Retain query parameters (uselang etc) $params = array_diff_key($this->getRequest()->getQueryValues(), array('title' => null)); $form->addHiddenField('redirectparams', wfArrayToCGI($params)); $form->addPreText($this->preText()); $form->addPostText($this->postText()); $this->alterForm($form); // Give hooks a chance to alter the form, adding extra fields or text etc wfRunHooks("Special{$this->getName()}BeforeFormDisplay", array(&$form)); return $form; }
/** * Get the HTMLForm to control behavior * @return HTMLForm|null */ protected function getForm() { $this->fields = $this->getFormFields(); $form = new HTMLForm($this->fields, $this->getContext(), $this->getMessagePrefix()); $form->setSubmitCallback(array($this, 'onSubmit')); // If the form is a compact vertical form, then don't output this ugly // fieldset surrounding it. // XXX Special pages can setDisplayFormat to 'vform' in alterForm(), but that // is called after this. if (!$form->isVForm()) { $form->setWrapperLegendMsg($this->getMessagePrefix() . '-legend'); } $headerMsg = $this->msg($this->getMessagePrefix() . '-text'); if (!$headerMsg->isDisabled()) { $form->addHeaderText($headerMsg->parseAsBlock()); } // Retain query parameters (uselang etc) $params = array_diff_key($this->getRequest()->getQueryValues(), array('title' => null)); $form->addHiddenField('redirectparams', wfArrayToCgi($params)); $form->addPreText($this->preText()); $form->addPostText($this->postText()); $this->alterForm($form); // Give hooks a chance to alter the form, adding extra fields or text etc wfRunHooks('SpecialPageBeforeFormDisplay', array($this->getName(), &$form)); return $form; }
/** * Handle ?action=create * @return bool */ function createInstance() { global $wgOpenStackManagerPuppetOptions; global $wgOpenStackManagerInstanceBannedInstanceTypes; global $wgOpenStackManagerInstanceDefaultImage; $this->setHeaders(); $this->getOutput()->setPagetitle($this->msg('openstackmanager-createinstance')); $project = $this->getRequest()->getText('project'); $region = $this->getRequest()->getText('region'); if (!$this->userLDAP->inRole('projectadmin', $project)) { $this->notInRole('projectadmin', $project); return false; } $instanceInfo = array(); $instanceInfo['instancename'] = array('type' => 'text', 'label-message' => 'openstackmanager-instancename', 'validation-callback' => array($this, 'validateText'), 'default' => '', 'section' => 'info', 'name' => 'instancename'); $instanceTypes = $this->userNova->getInstanceTypes(); $instanceType_keys = array(); foreach ($instanceTypes as $instanceType) { $instanceTypeName = $instanceType->getInstanceTypeName(); if (in_array($instanceTypeName, $wgOpenStackManagerInstanceBannedInstanceTypes)) { continue; } $instanceTypeId = $instanceType->getInstanceTypeId(); $cpus = $instanceType->getNumberOfCPUs(); $ram = $instanceType->getMemorySize(); $root_storage = $instanceType->getRootStorageSize(); $storage = $instanceType->getStorageSize(); // @todo FIXME: Hard coded parentheses. $instanceLabel = $instanceTypeName . ' (' . $this->msg('openstackmanager-instancetypelabel', $cpus, $ram, $root_storage, $storage)->text() . ')'; $instanceType_keys[$instanceLabel] = $instanceTypeId; } $instanceInfo['instanceType'] = array('type' => 'select', 'label-message' => 'openstackmanager-instancetype', 'section' => 'info', 'options' => $instanceType_keys, 'name' => 'instanceType'); $instanceInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region'); # Image names can't be translated. Get the image, and make an array # where the name points to itself as a value $images = $this->userNova->getImages(); $image_keys = array(); $default = ""; foreach ($images as $image) { if ($image->getImageState() !== "ACTIVE") { continue; } $imageName = $image->getImageName(); if ($imageName === '') { continue; } $showImage = $image->getImageMetadata('show'); if (!$showImage) { continue; } $imageLabel = $imageName; $isDefault = $image->getImageMetadata('default'); if ($isDefault) { $default = $imageLabel; } $image_keys[$imageLabel] = $image->getImageId(); } if (isset($image_keys[$default])) { $default = $image_keys[$default]; } $instanceInfo['imageType'] = array('type' => 'select', 'section' => 'info', 'options' => $image_keys, 'default' => $default, 'label-message' => 'openstackmanager-imagetype', 'name' => 'imageType'); # Keypair names can't be translated. Get the keys, and make an array # where the name points to itself as a value # TODO: get keypairs as the user, not the admin # $keypairs = $this->userNova->getKeypairs(); # $keypair_keys = array(); # foreach ( array_keys( $keypairs ) as $keypair_key ) { # $keypair_keys[$keypair_key] = $keypair_key; # } # $instanceInfo['keypair'] = array( # 'type' => 'select', # 'section' => 'info', # 'options' => $keypair_keys, # 'label-message' => 'keypair', # ); #$domains = OpenStackNovaDomain::getAllDomains( 'local' ); #$domain_keys = array(); #foreach ( $domains as $domain ) { # $domainname = $domain->getDomainName(); # $domain_keys[$domainname] = $domainname; #} #$instanceInfo['domain'] = array( # 'type' => 'select', # 'section' => 'info', # 'options' => $domain_keys, # 'label-message' => 'openstackmanager-dnsdomain', # 'name' => 'domain', #); $securityGroups = $this->userNova->getSecurityGroups(); $group_keys = array(); $defaults = array(); foreach ($securityGroups as $securityGroup) { if ($securityGroup->getProject() === $project) { $securityGroupName = $securityGroup->getGroupName(); $group_keys[$securityGroupName] = $securityGroupName; if ($securityGroupName === "default") { $defaults["default"] = "default"; } } } $instanceInfo['groups'] = array('type' => 'multiselect', 'section' => 'info', 'options' => $group_keys, 'default' => $defaults, 'label-message' => 'openstackmanager-securitygroups', 'name' => 'groups'); $instanceInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project'); $instanceInfo['action'] = array('type' => 'hidden', 'default' => 'create', 'name' => 'action'); $instanceForm = new HTMLForm($instanceInfo, $this->getContext(), 'openstackmanager-novainstance'); $instanceForm->addHeaderText($this->msg('openstackmanager-createinstancepuppetwarning')->text() . '<div class="mw-collapsible mw-collapsed">', 'puppetinfo'); $instanceForm->addFooterText('</div>', 'puppetinfo'); $instanceForm->setSubmitID('openstackmanager-novainstance-createinstancesubmit'); $instanceForm->setSubmitCallback(array($this, 'tryCreateSubmit')); $instanceForm->show(); return true; }
protected function alterForm(HTMLForm $form) { $form->setId('mw-changeemail-form'); $form->setTableId('mw-changeemail-table'); $form->setSubmitTextMsg('changeemail-submit'); $form->addHiddenFields($this->getRequest()->getValues('returnto', 'returntoquery')); $form->addHeaderText($this->msg('changeemail-header')->parseAsBlock()); if ($this->getConfig()->get('RequirePasswordforEmailChange')) { $form->addHeaderText($this->msg('changeemail-passwordrequired')->parseAsBlock()); } }
/** * Get a form for editing the watchlist in "raw" mode * * @return HTMLForm */ protected function getRawForm() { $titles = implode($this->getWatchlist(), "\n"); $fields = array('Titles' => array('type' => 'textarea', 'label-message' => 'watchlistedit-raw-titles', 'default' => $titles)); $form = new HTMLForm($fields); $form->setTitle($this->getTitle('raw')); $form->setSubmitText(wfMessage('watchlistedit-raw-submit')->text()); $form->setWrapperLegend(wfMessage('watchlistedit-raw-legend')->text()); $form->addHeaderText(wfMessage('watchlistedit-raw-explain')->parse()); $form->setSubmitCallback(array($this, 'submitRaw')); return $form; }
/** * Add header text inside the form, just underneath where the errors would go * @param $form HTMLForm * @return void */ protected function doHeaderText(HTMLForm &$form) { global $wgRequest; # Don't need to do anything if the form has been posted if (!$wgRequest->wasPosted() && $this->preErrors) { $s = HTMLForm::formatErrors($this->preErrors); if ($s) { $form->addHeaderText(Html::rawElement('div', array('class' => 'error'), $s)); } } }