Nischayn22 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/70027
Change subject: Show a disabled form for users without permissions.
......................................................................
Show a disabled form for users without permissions.
* This is a bit hacky
* How to still show the permissions error but not as an exception
Bug: 36914
Change-Id: I1f65a4bb6eadc0696b8aa8c3b4e8972b299b8db8
---
M includes/specials/SpecialUploadCampaign.php
1 file changed, 39 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/27/70027/1
diff --git a/includes/specials/SpecialUploadCampaign.php
b/includes/specials/SpecialUploadCampaign.php
index f7009e9..e9514bd 100644
--- a/includes/specials/SpecialUploadCampaign.php
+++ b/includes/specials/SpecialUploadCampaign.php
@@ -45,14 +45,34 @@
}
/**
+ * Handles user permissions by disabling fields
+ *
* @see parent::execute
*
* @param string $subPage
*/
public function execute( $subPage ) {
- parent::execute( $subPage );
+ $this->setHeaders();
+ $this->outputHeader();
+ $form = $this->getForm();
+ if ( $form->show() ) {
+ $this->onSuccess();
+ }
$this->getOutput()->addModules( 'ext.uploadWizard.campaign' );
+ }
+
+ /**
+ * Disables HTMLFormFields if use doesn't have permissions
+ *
+ * @param array form fields
+ */
+ protected function checkDisabledFields( &$fields ) {
+ if ( !$this->userCanExecute( $this->getUser() ) ) {
+ foreach( $fields as &$field ) {
+ $field += array( 'disabled' => 'disabled' );
+ }
+ }
}
/**
@@ -62,18 +82,25 @@
protected function getForm() {
$form = parent::getForm();
- $attribs = array(
- 'onclick' => 'window.location="' .
SpecialPage::getTitleFor( 'UploadCampaigns' )->getFullURL() . '";return false;'
- );
+ // If user can't execute don't show submit button else show
cancel button as well
+ // TODO Use a less hacky solution
+ if ( !$this->userCanExecute( $this->getUser() ) ) {
+ $form->suppressDefaultSubmit();
+ } else {
- $attribs += Linker::tooltipAndAccesskeyAttribs(
'cancel-upload-campaign' );
+ $attribs = array(
+ 'onclick' => 'window.location="' .
SpecialPage::getTitleFor( 'UploadCampaigns' )->getFullURL() . '";return false;'
+ );
- $form->addButton(
- 'cancelEdit',
- $this->msg( 'cancel' )->text(),
- 'cancelEdit',
- $attribs
- );
+ $attribs += Linker::tooltipAndAccesskeyAttribs(
'cancel-upload-campaign' );
+
+ $form->addButton(
+ 'cancelEdit',
+ $this->msg( 'cancel' )->text(),
+ 'cancelEdit',
+ $attribs
+ );
+ }
return $form;
}
@@ -110,6 +137,7 @@
$fields[$name] = $data;
}
+ $this->checkDisabledFields( $fields );
return $fields;
}
--
To view, visit https://gerrit.wikimedia.org/r/70027
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f65a4bb6eadc0696b8aa8c3b4e8972b299b8db8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Nischayn22 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits