https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112722
Revision: 112722
Author: reedy
Date: 2012-02-29 20:54:46 +0000 (Wed, 29 Feb 2012)
Log Message:
-----------
Little bit of code tidying up and documentation
Modified Paths:
--------------
trunk/extensions/AssertEdit/AssertEdit.php
trunk/extensions/AssertEdit/AssertEdit_body.php
Modified: trunk/extensions/AssertEdit/AssertEdit.php
===================================================================
--- trunk/extensions/AssertEdit/AssertEdit.php 2012-02-29 20:52:44 UTC (rev
112721)
+++ trunk/extensions/AssertEdit/AssertEdit.php 2012-02-29 20:54:46 UTC (rev
112722)
@@ -78,7 +78,7 @@
* @param $editPage EditPage
* @param $textBox
* @param $result array
- * @return bool|mixed
+ * @return bool
*/
function efAssertApiEditHook( $editPage, $textBox, &$result ) {
global $wgRequest;
@@ -117,7 +117,7 @@
return true;
}
- $options = array_keys( AssertEdit::$msAssert );
+ $options = array_keys( AssertEdit::getAssertions() );
$params['assert'][ApiBase::PARAM_TYPE] = $options;
$params['nassert'][ApiBase::PARAM_TYPE] = $options;
Modified: trunk/extensions/AssertEdit/AssertEdit_body.php
===================================================================
--- trunk/extensions/AssertEdit/AssertEdit_body.php 2012-02-29 20:52:44 UTC
(rev 112721)
+++ trunk/extensions/AssertEdit/AssertEdit_body.php 2012-02-29 20:54:46 UTC
(rev 112722)
@@ -1,42 +1,44 @@
<?php
-if ( ! defined( 'MEDIAWIKI' ) )
+if ( ! defined( 'MEDIAWIKI' ) ) {
die();
+}
+/**
+ * Assert!
+ */
class AssertEdit {
/**
* methods for core assertions
*
- * @param $editPage
+ * @param $editPage EditPage
* @return bool
*/
- static function assert_user( $editPage ) {
+ public static function assert_user( $editPage ) {
global $wgUser;
return $wgUser->isLoggedIn();
}
/**
- * @static
* @param $editPage EditPage
* @return bool
*/
- static function assert_bot( $editPage ) {
+ public static function assert_bot( $editPage ) {
global $wgUser;
return $wgUser->isAllowed( 'bot' );
}
/**
- * @static
* @param $editPage EditPage
* @return bool
*/
- static function assert_exists( $editPage ) {
+ public static function assert_exists( $editPage ) {
return $editPage->mTitle->exists();
}
/**
* List of assertions; can be modified with setAssert
*/
- public static $msAssert = array(
+ private static $msAssert = array(
// simple constants, i.e. to test if the extension is installed.
'true' => true,
'false' => false,
@@ -49,7 +51,19 @@
'test' => false // Do we allow random tests?
);
- static function setAssert( $key, $value ) {
+ /**
+ * @return array
+ */
+ public static function getAssertions() {
+ return self::$msAssert;
+ }
+
+ /**
+ * @param $key string
+ * @param $value bool|Callback
+ * @return bool
+ */
+ public static function setAssert( $key, $value ) {
// Don't confuse things by changing core assertions.
switch ( $key ) {
case 'true':
@@ -68,8 +82,16 @@
}
}
- // call the specified assertion
- static function callAssert( $editPage, $assertName, $negate ) {
+ /**
+ * call the specified assertion
+ * @param $editPage Editpage
+ * @param $assertName string
+ * @param $negate bool
+ * @return bool
+ */
+ public static function callAssert( $editPage, $assertName, $negate ) {
+ // unrecognized assert fails, regardless of negation.
+ $pass = false;
if ( isset( self::$msAssert[$assertName] ) ) {
if ( is_bool( self::$msAssert[$assertName] ) ) {
$pass = self::$msAssert[$assertName];
@@ -80,9 +102,6 @@
if ( $negate && isset( $pass ) ) {
$pass = !$pass;
}
- } else {
- // unrecognized assert fails, regardless of negation.
- $pass = false;
}
return $pass;
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs