r76518 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76517‎ | r76518 | r76519 >
Date:15:33, 11 November 2010
Author:raymond
Status:ok (Comments)
Tags:
Comment:
Whitespace tweaks, coding styles etc. No functional changes
Modified paths:
  • /trunk/extensions/HTMLets/HTMLets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/HTMLets/HTMLets.php
@@ -31,21 +31,21 @@
3232 /**
3333 * Pass file content unchanged. May get mangeled by late server pass.
3434 **/
35 -define('HTMLETS_NO_HACK', 'none');
 35+define( 'HTMLETS_NO_HACK', 'none' );
3636
3737 /**
3838 * Normalize whitespace, apply special stripping and escaping to avoid mangeling.
3939 * This will break pre-formated text (pre tags), and may interfere with JavaScript
4040 * code under some circumstances.
4141 **/
42 -define('HTMLETS_STRIP_HACK', 'strip');
 42+define( 'HTMLETS_STRIP_HACK', 'strip' );
4343
4444 /**
4545 * bypass late parser pass using ParserAfterTidy.
4646 * This will get the file content safely into the final HTML.
4747 * There's no obvious trouble with it, but it just might interfere with other extensions.
4848 **/
49 -define('HTMLETS_BYPASS_HACK', 'bypass');
 49+define( 'HTMLETS_BYPASS_HACK', 'bypass' );
