r63377 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63376‎ | r63377 | r63378 >
Date:23:59, 7 March 2010
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
Small improvement to Special:StoryReview permission check and added JS to disable submission button to storysubmission form
Modified paths:
  • /trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storysubmission/storysubmission.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/specials/StoryReview/StoryReview_body.php
@@ -16,20 +16,19 @@
1717 class SpecialStoryReview extends SpecialPage {
1818
1919 public function __construct() {
20 - parent::__construct( 'StoryReview' );
 20+ parent::__construct( 'StoryReview', 'storyreview' );
2121 }
2222
2323 public function execute( $language ) {
2424 wfProfileIn( __METHOD__ );
2525
2626 global $wgUser;
27 - if ( $wgUser->isAllowed( 'storyreview' ) && !$wgUser->isBlocked() ) {
 27+ if( $this->userCanExecute( $wgUser ) ){
2828 // If the user has the storyreview permission and is not blocked, show the regular output.
2929 $this->addOutput();
3030 } else {
3131 // If the user is not authorized, show an error.
32 - global $wgOut;
33 - $wgOut->permissionRequired( 'storyreview' );
 32+ $this->displayRestrictionError();
3433 }
3534
3635 wfProfileOut( __METHOD__ );
Index: trunk/extensions/Storyboard/tags/Storysubmission/Storysubmission_body.php
@@ -25,6 +25,8 @@
2626
2727 global $wgRequest;
2828
 29+ var_dump($wgRequest->wasPosted()); die();
 30+
2931 if ( $wgRequest->wasPosted() ) {
3032 $output = self::doSubmissionAndGetResult();
3133 } else {
@@ -37,7 +39,7 @@
3840 }
3941
4042 private static function getFrom( $parser, $args ) {
41 - global $wgOut, $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen;
 43+ global $wgOut, $wgJsMimeType, $wgSc, $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen;
4244
4345 $wgOut->addStyle( $egStoryboardScriptPath . '/tags/Storysubmission/storysubmission.css' );
4446 $wgOut->addScriptFile( $egStoryboardScriptPath . '/tags/Storysubmission/storysubmission.js' );
@@ -48,7 +50,7 @@
4951 $maxLen = array_key_exists('maxlength', $args) && is_numeric($args['maxlength']) ? $args['maxlength'] : $egStoryboardMaxStoryLen;
5052 $minLen = array_key_exists('minlength', $args) && is_numeric($args['minlength']) ? $args['minlength'] : $egStoryboardMinStoryLen;
5153
52 - $submissionUrl = $parser->getTitle()->getLocalURL( 'action=submit' ); // TODO: fix parameters
 54+ $submissionUrl = $parser->getTitle()->getLocalURL( '' ); // TODO: fix parameters
5355
5456 $formBody = "<table width='$width'>";
5557
@@ -105,7 +107,7 @@
106108
107109 $formBody .= '</table>';
108110
109 - return Html::rawElement(
 111+ $formHtml = Html::rawElement(
110112 'form',
111113 array(
112114 'id' => 'storyform',
@@ -116,6 +118,11 @@
117119 ),
118120 $formBody
119121 );
 122+
 123+ // Disable the submission button when JS is enabled.
 124+ $formJs = "<script type='$wgJsMimeType'>/*<![CDATA[*/ document.getElementById( 'storysubmission-button' ).disabled = true; /*]]>*/</script>";
 125+
 126+ return $formHtml . $formJs;
120127 }
121128
122129 private static function doSubmissionAndGetResult() {
Index: trunk/extensions/Storyboard/tags/Storysubmission/storysubmission.js
@@ -16,7 +16,7 @@
1717 var info = document.getElementById( infodiv );
1818
1919 if(textlength > upperLimit) {
20 - info.innerHTML = 'Your story may not exceed ' + upperLimit + ' characters!'; // TODO: i18n
 20+ info.innerHTML = ( upperLimit - textlength ) + ' characters to many!'; // TODO: i18n
2121 return false;
2222 } else if (textlength < lowerLimit) {
2323 info.innerHTML = '('+ ( lowerLimit - textlength ) + ' more characters needed)'; // TODO: i18n

Follow-up revisions

RevisionCommit summaryAuthorDate
r63391Follow up to r63378 and r63377. Added stuff to storysubmission tag.jeroendedauw14:17, 8 March 2010

Comments

#Comment by Aaron Schulz (talk | contribs)   00:23, 8 March 2010

+ var_dump($wgRequest->wasPosted()); die(); ?

#Comment by Jeroen De Dauw (talk | contribs)   00:26, 8 March 2010

Yeah, debug line I obviously forgot to remove. Gone in r63378

#Comment by Catrope (talk | contribs)   12:37, 8 March 2010
+		global $wgOut, $wgJsMimeType, $wgSc, $egStoryboardScriptPath, $egStorysubmissionWidth, $egStoryboardMaxStoryLen, $egStoryboardMinStoryLen;

$wgSc seems to be a typo.

+		// Disable the submission button when JS is enabled.
+		$formJs = "<script type='$wgJsMimeType'>/*<![CDATA[*/ document.getElementById( 'storysubmission-button' ).disabled = true; /*]]>*/</script>";

Why not just add this to the .js file?

#Comment by Jeroen De Dauw (talk | contribs)   13:04, 8 March 2010

No idea why I pt that global there :)

The JS file is loaded before the button, so I don't want to get a 'nullReferenceException'. Is there any relevant disadvantage to doing it like this?

#Comment by Catrope (talk | contribs)   14:04, 8 March 2010

Put the code in addOnloadHook( function() { your code here } );, which is the wikibits-provided equivalent of jQuery's $(document).ready( function() { ... } );

#Comment by Jeroen De Dauw (talk | contribs)   14:18, 8 March 2010

Oh yeah right - I should have known that, since I already used it several times. Fixed in r63391

Status & tagging log