Rahul21 has uploaded a new change for review. https://gerrit.wikimedia.org/r/81503
Change subject: Added upload permissions for accessing Special:PronunciationRecording ...................................................................... Added upload permissions for accessing Special:PronunciationRecording * It checks whether a particular user is blocked, logged in and if he/her has upload permissions. Bug: 53293 Change-Id: Ic368b08f2f361f3c83c63fd7af804485b1b2953e --- M PronunciationRecording.i18n.php M SpecialPronunciationRecording.php 2 files changed, 61 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PronunciationRecording refs/changes/03/81503/1 diff --git a/PronunciationRecording.i18n.php b/PronunciationRecording.i18n.php index 318122b..3d963b9 100644 --- a/PronunciationRecording.i18n.php +++ b/PronunciationRecording.i18n.php @@ -20,6 +20,7 @@ 'pronunciationrecording-toolbar-clear-label' => 'Clear', 'pronunciationrecording-toolbar-upload-label' => 'Upload', 'pronunciationrecording-webaudio-not-supported' => 'WebAudio API is not supported for this browser', + 'pronunciationrecording-specialpage-error-nologin' => 'You must be <span class="plainlinks">[{{fullurl:{{#Special:UserLogin}}|returnto=$1}} logged in]</span> to record and upload pronunciations.', ); $messages['qqq'] = array( @@ -31,6 +32,7 @@ 'pronunciationrecording-toolbar-clear-label' => 'Label text for the button to clear the recording', 'pronunciationrecording-toolbar-upload-label' => 'Label text for the button to upload the recording', 'pronunciationrecording-webaudio-not-supported' => 'Used as an error message when the WebAudio API is not supported by the browser', + 'pronunciationrecording-specialpage-error-nologin' => 'Error shown when user is not logged in' ); diff --git a/SpecialPronunciationRecording.php b/SpecialPronunciationRecording.php index 957cd62..a3908a8 100644 --- a/SpecialPronunciationRecording.php +++ b/SpecialPronunciationRecording.php @@ -6,6 +6,9 @@ } function execute( $par ) { + if ( !( $this->isUploadAllowed() && $this->isUserUploadAllowed( $this->getUser() ) ) ) { + return; + } $request = $this->getRequest(); $output = $this->getOutput(); $this->setHeaders(); @@ -20,5 +23,61 @@ $output->addHTML( '<div class="mw-pronunciationrecording-preview-div" id="mw-pronunciationrecording-preview-div" disabled ></div>' ); $output->addHTML( '</div>' ); } + + private function isUploadAllowed() { + // Check uploading enabled + if ( !UploadBase::isEnabled() ) { + $this->getOutput()->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' ); + return false; + } + + // XXX does wgEnableAPI affect all uploads too? + + // Check whether we actually want to allow changing stuff + if ( wfReadOnly() ) { + $this->getOutput()->readOnlyPage(); + return false; + } + + // we got all the way here, so it must be okay to upload + return true; + } + + /** + * Check if the user can upload + * Side effect: will print error page to wgOut if cannot upload. + * @param User + * @return boolean -- true if can upload + */ + private function isUserUploadAllowed( $user ) { + global $wgGroupPermissions; + + if ( !$user->isAllowed( 'upload' ) ) { + if ( !$user->isLoggedIn() && ( $wgGroupPermissions['user']['upload']|| $wgGroupPermissions['autoconfirmed']['upload'] ) ) { + // Custom message if logged-in users without any special rights can upload + $returnstr = $this->getTitle(); + $values = $this->getRequest()->getValues(); + if ( isset( $values['title'] ) ) { + unset( $values['title'] ); + } + $rtq = wfArrayToCgi( $values ); + if ( $rtq && $rtq != '' ) { + $returnstr .= '&returntoquery=' . urlencode($rtq); + } + $this->getOutput()->showErrorPage( 'uploadnologin', 'pronunciationrecording-specialpage-error-nologin', $returnstr ); + } else { + throw new PermissionsError( 'upload' ); + } + return false; + } + + // Check blocks + if ( $user->isBlocked() ) { + throw new UserBlockedError( $this->getUser()->mBlock ); + } + + // we got all the way here, so it must be okay to upload + return true; + } } -- To view, visit https://gerrit.wikimedia.org/r/81503 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic368b08f2f361f3c83c63fd7af804485b1b2953e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PronunciationRecording Gerrit-Branch: master Gerrit-Owner: Rahul21 <rahul14...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits