r111313 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111312‎ | r111313 | r111314 >
Date:18:53, 12 February 2012
Author:wikinaut
Status:deferred (Comments)
Tags:
Comment:
follow-up r111286 . changed attribute names pad-id to id, pad-url to src. Using Sanitizer to sanitize width, height, id, src attributes when composing the iframe. The other boolean attributes are sanitized manually
Modified paths:
  • /trunk/extensions/EtherpadLite/EtherpadLite.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EtherpadLite/EtherpadLite.php
@@ -11,9 +11,10 @@
1212 *
1313 * Usage:
1414 *
15 - * <eplite pad-id="padid" />
16 - * <eplite pad-id="myPseudoSecretPadHash-7ujHvhq06g" />
17 - * <eplite pad-id="padid" height="200px" width="600px" />
 15+ * <eplite id="padid" />
 16+ * <eplite id="myPseudoSecretPadHash-7ujHvhq06g" />
 17+ * <eplite id="padid" height="200px" width="600px" />
 18+ * <eplite id="padid" src="http://www.another-pad-server.org/p/" />
1819 *
1920 * Installation:
2021 *
@@ -49,18 +50,18 @@
5051 *
5152 */
5253
53 -// Check environment
 54+# Check environment
5455 if ( !defined( 'MEDIAWIKI' ) ) {
5556 echo( "This is an extension to MediaWiki and cannot be run standalone.\n" );
5657 die( - 1 );
5758 }
5859
59 -// Credits
 60+# Credits
6061 $wgExtensionCredits['parserhook'][] = array(
6162 'path' => __FILE__,
6263 'name' => 'EtherpadLite',
6364 'author' => array( 'Thomas Gries' ),
64 - 'version' => '1.02 20120212',
 65+ 'version' => '1.03 20120212',
6566 'url' => 'https://www.mediawiki.org/wiki/Extension:EtherpadLite',
6667 'descriptionmsg' => 'etherpadlite-desc',
6768 );
@@ -70,14 +71,14 @@
7172 $wgExtensionMessagesFiles['EtherpadLite'] = $dir . 'EtherpadLite.i18n.php';
7273 $wgHooks['ParserFirstCallInit'][] = 'wfEtherpadLiteParserInit';
7374
74 -// https://www.mediawiki.org/wiki/Manual:Tag_extensions
 75+# https://www.mediawiki.org/wiki/Manual:Tag_extensions
7576 function wfEtherpadLiteParserInit( $parser ) {
7677 $parser->setHook('eplite', 'wfEtherpadLiteRender');
7778 return true;
7879 }
7980
8081 # Define a default Etherpad Lite server Url and base path
81 -# this server is used unless a distinct server is defined by pad-id="..."
 82+# this server is used unless a distinct server is defined by id="..."
8283 $wgEtherpadLiteDefaultPadUrl = "http://www.example.com/p/";
8384 $wgEtherpadLiteDefaultWidth = "300px";
8485 $wgEtherpadLiteDefaultHeight = "200px";
@@ -101,33 +102,39 @@
102103 $wgEtherpadLiteMonospacedFont, $wgEtherpadLiteShowControls, $wgEtherpadLiteShowLineNumbers,
103104 $wgEtherpadLiteShowChat, $wgEtherpadLiteShowAuthorColors;
104105
105 - $padId = ( isset( $args['pad-id'] ) ) ? $args['pad-id'] : "" ;
106 - $height = ( isset( $args['height'] ) ) ? $args['height'] : $wgEtherpadLiteDefaultHeight;
107 - $width = ( isset( $args['width'] ) ) ? $args['width'] : $wgEtherpadLiteDefaultWidth;
 106+ # undefined id= attributes are replaced by id="" and result
 107+ # in Etherpad Lite server showing its entry page - where you can open a new pad.
 108+ $args['id'] = ( isset( $args['id'] ) ) ? $args['id'] : "";
108109
 110+ $args['height'] = ( isset( $args['height'] ) ) ? $args['height'] : $wgEtherpadLiteDefaultHeight;
 111+ $args['width'] = ( isset( $args['width'] ) ) ? $args['width'] : $wgEtherpadLiteDefaultWidth;
 112+
109113 $useMonospaceFont = wfEtherpadLiteStringFromTestedBoolean( $args['monospaced-font'], $wgEtherpadLiteMonospacedFont );
110114 $showControls = wfEtherpadLiteStringFromTestedBoolean( $args['show-controls'], $wgEtherpadLiteShowControls ) ;
111115 $showLineNumbers = wfEtherpadLiteStringFromTestedBoolean( $args['show-linenumbers'], $wgEtherpadLiteShowLineNumbers );
112116 $showChat = wfEtherpadLiteStringFromTestedBoolean( $args['show-chat'], $wgEtherpadLiteShowChat );
113117 $noColors = ! ( wfEtherpadLiteStringFromTestedBoolean( $args['show-colors'], $wgEtherpadLiteShowAuthorColors ) );
114118
115 - $epliteHostUrl = Sanitizer::cleanUrl (
116 - ( isset( $args['pad-url'] ) ) ? $args['pad-url'] : $wgEtherpadLiteDefaultPadUrl
 119+ $args['src'] = Sanitizer::cleanUrl (
 120+ ( isset( $args['src'] ) ) ? $args['src'] : $wgEtherpadLiteDefaultPadUrl
117121 );
118122
119 - // preset the pad username from MediaWiki username or IP
 123+ # preset the pad username from MediaWiki username or IP
120124
121 - // attention:
122 - // 1. we must render the page for each visiting user to get their username
123 - // 2. the pad username can currently be overwritten when editing the pad
 125+ # attention:
 126+ # 1. we must render the page for each visiting user to get their username
 127+ # 2. the pad username can currently be overwritten when editing the pad
124128
125129 $parser->disableCache();
126130 $userName = $wgUser->getName();
127 -
 131+
 132+ $sanitizedAttributes = Sanitizer::validateAttributes( $args, array ( "width", "height", "id", "src" ) );
 133+
128134 $iframeAttributes = array(
129 - "style" => "width:$width;height:$height",
130 - "id" => "epframe$padId",
131 - "src" => "$epliteHostUrl/$padId" .
 135+ "style" => "width:" . $sanitizedAttributes['width'] . ";" .
 136+ "height:" . $sanitizedAttributes['height'],
 137+ "id" => "eplite-iframe-" . $sanitizedAttributes['id'] ,
 138+ "src" => $sanitizedAttributes['src'] . "/" . $sanitizedAttributes['id'] .
132139 "?showControls=$showControls" .
133140 "&showChat=$showChat" .
134141 "&showLineNumbers=$showLineNumbers" .

Follow-up revisions

RevisionCommit summaryAuthorDate
r111327follow-up r111313 . iframes have class= instead of id= . proper use of isset(...wikinaut21:22, 12 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111286there was a SVN post hook erro 8 glithc and revision 111285 disappeared silen...wikinaut08:12, 12 February 2012

Comments

#Comment by Wikinaut (talk | contribs)   19:06, 12 February 2012

In r111313 I fixed (I think) all of the issues mentioned in r111263 .

Let me explain here again:

1. I changed the attribute names from pad-id => id and pad-url => src. This allows to treat (id, src, height, width) as standard attributes and to use

$sanitizedAttributes = Sanitizer::validateAttributes( $args, array ( "width", "height", "id", "src" ) );

for this, and then to use $santizedAttributes['src'] for example.

2. The boolean parameters are manually checked.

Please have a look to r111313 . Documentation https://www.mediawiki.org/wiki/Extension:EtherpadLite has been updated as well.

Status & tagging log