Index: trunk/extensions/AssertEdit/AssertEdit_body.php |
— | — | @@ -1,42 +1,44 @@ |
2 | 2 | <?php |
3 | | -if ( ! defined( 'MEDIAWIKI' ) ) |
| 3 | +if ( ! defined( 'MEDIAWIKI' ) ) { |
4 | 4 | die(); |
| 5 | +} |
5 | 6 | |
| 7 | +/** |
| 8 | + * Assert! |
| 9 | + */ |
6 | 10 | class AssertEdit { |
7 | 11 | /** |
8 | 12 | * methods for core assertions |
9 | 13 | * |
10 | | - * @param $editPage |
| 14 | + * @param $editPage EditPage |
11 | 15 | * @return bool |
12 | 16 | */ |
13 | | - static function assert_user( $editPage ) { |
| 17 | + public static function assert_user( $editPage ) { |
14 | 18 | global $wgUser; |
15 | 19 | return $wgUser->isLoggedIn(); |
16 | 20 | } |
17 | 21 | |
18 | 22 | /** |
19 | | - * @static |
20 | 23 | * @param $editPage EditPage |
21 | 24 | * @return bool |
22 | 25 | */ |
23 | | - static function assert_bot( $editPage ) { |
| 26 | + public static function assert_bot( $editPage ) { |
24 | 27 | global $wgUser; |
25 | 28 | return $wgUser->isAllowed( 'bot' ); |
26 | 29 | } |
27 | 30 | |
28 | 31 | /** |
29 | | - * @static |
30 | 32 | * @param $editPage EditPage |
31 | 33 | * @return bool |
32 | 34 | */ |
33 | | - static function assert_exists( $editPage ) { |
| 35 | + public static function assert_exists( $editPage ) { |
34 | 36 | return $editPage->mTitle->exists(); |
35 | 37 | } |
36 | 38 | |
37 | 39 | /** |
38 | 40 | * List of assertions; can be modified with setAssert |
39 | 41 | */ |
40 | | - public static $msAssert = array( |
| 42 | + private static $msAssert = array( |
41 | 43 | // simple constants, i.e. to test if the extension is installed. |
42 | 44 | 'true' => true, |
43 | 45 | 'false' => false, |
— | — | @@ -49,7 +51,19 @@ |
50 | 52 | 'test' => false // Do we allow random tests? |
51 | 53 | ); |
52 | 54 | |
53 | | - static function setAssert( $key, $value ) { |
| 55 | + /** |
| 56 | + * @return array |
| 57 | + */ |
| 58 | + public static function getAssertions() { |
| 59 | + return self::$msAssert; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @param $key string |
| 64 | + * @param $value bool|Callback |
| 65 | + * @return bool |
| 66 | + */ |
| 67 | + public static function setAssert( $key, $value ) { |
54 | 68 | // Don't confuse things by changing core assertions. |
55 | 69 | switch ( $key ) { |
56 | 70 | case 'true': |
— | — | @@ -68,8 +82,16 @@ |
69 | 83 | } |
70 | 84 | } |
71 | 85 | |
72 | | - // call the specified assertion |
73 | | - static function callAssert( $editPage, $assertName, $negate ) { |
| 86 | + /** |
| 87 | + * call the specified assertion |
| 88 | + * @param $editPage Editpage |
| 89 | + * @param $assertName string |
| 90 | + * @param $negate bool |
| 91 | + * @return bool |
| 92 | + */ |
| 93 | + public static function callAssert( $editPage, $assertName, $negate ) { |
| 94 | + // unrecognized assert fails, regardless of negation. |
| 95 | + $pass = false; |
74 | 96 | if ( isset( self::$msAssert[$assertName] ) ) { |
75 | 97 | if ( is_bool( self::$msAssert[$assertName] ) ) { |
76 | 98 | $pass = self::$msAssert[$assertName]; |
— | — | @@ -80,9 +102,6 @@ |
81 | 103 | if ( $negate && isset( $pass ) ) { |
82 | 104 | $pass = !$pass; |
83 | 105 | } |
84 | | - } else { |
85 | | - // unrecognized assert fails, regardless of negation. |
86 | | - $pass = false; |
87 | 106 | } |
88 | 107 | return $pass; |
89 | 108 | } |
Index: trunk/extensions/AssertEdit/AssertEdit.php |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | * @param $editPage EditPage |
80 | 80 | * @param $textBox |
81 | 81 | * @param $result array |
82 | | - * @return bool|mixed |
| 82 | + * @return bool |
83 | 83 | */ |
84 | 84 | function efAssertApiEditHook( $editPage, $textBox, &$result ) { |
85 | 85 | global $wgRequest; |
— | — | @@ -117,7 +117,7 @@ |
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | |
121 | | - $options = array_keys( AssertEdit::$msAssert ); |
| 121 | + $options = array_keys( AssertEdit::getAssertions() ); |
122 | 122 | $params['assert'][ApiBase::PARAM_TYPE] = $options; |
123 | 123 | $params['nassert'][ApiBase::PARAM_TYPE] = $options; |
124 | 124 | |