r83181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83180‎ | r83181 | r83182 >
Date:23:47, 3 March 2011
Author:reedy
Status:ok
Tags:
Comment:
Redo r62840 properly

Use Umherirrenders idea to do it http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62840#c7254

Add in a few tweaks, to keep it more consistent, and reduce duplication

Add some documentation also
Modified paths:
  • /trunk/extensions/AssertEdit/AssertEdit.php (modified) (history)
  • /trunk/extensions/AssertEdit/AssertEdit_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AssertEdit/AssertEdit_body.php
@@ -2,19 +2,33 @@
33 if ( ! defined( 'MEDIAWIKI' ) )
44 die();
55
6 -class AssertEdit
7 -{
 6+class AssertEdit {
87 /**
98 * methods for core assertions
 9+ *
 10+ * @param $editPage
 11+ * @return bool
1012 */
1113 static function assert_user( $editPage ) {
1214 global $wgUser;
1315 return $wgUser->isLoggedIn();
1416 }
 17+
 18+ /**
 19+ * @static
 20+ * @param $editPage EditPage
 21+ * @return bool
 22+ */
1523 static function assert_bot( $editPage ) {
1624 global $wgUser;
1725 return $wgUser->isAllowed( 'bot' );
1826 }
 27+
 28+ /**
 29+ * @static
 30+ * @param $editPage EditPage
 31+ * @return bool
 32+ */
1933 static function assert_exists( $editPage ) {
2034 return $editPage->mTitle->exists();
2135 }
@@ -22,7 +36,7 @@
2337 /*
2438 * List of assertions; can be modified with setAssert
2539 */
26 - static private $msAssert = array(
 40+ public static $msAssert = array(
2741 // simple constants, i.e. to test if the extension is installed.
2842 'true' => true,
2943 'false' => false,
Index: trunk/extensions/AssertEdit/AssertEdit.php
@@ -27,8 +27,11 @@
2828 $dir = dirname( __FILE__ ) . '/';
2929 $wgExtensionMessagesFiles['AssertEdit'] = $dir . 'AssertEdit.i18n.php';
3030 $wgAutoloadClasses['AssertEdit'] = $dir . 'AssertEdit_body.php';
 31+
3132 $wgHooks['AlternateEdit'][] = 'efAssertEditHook';
3233 $wgHooks['APIEditBeforeSave'][] = 'efAssertApiEditHook';
 34+$wgHooks['APIGetAllowedParams'][] = 'efAssertApiEditGetAllowedParams';
 35+$wgHooks['APIGetParamDescription'][] = 'efAssertApiEditGetParamDescription';
3336
3437 function efAssertEditHook( $editpage ) {
3538 global $wgOut, $wgRequest;
@@ -93,3 +96,34 @@
9497
9598 return $pass;
9699 }
 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+}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62840Add a simple Api Module to display the possible parameters (ie an API help) f...reedy20:54, 22 February 2010

Status & tagging log