Index: trunk/extensions/AbuseFilter/AbuseFilter.parser.php |
— | — | @@ -79,6 +79,11 @@ |
80 | 80 | $this->data = $val; |
81 | 81 | } |
82 | 82 | |
| 83 | + /** |
| 84 | + * @param $var |
| 85 | + * @return AFPData |
| 86 | + * @throws AFPException |
| 87 | + */ |
83 | 88 | public static function newFromPHPVar( $var ) { |
84 | 89 | if ( is_string( $var ) ) { |
85 | 90 | return new AFPData( self::DString, $var ); |
— | — | @@ -103,10 +108,19 @@ |
104 | 109 | } |
105 | 110 | } |
106 | 111 | |
| 112 | + /** |
| 113 | + * @return AFPData |
| 114 | + */ |
107 | 115 | public function dup() { |
108 | 116 | return new AFPData( $this->type, $this->data ); |
109 | 117 | } |
110 | 118 | |
| 119 | + /** |
| 120 | + * @static |
| 121 | + * @param $orig |
| 122 | + * @param $target |
| 123 | + * @return AFPData |
| 124 | + */ |
111 | 125 | public static function castTypes( $orig, $target ) { |
112 | 126 | if ( $orig->type == $target ) { |
113 | 127 | return $orig->dup(); |
— | — | @@ -120,7 +134,7 @@ |
121 | 135 | return new AFPData( self::DBool, (bool)count( $orig->data ) ); |
122 | 136 | } |
123 | 137 | if ( $target == self::DFloat ) { |
124 | | - return new AFPData( self::DFloat, doubleval( count( $orig->data ) ) ); |
| 138 | + return new AFPData( self::DFloat, floatval( count( $orig->data ) ) ); |
125 | 139 | } |
126 | 140 | if ( $target == self::DInt ) { |
127 | 141 | return new AFPData( self::DInt, intval( count( $orig->data ) ) ); |
— | — | @@ -138,7 +152,7 @@ |
139 | 153 | return new AFPData( self::DBool, (bool)$orig->data ); |
140 | 154 | } |
141 | 155 | if ( $target == self::DFloat ) { |
142 | | - return new AFPData( self::DFloat, doubleval( $orig->data ) ); |
| 156 | + return new AFPData( self::DFloat, floatval( $orig->data ) ); |
143 | 157 | } |
144 | 158 | if ( $target == self::DInt ) { |
145 | 159 | return new AFPData( self::DInt, intval( $orig->data ) ); |
— | — | @@ -151,14 +165,28 @@ |
152 | 166 | } |
153 | 167 | } |
154 | 168 | |
| 169 | + /** |
| 170 | + * @param $value |
| 171 | + * @return AFPData |
| 172 | + */ |
155 | 173 | public static function boolInvert( $value ) { |
156 | 174 | return new AFPData( self::DBool, !$value->toBool() ); |
157 | 175 | } |
158 | 176 | |
| 177 | + /** |
| 178 | + * @param $base |
| 179 | + * @param $exponent |
| 180 | + * @return AFPData |
| 181 | + */ |
159 | 182 | public static function pow( $base, $exponent ) { |
160 | 183 | return new AFPData( self::DFloat, pow( $base->toFloat(), $exponent->toFloat() ) ); |
161 | 184 | } |
162 | 185 | |
| 186 | + /** |
| 187 | + * @param $a |
| 188 | + * @param $b |
| 189 | + * @return AFPData |
| 190 | + */ |
163 | 191 | public static function keywordIn( $a, $b ) { |
164 | 192 | $a = $a->toString(); |
165 | 193 | $b = $b->toString(); |
— | — | @@ -170,6 +198,11 @@ |
171 | 199 | return new AFPData( self::DBool, in_string( $a, $b ) ); |
172 | 200 | } |
173 | 201 | |
| 202 | + /** |
| 203 | + * @param $a |
| 204 | + * @param $b |
| 205 | + * @return AFPData |
| 206 | + */ |
174 | 207 | public static function keywordContains( $a, $b ) { |
175 | 208 | $a = $a->toString(); |
176 | 209 | $b = $b->toString(); |
— | — | @@ -181,6 +214,11 @@ |
182 | 215 | return new AFPData( self::DBool, in_string( $b, $a ) ); |
183 | 216 | } |
184 | 217 | |
| 218 | + /** |
| 219 | + * @param $value |
| 220 | + * @param $list |
| 221 | + * @return bool |
| 222 | + */ |
185 | 223 | public static function listContains( $value, $list ) { |
186 | 224 | // Should use built-in PHP function somehow |
187 | 225 | foreach ( $list->data as $item ) { |
— | — | @@ -191,11 +229,21 @@ |
192 | 230 | return false; |
193 | 231 | } |
194 | 232 | |
| 233 | + /** |
| 234 | + * @param $d1 |
| 235 | + * @param $d2 |
| 236 | + * @return bool |
| 237 | + */ |
195 | 238 | public static function equals( $d1, $d2 ) { |
196 | 239 | return $d1->type != self::DList && $d2->type != self::DList && |
197 | 240 | $d1->toString() === $d2->toString(); |
198 | 241 | } |
199 | 242 | |
| 243 | + /** |
| 244 | + * @param $str |
| 245 | + * @param $pattern |
| 246 | + * @return AFPData |
| 247 | + */ |
200 | 248 | public static function keywordLike( $str, $pattern ) { |
201 | 249 | $str = $str->toString(); |
202 | 250 | $pattern = $pattern->toString(); |
— | — | @@ -205,6 +253,14 @@ |
206 | 254 | return new AFPData( self::DBool, (bool)$result ); |
207 | 255 | } |
208 | 256 | |
| 257 | + /** |
| 258 | + * @param $str |
| 259 | + * @param $regex |
| 260 | + * @param $pos |
| 261 | + * @param $insensitive bool |
| 262 | + * @return AFPData |
| 263 | + * @throws Exception |
| 264 | + */ |
209 | 265 | public static function keywordRegex( $str, $regex, $pos, $insensitive = false ) { |
210 | 266 | $str = $str->toString(); |
211 | 267 | $pattern = $regex->toString(); |
— | — | @@ -228,10 +284,20 @@ |
229 | 285 | return new AFPData( self::DBool, (bool)$result ); |
230 | 286 | } |
231 | 287 | |
| 288 | + /** |
| 289 | + * @param $str |
| 290 | + * @param $regex |
| 291 | + * @param $pos |
| 292 | + * @return AFPData |
| 293 | + */ |
232 | 294 | public static function keywordRegexInsensitive( $str, $regex, $pos ) { |
233 | 295 | return self::keywordRegex( $str, $regex, $pos, true ); |
234 | 296 | } |
235 | 297 | |
| 298 | + /** |
| 299 | + * @param $data |
| 300 | + * @return AFPData |
| 301 | + */ |
236 | 302 | public static function unaryMinus( $data ) { |
237 | 303 | if ( $data->type == self::DInt ) { |
238 | 304 | return new AFPData( $data->type, - $data->toInt() ); |
— | — | @@ -240,6 +306,13 @@ |
241 | 307 | } |
242 | 308 | } |
243 | 309 | |
| 310 | + /** |
| 311 | + * @param $a |
| 312 | + * @param $b |
| 313 | + * @param $op |
| 314 | + * @return AFPData |
| 315 | + * @throws AFPException |
| 316 | + */ |
244 | 317 | public static function boolOp( $a, $b, $op ) { |
245 | 318 | $a = $a->toBool(); |
246 | 319 | $b = $b->toBool(); |
— | — | @@ -255,6 +328,13 @@ |
256 | 329 | throw new AFPException( "Invalid boolean operation: {$op}" ); // Should never happen. |
257 | 330 | } |
258 | 331 | |
| 332 | + /** |
| 333 | + * @param $a |
| 334 | + * @param $b |
| 335 | + * @param $op |
| 336 | + * @return AFPData |
| 337 | + * @throws AFPException |
| 338 | + */ |
259 | 339 | public static function compareOp( $a, $b, $op ) { |
260 | 340 | if ( $op == '==' || $op == '=' ) { |
261 | 341 | return new AFPData( self::DBool, self::equals( $a, $b ) ); |
— | — | @@ -285,6 +365,15 @@ |
286 | 366 | throw new AFPException( "Invalid comparison operation: {$op}" ); // Should never happen |
287 | 367 | } |
288 | 368 | |
| 369 | + /** |
| 370 | + * @param $a |
| 371 | + * @param $b |
| 372 | + * @param $op |
| 373 | + * @param $pos |
| 374 | + * @return AFPData |
| 375 | + * @throws AFPUserVisibleException |
| 376 | + * @throws AFPException |
| 377 | + */ |
289 | 378 | public static function mulRel( $a, $b, $op, $pos ) { |
290 | 379 | // Figure out the type. |
291 | 380 | if ( $a->type == self::DFloat || $b->type == self::DFloat || |
— | — | @@ -315,12 +404,17 @@ |
316 | 405 | if ( $type == self::DInt ) { |
317 | 406 | $data = intval( $data ); |
318 | 407 | } else { |
319 | | - $data = doubleval( $data ); |
| 408 | + $data = floatval( $data ); |
320 | 409 | } |
321 | 410 | |
322 | 411 | return new AFPData( $type, $data ); |
323 | 412 | } |
324 | 413 | |
| 414 | + /** |
| 415 | + * @param $a |
| 416 | + * @param $b |
| 417 | + * @return AFPData |
| 418 | + */ |
325 | 419 | public static function sum( $a, $b ) { |
326 | 420 | if ( $a->type == self::DString || $b->type == self::DString ) { |
327 | 421 | return new AFPData( self::DString, $a->toString() . $b->toString() ); |
— | — | @@ -331,6 +425,11 @@ |
332 | 426 | } |
333 | 427 | } |
334 | 428 | |
| 429 | + /** |
| 430 | + * @param $a |
| 431 | + * @param $b |
| 432 | + * @return AFPData |
| 433 | + */ |
335 | 434 | public static function sub( $a, $b ) { |
336 | 435 | return new AFPData( self::DFloat, $a->toFloat() - $b->toFloat() ); |
337 | 436 | } |
— | — | @@ -338,6 +437,7 @@ |
339 | 438 | /** Convert shorteners */ |
340 | 439 | |
341 | 440 | /** |
| 441 | + * @throws MWException |
342 | 442 | * @return mixed |
343 | 443 | */ |
344 | 444 | public function toNative() { |
— | — | @@ -434,6 +534,15 @@ |
435 | 535 | $this->pos = $pos; |
436 | 536 | } |
437 | 537 | |
| 538 | + /** |
| 539 | + * @param $errno |
| 540 | + * @param $errstr |
| 541 | + * @param $errfile |
| 542 | + * @param $errline |
| 543 | + * @param $context |
| 544 | + * @return bool |
| 545 | + * @throws AFPUserVisibleException |
| 546 | + */ |
438 | 547 | function handleError( $errno, $errstr, $errfile, $errline, $context ) { |
439 | 548 | if ( error_reporting() == 0 ) { |
440 | 549 | return true; |
— | — | @@ -455,8 +564,13 @@ |
456 | 565 | } |
457 | 566 | |
458 | 567 | class AbuseFilterParser { |
459 | | - var $mParams, $mVars, $mCode, $mTokens, $mPos, $mCur, $mShortCircuit, $mAllowShort; |
| 568 | + var $mParams, $mCode, $mTokens, $mPos, $mCur, $mShortCircuit, $mAllowShort, $mLen; |
460 | 569 | |
| 570 | + /** |
| 571 | + * @var AbuseFilterVariableHolder |
| 572 | + */ |
| 573 | + var $mVars; |
| 574 | + |
461 | 575 | // length,lcase,ccnorm,rmdoubles,specialratio,rmspecials,norm,count |
462 | 576 | static $mFunctions = array( |
463 | 577 | 'lcase' => 'funcLc', |
— | — | @@ -529,6 +643,10 @@ |
530 | 644 | $this->mAllowShort = true; |
531 | 645 | } |
532 | 646 | |
| 647 | + /** |
| 648 | + * @param $filter |
| 649 | + * @return array|bool |
| 650 | + */ |
533 | 651 | public function checkSyntax( $filter ) { |
534 | 652 | try { |
535 | 653 | $origAS = $this->mAllowShort; |
— | — | @@ -542,11 +660,18 @@ |
543 | 661 | return true; |
544 | 662 | } |
545 | 663 | |
| 664 | + /** |
| 665 | + * @param $name |
| 666 | + * @param $value |
| 667 | + */ |
546 | 668 | public function setVar( $name, $value ) { |
547 | 669 | $name = strtolower( $name ); |
548 | 670 | $this->mVars->setVar( $name, $value ); |
549 | 671 | } |
550 | 672 | |
| 673 | + /** |
| 674 | + * @param $vars |
| 675 | + */ |
551 | 676 | public function setVars( $vars ) { |
552 | 677 | if ( is_array( $vars ) ) { |
553 | 678 | foreach ( $vars as $name => $var ) { |
— | — | @@ -557,6 +682,9 @@ |
558 | 683 | } |
559 | 684 | } |
560 | 685 | |
| 686 | + /** |
| 687 | + * @return AFPToken |
| 688 | + */ |
561 | 689 | protected function move( ) { |
562 | 690 | wfProfileIn( __METHOD__ ); |
563 | 691 | list( $val, $type, $code, $offset ) = |
— | — | @@ -568,17 +696,28 @@ |
569 | 697 | return $this->mCur = $token; |
570 | 698 | } |
571 | 699 | |
572 | | - // getState() and setState() function allows parser state to be rollbacked to several tokens back |
| 700 | + /** |
| 701 | + * getState() function allows parser state to be rollbacked to several tokens back |
| 702 | + * @return AFPParserState |
| 703 | + */ |
573 | 704 | protected function getState() { |
574 | 705 | return new AFPParserState( $this->mCur, $this->mPos ); |
575 | 706 | } |
576 | 707 | |
| 708 | + /** |
| 709 | + * setState() function allows parser state to be rollbacked to several tokens back |
| 710 | + * @param AFPParserState $state |
| 711 | + */ |
577 | 712 | protected function setState( AFPParserState $state ) { |
578 | 713 | $this->mCur = $state->token; |
579 | 714 | $this->mPos = $state->pos; |
580 | 715 | self::$lastHandledToken = $state->lastInput; |
581 | 716 | } |
582 | 717 | |
| 718 | + /** |
| 719 | + * @return mixed |
| 720 | + * @throws AFPUserVisibleException |
| 721 | + */ |
583 | 722 | protected function skipOverBraces() { |
584 | 723 | if ( !( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == '(' ) || !$this->mShortCircuit ) { |
585 | 724 | return; |
— | — | @@ -601,14 +740,26 @@ |
602 | 741 | throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, array( ')' ) ); |
603 | 742 | } |
604 | 743 | |
| 744 | + /** |
| 745 | + * @param $code |
| 746 | + * @return bool |
| 747 | + */ |
605 | 748 | public function parse( $code ) { |
606 | 749 | return $this->intEval( $code )->toBool(); |
607 | 750 | } |
608 | 751 | |
| 752 | + /** |
| 753 | + * @param $filter |
| 754 | + * @return string |
| 755 | + */ |
609 | 756 | public function evaluateExpression( $filter ) { |
610 | 757 | return $this->intEval( $filter )->toString(); |
611 | 758 | } |
612 | 759 | |
| 760 | + /** |
| 761 | + * @param $code |
| 762 | + * @return AFPData |
| 763 | + */ |
613 | 764 | function intEval( $code ) { |
614 | 765 | // Setup, resetting |
615 | 766 | $this->mCode = $code; |
— | — | @@ -621,6 +772,11 @@ |
622 | 773 | return $result; |
623 | 774 | } |
624 | 775 | |
| 776 | + /** |
| 777 | + * @param $a |
| 778 | + * @param $b |
| 779 | + * @return int |
| 780 | + */ |
625 | 781 | static function lengthCompare( $a, $b ) { |
626 | 782 | if ( strlen( $a ) == strlen( $b ) ) { |
627 | 783 | return 0; |
— | — | @@ -635,6 +791,7 @@ |
636 | 792 | * Handles unexpected characters after the expression |
637 | 793 | * |
638 | 794 | * @param $result |
| 795 | + * @throws AFPUserVisibleException |
639 | 796 | */ |
640 | 797 | protected function doLevelEntry( &$result ) { |
641 | 798 | $this->doLevelSemicolon( $result ); |
— | — | @@ -661,6 +818,8 @@ |
662 | 819 | * Handles multiple expressions |
663 | 820 | * |
664 | 821 | * @param $result |
| 822 | + * @throws AFPUserVisibleException |
| 823 | + * @return |
665 | 824 | */ |
666 | 825 | protected function doLevelSet( &$result ) { |
667 | 826 | if ( $this->mCur->type == AFPToken::TID ) { |
— | — | @@ -724,6 +883,10 @@ |
725 | 884 | $this->doLevelConditions( $result ); |
726 | 885 | } |
727 | 886 | |
| 887 | + /** |
| 888 | + * @param $result |
| 889 | + * @throws AFPUserVisibleException |
| 890 | + */ |
728 | 891 | protected function doLevelConditions( &$result ) { |
729 | 892 | if ( $this->mCur->type == AFPToken::TKeyword && $this->mCur->value == 'if' ) { |
730 | 893 | $this->move(); |
— | — | @@ -838,6 +1001,9 @@ |
839 | 1002 | } |
840 | 1003 | } |
841 | 1004 | |
| 1005 | + /** |
| 1006 | + * @param $result |
| 1007 | + */ |
842 | 1008 | protected function doLevelBoolOps( &$result ) { |
843 | 1009 | $this->doLevelCompares( $result ); |
844 | 1010 | $ops = array( '&', '|', '^' ); |
— | — | @@ -876,6 +1042,9 @@ |
877 | 1043 | } |
878 | 1044 | } |
879 | 1045 | |
| 1046 | + /** |
| 1047 | + * @param $result |
| 1048 | + */ |
880 | 1049 | protected function doLevelCompares( &$result ) { |
881 | 1050 | AbuseFilter::triggerLimiter(); |
882 | 1051 | $this->doLevelSumRels( $result ); |
— | — | @@ -891,6 +1060,9 @@ |
892 | 1061 | } |
893 | 1062 | } |
894 | 1063 | |
| 1064 | + /** |
| 1065 | + * @param $result |
| 1066 | + */ |
895 | 1067 | protected function doLevelSumRels( &$result ) { |
896 | 1068 | $this->doLevelMulRels( $result ); |
897 | 1069 | wfProfileIn( __METHOD__ ); |
— | — | @@ -910,6 +1082,9 @@ |
911 | 1083 | wfProfileOut( __METHOD__ ); |
912 | 1084 | } |
913 | 1085 | |
| 1086 | + /** |
| 1087 | + * @param $result |
| 1088 | + */ |
914 | 1089 | protected function doLevelMulRels( &$result ) { |
915 | 1090 | $this->doLevelPow( $result ); |
916 | 1091 | wfProfileIn( __METHOD__ ); |
— | — | @@ -924,6 +1099,9 @@ |
925 | 1100 | wfProfileOut( __METHOD__ ); |
926 | 1101 | } |
927 | 1102 | |
| 1103 | + /** |
| 1104 | + * @param $result |
| 1105 | + */ |
928 | 1106 | protected function doLevelPow( &$result ) { |
929 | 1107 | $this->doLevelBoolInvert( $result ); |
930 | 1108 | wfProfileIn( __METHOD__ ); |
— | — | @@ -936,6 +1114,9 @@ |
937 | 1115 | wfProfileOut( __METHOD__ ); |
938 | 1116 | } |
939 | 1117 | |
| 1118 | + /** |
| 1119 | + * @param $result |
| 1120 | + */ |
940 | 1121 | protected function doLevelBoolInvert( &$result ) { |
941 | 1122 | if ( $this->mCur->type == AFPToken::TOp && $this->mCur->value == '!' ) { |
942 | 1123 | $this->move(); |
— | — | @@ -948,6 +1129,9 @@ |
949 | 1130 | } |
950 | 1131 | } |
951 | 1132 | |
| 1133 | + /** |
| 1134 | + * @param $result |
| 1135 | + */ |
952 | 1136 | protected function doLevelSpecialWords( &$result ) { |
953 | 1137 | $this->doLevelUnarys( $result ); |
954 | 1138 | $keyword = strtolower( $this->mCur->value ); |
— | — | @@ -979,6 +1163,9 @@ |
980 | 1164 | } |
981 | 1165 | } |
982 | 1166 | |
| 1167 | + /** |
| 1168 | + * @param $result |
| 1169 | + */ |
983 | 1170 | protected function doLevelUnarys( &$result ) { |
984 | 1171 | $op = $this->mCur->value; |
985 | 1172 | if ( $this->mCur->type == AFPToken::TOp && ( $op == "+" || $op == "-" ) ) { |
— | — | @@ -994,6 +1181,10 @@ |
995 | 1182 | } |
996 | 1183 | } |
997 | 1184 | |
| 1185 | + /** |
| 1186 | + * @param $result |
| 1187 | + * @throws AFPUserVisibleException |
| 1188 | + */ |
998 | 1189 | protected function doLevelListElements( &$result ) { |
999 | 1190 | $this->doLevelBraces( $result ); |
1000 | 1191 | while ( $this->mCur->type == AFPToken::TSquareBracket && $this->mCur->value == '[' ) { |
— | — | @@ -1017,6 +1208,10 @@ |
1018 | 1209 | } |
1019 | 1210 | } |
1020 | 1211 | |
| 1212 | + /** |
| 1213 | + * @param $result |
| 1214 | + * @throws AFPUserVisibleException |
| 1215 | + */ |
1021 | 1216 | protected function doLevelBraces( &$result ) { |
1022 | 1217 | if ( $this->mCur->type == AFPToken::TBrace && $this->mCur->value == '(' ) { |
1023 | 1218 | if ( $this->mShortCircuit ) { |
— | — | @@ -1036,6 +1231,10 @@ |
1037 | 1232 | } |
1038 | 1233 | } |
1039 | 1234 | |
| 1235 | + /** |
| 1236 | + * @param $result |
| 1237 | + * @throws AFPUserVisibleException |
| 1238 | + */ |
1040 | 1239 | protected function doLevelFunction( &$result ) { |
1041 | 1240 | if ( $this->mCur->type == AFPToken::TID && isset( self::$mFunctions[$this->mCur->value] ) ) { |
1042 | 1241 | wfProfileIn( __METHOD__ ); |
— | — | @@ -1104,6 +1303,11 @@ |
1105 | 1304 | } |
1106 | 1305 | } |
1107 | 1306 | |
| 1307 | + /** |
| 1308 | + * @param $result |
| 1309 | + * @throws AFPUserVisibleException |
| 1310 | + * @return AFPData |
| 1311 | + */ |
1108 | 1312 | protected function doLevelAtom( &$result ) { |
1109 | 1313 | wfProfileIn( __METHOD__ ); |
1110 | 1314 | $tok = $this->mCur->value; |
— | — | @@ -1186,6 +1390,11 @@ |
1187 | 1391 | |
1188 | 1392 | /* End of levels */ |
1189 | 1393 | |
| 1394 | + /** |
| 1395 | + * @param $var |
| 1396 | + * @return AFPData |
| 1397 | + * @throws AFPUserVisibleException |
| 1398 | + */ |
1190 | 1399 | protected function getVarValue( $var ) { |
1191 | 1400 | wfProfileIn( __METHOD__ ); |
1192 | 1401 | $var = strtolower( $var ); |
— | — | @@ -1206,6 +1415,11 @@ |
1207 | 1416 | } |
1208 | 1417 | } |
1209 | 1418 | |
| 1419 | + /** |
| 1420 | + * @param $name |
| 1421 | + * @param $value |
| 1422 | + * @throws AFPUserVisibleException |
| 1423 | + */ |
1210 | 1424 | protected function setUserVariable( $name, $value ) { |
1211 | 1425 | $builderValues = AbuseFilter::getBuilderValues(); |
1212 | 1426 | if ( array_key_exists( $name, $builderValues['vars'] ) ) { |
— | — | @@ -1214,6 +1428,13 @@ |
1215 | 1429 | $this->mVars->setVar( $name, $value ); |
1216 | 1430 | } |
1217 | 1431 | |
| 1432 | + /** |
| 1433 | + * @param $code |
| 1434 | + * @param $offset |
| 1435 | + * @return array |
| 1436 | + * @throws AFPException |
| 1437 | + * @throws AFPUserVisibleException |
| 1438 | + */ |
1218 | 1439 | static function nextToken( $code, $offset ) { |
1219 | 1440 | $tok = ''; |
1220 | 1441 | |
— | — | @@ -1394,7 +1615,7 @@ |
1395 | 1616 | |
1396 | 1617 | return array( |
1397 | 1618 | $float |
1398 | | - ? doubleval( $num ) |
| 1619 | + ? floatval( $num ) |
1399 | 1620 | : intval( $num ), |
1400 | 1621 | $float |
1401 | 1622 | ? AFPToken::TFloat |
— | — | @@ -1426,6 +1647,12 @@ |
1427 | 1648 | } |
1428 | 1649 | |
1429 | 1650 | // Built-in functions |
| 1651 | + |
| 1652 | + /** |
| 1653 | + * @param $args |
| 1654 | + * @return AFPData |
| 1655 | + * @throws AFPUserVisibleException |
| 1656 | + */ |
1430 | 1657 | protected function funcLc( $args ) { |
1431 | 1658 | global $wgContLang; |
1432 | 1659 | if ( count( $args ) < 1 ) { |
— | — | @@ -1439,6 +1666,11 @@ |
1440 | 1667 | return new AFPData( AFPData::DString, $wgContLang->lc( $s ) ); |
1441 | 1668 | } |
1442 | 1669 | |
| 1670 | + /** |
| 1671 | + * @param $args |
| 1672 | + * @return AFPData |
| 1673 | + * @throws AFPUserVisibleException |
| 1674 | + */ |
1443 | 1675 | protected function funcLen( $args ) { |
1444 | 1676 | if ( count( $args ) < 1 ) { |
1445 | 1677 | throw new AFPUserVisibleException( |
— | — | @@ -1451,6 +1683,11 @@ |
1452 | 1684 | return new AFPData( AFPData::DInt, mb_strlen( $s, 'utf-8' ) ); |
1453 | 1685 | } |
1454 | 1686 | |
| 1687 | + /** |
| 1688 | + * @param $args |
| 1689 | + * @return AFPData |
| 1690 | + * @throws AFPUserVisibleException |
| 1691 | + */ |
1455 | 1692 | protected function funcSimpleNorm( $args ) { |
1456 | 1693 | if ( count( $args ) < 1 ) { |
1457 | 1694 | throw new AFPUserVisibleException( |
— | — | @@ -1466,6 +1703,11 @@ |
1467 | 1704 | return new AFPData( AFPData::DString, $s ); |
1468 | 1705 | } |
1469 | 1706 | |
| 1707 | + /** |
| 1708 | + * @param $args |
| 1709 | + * @return AFPData |
| 1710 | + * @throws AFPUserVisibleException |
| 1711 | + */ |
1470 | 1712 | protected function funcSpecialRatio( $args ) { |
1471 | 1713 | if ( count( $args ) < 1 ) { |
1472 | 1714 | throw new AFPUserVisibleException( |
— | — | @@ -1487,6 +1729,11 @@ |
1488 | 1730 | return new AFPData( AFPData::DFloat, $val ); |
1489 | 1731 | } |
1490 | 1732 | |
| 1733 | + /** |
| 1734 | + * @param $args |
| 1735 | + * @return AFPData |
| 1736 | + * @throws AFPUserVisibleException |
| 1737 | + */ |
1491 | 1738 | protected function funcCount( $args ) { |
1492 | 1739 | if ( count( $args ) < 1 ) { |
1493 | 1740 | throw new AFPUserVisibleException( |
— | — | @@ -1517,6 +1764,12 @@ |
1518 | 1765 | return new AFPData( AFPData::DInt, $count ); |
1519 | 1766 | } |
1520 | 1767 | |
| 1768 | + /** |
| 1769 | + * @param $args |
| 1770 | + * @return AFPData |
| 1771 | + * @throws AFPUserVisibleException |
| 1772 | + * @throws Exception |
| 1773 | + */ |
1521 | 1774 | protected function funcRCount( $args ) { |
1522 | 1775 | if ( count( $args ) < 1 ) { |
1523 | 1776 | throw new AFPUserVisibleException( |
— | — | @@ -1552,6 +1805,11 @@ |
1553 | 1806 | return new AFPData( AFPData::DInt, $count ); |
1554 | 1807 | } |
1555 | 1808 | |
| 1809 | + /** |
| 1810 | + * @param $args |
| 1811 | + * @return AFPData |
| 1812 | + * @throws AFPUserVisibleException |
| 1813 | + */ |
1556 | 1814 | protected function funcIPInRange( $args ) { |
1557 | 1815 | if ( count( $args ) < 2 ) { |
1558 | 1816 | throw new AFPUserVisibleException( |
— | — | @@ -1569,6 +1827,11 @@ |
1570 | 1828 | return new AFPData( AFPData::DBool, $result ); |
1571 | 1829 | } |
1572 | 1830 | |
| 1831 | + /** |
| 1832 | + * @param $args |
| 1833 | + * @return AFPData |
| 1834 | + * @throws AFPUserVisibleException |
| 1835 | + */ |
1573 | 1836 | protected function funcCCNorm( $args ) { |
1574 | 1837 | if ( count( $args ) < 1 ) { |
1575 | 1838 | throw new AFPUserVisibleException( |
— | — | @@ -1585,6 +1848,11 @@ |
1586 | 1849 | return new AFPData( AFPData::DString, $s ); |
1587 | 1850 | } |
1588 | 1851 | |
| 1852 | + /** |
| 1853 | + * @param $args |
| 1854 | + * @return AFPData |
| 1855 | + * @throws AFPUserVisibleException |
| 1856 | + */ |
1589 | 1857 | protected function funcContainsAny( $args ) { |
1590 | 1858 | if ( count( $args ) < 2 ) { |
1591 | 1859 | throw new AFPUserVisibleException( |
— | — | @@ -1621,6 +1889,10 @@ |
1622 | 1890 | return new AFPData( AFPData::DBool, $ok ); |
1623 | 1891 | } |
1624 | 1892 | |
| 1893 | + /** |
| 1894 | + * @param $s |
| 1895 | + * @return mixed |
| 1896 | + */ |
1625 | 1897 | protected function ccnorm( $s ) { |
1626 | 1898 | static $equivset = null; |
1627 | 1899 | static $replacementArray = null; |
— | — | @@ -1634,20 +1906,35 @@ |
1635 | 1907 | return $replacementArray->replace( $s ); |
1636 | 1908 | } |
1637 | 1909 | |
| 1910 | + /** |
| 1911 | + * @param $s string |
| 1912 | + * @return array|string |
| 1913 | + */ |
1638 | 1914 | protected function rmspecials( $s ) { |
1639 | | - $s = preg_replace( '/[^\p{L}\p{N}]/u', '', $s ); |
1640 | | - |
1641 | | - return $s; |
| 1915 | + return preg_replace( '/[^\p{L}\p{N}]/u', '', $s ); |
1642 | 1916 | } |
1643 | 1917 | |
| 1918 | + /** |
| 1919 | + * @param $s string |
| 1920 | + * @return array|string |
| 1921 | + */ |
1644 | 1922 | protected function rmdoubles( $s ) { |
1645 | 1923 | return preg_replace( '/(.)\1+/us', '\1', $s ); |
1646 | 1924 | } |
1647 | 1925 | |
| 1926 | + /** |
| 1927 | + * @param $s string |
| 1928 | + * @return array|string |
| 1929 | + */ |
1648 | 1930 | protected function rmwhitespace( $s ) { |
1649 | 1931 | return preg_replace( '/\s+/u', '', $s ); |
1650 | 1932 | } |
1651 | 1933 | |
| 1934 | + /** |
| 1935 | + * @param $args array |
| 1936 | + * @return AFPData |
| 1937 | + * @throws AFPUserVisibleException |
| 1938 | + */ |
1652 | 1939 | protected function funcRMSpecials( $args ) { |
1653 | 1940 | if ( count( $args ) < 1 ) { |
1654 | 1941 | throw new AFPUserVisibleException( |
— | — | @@ -1663,6 +1950,11 @@ |
1664 | 1951 | return new AFPData( AFPData::DString, $s ); |
1665 | 1952 | } |
1666 | 1953 | |
| 1954 | + /** |
| 1955 | + * @param $args array |
| 1956 | + * @return AFPData |
| 1957 | + * @throws AFPUserVisibleException |
| 1958 | + */ |
1667 | 1959 | protected function funcRMWhitespace( $args ) { |
1668 | 1960 | if ( count( $args ) < 1 ) { |
1669 | 1961 | throw new AFPUserVisibleException( |
— | — | @@ -1678,6 +1970,11 @@ |
1679 | 1971 | return new AFPData( AFPData::DString, $s ); |
1680 | 1972 | } |
1681 | 1973 | |
| 1974 | + /** |
| 1975 | + * @param $args array |
| 1976 | + * @return AFPData |
| 1977 | + * @throws AFPUserVisibleException |
| 1978 | + */ |
1682 | 1979 | protected function funcRMDoubles( $args ) { |
1683 | 1980 | if ( count( $args ) < 1 ) { |
1684 | 1981 | throw new AFPUserVisibleException( |
— | — | @@ -1693,6 +1990,11 @@ |
1694 | 1991 | return new AFPData( AFPData::DString, $s ); |
1695 | 1992 | } |
1696 | 1993 | |
| 1994 | + /** |
| 1995 | + * @param $args array |
| 1996 | + * @return AFPData |
| 1997 | + * @throws AFPUserVisibleException |
| 1998 | + */ |
1697 | 1999 | protected function funcNorm( $args ) { |
1698 | 2000 | if ( count( $args ) < 1 ) { |
1699 | 2001 | throw new AFPUserVisibleException( |
— | — | @@ -1711,6 +2013,11 @@ |
1712 | 2014 | return new AFPData( AFPData::DString, $s ); |
1713 | 2015 | } |
1714 | 2016 | |
| 2017 | + /** |
| 2018 | + * @param $args array |
| 2019 | + * @return AFPData |
| 2020 | + * @throws AFPUserVisibleException |
| 2021 | + */ |
1715 | 2022 | protected function funcSubstr( $args ) { |
1716 | 2023 | if ( count( $args ) < 2 ) { |
1717 | 2024 | throw new AFPUserVisibleException( |
— | — | @@ -1734,6 +2041,11 @@ |
1735 | 2042 | return new AFPData( AFPData::DString, $result ); |
1736 | 2043 | } |
1737 | 2044 | |
| 2045 | + /** |
| 2046 | + * @param $args array |
| 2047 | + * @return AFPData |
| 2048 | + * @throws AFPUserVisibleException |
| 2049 | + */ |
1738 | 2050 | protected function funcStrPos( $args ) { |
1739 | 2051 | if ( count( $args ) < 2 ) { |
1740 | 2052 | throw new AFPUserVisibleException( |
— | — | @@ -1760,6 +2072,11 @@ |
1761 | 2073 | return new AFPData( AFPData::DInt, $result ); |
1762 | 2074 | } |
1763 | 2075 | |
| 2076 | + /** |
| 2077 | + * @param $args array |
| 2078 | + * @return AFPData |
| 2079 | + * @throws AFPUserVisibleException |
| 2080 | + */ |
1764 | 2081 | protected function funcStrReplace( $args ) { |
1765 | 2082 | if ( count( $args ) < 3 ) { |
1766 | 2083 | throw new AFPUserVisibleException( |
— | — | @@ -1776,6 +2093,11 @@ |
1777 | 2094 | return new AFPData( AFPData::DString, str_replace( $search, $replace, $subject ) ); |
1778 | 2095 | } |
1779 | 2096 | |
| 2097 | + /** |
| 2098 | + * @param $args array |
| 2099 | + * @return AFPData |
| 2100 | + * @throws AFPUserVisibleException |
| 2101 | + */ |
1780 | 2102 | protected function funcStrRegexEscape( $args ) { |
1781 | 2103 | if ( count( $args ) < 1 ) { |
1782 | 2104 | throw new AFPUserVisibleException( 'notenoughargs', $this->mCur->pos, |
— | — | @@ -1788,6 +2110,11 @@ |
1789 | 2111 | return new AFPData( AFPData::DString, preg_quote( $string ) ); |
1790 | 2112 | } |
1791 | 2113 | |
| 2114 | + /** |
| 2115 | + * @param $args array |
| 2116 | + * @return mixed |
| 2117 | + * @throws AFPUserVisibleException |
| 2118 | + */ |
1792 | 2119 | protected function funcSetVar( $args ) { |
1793 | 2120 | if ( count( $args ) < 2 ) { |
1794 | 2121 | throw new AFPUserVisibleException( |
— | — | @@ -1805,6 +2132,11 @@ |
1806 | 2133 | return $value; |
1807 | 2134 | } |
1808 | 2135 | |
| 2136 | + /** |
| 2137 | + * @param $args array |
| 2138 | + * @return AFPData |
| 2139 | + * @throws AFPUserVisibleException |
| 2140 | + */ |
1809 | 2141 | protected function castString( $args ) { |
1810 | 2142 | if ( count( $args ) < 1 ) { |
1811 | 2143 | throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) ); |
— | — | @@ -1814,6 +2146,11 @@ |
1815 | 2147 | return AFPData::castTypes( $val, AFPData::DString ); |
1816 | 2148 | } |
1817 | 2149 | |
| 2150 | + /** |
| 2151 | + * @param $args array |
| 2152 | + * @return AFPData |
| 2153 | + * @throws AFPUserVisibleException |
| 2154 | + */ |
1818 | 2155 | protected function castInt( $args ) { |
1819 | 2156 | if ( count( $args ) < 1 ) { |
1820 | 2157 | throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) ); |
— | — | @@ -1823,6 +2160,11 @@ |
1824 | 2161 | return AFPData::castTypes( $val, AFPData::DInt ); |
1825 | 2162 | } |
1826 | 2163 | |
| 2164 | + /** |
| 2165 | + * @param $args array |
| 2166 | + * @return AFPData |
| 2167 | + * @throws AFPUserVisibleException |
| 2168 | + */ |
1827 | 2169 | protected function castFloat( $args ) { |
1828 | 2170 | if ( count( $args ) < 1 ) { |
1829 | 2171 | throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) ); |
— | — | @@ -1832,6 +2174,11 @@ |
1833 | 2175 | return AFPData::castTypes( $val, AFPData::DFloat ); |
1834 | 2176 | } |
1835 | 2177 | |
| 2178 | + /** |
| 2179 | + * @param $args array |
| 2180 | + * @return AFPData |
| 2181 | + * @throws AFPUserVisibleException |
| 2182 | + */ |
1836 | 2183 | protected function castBool( $args ) { |
1837 | 2184 | if ( count( $args ) < 1 ) { |
1838 | 2185 | throw new AFPUserVisibleException( 'noparams', $this->mCur->pos, array( __METHOD__ ) ); |
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php |
— | — | @@ -120,6 +120,10 @@ |
121 | 121 | ); |
122 | 122 | public static $editboxName = null; |
123 | 123 | |
| 124 | + /** |
| 125 | + * @param $context IContextSource |
| 126 | + * @param $pageType |
| 127 | + */ |
124 | 128 | public static function addNavigationLinks( IContextSource $context, $pageType ) { |
125 | 129 | $linkDefs = array( |
126 | 130 | 'home' => 'Special:AbuseFilter', |
— | — | @@ -159,7 +163,7 @@ |
160 | 164 | if ( $name == $pageType ) { |
161 | 165 | $links[] = Xml::tags( 'strong', null, $msg ); |
162 | 166 | } else { |
163 | | - $links[] = $context->getSkin()->link( $title, $msg ); |
| 167 | + $links[] = Linker::link( $title, $msg ); |
164 | 168 | } |
165 | 169 | } |
166 | 170 | |
— | — | @@ -192,6 +196,9 @@ |
193 | 197 | return $vars; |
194 | 198 | } |
195 | 199 | |
| 200 | + /** |
| 201 | + * @return array |
| 202 | + */ |
196 | 203 | public static function getBuilderValues() { |
197 | 204 | static $realValues = null; |
198 | 205 | |
— | — | @@ -205,6 +212,10 @@ |
206 | 213 | return $realValues; |
207 | 214 | } |
208 | 215 | |
| 216 | + /** |
| 217 | + * @param $filter |
| 218 | + * @return bool |
| 219 | + */ |
209 | 220 | public static function filterHidden( $filter ) { |
210 | 221 | $globalIndex = self::decodeGlobalName( $filter ); |
211 | 222 | if ( $globalIndex ) { |
— | — | @@ -226,6 +237,10 @@ |
227 | 238 | return $hidden ? true : false; |
228 | 239 | } |
229 | 240 | |
| 241 | + /** |
| 242 | + * @param $val int |
| 243 | + * @throws MWException |
| 244 | + */ |
230 | 245 | public static function triggerLimiter( $val = 1 ) { |
231 | 246 | self::$condCount += $val; |
232 | 247 | |
— | — | @@ -242,9 +257,8 @@ |
243 | 258 | } |
244 | 259 | |
245 | 260 | /** |
246 | | - * @static |
247 | | - * @param $title Title |
248 | | - * @param $prefix |
| 261 | + * @param $title Title |
| 262 | + * @param $prefix |
249 | 263 | * @return AbuseFilterVariableHolder |
250 | 264 | */ |
251 | 265 | public static function generateTitleVars( $title, $prefix ) { |
— | — | @@ -280,6 +294,10 @@ |
281 | 295 | return $vars; |
282 | 296 | } |
283 | 297 | |
| 298 | + /** |
| 299 | + * @param $filter |
| 300 | + * @return mixed |
| 301 | + */ |
284 | 302 | public static function checkSyntax( $filter ) { |
285 | 303 | global $wgAbuseFilterParserClass; |
286 | 304 | |
— | — | @@ -288,6 +306,11 @@ |
289 | 307 | return $parser->checkSyntax( $filter ); |
290 | 308 | } |
291 | 309 | |
| 310 | + /** |
| 311 | + * @param $expr |
| 312 | + * @param array $vars |
| 313 | + * @return string |
| 314 | + */ |
292 | 315 | public static function evaluateExpression( $expr, $vars = array() ) { |
293 | 316 | global $wgAbuseFilterParserClass; |
294 | 317 | |
— | — | @@ -302,6 +325,14 @@ |
303 | 326 | return $parser->evaluateExpression( $expr ); |
304 | 327 | } |
305 | 328 | |
| 329 | + /** |
| 330 | + * @param $conds |
| 331 | + * @param $vars |
| 332 | + * @param $ignoreError bool |
| 333 | + * @param $keepVars string |
| 334 | + * @return bool |
| 335 | + * @throws Exception |
| 336 | + */ |
306 | 337 | public static function checkConditions( |
307 | 338 | $conds, |
308 | 339 | $vars, |
— | — | @@ -392,6 +423,14 @@ |
393 | 424 | return $filter_matched; |
394 | 425 | } |
395 | 426 | |
| 427 | + /** |
| 428 | + * @static |
| 429 | + * @param $row |
| 430 | + * @param $vars |
| 431 | + * @param $profile bool |
| 432 | + * @param $prefix string |
| 433 | + * @return bool |
| 434 | + */ |
396 | 435 | public static function checkFilter( $row, $vars, $profile = false, $prefix = '' ) { |
397 | 436 | $filterID = $prefix . $row->af_id; |
398 | 437 | |
— | — | @@ -431,6 +470,9 @@ |
432 | 471 | return $result; |
433 | 472 | } |
434 | 473 | |
| 474 | + /** |
| 475 | + * @param $filter |
| 476 | + */ |
435 | 477 | public static function resetFilterProfile( $filter ) { |
436 | 478 | global $wgMemc; |
437 | 479 | $countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' ); |
— | — | @@ -440,6 +482,11 @@ |
441 | 483 | $wgMemc->delete( $totalKey ); |
442 | 484 | } |
443 | 485 | |
| 486 | + /** |
| 487 | + * @param $filter |
| 488 | + * @param $time |
| 489 | + * @param $conds |
| 490 | + */ |
444 | 491 | public static function recordProfilingResult( $filter, $time, $conds ) { |
445 | 492 | global $wgMemc; |
446 | 493 | |
— | — | @@ -462,6 +509,10 @@ |
463 | 510 | } |
464 | 511 | } |
465 | 512 | |
| 513 | + /** |
| 514 | + * @param $filter |
| 515 | + * @return array |
| 516 | + */ |
466 | 517 | public static function getFilterProfile( $filter ) { |
467 | 518 | global $wgMemc; |
468 | 519 | |
— | — | @@ -491,7 +542,7 @@ |
492 | 543 | * |
493 | 544 | * @param $filter string |
494 | 545 | * |
495 | | - * @return string|false |
| 546 | + * @return string|bool |
496 | 547 | */ |
497 | 548 | public static function decodeGlobalName( $filter ) { |
498 | 549 | if ( strpos( $filter, 'global-' ) == 0 ) { |
— | — | @@ -501,6 +552,10 @@ |
502 | 553 | return false; |
503 | 554 | } |
504 | 555 | |
| 556 | + /** |
| 557 | + * @param $filters array |
| 558 | + * @return array |
| 559 | + */ |
505 | 560 | public static function getConsequencesForFilters( $filters ) { |
506 | 561 | $globalFilters = array(); |
507 | 562 | $localFilters = array(); |
— | — | @@ -536,6 +591,12 @@ |
537 | 592 | return $consequences; |
538 | 593 | } |
539 | 594 | |
| 595 | + /** |
| 596 | + * @param $dbr DatabaseBase |
| 597 | + * @param $filters array |
| 598 | + * @param $prefix string |
| 599 | + * @return array |
| 600 | + */ |
540 | 601 | public static function loadConsequencesFromDB( $dbr, $filters, $prefix = '' ) { |
541 | 602 | $actionsByFilter = array(); |
542 | 603 | foreach ( $filters as $filter ) { |
— | — | @@ -670,6 +731,11 @@ |
671 | 732 | return array( $actionsTaken, implode( "\n", $messages ) ); |
672 | 733 | } |
673 | 734 | |
| 735 | + /** |
| 736 | + * @param $vars AbuseFilterVariableHolder |
| 737 | + * @param $title |
| 738 | + * @return bool |
| 739 | + */ |
674 | 740 | public static function filterAction( $vars, $title ) { |
675 | 741 | global $wgUser, $wgTitle; |
676 | 742 | |
— | — | @@ -731,6 +797,13 @@ |
732 | 798 | return $error_msg; |
733 | 799 | } |
734 | 800 | |
| 801 | + /** |
| 802 | + * @param $actions_taken |
| 803 | + * @param $log_template |
| 804 | + * @param $action |
| 805 | + * @param $vars AbuseFilterVariableHolder |
| 806 | + * @return mixed |
| 807 | + */ |
735 | 808 | public static function addLogEntries( $actions_taken, $log_template, $action, $vars ) { |
736 | 809 | wfProfileIn( __METHOD__ ); |
737 | 810 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -961,6 +1034,14 @@ |
962 | 1035 | return $obj; |
963 | 1036 | } |
964 | 1037 | |
| 1038 | + /** |
| 1039 | + * @param $action |
| 1040 | + * @param $parameters |
| 1041 | + * @param $title |
| 1042 | + * @param $vars AbuseFilterVariableHolder |
| 1043 | + * @param $rule_desc |
| 1044 | + * @return string |
| 1045 | + */ |
965 | 1046 | public static function takeConsequenceAction( $action, $parameters, $title, |
966 | 1047 | $vars, $rule_desc ) |
967 | 1048 | { |
— | — | @@ -1120,6 +1201,14 @@ |
1121 | 1202 | return $display; |
1122 | 1203 | } |
1123 | 1204 | |
| 1205 | + /** |
| 1206 | + * @param $throttleId |
| 1207 | + * @param $types |
| 1208 | + * @param $title |
| 1209 | + * @param $rateCount |
| 1210 | + * @param $ratePeriod |
| 1211 | + * @return bool |
| 1212 | + */ |
1124 | 1213 | public static function isThrottled( $throttleId, $types, $title, $rateCount, $ratePeriod ) { |
1125 | 1214 | global $wgMemc; |
1126 | 1215 | |
— | — | @@ -1148,6 +1237,11 @@ |
1149 | 1238 | return false; // NOT THROTTLED |
1150 | 1239 | } |
1151 | 1240 | |
| 1241 | + /** |
| 1242 | + * @param $type |
| 1243 | + * @param $title Title |
| 1244 | + * @return Int|string |
| 1245 | + */ |
1152 | 1246 | public static function throttleIdentifier( $type, $title ) { |
1153 | 1247 | global $wgUser; |
1154 | 1248 | |
— | — | @@ -1178,6 +1272,12 @@ |
1179 | 1273 | return $identifier; |
1180 | 1274 | } |
1181 | 1275 | |
| 1276 | + /** |
| 1277 | + * @param $throttleId |
| 1278 | + * @param $type |
| 1279 | + * @param $title Title |
| 1280 | + * @return String |
| 1281 | + */ |
1182 | 1282 | public static function throttleKey( $throttleId, $type, $title ) { |
1183 | 1283 | $types = explode( ',', $type ); |
1184 | 1284 | |
— | — | @@ -1192,10 +1292,17 @@ |
1193 | 1293 | return wfMemcKey( 'abusefilter', 'throttle', $throttleId, $type, $identifier ); |
1194 | 1294 | } |
1195 | 1295 | |
| 1296 | + /** |
| 1297 | + * @param $user User |
| 1298 | + * @return String |
| 1299 | + */ |
1196 | 1300 | public static function autoPromoteBlockKey( $user ) { |
1197 | 1301 | return wfMemcKey( 'abusefilter', 'block-autopromote', $user->getId() ); |
1198 | 1302 | } |
1199 | 1303 | |
| 1304 | + /** |
| 1305 | + * @param $filters |
| 1306 | + */ |
1200 | 1307 | public static function recordStats( $filters ) { |
1201 | 1308 | global $wgAbuseFilterConditionLimit, $wgMemc; |
1202 | 1309 | |
— | — | @@ -1234,6 +1341,10 @@ |
1235 | 1342 | wfProfileOut( __METHOD__ ); |
1236 | 1343 | } |
1237 | 1344 | |
| 1345 | + /** |
| 1346 | + * @param $filters |
| 1347 | + * @param $total |
| 1348 | + */ |
1238 | 1349 | public static function checkEmergencyDisable( $filters, $total ) { |
1239 | 1350 | global $wgAbuseFilterEmergencyDisableThreshold, $wgAbuseFilterEmergencyDisableCount, |
1240 | 1351 | $wgAbuseFilterEmergencyDisableAge, $wgMemc; |
— | — | @@ -1272,18 +1383,31 @@ |
1273 | 1384 | } |
1274 | 1385 | } |
1275 | 1386 | |
| 1387 | + /** |
| 1388 | + * @return String |
| 1389 | + */ |
1276 | 1390 | public static function filterLimitReachedKey() { |
1277 | 1391 | return wfMemcKey( 'abusefilter', 'stats', 'overflow' ); |
1278 | 1392 | } |
1279 | 1393 | |
| 1394 | + /** |
| 1395 | + * @return String |
| 1396 | + */ |
1280 | 1397 | public static function filterUsedKey() { |
1281 | 1398 | return wfMemcKey( 'abusefilter', 'stats', 'total' ); |
1282 | 1399 | } |
1283 | 1400 | |
| 1401 | + /** |
| 1402 | + * @param $filter |
| 1403 | + * @return String |
| 1404 | + */ |
1284 | 1405 | public static function filterMatchesKey( $filter = null ) { |
1285 | 1406 | return wfMemcKey( 'abusefilter', 'stats', 'matches', $filter ); |
1286 | 1407 | } |
1287 | 1408 | |
| 1409 | + /** |
| 1410 | + * @return User |
| 1411 | + */ |
1288 | 1412 | public static function getFilterUser() { |
1289 | 1413 | $user = User::newFromName( wfMsgForContent( 'abusefilter-blocker' ) ); |
1290 | 1414 | $user->load(); |
— | — | @@ -1318,6 +1442,7 @@ |
1319 | 1443 | * @param $textName String |
1320 | 1444 | * @param $addResultDiv Boolean |
1321 | 1445 | * @param $canEdit Boolean |
| 1446 | + * @return string |
1322 | 1447 | */ |
1323 | 1448 | static function buildEditBox( $rules, $textName = 'wpFilterRules', $addResultDiv = true, |
1324 | 1449 | $canEdit = true ) { |
— | — | @@ -1442,6 +1567,10 @@ |
1443 | 1568 | return array_unique( $differences ); |
1444 | 1569 | } |
1445 | 1570 | |
| 1571 | + /** |
| 1572 | + * @param $row |
| 1573 | + * @return array |
| 1574 | + */ |
1446 | 1575 | static function translateFromHistory( $row ) { |
1447 | 1576 | # Translate into an abuse_filter row with some black magic. |
1448 | 1577 | # This is ever so slightly evil! |
— | — | @@ -1477,12 +1606,20 @@ |
1478 | 1607 | return array( $af_row, $actions_output ); |
1479 | 1608 | } |
1480 | 1609 | |
| 1610 | + /** |
| 1611 | + * @param $action string |
| 1612 | + * @return String |
| 1613 | + */ |
1481 | 1614 | static function getActionDisplay( $action ) { |
1482 | 1615 | $display = wfMsg( "abusefilter-action-$action" ); |
1483 | 1616 | $display = wfEmptyMsg( "abusefilter-action-$action", $display ) ? $action : $display; |
1484 | 1617 | return $display; |
1485 | 1618 | } |
1486 | 1619 | |
| 1620 | + /** |
| 1621 | + * @param $row |
| 1622 | + * @return AbuseFilterVariableHolder|null |
| 1623 | + */ |
1487 | 1624 | public static function getVarsFromRCRow( $row ) { |
1488 | 1625 | if ( $row->rc_this_oldid ) { |
1489 | 1626 | // It's an edit. |
— | — | @@ -1502,6 +1639,10 @@ |
1503 | 1640 | return $vars; |
1504 | 1641 | } |
1505 | 1642 | |
| 1643 | + /** |
| 1644 | + * @param $row |
| 1645 | + * @return AbuseFilterVariableHolder |
| 1646 | + */ |
1506 | 1647 | public static function getCreateVarsFromRCRow( $row ) { |
1507 | 1648 | $vars = new AbuseFilterVariableHolder; |
1508 | 1649 | |
— | — | @@ -1518,6 +1659,10 @@ |
1519 | 1660 | return $vars; |
1520 | 1661 | } |
1521 | 1662 | |
| 1663 | + /** |
| 1664 | + * @param $row |
| 1665 | + * @return AbuseFilterVariableHolder |
| 1666 | + */ |
1522 | 1667 | public static function getEditVarsFromRCRow( $row ) { |
1523 | 1668 | $vars = new AbuseFilterVariableHolder; |
1524 | 1669 | $title = Title::makeTitle( $row->rc_namespace, $row->rc_title ); |
— | — | @@ -1551,6 +1696,10 @@ |
1552 | 1697 | return $vars; |
1553 | 1698 | } |
1554 | 1699 | |
| 1700 | + /** |
| 1701 | + * @param $row |
| 1702 | + * @return AbuseFilterVariableHolder |
| 1703 | + */ |
1555 | 1704 | public static function getMoveVarsFromRCRow( $row ) { |
1556 | 1705 | $vars = new AbuseFilterVariableHolder; |
1557 | 1706 | |
— | — | @@ -1580,8 +1729,8 @@ |
1581 | 1730 | } |
1582 | 1731 | |
1583 | 1732 | /** |
1584 | | - * @static |
1585 | | - * @param $title Title |
| 1733 | + * @param $title Title |
| 1734 | + * @param $article Array |
1586 | 1735 | * @return AbuseFilterVariableHolder |
1587 | 1736 | */ |
1588 | 1737 | public static function getEditVars( $title, $article = null ) { |
— | — | @@ -1640,6 +1789,10 @@ |
1641 | 1790 | return $vars; |
1642 | 1791 | } |
1643 | 1792 | |
| 1793 | + /** |
| 1794 | + * @param $vars AbuseFilterVariableHolder |
| 1795 | + * @return string |
| 1796 | + */ |
1644 | 1797 | public static function buildVarDumpTable( $vars ) { |
1645 | 1798 | // Export all values |
1646 | 1799 | if ( $vars instanceof AbuseFilterVariableHolder ) { |
— | — | @@ -1693,20 +1846,32 @@ |
1694 | 1847 | return $output; |
1695 | 1848 | } |
1696 | 1849 | |
| 1850 | + /** |
| 1851 | + * @param $page |
| 1852 | + * @param $type |
| 1853 | + * @param $title Title |
| 1854 | + * @param $sk Skin |
| 1855 | + * @param $args array |
| 1856 | + * @return String |
| 1857 | + */ |
1697 | 1858 | static function modifyActionText( $page, $type, $title, $sk, $args ) { |
1698 | 1859 | list( $history_id, $filter_id ) = $args; |
1699 | 1860 | |
1700 | | - $filter_link = $sk ? $sk->link( $title ) : $title->getCanonicalURL(); |
| 1861 | + $filter_link = Linker::link( $title ); |
1701 | 1862 | |
1702 | 1863 | $details_title = SpecialPage::getTitleFor( 'AbuseFilter', "history/$filter_id/diff/prev/$history_id" ); |
1703 | 1864 | $details_text = wfMsgExt( 'abusefilter-log-detailslink', 'parseinline' ); |
1704 | | - $details_link = |
1705 | | - $sk ? $sk->link( $details_title, $details_text ) : $details_title->getCanonicalURL(); |
| 1865 | + $details_link = Linker::link( $details_title, $details_text ); |
1706 | 1866 | |
1707 | 1867 | return wfMsgExt( 'abusefilter-log-entry-modify', |
1708 | 1868 | array( 'parseinline', 'replaceafter' ), array( $filter_link, $details_link ) ); |
1709 | 1869 | } |
1710 | 1870 | |
| 1871 | + /** |
| 1872 | + * @param $action |
| 1873 | + * @param $parameters |
| 1874 | + * @return String |
| 1875 | + */ |
1711 | 1876 | static function formatAction( $action, $parameters ) { |
1712 | 1877 | global $wgLang; |
1713 | 1878 | if ( count( $parameters ) == 0 ) { |
— | — | @@ -1719,6 +1884,10 @@ |
1720 | 1885 | return $displayAction; |
1721 | 1886 | } |
1722 | 1887 | |
| 1888 | + /** |
| 1889 | + * @param $value array |
| 1890 | + * @return string |
| 1891 | + */ |
1723 | 1892 | static function formatFlags( $value ) { |
1724 | 1893 | global $wgLang; |
1725 | 1894 | $flags = array_filter( explode( ',', $value ) ); |
— | — | @@ -1729,6 +1898,9 @@ |
1730 | 1899 | return $wgLang->commaList( $flags_display ); |
1731 | 1900 | } |
1732 | 1901 | |
| 1902 | + /** |
| 1903 | + * @param $data string |
| 1904 | + */ |
1733 | 1905 | static function sendToUDP( $data ) { |
1734 | 1906 | global $wgAbuseFilterUDPPrefix, $wgAbuseFilterUDPAddress, $wgAbuseFilterUDPPort; |
1735 | 1907 | |
— | — | @@ -1740,11 +1912,15 @@ |
1741 | 1913 | ); |
1742 | 1914 | } |
1743 | 1915 | |
| 1916 | + /** |
| 1917 | + * @param $filterID |
| 1918 | + * @return bool|mixed|string |
| 1919 | + */ |
1744 | 1920 | static function getGlobalFilterDescription( $filterID ) { |
1745 | 1921 | global $wgAbuseFilterCentralDB; |
1746 | 1922 | |
1747 | 1923 | if ( !$wgAbuseFilterCentralDB ) { |
1748 | | - return; |
| 1924 | + return ''; |
1749 | 1925 | } |
1750 | 1926 | |
1751 | 1927 | $fdb = wfGetDB( DB_SLAVE, array(), $wgAbuseFilterCentralDB ); |
Index: trunk/extensions/AbuseFilter/AbuseFilterVariableHolder.php |
— | — | @@ -3,6 +3,10 @@ |
4 | 4 | var $mVars = array(); |
5 | 5 | static $varBlacklist = array( 'context' ); |
6 | 6 | |
| 7 | + /** |
| 8 | + * @param $variable |
| 9 | + * @param $datum |
| 10 | + */ |
7 | 11 | function setVar( $variable, $datum ) { |
8 | 12 | $variable = strtolower( $variable ); |
9 | 13 | if ( !( $datum instanceof AFPData || $datum instanceof AFComputedVariable ) ) { |
— | — | @@ -12,11 +16,20 @@ |
13 | 17 | $this->mVars[$variable] = $datum; |
14 | 18 | } |
15 | 19 | |
| 20 | + /** |
| 21 | + * @param $variable |
| 22 | + * @param $method |
| 23 | + * @param $parameters |
| 24 | + */ |
16 | 25 | function setLazyLoadVar( $variable, $method, $parameters ) { |
17 | 26 | $placeholder = new AFComputedVariable( $method, $parameters ); |
18 | 27 | $this->setVar( $variable, $placeholder ); |
19 | 28 | } |
20 | 29 | |
| 30 | + /** |
| 31 | + * @param $variable |
| 32 | + * @return AFPData |
| 33 | + */ |
21 | 34 | function getVar( $variable ) { |
22 | 35 | $variable = strtolower( $variable ); |
23 | 36 | if ( isset( $this->mVars[$variable] ) ) { |
— | — | @@ -32,6 +45,9 @@ |
33 | 46 | } |
34 | 47 | } |
35 | 48 | |
| 49 | + /** |
| 50 | + * @return AbuseFilterVariableHolder |
| 51 | + */ |
36 | 52 | static function merge() { |
37 | 53 | $newHolder = new AbuseFilterVariableHolder; |
38 | 54 | |
— | — | @@ -42,6 +58,10 @@ |
43 | 59 | return $newHolder; |
44 | 60 | } |
45 | 61 | |
| 62 | + /** |
| 63 | + * @param $addHolder |
| 64 | + * @throws MWException |
| 65 | + */ |
46 | 66 | function addHolder( $addHolder ) { |
47 | 67 | if ( !is_object( $addHolder ) ) { |
48 | 68 | throw new MWException( 'Invalid argument to AbuseFilterVariableHolder::addHolder' ); |
— | — | @@ -54,6 +74,9 @@ |
55 | 75 | $this->setVar( 'context', 'stored' ); |
56 | 76 | } |
57 | 77 | |
| 78 | + /** |
| 79 | + * @return array |
| 80 | + */ |
58 | 81 | function exportAllVars() { |
59 | 82 | $allVarNames = array_keys( $this->mVars ); |
60 | 83 | $exported = array(); |
— | — | @@ -67,6 +90,10 @@ |
68 | 91 | return $exported; |
69 | 92 | } |
70 | 93 | |
| 94 | + /** |
| 95 | + * @param $var |
| 96 | + * @return bool |
| 97 | + */ |
71 | 98 | function varIsSet( $var ) { |
72 | 99 | return array_key_exists( $var, $this->mVars ); |
73 | 100 | } |
— | — | @@ -102,6 +129,10 @@ |
103 | 130 | static $userCache = array(); |
104 | 131 | static $articleCache = array(); |
105 | 132 | |
| 133 | + /** |
| 134 | + * @param $method |
| 135 | + * @param $parameters |
| 136 | + */ |
106 | 137 | function __construct( $method, $parameters ) { |
107 | 138 | $this->mMethod = $method; |
108 | 139 | $this->mParameters = $parameters; |
— | — | @@ -119,7 +150,7 @@ |
120 | 151 | function parseNonEditWikitext( $wikitext, $article ) { |
121 | 152 | static $cache = array(); |
122 | 153 | |
123 | | - $cacheKey = md5( $wikitext ) . ':' . $article->mTitle->getPrefixedText(); |
| 154 | + $cacheKey = md5( $wikitext ) . ':' . $article->getTitle()->getPrefixedText(); |
124 | 155 | |
125 | 156 | if ( isset( $cache[$cacheKey] ) ) { |
126 | 157 | return $cache[$cacheKey]; |
— | — | @@ -135,6 +166,10 @@ |
136 | 167 | return $edit; |
137 | 168 | } |
138 | 169 | |
| 170 | + /** |
| 171 | + * @param $username string |
| 172 | + * @return User |
| 173 | + */ |
139 | 174 | static function userObjectFromName( $username ) { |
140 | 175 | if ( isset( self::$userCache[$username] ) ) { |
141 | 176 | return self::$userCache[$username]; |
— | — | @@ -160,6 +195,11 @@ |
161 | 196 | return $user; |
162 | 197 | } |
163 | 198 | |
| 199 | + /** |
| 200 | + * @param $namespace |
| 201 | + * @param $title Title |
| 202 | + * @return Article |
| 203 | + */ |
164 | 204 | static function articleFromTitle( $namespace, $title ) { |
165 | 205 | if ( isset( self::$articleCache["$namespace:$title"] ) ) { |
166 | 206 | return self::$articleCache["$namespace:$title"]; |
— | — | @@ -177,6 +217,10 @@ |
178 | 218 | return self::$articleCache["$namespace:$title"]; |
179 | 219 | } |
180 | 220 | |
| 221 | + /** |
| 222 | + * @param $article Article |
| 223 | + * @return array |
| 224 | + */ |
181 | 225 | static function getLinksFromDB( $article ) { |
182 | 226 | // Stolen from ConfirmEdit |
183 | 227 | $id = $article->getId(); |
— | — | @@ -198,6 +242,12 @@ |
199 | 243 | return $links; |
200 | 244 | } |
201 | 245 | |
| 246 | + /** |
| 247 | + * @param $vars AbuseFilterVariableHolder |
| 248 | + * @return AFPData|array|int|mixed|null|string |
| 249 | + * @throws MWException |
| 250 | + * @throws AFPException |
| 251 | + */ |
202 | 252 | function compute( $vars ) { |
203 | 253 | $parameters = $this->mParameters; |
204 | 254 | $result = null; |