Index: trunk/extensions/AssertEdit/AssertEdit_body.php |
— | — | @@ -2,19 +2,33 @@ |
3 | 3 | if ( ! defined( 'MEDIAWIKI' ) ) |
4 | 4 | die(); |
5 | 5 | |
6 | | -class AssertEdit |
7 | | -{ |
| 6 | +class AssertEdit { |
8 | 7 | /** |
9 | 8 | * methods for core assertions |
| 9 | + * |
| 10 | + * @param $editPage |
| 11 | + * @return bool |
10 | 12 | */ |
11 | 13 | static function assert_user( $editPage ) { |
12 | 14 | global $wgUser; |
13 | 15 | return $wgUser->isLoggedIn(); |
14 | 16 | } |
| 17 | + |
| 18 | + /** |
| 19 | + * @static |
| 20 | + * @param $editPage EditPage |
| 21 | + * @return bool |
| 22 | + */ |
15 | 23 | static function assert_bot( $editPage ) { |
16 | 24 | global $wgUser; |
17 | 25 | return $wgUser->isAllowed( 'bot' ); |
18 | 26 | } |
| 27 | + |
| 28 | + /** |
| 29 | + * @static |
| 30 | + * @param $editPage EditPage |
| 31 | + * @return bool |
| 32 | + */ |
19 | 33 | static function assert_exists( $editPage ) { |
20 | 34 | return $editPage->mTitle->exists(); |
21 | 35 | } |
— | — | @@ -22,7 +36,7 @@ |
23 | 37 | /* |
24 | 38 | * List of assertions; can be modified with setAssert |
25 | 39 | */ |
26 | | - static private $msAssert = array( |
| 40 | + public static $msAssert = array( |
27 | 41 | // simple constants, i.e. to test if the extension is installed. |
28 | 42 | 'true' => true, |
29 | 43 | 'false' => false, |
Index: trunk/extensions/AssertEdit/AssertEdit.php |
— | — | @@ -27,8 +27,11 @@ |
28 | 28 | $dir = dirname( __FILE__ ) . '/'; |
29 | 29 | $wgExtensionMessagesFiles['AssertEdit'] = $dir . 'AssertEdit.i18n.php'; |
30 | 30 | $wgAutoloadClasses['AssertEdit'] = $dir . 'AssertEdit_body.php'; |
| 31 | + |
31 | 32 | $wgHooks['AlternateEdit'][] = 'efAssertEditHook'; |
32 | 33 | $wgHooks['APIEditBeforeSave'][] = 'efAssertApiEditHook'; |
| 34 | +$wgHooks['APIGetAllowedParams'][] = 'efAssertApiEditGetAllowedParams'; |
| 35 | +$wgHooks['APIGetParamDescription'][] = 'efAssertApiEditGetParamDescription'; |
33 | 36 | |
34 | 37 | function efAssertEditHook( $editpage ) { |
35 | 38 | global $wgOut, $wgRequest; |
— | — | @@ -93,3 +96,34 @@ |
94 | 97 | |
95 | 98 | return $pass; |
96 | 99 | } |
| 100 | + |
| 101 | +function efAssertApiEditGetAllowedParams( &$module, &$params ) { |
| 102 | + if ( !$module instanceof ApiEditPage ) { |
| 103 | + return true; |
| 104 | + } |
| 105 | + |
| 106 | + $options = array_keys( AssertEdit::$msAssert ); |
| 107 | + $params['assert'][ApiBase::PARAM_TYPE] = $options; |
| 108 | + $params['nassert'][ApiBase::PARAM_TYPE] = $options; |
| 109 | + |
| 110 | + return true; |
| 111 | +} |
| 112 | + |
| 113 | +function efAssertApiEditGetParamDescription( &$module, &$desc ) { |
| 114 | + if ( !$module instanceof ApiEditPage ) { |
| 115 | + return true; |
| 116 | + } |
| 117 | + |
| 118 | + $options = array( |
| 119 | + ' true - Always true; nassert=true will fail if the extension is installed.', |
| 120 | + ' false - Always false; assert=false will fail if the extension is installed.', |
| 121 | + ' user - Verify that bot is logged in, to prevent anonymous edits.', |
| 122 | + ' bot - Verify that bot is logged in and has a bot flag.', |
| 123 | + ' exists - Verify that page exists. Could be useful from other extensions, i.e. adding nassert=exists to the inputbox extension.', |
| 124 | + ' test - Verify that this wiki allows random testing. Defaults to false, but can be overridden in LocalSettings.php.' |
| 125 | + ); |
| 126 | + $desc['assert'] = array_merge( array( 'Allows bots to make assertions.' ), $options ); |
| 127 | + $desc['nassert'] = array_merge( array( 'Allows bots to make negative assertions.' ), $options ); |
| 128 | + |
| 129 | + return true; |
| 130 | +} |