r112722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112721‎ | r112722 | r112723 >
Date:20:54, 29 February 2012
Author:reedy
Status:ok
Tags:
Comment:
Little bit of code tidying up and documentation
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
@@ -1,42 +1,44 @@
22 <?php
3 -if ( ! defined( 'MEDIAWIKI' ) )
 3+if ( ! defined( 'MEDIAWIKI' ) ) {
44 die();
 5+}
56
 7+/**
 8+ * Assert!
 9+ */
610 class AssertEdit {
711 /**
812 * methods for core assertions
913 *
10 - * @param $editPage
 14+ * @param $editPage EditPage
1115 * @return bool
1216 */
13 - static function assert_user( $editPage ) {
 17+ public static function assert_user( $editPage ) {
1418 global $wgUser;
1519 return $wgUser->isLoggedIn();
1620 }
1721
1822 /**
19 - * @static
2023 * @param $editPage EditPage
2124 * @return bool
2225 */
23 - static function assert_bot( $editPage ) {
 26+ public static function assert_bot( $editPage ) {
2427 global $wgUser;
2528 return $wgUser->isAllowed( 'bot' );
2629 }
2730
2831 /**
29 - * @static
3032 * @param $editPage EditPage
3133 * @return bool
3234 */
33 - static function assert_exists( $editPage ) {
 35+ public static function assert_exists( $editPage ) {
3436 return $editPage->mTitle->exists();
3537 }
3638
3739 /**
3840 * List of assertions; can be modified with setAssert
3941 */
40 - public static $msAssert = array(
 42+ private static $msAssert = array(
4143 // simple constants, i.e. to test if the extension is installed.
4244 'true' => true,
4345 'false' => false,
@@ -49,7 +51,19 @@
5052 'test' => false // Do we allow random tests?
5153 );
5254
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 ) {
5468 // Don't confuse things by changing core assertions.
5569 switch ( $key ) {
5670 case 'true':
@@ -68,8 +82,16 @@
6983 }
7084 }
7185
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;
7496 if ( isset( self::$msAssert[$assertName] ) ) {
7597 if ( is_bool( self::$msAssert[$assertName] ) ) {
7698 $pass = self::$msAssert[$assertName];
@@ -80,9 +102,6 @@
81103 if ( $negate && isset( $pass ) ) {
82104 $pass = !$pass;
83105 }
84 - } else {
85 - // unrecognized assert fails, regardless of negation.
86 - $pass = false;
87106 }
88107 return $pass;
89108 }
Index: trunk/extensions/AssertEdit/AssertEdit.php
@@ -78,7 +78,7 @@
7979 * @param $editPage EditPage
8080 * @param $textBox
8181 * @param $result array
82 - * @return bool|mixed
 82+ * @return bool
8383 */
8484 function efAssertApiEditHook( $editPage, $textBox, &$result ) {
8585 global $wgRequest;
@@ -117,7 +117,7 @@
118118 return true;
119119 }
120120
121 - $options = array_keys( AssertEdit::$msAssert );
 121+ $options = array_keys( AssertEdit::getAssertions() );
122122 $params['assert'][ApiBase::PARAM_TYPE] = $options;
123123 $params['nassert'][ApiBase::PARAM_TYPE] = $options;
124124

Status & tagging log