5050
5151 $wgHTMLetsHack = HTMLETS_BYPASS_HACK; #hack to use to work around bug #8997. see constant declarations.
5252
@@ -54,73 +54,88 @@
5555 $wgExtensionFunctions[] = "wfHTMLetsExtension";
5656
5757 function wfHTMLetsExtension() {
58 - global $wgParser;
59 - $wgParser->setHook( "htmlet", "wfRenderHTMLet" );
 58+ global $wgParser;
 59+ $wgParser->setHook( "htmlet", "wfRenderHTMLet" );
6060 }
6161
6262 # The callback function for converting the input text to HTML output
6363 function wfRenderHTMLet( $name, $argv, $parser ) {
64 - global $wgHTMLetsDirectory, $wgHTMLetsHack, $IP;
 64+ global $wgHTMLetsDirectory, $wgHTMLetsHack, $IP;
6565
66 - if (@$argv['nocache']) $parser->disableCache();
 66+ if ( @$argv['nocache'] ) {
 67+ $parser->disableCache();
 68+ }
6769
68 - #HACKs for bug 8997
69 - $hack = @$argv['hack'];
70 - if ( $hack == 'strip' ) $hack = HTMLETS_STRIP_HACK;
71 - else if ( $hack == 'bypass' ) $hack = HTMLETS_BYPASS_HACK;
72 - else if ( $hack == 'none' || $hack == 'no' ) $hack = HTMLETS_NO_HACK;
73 - else $hack = $wgHTMLetsHack;
 70+ #HACKs for bug 8997
 71+ $hack = @$argv['hack'];
 72+ if ( $hack == 'strip' ) {
 73+ $hack = HTMLETS_STRIP_HACK;
 74+ } elseif ( $hack == 'bypass' ) {
 75+ $hack = HTMLETS_BYPASS_HACK;
 76+ } else if ( $hack == 'none' || $hack == 'no' ) {
 77+ $hack = HTMLETS_NO_HACK;
 78+ } else {
 79+ $hack = $wgHTMLetsHack;
 80+ }
7481
75 - $dir = $wgHTMLetsDirectory;
76 - if (!$dir) $dir = "$IP/htmlets";
 82+ $dir = $wgHTMLetsDirectory;
 83+ if ( !$dir ) {
 84+ $dir = "$IP/htmlets";
 85+ }
7786
78 - $name = preg_replace('@[\\\\/!]|^\.+?&#@', '', $name); #strip path separators and leading dots.
79 - $name .= '.html'; #append html ending, for added security and conveniance
 87+ $name = preg_replace( '@[\\\\/!]|^\.+?&#@', '', $name ); #strip path separators and leading dots.
 88+ $name .= '.html'; #append html ending, for added security and conveniance
8089
81 - $f = "$dir/$name";
 90+ $f = "$dir/$name";
8291
83 - if (!preg_match('!^\w+://!', $dir) && !file_exists($f)) {
84 - $output = '<div class="error">Can\'t find html file '.htmlspecialchars($name).'</div>';
85 - }
86 - else {
87 - $output = file_get_contents($f);
88 - if ($output === false) $output = '<div class="error">Failed to load html file '.htmlspecialchars($name).'</div>';
89 - }
 92+ if ( !preg_match('!^\w+://!', $dir ) && !file_exists( $f ) ) {
 93+ $output = '<div class="error">Can\'t find html file ' . htmlspecialchars( $name ) . '</div>';
 94+ } else {
 95+ $output = file_get_contents( $f );
 96+ if ( $output === false ) {
 97+ $output = '<div class="error">Failed to load html file ' . htmlspecialchars( $name ) . '</div>';
 98+ }
 99+ }
90100
91 - #HACKs for bug 8997
92 - if ( $hack == HTMLETS_STRIP_HACK ) {
93 - $output = trim( preg_replace( '![\r\n\t ]+!', ' ', $output ) ); //normalize whitespace
94 - $output = preg_replace( '!(.) *:!', '\1:', $output ); //strip blanks before colons
 101+ #HACKs for bug 8997
 102+ if ( $hack == HTMLETS_STRIP_HACK ) {
 103+ $output = trim( preg_replace( '![\r\n\t ]+!', ' ', $output ) ); //normalize whitespace
 104+ $output = preg_replace( '!(.) *:!', '\1:', $output ); //strip blanks before colons
95105
96 - if ( strlen($output) > 0 ) { //escape first char if it may trigger wiki formatting
97 - $ch = substr( $output, 0, 1);
 106+ if ( strlen( $output ) > 0 ) { //escape first char if it may trigger wiki formatting
 107+ $ch = substr( $output, 0, 1 );
98108
99 - if ( $ch == '#' ) $output = '&#35;' . substr( $output, 1);
100 - else if ( $ch == '*' ) $output = '&#42;' . substr( $output, 1);
101 - else if ( $ch == ':' ) $output = '&#58;' . substr( $output, 1);
102 - else if ( $ch == ';' ) $output = '&#59;' . substr( $output, 1);
103 - }
104 - }
105 - else if ( $hack == HTMLETS_BYPASS_HACK ) {
106 - global $wgHooks;
 109+ if ( $ch == '#' ) {
 110+ $output = '&#35;' . substr( $output, 1 );
 111+ } elseif ( $ch == '*' ) {
 112+ $output = '&#42;' . substr( $output, 1 );
 113+ } elseif ( $ch == ':' ) {
 114+ $output = '&#58;' . substr( $output, 1 );
 115+ } elseif ( $ch == ';' ) {
 116+ $output = '&#59;' . substr( $output, 1 );
 117+ }
 118+ }
 119+ }
 120+ elseif ( $hack == HTMLETS_BYPASS_HACK ) {
 121+ global $wgHooks;
107122
108 - if ( !isset($wgHooks['ParserAfterTidy']) || !in_array('wfRenderHTMLetHackPostProcess', $wgHooks['ParserAfterTidy']) ) {
109 - $wgHooks['ParserAfterTidy'][] = 'wfRenderHTMLetHackPostProcess';
110 - }
 123+ if ( !isset($wgHooks['ParserAfterTidy']) || !in_array('wfRenderHTMLetHackPostProcess', $wgHooks['ParserAfterTidy']) ) {
 124+ $wgHooks['ParserAfterTidy'][] = 'wfRenderHTMLetHackPostProcess';
 125+ }
111126
112 - $output = '<!-- @HTMLetsHACK@ '.base64_encode($output).' @HTMLetsHACK@ -->';
113 - }
 127+ $output = '<!-- @HTMLetsHACK@ '.base64_encode($output).' @HTMLetsHACK@ -->';
 128+ }
114129
115 - return $output;
 130+ return $output;
116131 }
117132
118133 function wfRenderHTMLetHackPostProcess( $parser, &$text ) {
119 - $text = preg_replace(
120 - '/<!-- @HTMLetsHACK@ ([0-9a-zA-Z\\+\\/]+=*) @HTMLetsHACK@ -->/esm',
121 - 'base64_decode("$1")',
122 - $text
123 - );
 134+ $text = preg_replace(
 135+ '/<!-- @HTMLetsHACK@ ([0-9a-zA-Z\\+\\/]+=*) @HTMLetsHACK@ -->/esm',
 136+ 'base64_decode("$1")',
 137+ $text
 138+ );
124139
125 - return true;
 140+ return true;
126141 }
127142

Comments

#Comment by Nikerabbit (talk | contribs)   17:14, 11 November 2010

+ global $wgParser;

+       $wgParser->setHook( "htmlet", "wfRenderHTMLet" );

Yuck, weren't these killed eons ago?

#Comment by Siebrand (talk | contribs)   16:31, 8 March 2011

Still requires follow-up?

#Comment by Nikerabbit (talk | contribs)   16:43, 8 March 2011

Looks to be an unmaintained extensions.

#Comment by Nikerabbit (talk | contribs)   16:44, 8 March 2011

Perhaps should be dropped from twn at least?

#Comment by Raymond (talk | contribs)   18:37, 8 March 2011

No, it's used at least on a lot of wikis I maintain.

#Comment by Nikerabbit (talk | contribs)   18:45, 8 March 2011

But with the current it will just bitrot until some nice day it breaks.

#Comment by Siebrand (talk | contribs)   18:48, 8 March 2011

Being unmaintained is currently not part of the criteria to no longer be included in Translate or supported on translatewiki.net. If it's in svn and has any decent i18n, it's just added. I would however support anything that looks like a quality standard with regards to MediaWiki extensions.

Status & tagging log