https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111868

Revision: 111868
Author:   wikinaut
Date:     2012-02-19 15:51:08 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
wrapped into class EtherpadLite. no new features.

Modified Paths:
--------------
    trunk/extensions/EtherpadLite/EtherpadLite.i18n.php
    trunk/extensions/EtherpadLite/EtherpadLite.php

Modified: trunk/extensions/EtherpadLite/EtherpadLite.i18n.php
===================================================================
--- trunk/extensions/EtherpadLite/EtherpadLite.i18n.php 2012-02-19 15:27:18 UTC 
(rev 111867)
+++ trunk/extensions/EtherpadLite/EtherpadLite.i18n.php 2012-02-19 15:51:08 UTC 
(rev 111868)
@@ -16,7 +16,7 @@
        'etherpadlite-invalid-pad-url' => '"$1" is not a valid Etherpad Lite 
URL or pad name.',
        'etherpadlite-url-is-not-whitelisted' => '"$1" is not in the whitelist 
of allowed Etherpad Lite servers. {{PLURAL:$3|$2 is the only allowed server|The 
allowed servers are as follows: $2}}.',
        'etherpadlite-empty-whitelist' => '"$1" is not in the whitelist of 
allowed Etherpad Lite servers. There are no allowed servers in the whitelist.',
-       'etherpadlite-pad-used-more-than-once' => 'The pad "$1" has already 
been used before on this page; you can have many pads on a page, but only if 
they are different pads.', 
+       'etherpadlite-pad-used-more-than-once' => 'The pad "$1" has already 
been used before on this page; you can have many pads on a page, but only if 
they are different pads.',
 );
 
 /** Message documentation (Message documentation) */

Modified: trunk/extensions/EtherpadLite/EtherpadLite.php
===================================================================
--- trunk/extensions/EtherpadLite/EtherpadLite.php      2012-02-19 15:27:18 UTC 
(rev 111867)
+++ trunk/extensions/EtherpadLite/EtherpadLite.php      2012-02-19 15:51:08 UTC 
(rev 111868)
@@ -64,7 +64,7 @@
        'path' => __FILE__,
        'name' => 'EtherpadLite',
        'author' => array( 'Thomas Gries' ),
-       'version' => '1.09 20120218',
+       'version' => '1.10 20120219',
        'url' => 'https://www.mediawiki.org/wiki/Extension:EtherpadLite',
        'descriptionmsg' => 'etherpadlite-desc',
 );
@@ -72,192 +72,212 @@
 $dir = dirname( __FILE__ ) . '/';
 
 $wgExtensionMessagesFiles['EtherpadLite'] = $dir . 'EtherpadLite.i18n.php';
-$wgHooks['ParserFirstCallInit'][] = 'wfEtherpadLiteParserInit';
+$wgHooks['ParserFirstCallInit'][] = 'EtherpadLite::EtherpadLiteParserInit';
 
