r15498 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15497‎ | r15498 | r15499 >
Date:15:41, 10 July 2006
Author:hashar
Status:old
Tags:
Comment:
A lot more of static issues when using E_STRICT from the commandline.
Modified paths:
  • /trunk/phase3/includes/LinkCache.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/Math.php (modified) (history)
  • /trunk/phase3/includes/Namespace.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/ParserCache.php (modified) (history)
  • /trunk/phase3/includes/RecentChange.php (modified) (history)
  • /trunk/phase3/includes/Revision.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -56,8 +56,8 @@
5757 }
5858
5959 // Shortcuts
60 - function openElement( $element, $attribs = null ) { return self::element( $element, $attribs, null ); }
61 - function closeElement( $element ) { return "</$element>"; }
 60+ public static function openElement( $element, $attribs = null ) { return self::element( $element, $attribs, null ); }
 61+ public static function closeElement( $element ) { return "</$element>"; }
6262
6363 /**
6464 * Create a namespace selector
@@ -216,7 +216,7 @@
217217 * @param string $string
218218 * @return string
219219 */
220 - function escapeJsString( $string ) {
 220+ public static function escapeJsString( $string ) {
221221 // See ECMA 262 section 7.8.4 for string literal format
222222 $pairs = array(
223223 "\\" => "\\\\",
Index: trunk/phase3/includes/RecentChange.php
@@ -243,9 +243,14 @@
244244 return( $rc->mAttribs['rc_id'] );
245245 }
246246
247 - # Makes an entry in the database corresponding to page creation
248 - # Note: the title object must be loaded with the new id using resetArticleID()
249 - /*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
 247+ /**
 248+ * Makes an entry in the database corresponding to page creation
 249+ * Note: the title object must be loaded with the new id using resetArticleID()
 250+ * @todo Document parameters and return
 251+ * @public
 252+ * @static
 253+ */
 254+ public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default",
250255 $ip='', $size = 0, $newId = 0 )
251256 {
252257 if ( !$ip ) {
Index: trunk/phase3/includes/Linker.php
@@ -1081,7 +1081,7 @@
10821082 *
10831083 * @static
10841084 */
1085 - function splitTrail( $trail ) {
 1085+ static function splitTrail( $trail ) {
10861086 static $regex = false;
10871087 if ( $regex === false ) {
10881088 global $wgContLang;
Index: trunk/phase3/includes/Parser.php
@@ -1316,7 +1316,7 @@
13171317 * the URL differently; as a workaround, just use the output for
13181318 * statistical records, not for actual linking/output.
13191319 */
1320 - function replaceUnusualEscapes( $url ) {
 1320+ static function replaceUnusualEscapes( $url ) {
13211321 return preg_replace_callback( '/%[0-9A-Fa-f]{2}/',
13221322 array( 'Parser', 'replaceUnusualEscapesCallback' ), $url );
13231323 }
@@ -1327,7 +1327,7 @@
13281328 * @static
13291329 * @private
13301330 */
1331 - function replaceUnusualEscapesCallback( $matches ) {
 1331+ private static function replaceUnusualEscapesCallback( $matches ) {
13321332 $char = urldecode( $matches[0] );
13331333 $ord = ord( $char );
13341334 // Is it an unsafe or HTTP reserved character according to RFC 1738?
Index: trunk/phase3/includes/Sanitizer.php
@@ -327,7 +327,7 @@
328328 * @param array $args for the processing callback
329329 * @return string
330330 */
331 - function removeHTMLtags( $text, $processCallback = null, $args = array() ) {
 331+ static function removeHTMLtags( $text, $processCallback = null, $args = array() ) {
332332 global $wgUseTidy, $wgUserHtml;
333333 $fname = 'Parser::removeHTMLtags';
334334 wfProfileIn( $fname );
@@ -501,7 +501,7 @@
502502 * @param string $text
503503 * @return string
504504 */
505 - function removeHTMLcomments( $text ) {
 505+ static function removeHTMLcomments( $text ) {
506506 $fname='Parser::removeHTMLcomments';
507507 wfProfileIn( $fname );
508508 while (($start = strpos($text, '<!--')) !== false) {
@@ -551,7 +551,7 @@
552552 * @todo Check for legal values where the DTD limits things.
553553 * @todo Check for unique id attribute :P
554554 */
555 - function validateTagAttributes( $attribs, $element ) {
 555+ static function validateTagAttributes( $attribs, $element ) {
556556 $whitelist = array_flip( Sanitizer::attributeWhitelist( $element ) );
557557 $out = array();
558558 foreach( $attribs as $attribute => $value ) {
@@ -626,7 +626,7 @@
627627 * @param string $element
628628 * @return string
629629 */
630 - function fixTagAttributes( $text, $element ) {
 630+ static function fixTagAttributes( $text, $element ) {
631631 if( trim( $text ) == '' ) {
632632 return '';
633633 }
@@ -649,7 +649,7 @@
650650 * @param $text
651651 * @return HTML-encoded text fragment
652652 */
653 - function encodeAttribute( $text ) {
 653+ static function encodeAttribute( $text ) {
654654 $encValue = htmlspecialchars( $text );
655655
656656 // Whitespace is normalized during attribute decoding,
@@ -670,7 +670,7 @@
671671 * @param $text
672672 * @return HTML-encoded text fragment
673673 */
674 - function safeEncodeAttribute( $text ) {
 674+ static function safeEncodeAttribute( $text ) {
675675 $encValue = Sanitizer::encodeAttribute( $text );
676676
677677 # Templates and links may be expanded in later parsing,
@@ -713,7 +713,7 @@
714714 * @param string $id
715715 * @return string
716716 */
717 - function escapeId( $id ) {
 717+ static function escapeId( $id ) {
718718 static $replace = array(
719719 '%3A' => ':',
720720 '%' => '.'
@@ -730,7 +730,7 @@
731731 * @return string
732732 * @private
733733 */
734 - function armorLinksCallback( $matches ) {
 734+ private static function armorLinksCallback( $matches ) {
735735 return str_replace( ':', '&#58;', $matches[1] );
736736 }
737737
@@ -742,7 +742,7 @@
743743 * @param string
744744 * @return array
745745 */
746 - function decodeTagAttributes( $text ) {
 746+ static function decodeTagAttributes( $text ) {
747747 $attribs = array();
748748
749749 if( trim( $text ) == '' ) {
@@ -780,7 +780,7 @@
781781 * @return string
782782 * @private
783783 */
784 - function getTagAttributeCallback( $set ) {
 784+ private static function getTagAttributeCallback( $set ) {
785785 if( isset( $set[6] ) ) {
786786 # Illegal #XXXXXX color with no quotes.
787787 return $set[6];
@@ -814,7 +814,7 @@
815815 * @return string
816816 * @private
817817 */
818 - function normalizeAttributeValue( $text ) {
 818+ private static function normalizeAttributeValue( $text ) {
819819 return str_replace( '"', '&quot;',
820820 preg_replace(
821821 '/\r\n|[\x20\x0d\x0a\x09]/',
@@ -836,7 +836,7 @@
837837 * @return string
838838 * @private
839839 */
840 - function normalizeCharReferences( $text ) {
 840+ static function normalizeCharReferences( $text ) {
841841 return preg_replace_callback(
842842 MW_CHAR_REFS_REGEX,
843843 array( 'Sanitizer', 'normalizeCharReferencesCallback' ),
@@ -846,7 +846,7 @@
847847 * @param string $matches
848848 * @return string
849849 */
850 - function normalizeCharReferencesCallback( $matches ) {
 850+ static function normalizeCharReferencesCallback( $matches ) {
851851 $ret = null;
852852 if( $matches[1] != '' ) {
853853 $ret = Sanitizer::normalizeEntity( $matches[1] );
@@ -871,8 +871,9 @@
872872 *
873873 * @param string $name
874874 * @return string
 875+ * @static
875876 */
876 - function normalizeEntity( $name ) {
 877+ static function normalizeEntity( $name ) {
877878 global $wgHtmlEntities;
878879 if( isset( $wgHtmlEntities[$name] ) ) {
879880 return "&$name;";
@@ -881,7 +882,7 @@
882883 }
883884 }
884885
885 - function decCharReference( $codepoint ) {
 886+ static function decCharReference( $codepoint ) {
886887 $point = intval( $codepoint );
887888 if( Sanitizer::validateCodepoint( $point ) ) {
888889 return sprintf( '&#%d;', $point );
@@ -890,7 +891,7 @@
891892 }
892893 }
893894
894 - function hexCharReference( $codepoint ) {
 895+ static function hexCharReference( $codepoint ) {
895896 $point = hexdec( $codepoint );
896897 if( Sanitizer::validateCodepoint( $point ) ) {
897898 return sprintf( '&#x%x;', $point );
@@ -904,7 +905,7 @@
905906 * @param int $codepoint
906907 * @return bool
907908 */
908 - function validateCodepoint( $codepoint ) {
 909+ private static function validateCodepoint( $codepoint ) {
909910 return ($codepoint == 0x09)
910911 || ($codepoint == 0x0a)
911912 || ($codepoint == 0x0d)
@@ -954,7 +955,7 @@
955956 * @return string
956957 * @private
957958 */
958 - function decodeChar( $codepoint ) {
 959+ static function decodeChar( $codepoint ) {
959960 if( Sanitizer::validateCodepoint( $codepoint ) ) {
960961 return codepointToUtf8( $codepoint );
961962 } else {
@@ -970,7 +971,7 @@
971972 * @param string $name
972973 * @return string
973974 */
974 - function decodeEntity( $name ) {
 975+ static function decodeEntity( $name ) {
975976 global $wgHtmlEntities;
976977 if( isset( $wgHtmlEntities[$name] ) ) {
977978 return codepointToUtf8( $wgHtmlEntities[$name] );
@@ -986,7 +987,7 @@
987988 * @param string $element
988989 * @return array
989990 */
990 - function attributeWhitelist( $element ) {
 991+ static function attributeWhitelist( $element ) {
991992 static $list;
992993 if( !isset( $list ) ) {
993994 $list = Sanitizer::setupAttributeWhitelist();
@@ -997,9 +998,10 @@
998999 }
9991000
10001001 /**
 1002+ * @todo Document it a bit
10011003 * @return array
10021004 */
1003 - function setupAttributeWhitelist() {
 1005+ static function setupAttributeWhitelist() {
10041006 $common = array( 'id', 'class', 'lang', 'dir', 'title', 'style' );
10051007 $block = array_merge( $common, array( 'align' ) );
10061008 $tablealign = array( 'align', 'char', 'charoff', 'valign' );
@@ -1143,7 +1145,7 @@
11441146 * @param string $text HTML fragment
11451147 * @return string
11461148 */
1147 - function stripAllTags( $text ) {
 1149+ static function stripAllTags( $text ) {
11481150 # Actual <tags>
11491151 $text = preg_replace( '/ < .*? > /x', '', $text );
11501152
@@ -1170,7 +1172,7 @@
11711173 * @return string
11721174 * @static
11731175 */
1174 - function hackDocType() {
 1176+ static function hackDocType() {
11751177 global $wgHtmlEntities;
11761178 $out = "<!DOCTYPE html [\n";
11771179 foreach( $wgHtmlEntities as $entity => $codepoint ) {
Index: trunk/phase3/includes/Revision.php
@@ -25,7 +25,7 @@
2626 * @static
2727 * @access public
2828 */
29 - function newFromId( $id ) {
 29+ public static function newFromId( $id ) {
3030 return Revision::newFromConds(
3131 array( 'page_id=rev_page',
3232 'rev_id' => intval( $id ) ) );
@@ -42,7 +42,7 @@
4343 * @access public
4444 * @static
4545 */
46 - function newFromTitle( &$title, $id = 0 ) {
 46+ public static function newFromTitle( &$title, $id = 0 ) {
4747 if( $id ) {
4848 $matchId = intval( $id );
4949 } else {
@@ -66,7 +66,7 @@
6767 * @return Revision
6868 * @access public
6969 */
70 - function loadFromPageId( &$db, $pageid, $id = 0 ) {
 70+ public static function loadFromPageId( &$db, $pageid, $id = 0 ) {
7171 $conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid ));
7272 if( $id ) {
7373 $conds['rev_id']=intval($id);
@@ -130,7 +130,7 @@
131131 * @static
132132 * @access private
133133 */
134 - function newFromConds( $conditions ) {
 134+ private static function newFromConds( $conditions ) {
135135 $db =& wfGetDB( DB_SLAVE );
136136 $row = Revision::loadFromConds( $db, $conditions );
137137 if( is_null( $row ) ) {
@@ -150,7 +150,7 @@
151151 * @static
152152 * @access private
153153 */
154 - function loadFromConds( &$db, $conditions ) {
 154+ private static function loadFromConds( &$db, $conditions ) {
155155 $res = Revision::fetchFromConds( $db, $conditions );
156156 if( $res ) {
157157 $row = $res->fetchObject();
@@ -192,7 +192,7 @@
193193 * @static
194194 * @access public
195195 */
196 - function fetchRevision( &$title ) {
 196+ public static function fetchRevision( &$title ) {
197197 return Revision::fetchFromConds(
198198 wfGetDB( DB_SLAVE ),
199199 array( 'rev_id=page_latest',
@@ -212,7 +212,7 @@
213213 * @static
214214 * @access private
215215 */
216 - function fetchFromConds( &$db, $conditions ) {
 216+ private static function fetchFromConds( &$db, $conditions ) {
217217 $res = $db->select(
218218 array( 'page', 'revision' ),
219219 array( 'page_namespace',
Index: trunk/phase3/includes/MagicWord.php
@@ -196,7 +196,7 @@
197197 * Factory: creates an object representing an ID
198198 * @static
199199 */
200 - function &get( $id ) {
 200+ static function &get( $id ) {
201201 global $wgMagicWords;
202202
203203 if ( !is_array( $wgMagicWords ) ) {
Index: trunk/phase3/includes/Title.php
@@ -256,7 +256,7 @@
257257 * @static
258258 * @access public
259259 */
260 - function makeTitleSafe( $ns, $title ) {
 260+ public static function makeTitleSafe( $ns, $title ) {
261261 $t = new Title();
262262 $t->mDbkeyform = Title::makeName( $ns, $title );
263263 if( $t->secureAndSplit() ) {
@@ -273,7 +273,7 @@
274274 * @return Title the new object
275275 * @access public
276276 */
277 - function newMainPage() {
 277+ public static function newMainPage() {
278278 return Title::newFromText( wfMsgForContent( 'mainpage' ) );
279279 }
280280
@@ -285,7 +285,7 @@
286286 * @static
287287 * @access public
288288 */
289 - function newFromRedirect( $text ) {
 289+ public static function newFromRedirect( $text ) {
290290 $mwRedir = MagicWord::get( MAG_REDIRECT );
291291 $rt = NULL;
292292 if ( $mwRedir->matchStart( $text ) ) {
@@ -336,7 +336,7 @@
337337 * @static
338338 * @access public
339339 */
340 - function legalChars() {
 340+ public static function legalChars() {
341341 global $wgLegalTitleChars;
342342 return $wgLegalTitleChars;
343343 }
@@ -376,7 +376,7 @@
377377 * @param string $title the DB key form the title
378378 * @return string the prefixed form of the title
379379 */
380 - /* static */ function makeName( $ns, $title ) {
 380+ public static function makeName( $ns, $title ) {
381381 global $wgContLang;
382382
383383 $n = $wgContLang->getNsText( $ns );
Index: trunk/phase3/includes/Namespace.php
@@ -65,7 +65,7 @@
6666 * Check if the give namespace is a talk page
6767 * @return bool
6868 */
69 - function isTalk( $index ) {
 69+ static function isTalk( $index ) {
7070 return ($index > NS_MAIN) // Special namespaces are negative
7171 && ($index % 2); // Talk namespaces are odd-numbered
7272 }
Index: trunk/phase3/includes/Skin.php
@@ -33,7 +33,7 @@
3434 * @return array of strings
3535 * @static
3636 */
37 - function &getSkinNames() {
 37+ static function &getSkinNames() {
3838 global $wgValidSkinNames;
3939 static $skinsInitialised = false;
4040 if ( !$skinsInitialised ) {
@@ -68,7 +68,7 @@
6969 * @return string
7070 * @static
7171 */
72 - function normalizeKey( $key ) {
 72+ static function normalizeKey( $key ) {
7373 global $wgDefaultSkin;
7474 $skinNames = Skin::getSkinNames();
7575
@@ -107,7 +107,7 @@
108108 * @return Skin
109109 * @static
110110 */
111 - function &newFromKey( $key ) {
 111+ static function &newFromKey( $key ) {
112112 global $wgStyleDirectory;
113113
114114 $key = Skin::normalizeKey( $key );
Index: trunk/phase3/includes/SpecialPage.php
@@ -313,7 +313,7 @@
314314 * @param $title a title object
315315 * @param $including output is being captured for use in {{special:whatever}}
316316 */
317 - function executePath( &$title, $including = false ) {
 317+ static function executePath( &$title, $including = false ) {
318318 global $wgOut, $wgTitle;
319319 $fname = 'SpecialPage::executePath';
320320 wfProfileIn( $fname );
Index: trunk/phase3/includes/ParserCache.php
@@ -13,7 +13,7 @@
1414 /**
1515 * Get an instance of this object
1616 */
17 - function &singleton() {
 17+ public static function &singleton() {
1818 static $instance;
1919 if ( !isset( $instance ) ) {
2020 global $parserMemc;
Index: trunk/phase3/includes/Math.php
@@ -259,7 +259,7 @@
260260 return $path;
261261 }
262262
263 - function renderMath( $tex ) {
 263+ public static function renderMath( $tex ) {
264264 global $wgUser;
265265 $math = new MathRenderer( $tex );
266266 $math->setOutputMode( $wgUser->getOption('math'));
Index: trunk/phase3/includes/LinkCache.php
@@ -21,7 +21,7 @@
2222 /**
2323 * Get an instance of this class
2424 */
25 - function &singleton() {
 25+ static function &singleton() {
2626 static $instance;
2727 if ( !isset( $instance ) ) {
2828 $instance = new LinkCache;