r111327 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111326‎ | r111327 | r111328 >
Date:21:22, 12 February 2012
Author:wikinaut
Status:deferred (Comments)
Tags:
Comment:
follow-up r111313 . iframes have class= instead of id= . proper use of isset() . Sanitizing the attributes immediately before composing the iframe . rawhtmlencoding the username, so that also spaces arrive as epl usernames. negation of boolean instead of inappropriate negation of string
Modified paths:
  • /trunk/extensions/EtherpadLite/EtherpadLite.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EtherpadLite/EtherpadLite.php
@@ -61,7 +61,7 @@
6262 'path' => __FILE__,
6363 'name' => 'EtherpadLite',
6464 'author' => array( 'Thomas Gries' ),
65 - 'version' => '1.03 20120212',
 65+ 'version' => '1.04 20120212',
6666 'url' => 'https://www.mediawiki.org/wiki/Extension:EtherpadLite',
6767 'descriptionmsg' => 'etherpadlite-desc',
6868 );
@@ -89,10 +89,8 @@
9090 $wgEtherpadLiteShowAuthorColors = true;
9191
9292
93 -function wfEtherpadLiteStringFromTestedBoolean( $var, $default ) {
94 - # http://www.php.net/manual/en/function.is-bool.php#104643
95 - $booleanVar = ( isset( $var ) ) ? filter_var( $var, FILTER_VALIDATE_BOOLEAN ) : $default;
96 - return ( $booleanVar ) ? "true" : "false";
 93+function wfEtherpadLiteStringFromBoolean( $bool ) {
 94+ return ( $bool ) ? "true" : "false";
9795 }
9896
9997 function wfEtherpadLiteRender( $input, $args, $parser, $frame ) {
@@ -109,12 +107,26 @@
110108 $args['height'] = ( isset( $args['height'] ) ) ? $args['height'] : $wgEtherpadLiteDefaultHeight;
111109 $args['width'] = ( isset( $args['width'] ) ) ? $args['width'] : $wgEtherpadLiteDefaultWidth;
112110
113 - $useMonospaceFont = wfEtherpadLiteStringFromTestedBoolean( $args['monospaced-font'], $wgEtherpadLiteMonospacedFont );
114 - $showControls = wfEtherpadLiteStringFromTestedBoolean( $args['show-controls'], $wgEtherpadLiteShowControls ) ;
115 - $showLineNumbers = wfEtherpadLiteStringFromTestedBoolean( $args['show-linenumbers'], $wgEtherpadLiteShowLineNumbers );
116 - $showChat = wfEtherpadLiteStringFromTestedBoolean( $args['show-chat'], $wgEtherpadLiteShowChat );
117 - $noColors = ! ( wfEtherpadLiteStringFromTestedBoolean( $args['show-colors'], $wgEtherpadLiteShowAuthorColors ) );
 111+ $useMonospaceFont = wfEtherpadLiteStringFromBoolean(
 112+ ( ( isset( $args['monospaced-font'] ) ) ? filter_var( $args['monospaced-font'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteMonospacedFont )
 113+ );
118114
 115+ $showControls = wfEtherpadLiteStringFromBoolean(
 116+ ( ( isset( $args['show-controls'] ) ) ? filter_var( $args['show-controls'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowControls )
 117+ );
 118+
 119+ $showLineNumbers = wfEtherpadLiteStringFromBoolean(
 120+ ( ( isset( $args['show-linenumbers'] ) ) ? filter_var( $args['show-linenumbers'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowLineNumbers )
 121+ );
 122+
 123+ $showChat = wfEtherpadLiteStringFromBoolean(
 124+ ( ( isset( $args['show-chat'] ) ) ? filter_var( $args['show-chat'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowChat )
 125+ );
 126+
 127+ $noColors = wfEtherpadLiteStringFromBoolean(
 128+ ! ( ( isset( $args['show-colors'] ) ) ? filter_var( $args['show-colors'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowAuthorColors )
 129+ );
 130+
119131 $args['src'] = Sanitizer::cleanUrl (
120132 ( isset( $args['src'] ) ) ? $args['src'] : $wgEtherpadLiteDefaultPadUrl
121133 );
@@ -126,24 +138,29 @@
127139 # 2. the pad username can currently be overwritten when editing the pad
128140
129141 $parser->disableCache();
130 - $userName = $wgUser->getName();
 142+ $userName = rawurlencode( $wgUser->getName() );
131143
132144 $sanitizedAttributes = Sanitizer::validateAttributes( $args, array ( "width", "height", "id", "src" ) );
133145
134146 $iframeAttributes = array(
135 - "style" => "width:" . $sanitizedAttributes['width'] . ";" .
 147+ "style" => "width:" . $sanitizedAttributes['width'] . ";" .
136148 "height:" . $sanitizedAttributes['height'],
137 - "id" => "eplite-iframe-" . $sanitizedAttributes['id'] ,
138 - "src" => $sanitizedAttributes['src'] . "/" . $sanitizedAttributes['id'] .
139 - "?showControls=$showControls" .
140 - "&showChat=$showChat" .
141 - "&showLineNumbers=$showLineNumbers" .
142 - "&useMonospaceFont=$useMonospaceFont" .
143 - "&userName=$userName" .
144 - "&noColors=$noColors"
145 - );
 149+ "class" => "eplite-iframe-" . $sanitizedAttributes['id'] ,
 150+ "src" => Sanitizer::cleanUrl(
 151+ $sanitizedAttributes['src'] . "/" . $sanitizedAttributes['id'] .
 152+ "?showControls=$showControls" .
 153+ "&showChat=$showChat" .
 154+ "&showLineNumbers=$showLineNumbers" .
 155+ "&useMonospaceFont=$useMonospaceFont" .
 156+ "&noColors=$noColors" .
 157+ "&userName=$userName"
 158+ ),
 159+ );
146160
147 - $output = Html::rawElement( 'iframe', $iframeAttributes );
 161+ $output = Html::rawElement(
 162+ 'iframe',
 163+ Sanitizer::validateAttributes( $iframeAttributes, array ( "style", "class", "src" ) )
 164+ );
148165
149166 wfDebug( "EtherpadLite:wfEtherpadLiteRender $output\n" );
150167 return array( $output );

Follow-up revisions

RevisionCommit summaryAuthorDate
r111412follow-up 111327 . here we got: using wfBoolToStr(), wfAppendUrl, Http::isVal...wikinaut20:22, 13 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111313follow-up r111286 . changed attribute names pad-id to id, pad-url to src. Usi...wikinaut18:53, 12 February 2012

Comments

#Comment by Wikinaut (talk | contribs)   21:24, 12 February 2012

I think, it looks better. Last open issue: the url.

#Comment by 😂 (talk | contribs)   15:24, 13 February 2012

Just use wfBoolToStr() rather than doing it yourself.

Status & tagging log