-# Define a default Etherpad Lite server Url and base path
-# this server is used unless a distinct server is defined by id="..."
-$wgEtherpadLiteDefaultPadUrl    = "http://beta.etherpad.org/p/";;
-$wgEtherpadLiteDefaultWidth     = "300px";
-$wgEtherpadLiteDefaultHeight    = "200px";
-$wgEtherpadLiteMonospacedFont   = false;
-$wgEtherpadLiteShowControls     = true;
-$wgEtherpadLiteShowLineNumbers  = true;
-$wgEtherpadLiteShowChat         = true;
-$wgEtherpadLiteShowAuthorColors = true;
+class EtherpadLite {
 
-# Whitelist of allowed Etherpad Lite server Urls
-#
-# If there are items in the array, and the user supplied URL is not in the 
array,
-# the url will not be allowed (proposed in bug 27768 for Extension:RSS)
-# Attention: 
-# Urls are case-sensitively tested against values in the array. 
-# They must exactly match including any trailing "/" character.
-#
-# Warning: Allowing all urls (not setting a whitelist)
-# may be a security concern.
-#
-# an empty or non-existent array means: no whitelist defined
-# this is the default: an empty whitelist. No servers are allowed by default.
-$wgEtherpadLiteUrlWhitelist = array();
-#
-# include "*" if you expressly want to allow all urls (you should not do this)
-# $wgEtherpadLiteUrlWhitelist = array( "*" );
+       # Define a default Etherpad Lite server Url and base path
+       # this server is used unless a distinct server is defined by id="..."
+       public $wgEtherpadLiteDefaultPadUrl    = "http://beta.etherpad.org/p/";;
 
-# https://www.mediawiki.org/wiki/Manual:Tag_extensions
-function wfEtherpadLiteParserInit( $parser ) {
-       global $wgEtherpadLitePadsOnThisPage;
-       $wgEtherpadLitePadsOnThisPage = array();
-       $parser->setHook('eplite', 'wfEtherpadLiteRender');
-       return true;
-}
+       public $wgEtherpadLiteDefaultWidth     = "300px";
+       public $wgEtherpadLiteDefaultHeight    = "200px";
+       public $wgEtherpadLiteMonospacedFont   = false;
+       public $wgEtherpadLiteShowControls     = true;
+       public $wgEtherpadLiteShowLineNumbers  = true;
+       public $wgEtherpadLiteShowChat         = true;
+       public $wgEtherpadLiteShowAuthorColors = true;
 
-function wfEtherpadLiteRender( $input, $args, $parser, $frame ) {
+       # Whitelist of allowed Etherpad Lite server Urls
+       #
+       # If there are items in the array, and the user supplied URL is not in 
the array,
+       # the url will not be allowed (proposed in bug 27768 for Extension:RSS)
+       # Attention: 
+       # Urls are case-sensitively tested against values in the array. 
+       # They must exactly match including any trailing "/" character.
+       #
+       # Warning: Allowing all urls (not setting a whitelist)
+       # may be a security concern.
+       #
+       # an empty or non-existent array means: no whitelist defined
+       # this is the default: an empty whitelist. No servers are allowed by 
default.
 
-       global $wgUser;
-       global $wgEtherpadLiteDefaultPadUrl, $wgEtherpadLiteDefaultWidth, 
$wgEtherpadLiteDefaultHeight,
-               $wgEtherpadLiteMonospacedFont, $wgEtherpadLiteShowControls, 
$wgEtherpadLiteShowLineNumbers,
-               $wgEtherpadLiteShowChat, $wgEtherpadLiteShowAuthorColors, 
$wgEtherpadLiteUrlWhitelist,
-               $wgEtherpadLitePadsOnThisPage;
+       public $wgEtherpadLiteUrlWhitelist = array();
+       
+       # include "*" if you expressly want to allow all urls (you should not 
do this)
+       # $wgEtherpadLiteUrlWhitelist = array( "*" );
 
-       # check the user input
+       /**
+        * Tell the parser how to handle <eplite> elements
+        * https://www.mediawiki.org/wiki/Manual:Tag_extensions
+        * @param $parser Parser Object
+        */
+       static function EtherpadLiteParserInit( $parser ) {
 
-       # undefined id= attributes are replaced by id="" and result
-       # in Etherpad Lite server showing its entry page - where you can open a 
new pad.
-       $args['id']       = ( isset( $args['id'] ) ) ? $args['id'] : "";
+               global $wgEtherpadLitePadsOnThisPage;
 
-       $args['height']   = ( isset( $args['height'] ) ) ? $args['height'] : 
$wgEtherpadLiteDefaultHeight;
-       $args['width']    = ( isset( $args['width'] ) ) ? $args['width'] : 
$wgEtherpadLiteDefaultWidth;
+               $wgEtherpadLitePadsOnThisPage = array();
+               $parser->setHook( 'eplite', array( __CLASS__, 
'EtherpadLiteRender' ) );
+
+               return true;
+
+       }
+
+       static function EtherpadLiteRender( $input, $args, $parser, $frame ) {
+
+               global $wgUser;
+               global $wgEtherpadLiteDefaultPadUrl, 
$wgEtherpadLiteDefaultWidth, $wgEtherpadLiteDefaultHeight,
+                       $wgEtherpadLiteMonospacedFont, 
$wgEtherpadLiteShowControls, $wgEtherpadLiteShowLineNumbers,
+                       $wgEtherpadLiteShowChat, 
$wgEtherpadLiteShowAuthorColors, $wgEtherpadLiteUrlWhitelist,
+                       $wgEtherpadLitePadsOnThisPage;
+
+               # check the user input
+
+               # undefined id= attributes are replaced by id="" and result
+               # in Etherpad Lite server showing its entry page - where you 
can open a new pad.
+               $args['id']       = ( isset( $args['id'] ) ) ? $args['id'] : "";
+
+               $args['height']   = ( isset( $args['height'] ) ) ? 
$args['height'] : $wgEtherpadLiteDefaultHeight;
+               $args['width']    = ( isset( $args['width'] ) ) ? 
$args['width'] : $wgEtherpadLiteDefaultWidth;
        
-       $useMonospaceFont = wfBoolToStr(
-               ( ( isset( $args['monospaced-font'] ) ) ? filter_var( 
$args['monospaced-font'], FILTER_VALIDATE_BOOLEAN ) : 
$wgEtherpadLiteMonospacedFont )
-       );
+               $useMonospaceFont = wfBoolToStr(
+                       ( ( isset( $args['monospaced-font'] ) ) ? filter_var( 
$args['monospaced-font'], FILTER_VALIDATE_BOOLEAN ) : 
$wgEtherpadLiteMonospacedFont )
+               );
 
-       $showControls = wfBoolToStr(
-               ( ( isset( $args['show-controls'] ) ) ? filter_var( 
$args['show-controls'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowControls 
)
-       );
+               $showControls = wfBoolToStr(
+                       ( ( isset( $args['show-controls'] ) ) ? filter_var( 
$args['show-controls'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowControls 
)
+               );
 
-       $showLineNumbers = wfBoolToStr(
-               ( ( isset( $args['show-linenumbers'] ) ) ? filter_var( 
$args['show-linenumbers'], FILTER_VALIDATE_BOOLEAN ) : 
$wgEtherpadLiteShowLineNumbers )
-       );
+               $showLineNumbers = wfBoolToStr(
+                       ( ( isset( $args['show-linenumbers'] ) ) ? filter_var( 
$args['show-linenumbers'], FILTER_VALIDATE_BOOLEAN ) : 
$wgEtherpadLiteShowLineNumbers )
+               );
                        
-       $showChat = wfBoolToStr(
-               ( ( isset( $args['show-chat'] ) ) ? filter_var( 
$args['show-chat'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowChat )
-       );
+               $showChat = wfBoolToStr(
+                       ( ( isset( $args['show-chat'] ) ) ? filter_var( 
$args['show-chat'], FILTER_VALIDATE_BOOLEAN ) : $wgEtherpadLiteShowChat )
+               );
        
-       $noColors = wfBoolToStr(
-               ! ( ( isset( $args['show-colors'] ) ) ? filter_var( 
$args['show-colors'], FILTER_VALIDATE_BOOLEAN ) : 
$wgEtherpadLiteShowAuthorColors )
-       );
+               $noColors = wfBoolToStr(
+                       ! ( ( isset( $args['show-colors'] ) ) ? filter_var( 
$args['show-colors'], FILTER_VALIDATE_BOOLEAN ) : 
$wgEtherpadLiteShowAuthorColors )
+               );
 
-       # src= is the pad server base url and is user input in <eplite src= > 
tag from MediaWiki page
-       # id=  is the pad name (also known as pad id) and is user input in 
<eplite id=  > tag from MediaWiki page
+               # src= is the pad server base url and is user input in <eplite 
src= > tag from MediaWiki page
+               # id=  is the pad name (also known as pad id) and is user input 
in <eplite id=  > tag from MediaWiki page
        
-       $src = ( isset( $args['src'] ) ) ? $args['src'] : 
$wgEtherpadLiteDefaultPadUrl;
-       # Sanitizer::cleanUrl just does some normalization, somewhat not needed.
-       $src = Sanitizer::cleanUrl( $src );
+               $src = ( isset( $args['src'] ) ) ? $args['src'] : 
$wgEtherpadLiteDefaultPadUrl;
+               # Sanitizer::cleanUrl just does some normalization, somewhat 
not needed.
+               $src = Sanitizer::cleanUrl( $src );
        
-       switch ( true ) {
+               switch ( true ) {
        
-       # disallow because there is no whitelist or emtpy whitelist
-       case ( !isset( $wgEtherpadLiteUrlWhitelist ) 
-               || !is_array( $wgEtherpadLiteUrlWhitelist )
-               || ( count( $wgEtherpadLiteUrlWhitelist ) === 0 ) ):
-               return wfEtherpadLiteError( 'etherpadlite-empty-whitelist',
-                       $src
-               );
-               break;
+               # disallow because there is no whitelist or emtpy whitelist
+               case ( !isset( $wgEtherpadLiteUrlWhitelist ) 
+                       || !is_array( $wgEtherpadLiteUrlWhitelist )
+                       || ( count( $wgEtherpadLiteUrlWhitelist ) === 0 ) ):
+                       return EtherpadLite::EtherpadLiteError( 
'etherpadlite-empty-whitelist',
+                               $src
+                       );
+                       break;
 
-       # allow
-       case ( in_array( "*", $wgEtherpadLiteUrlWhitelist ) ):
-       case ( in_array( $src, $wgEtherpadLiteUrlWhitelist ) ):
-               break;
+               # allow
+               case ( in_array( "*", $wgEtherpadLiteUrlWhitelist ) ):
+               case ( in_array( $src, $wgEtherpadLiteUrlWhitelist ) ):
+                       break;
 
-       # otherwise disallow
-       case ( !in_array( $src, $wgEtherpadLiteUrlWhitelist ) ):
-       default:
-               $listOfAllowed = $parser->getFunctionLang()->listToText( 
$wgEtherpadLiteUrlWhitelist );
-               $numberAllowed = $parser->getFunctionLang()->formatNum( count( 
$wgEtherpadLiteUrlWhitelist ) );
-               return wfEtherpadLiteError( 
'etherpadlite-url-is-not-whitelisted',
-                       array( $src, $listOfAllowed, $numberAllowed )
-               );
-       }
+               # otherwise disallow
+               case ( !in_array( $src, $wgEtherpadLiteUrlWhitelist ) ):
+               default:
+                       $listOfAllowed = 
$parser->getFunctionLang()->listToText( $wgEtherpadLiteUrlWhitelist );
+                       $numberAllowed = $parser->getFunctionLang()->formatNum( 
count( $wgEtherpadLiteUrlWhitelist ) );
+                       return EtherpadLite::EtherpadLiteError( 
'etherpadlite-url-is-not-whitelisted',
+                               array( $src, $listOfAllowed, $numberAllowed )
+                       );
+               }
 
-       # Append the id to end of url. Strip off trailing / if present before 
appending one.
-       $url = preg_replace( "/\/+$/", "", $src ) . "/" . $args['id'];
+               # Append the id to end of url. Strip off trailing / if present 
before appending one.
+               $url = preg_replace( "/\/+$/", "", $src ) . "/" . $args['id'];
 
-       # prevent multiple iframes and rendering of a same pad on a page
-       # show an error message if a pad is found more than once on a page.
-       #
-       # the empty id however may be used more than once as the empty id 
invokes an
-       # Etherpad Lite server showing its "create a pad" html page.
+               # prevent multiple iframes and rendering of a same pad on a page
+               # show an error message if a pad is found more than once on a 
page.
+               #
+               # the empty id however may be used more than once as the empty 
id invokes an
+               # Etherpad Lite server showing its "create a pad" html page.
 
-       if ( !in_array( $url, $wgEtherpadLitePadsOnThisPage ) ) {
-               $wgEtherpadLitePadsOnThisPage[] = $url;
-       } elseif ( $args['id'] !== "" ) {
-               return wfEtherpadLiteError( 
'etherpadlite-pad-used-more-than-once', $url );
-       }
+               if ( !in_array( $url, $wgEtherpadLitePadsOnThisPage ) ) {
+                       $wgEtherpadLitePadsOnThisPage[] = $url;
+               } elseif ( $args['id'] !== "" ) {
+                       return EtherpadLite::EtherpadLiteError( 
'etherpadlite-pad-used-more-than-once', $url );
+               }
 
        
-       # preset the pad username from MediaWiki username or IP
-       # this not strict, as the pad username can be overwritten in the pad
-       #
-       # attention: 
-       # 1. we must render the page for each visiting user to get their 
username
-       # 2. the pad username can currently be overwritten when editing the pad
-       #
-       # Future todo might be to make the adding of username optional
-       # since disabling of cache has a significant performance impact
-       # on larger sites.
+               # preset the pad username from MediaWiki username or IP
+               # this not strict, as the pad username can be overwritten in 
the pad
+               #
+               # attention: 
+               # 1. we must render the page for each visiting user to get 
their username
+               # 2. the pad username can currently be overwritten when editing 
the pad
+               #
+               # Future todo might be to make the adding of username optional
+               # since disabling of cache has a significant performance impact
+               # on larger sites.
 
-       $parser->disableCache();
+               $parser->disableCache();
 
-       # Etherpad Lite requires rawurlencoded userName, thus we must add it 
manually
+               # Etherpad Lite requires rawurlencoded userName, thus we must 
add it manually
        
-       $url = wfAppendQuery( $url, array(
-                       "showControls"     => $showControls,
-                       "showChat"         => $showChat,
-                       "showLineNumbers"  => $showLineNumbers,
-                       "useMonospaceFont" => $useMonospaceFont,
-                       "noColors"         => $noColors,
-               )
-       ) . "&userName=" . rawurlencode( $wgUser->getName() );
+               $url = wfAppendQuery( $url, array(
+                               "showControls"     => $showControls,
+                               "showChat"         => $showChat,
+                               "showLineNumbers"  => $showLineNumbers,
+                               "useMonospaceFont" => $useMonospaceFont,
+                               "noColors"         => $noColors,
+                       )
+               ) . "&userName=" . rawurlencode( $wgUser->getName() );
 
-       # @todo One could potentially stuff other css in the width argument
-       # since ; isn't checked for. Since overall css is checked for allowed
-       # rules, this isn't super big deal.
-       $iframeAttributes = array(
-               "style" => "width:" . $args['width'] . ";" .
-                       "height:" . $args['height'],
-               "class" => "eplite-iframe-" . $args['id'] ,
-               "src"   => Sanitizer::cleanUrl( $url ),
-       );
+               # @todo One could potentially stuff other css in the width 
argument
+               # since ; isn't checked for. Since overall css is checked for 
allowed
+               # rules, this isn't super big deal.
+               $iframeAttributes = array(
+                       "style" => "width:" . $args['width'] . ";" .
+                               "height:" . $args['height'],
+                       "class" => "eplite-iframe-" . $args['id'] ,
+                       "src"   => Sanitizer::cleanUrl( $url ),
+               );
 
-       $sanitizedAttributes = Sanitizer::validateAttributes( 
$iframeAttributes, array ( "style", "class", "src" ) );
+               $sanitizedAttributes = Sanitizer::validateAttributes( 
$iframeAttributes, array ( "style", "class", "src" ) );
 
-       if ( !isset( $sanitizedAttributes['src'] ) ) {
-               // The Sanitizer decided that the src attribute was no good.
-               // (aka used a protocol that isn't in the whitelist)
-               return wfEtherpadLiteError( 'etherpadlite-invalid-pad-url', 
$src );     
+               if ( !isset( $sanitizedAttributes['src'] ) ) {
+                       // The Sanitizer decided that the src attribute was no 
good.
+                       // (aka used a protocol that isn't in the whitelist)
+                       return EtherpadLite::EtherpadLiteError( 
'etherpadlite-invalid-pad-url', $src ); 
+               }
+
+               $output = Html::rawElement(
+                       'iframe', 
+                       $sanitizedAttributes
+               );
+
+               wfDebug( "EtherpadLite::EtherpadLiteRender $output\n" );
+
+               return $output;
+
        }
 
-       $output = Html::rawElement(
-               'iframe', 
-               $sanitizedAttributes
-       );
+       /**
+       * Output an error message, all wraped up nicely.
+       * @param String $errorName The system message that this error is
+       * @param String|Array $param Error parameter (or parameters)
+       * @return String Html that is the error.
+       */
+       private static function EtherpadLiteError( $errorName, $param ) {
 
-       wfDebug( "EtherpadLite:wfEtherpadLiteRender $output\n" );
-       return $output;
-}
-/**
- * Output an error message, all wraped up nicely.
- * @param String $errorName The system message that this error is
- * @param String|Array $param Error parameter (or parameters)
- * @return String Html that is the error.
- */
-function wfEtherpadLiteError( $errorName, $param ) {
-       // Anything from a parser tag should use Content lang for message,
-       // since the cache doesn't vary by user language: do not use 
wfMsgForContent but wfMsgForContent
-       // The ->parse() part makes everything safe from an escaping standpoint.
-       return Html::rawElement( 'span', array( 'class' => 'error' ),
-               wfMessage( $errorName )->inContentLanguage()->params( $param 
)->parse()
-       );
-}
+               // Anything from a parser tag should use Content lang for 
message,
+               // since the cache doesn't vary by user language: do not use 
wfMsgForContent but wfMsgForContent
+               // The ->parse() part makes everything safe from an escaping 
standpoint.
+
+               return Html::rawElement( 'span', array( 'class' => 'error' ),
+                       wfMessage( $errorName )->inContentLanguage()->params( 
$param )->parse()
+               );
+
+       }
+
+} /* class EtherpadLite */


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to