r49737 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49736‎ | r49737 | r49738 >
Date:20:56, 22 April 2009
Author:ialex
Status:ok
Tags:
Comment:
Update documentation:
* corrected @param syntax
* removed some usless @private and @static
Modified paths:
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Sanitizer.php
@@ -335,11 +335,11 @@
336336 * Cleans up HTML, removes dangerous tags and attributes, and
337337 * removes HTML comments
338338 * @private
339 - * @param string $text
340 - * @param callback $processCallback to do any variable or parameter replacements in HTML attribute values
341 - * @param array $args for the processing callback
342 - * @param array $extratags for any extra tags to include
343 - * @param array $removetags for any tags (default or extra) to exclude
 339+ * @param $text String
 340+ * @param $processCallback Callback to do any variable or parameter replacements in HTML attribute values
 341+ * @param $args Array for the processing callback
 342+ * @param $extratags Array for any extra tags to include
 343+ * @param $removetags Array for any tags (default or extra) to exclude
344344 * @return string
345345 */
346346 static function removeHTMLtags( $text, $processCallback = null, $args = array(), $extratags = array(), $removetags = array() ) {
@@ -530,7 +530,7 @@
531531 * trailing spaces and one of the newlines.
532532 *
533533 * @private
534 - * @param string $text
 534+ * @param $text String
535535 * @return string
536536 */
537537 static function removeHTMLcomments( $text ) {
@@ -576,9 +576,9 @@
577577 * - Unsafe style attributes are discarded
578578 * - Invalid id attributes are reencoded
579579 *
580 - * @param array $attribs
581 - * @param string $element
582 - * @return array
 580+ * @param $attribs Array
 581+ * @param $element String
 582+ * @return Array
583583 *
584584 * @todo Check for legal values where the DTD limits things.
585585 * @todo Check for unique id attribute :P
@@ -596,9 +596,9 @@
597597 * - Unsafe style attributes are discarded
598598 * - Invalid id attributes are reencoded
599599 *
600 - * @param array $attribs
601 - * @param array $whitelist list of allowed attribute names
602 - * @return array
 600+ * @param $attribs Array
 601+ * @param $whitelist Array: list of allowed attribute names
 602+ * @return Array
603603 *
604604 * @todo Check for legal values where the DTD limits things.
605605 * @todo Check for unique id attribute :P
@@ -639,8 +639,8 @@
640640 * will be combined (if they're both strings).
641641 *
642642 * @todo implement merging for other attributes such as style
643 - * @param array $a
644 - * @param array $b
 643+ * @param $a Array
 644+ * @param $b Array
645645 * @return array
646646 */
647647 static function mergeAttributes( $a, $b ) {
@@ -661,8 +661,8 @@
662662 *
663663 * Currently URL references, 'expression', 'tps' are forbidden.
664664 *
665 - * @param string $value
666 - * @return mixed
 665+ * @param $value String
 666+ * @return Mixed
667667 */
668668 static function checkCss( $value ) {
669669 $stripped = Sanitizer::decodeCharReferences( $value );
@@ -700,9 +700,9 @@
701701 * - Unsafe style attributes are discarded
702702 * - Prepends space if there are attributes.
703703 *
704 - * @param string $text
705 - * @param string $element
706 - * @return string
 704+ * @param $text String
 705+ * @param $element String
 706+ * @return String
707707 */
708708 static function fixTagAttributes( $text, $element ) {
709709 if( trim( $text ) == '' ) {
@@ -724,7 +724,7 @@
725725
726726 /**
727727 * Encode an attribute value for HTML output.
728 - * @param $text
 728+ * @param $text String
729729 * @return HTML-encoded text fragment
730730 */
731731 static function encodeAttribute( $text ) {
@@ -745,7 +745,7 @@
746746 /**
747747 * Encode an attribute value for HTML tags, with extra armoring
748748 * against further wiki processing.
749 - * @param $text
 749+ * @param $text String
750750 * @return HTML-encoded text fragment
751751 */
752752 static function safeEncodeAttribute( $text ) {
@@ -784,8 +784,8 @@
785785 * name attributes
786786 * @see http://www.w3.org/TR/html401/struct/links.html#h-12.2.3 Anchors with the id attribute
787787 *
788 - * @param string $id Id to validate
789 - * @param mixed $options String or array of strings (default is array()):
 788+ * @param $id String: id to validate
 789+ * @param $options Mixed: string or array of strings (default is array()):
790790 * 'noninitial': This is a non-initial fragment of an id, not a full id,
791791 * so don't pay attention if the first character isn't valid at the
792792 * beginning of an id.
@@ -794,7 +794,7 @@
795795 * Therefore, it also completely changes the type of escaping: instead
796796 * of weird dot-encoding, runs of invalid characters (mostly
797797 * whitespace) are just compressed into a single underscore.
798 - * @return string
 798+ * @return String
799799 */
800800 static function escapeId( $id, $options = array() ) {
801801 $options = (array)$options;
@@ -844,8 +844,8 @@
845845 *
846846 * @see http://www.w3.org/TR/CSS21/syndata.html Valid characters/format
847847 *
848 - * @param string $class
849 - * @return string
 848+ * @param $class String
 849+ * @return String
850850 */
851851 static function escapeClass( $class ) {
852852 // Convert ugly stuff to underscores and kill underscores in ugly places
@@ -859,8 +859,8 @@
860860 * Given HTML input, escape with htmlspecialchars but un-escape entites.
861861 * This allows (generally harmless) entities like   to survive.
862862 *
863 - * @param string $html String to escape
864 - * @return string Escaped input
 863+ * @param $html String to escape
 864+ * @return String: escaped input
865865 */
866866 static function escapeHtmlAllowEntities( $html ) {
867867 # It seems wise to escape ' as well as ", as a matter of course. Can't
@@ -873,9 +873,8 @@
874874
875875 /**
876876 * Regex replace callback for armoring links against further processing.
877 - * @param array $matches
 877+ * @param $matches Array
878878 * @return string
879 - * @private
880879 */
881880 private static function armorLinksCallback( $matches ) {
882881 return str_replace( ':', ':', $matches[1] );
@@ -886,8 +885,8 @@
887886 * a partial tag string. Attribute names are forces to lowercase,
888887 * character references are decoded to UTF-8 text.
889888 *
890 - * @param string
891 - * @return array
 889+ * @param $text String
 890+ * @return Array
892891 */
893892 public static function decodeTagAttributes( $text ) {
894893 $attribs = array();
@@ -923,9 +922,8 @@
924923 * Pick the appropriate attribute value from a match set from the
925924 * MW_ATTRIBS_REGEX matches.
926925 *
927 - * @param array $set
928 - * @return string
929 - * @private
 926+ * @param $set Array
 927+ * @return String
930928 */
931929 private static function getTagAttributeCallback( $set ) {
932930 if( isset( $set[6] ) ) {
@@ -957,9 +955,8 @@
958956 * but note that we're not returning the value, but are returning
959957 * XML source fragments that will be slapped into output.
960958 *
961 - * @param string $text
962 - * @return string
963 - * @private
 959+ * @param $text String
 960+ * @return String
964961 */
965962 private static function normalizeAttributeValue( $text ) {
966963 return str_replace( '"', '"',
@@ -984,8 +981,8 @@
985982 * c. use &#x, not &#X
986983 * d. fix or reject non-valid attributes
987984 *
988 - * @param string $text
989 - * @return string
 985+ * @param $text String
 986+ * @return String
990987 * @private
991988 */
992989 static function normalizeCharReferences( $text ) {
@@ -995,8 +992,8 @@
996993 $text );
997994 }
998995 /**
999 - * @param string $matches
1000 - * @return string
 996+ * @param $matches String
 997+ * @return String
1001998 */
1002999 static function normalizeCharReferencesCallback( $matches ) {
10031000 $ret = null;
@@ -1022,9 +1019,8 @@
10231020 * MediaWiki-specific alias, returns the HTML equivalent. Otherwise,
10241021 * returns HTML-escaped text of pseudo-entity source (eg &foo;)
10251022 *
1026 - * @param string $name
1027 - * @return string
1028 - * @static
 1023+ * @param $name String
 1024+ * @return String
10291025 */
10301026 static function normalizeEntity( $name ) {
10311027 global $wgHtmlEntities, $wgHtmlEntityAliases;
@@ -1057,8 +1053,8 @@
10581054
10591055 /**
10601056 * Returns true if a given Unicode codepoint is a valid character in XML.
1061 - * @param int $codepoint
1062 - * @return bool
 1057+ * @param $codepoint Integer
 1058+ * @return Boolean
10631059 */
10641060 private static function validateCodepoint( $codepoint ) {
10651061 return ($codepoint == 0x09)
@@ -1073,10 +1069,8 @@
10741070 * Decode any character references, numeric or named entities,
10751071 * in the text and return a UTF-8 string.
10761072 *
1077 - * @param string $text
1078 - * @return string
1079 - * @public
1080 - * @static
 1073+ * @param $text String
 1074+ * @return String
10811075 */
10821076 public static function decodeCharReferences( $text ) {
10831077 return preg_replace_callback(
@@ -1086,8 +1080,8 @@
10871081 }
10881082
10891083 /**
1090 - * @param string $matches
1091 - * @return string
 1084+ * @param $matches String
 1085+ * @return String
10921086 */
10931087 static function decodeCharReferencesCallback( $matches ) {
10941088 if( $matches[1] != '' ) {
@@ -1106,8 +1100,8 @@
11071101 /**
11081102 * Return UTF-8 string for a codepoint if that is a valid
11091103 * character reference, otherwise U+FFFD REPLACEMENT CHARACTER.
1110 - * @param int $codepoint
1111 - * @return string
 1104+ * @param $codepoint Integer
 1105+ * @return String
11121106 * @private
11131107 */
11141108 static function decodeChar( $codepoint ) {
@@ -1123,8 +1117,8 @@
11241118 * return the UTF-8 encoding of that character. Otherwise, returns
11251119 * pseudo-entity source (eg &foo;)
11261120 *
1127 - * @param string $name
1128 - * @return string
 1121+ * @param $name Strings
 1122+ * @return String
11291123 */
11301124 static function decodeEntity( $name ) {
11311125 global $wgHtmlEntities, $wgHtmlEntityAliases;
@@ -1139,11 +1133,10 @@
11401134 }
11411135
11421136 /**
1143 - * Fetch the whitelist of acceptable attributes for a given
1144 - * element name.
 1137+ * Fetch the whitelist of acceptable attributes for a given element name.
11451138 *
1146 - * @param string $element
1147 - * @return array
 1139+ * @param $element String
 1140+ * @return Array
11481141 */
11491142 static function attributeWhitelist( $element ) {
11501143 static $list;
@@ -1158,7 +1151,7 @@
11591152 /**
11601153 * Foreach array key (an allowed HTML element), return an array
11611154 * of allowed attributes
1162 - * @return array
 1155+ * @return Array
11631156 */
11641157 static function setupAttributeWhitelist() {
11651158 $common = array( 'id', 'class', 'lang', 'dir', 'title', 'style' );
@@ -1313,8 +1306,8 @@
13141307 * Warning: this return value must be further escaped for literal
13151308 * inclusion in HTML output as of 1.10!
13161309 *
1317 - * @param string $text HTML fragment
1318 - * @return string
 1310+ * @param $text String: HTML fragment
 1311+ * @return String
13191312 */
13201313 static function stripAllTags( $text ) {
13211314 # Actual <tags>
@@ -1334,8 +1327,7 @@
13351328 *
13361329 * Use for passing XHTML fragments to PHP's XML parsing functions
13371330 *
1338 - * @return string
1339 - * @static
 1331+ * @return String
13401332 */
13411333 static function hackDocType() {
13421334 global $wgHtmlEntities;

Status & tagging log