Template as parameter name.
[lhc/web/wiklou.git] / maintenance / fuzz-tester.php
index aadb935..3df3aa4 100644 (file)
@@ -139,11 +139,7 @@ Wiki configuration for testing:
 
   // Install & enable Special Page extensions to increase code coverage. E.g.:
   require_once("extensions/Cite/SpecialCite.php");
-  require_once("extensions/Filepath/SpecialFilepath.php");
-  require_once("extensions/Makebot/Makebot.php");
-  require_once("extensions/Makesysop/SpecialMakesysop.php");
   require_once("extensions/Renameuser/SpecialRenameuser.php");
-  require_once("extensions/LinkSearch/LinkSearch.php");
   // --------- End ---------
 
   If you want to try E_STRICT error logging, add this to the above:
@@ -763,14 +759,18 @@ class wikiFuzz {
        static private $maxparams = 10;
 
        /**
-        ** Returns random number between finish and start.
+        * Returns random number between finish and start.
+        * @param $finish
+        * @param $start int
+        * @return int
         */
        static public function randnum( $finish, $start = 0 ) {
                return mt_rand( $start, $finish );
        }
 
        /**
-        ** Returns a mix of random text and random wiki syntax.
+        * Returns a mix of random text and random wiki syntax.
+        * @return string
         */
        static private function randstring() {
                $thestring = "";
@@ -800,18 +800,17 @@ class wikiFuzz {
        }
 
        /**
-        ** Returns either random text, or random wiki syntax, or random data from "ints",
-        **        or random data from "other".
+        * Returns either random text, or random wiki syntax, or random data from "ints",
+        *        or random data from "other".
+        * @return string
         */
        static private function makestring() {
                $what = wikiFuzz::randnum( 2 );
                if ( $what == 0 ) {
                        return wikiFuzz::randstring();
-               }
-               elseif ( $what == 1 ) {
+               } elseif ( $what == 1 ) {
                        return wikiFuzz::$ints[wikiFuzz::randnum( count( wikiFuzz::$ints ) - 1 )];
-               }
-               else {
+               } else {
                        return wikiFuzz::$other[wikiFuzz::randnum( count( wikiFuzz::$other ) - 1 )];
                }
        }
@@ -819,14 +818,18 @@ class wikiFuzz {
        /**
         * Returns the matched character slash-escaped as in a C string
         * Helper for makeTitleSafe callback
+        * @param $matches
+        * @return atring
         */
        static private function stringEscape( $matches ) {
                return sprintf( "\\x%02x", ord( $matches[1] ) );
        }
-       
+
        /**
         ** Strips out the stuff that Mediawiki balks at in a page's title.
         **        Implementation copied/pasted from cleanupTable.inc & cleanupImages.php
+        * @param $str string
+        * @return string
         */
        static public function makeTitleSafe( $str ) {
                $legalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF";
@@ -837,6 +840,7 @@ class wikiFuzz {
 
        /**
         ** Returns a string of fuzz text.
+        * @return string
         */
        static private function loop() {
                switch ( wikiFuzz::randnum( 3 ) ) {
@@ -864,7 +868,8 @@ class wikiFuzz {
        }
 
        /**
-        ** Returns one of the three styles of random quote: ', ", and nothing.
+        * Returns one of the three styles of random quote: ', ", and nothing.
+        * @return string
         */
        static private function getRandQuote() {
                switch ( wikiFuzz::randnum( 3 ) ) {
@@ -876,6 +881,8 @@ class wikiFuzz {
 
        /**
         ** Returns fuzz text, with the parameter indicating approximately how many lines of text you want.
+        * @param $maxtypes int
+        * @return string
         */
        static public function makeFuzz( $maxtypes = 2 ) {
                $page = "";
@@ -1369,7 +1376,7 @@ class viewPageTest extends pageTest {
 
                // Tidy does not know how to valid atom or rss, so exclude from testing for the time being.
                if ( $this->params["feed"] == "atom" )     { unset( $this->params["feed"] ); }
-               else if ( $this->params["feed"] == "rss" ) { unset( $this->params["feed"] ); }
+               elseif ( $this->params["feed"] == "rss" ) { unset( $this->params["feed"] ); }
 
                // Raw pages cannot really be validated
                if ( $this->params["action"] == "raw" ) unset( $this->params["action"] );
@@ -1416,7 +1423,7 @@ class specialNewpagesPageTest extends pageTest {
 
                // Tidy does not know how to valid atom or rss, so exclude from testing for the time being.
                if ( $this->params["feed"] == "atom" )     { unset( $this->params["feed"] ); }
-               else if ( $this->params["feed"] == "rss" ) { unset( $this->params["feed"] ); }
+               elseif ( $this->params["feed"] == "rss" ) { unset( $this->params["feed"] ); }
        }
 }
 
@@ -1891,52 +1898,6 @@ class specialFilepathPageTest extends pageTest {
 }
 
 
-/**
- ** a test for Special:Makebot (extension Special page).
- */
-class specialMakebot extends pageTest {
-       function __construct() {
-               $this->pagePath = "index.php?title=Special:Makebot";
-
-               $this->params = array (
-                               "username" => wikiFuzz::chooseInput( array( "Nickj2", "192.168.0.2", wikiFuzz::makeFuzz( 1 ) ) ),
-                               "dosearch" => wikiFuzz::chooseInput( array( "0", "1", "++--34234", wikiFuzz::makeFuzz( 2 ) ) ),
-                               "grant"    => wikiFuzz::chooseInput( array( "0", "1", "++--34234", wikiFuzz::makeFuzz( 2 ) ) ),
-                               "comment"  => wikiFuzz::chooseInput( array( "20398702394", "", wikiFuzz::makeFuzz( 2 ) ) ),
-                               "token"    => wikiFuzz::chooseInput( array( "20398702394", "", wikiFuzz::makeFuzz( 2 ) ) ),
-                               );
-
-               // sometimes we don't want to specify certain parameters.
-               if ( wikiFuzz::randnum( 2 ) == 0 ) unset( $this->params["dosearch"] );
-               if ( wikiFuzz::randnum( 2 ) == 0 ) unset( $this->params["grant"] );
-               if ( wikiFuzz::randnum( 5 ) == 0 ) unset( $this->params["token"] );
-       }
-}
-
-
-/**
- ** a test for Special:Makesysop (extension Special page).
- */
-class specialMakesysop extends pageTest {
-       function __construct() {
-               $this->pagePath = "index.php?title=Special:Makesysop";
-
-               $this->params = array (
-                               "wpMakesysopUser"   => wikiFuzz::chooseInput( array( "Nickj2", "192.168.0.2", wikiFuzz::makeFuzz( 1 ) ) ),
-                               "action"            => wikiFuzz::chooseInput( array( "0", "1", "++--34234", wikiFuzz::makeFuzz( 2 ) ) ),
-                               "wpMakesysopSubmit" => wikiFuzz::chooseInput( array( "0", "1", "++--34234", wikiFuzz::makeFuzz( 2 ) ) ),
-                               "wpEditToken"       => wikiFuzz::chooseInput( array( "20398702394", "", wikiFuzz::makeFuzz( 2 ) ) ),
-                               "wpSetBureaucrat"   => wikiFuzz::chooseInput( array( "20398702394", "", wikiFuzz::makeFuzz( 2 ) ) ),
-                               );
-
-               // sometimes we don't want to specify certain parameters.
-               if ( wikiFuzz::randnum( 3 ) == 0 ) unset( $this->params["wpMakesysopSubmit"] );
-               if ( wikiFuzz::randnum( 3 ) == 0 ) unset( $this->params["wpEditToken"] );
-               if ( wikiFuzz::randnum( 3 ) == 0 ) unset( $this->params["wpSetBureaucrat"] );
-       }
-}
-
-
 /**
  ** a test for Special:Renameuser (extension Special page).
  */
@@ -2224,9 +2185,10 @@ class GeSHi_Test extends pageTest {
        }
 }
 
-
 /**
  ** selects a page test to run.
+ * @param $count
+ * @return \api|\confirmEmail|\contributionsTest|\editPageTest|\imagelistTest|\imagepageTest|\ipblocklistTest|\listusersTest|\mimeSearchTest|\newImagesTest|\pageDeletion|\pageHistoryTest|\pageProtectionForm|\prefixindexTest|\profileInfo|\recentchangesTest|\redirectTest|\searchTest|\specialAllmessagesTest|\specialAllpagesTest|\specialBlockip|\specialBlockmeTest|\specialBooksourcesTest|\specialCategoryTree|\specialChemicalsourcesTest|\specialCitePageTest|\specialExportTest|\specialFilepathPageTest|\specialImportPageTest|\specialLinksearch|\specialLockdbPageTest|\specialLogTest|\specialMovePage|\specialNewpagesPageTest|\specialRenameuserPageTest|\specialRevisionDeletePageTest|\specialUndeletePageTest|\specialUnlockdbPageTest|\specialUserrights|\successfulUserLoginTest|\thumbTest|\trackbackTest|\userLoginTest|\viewPageTest|\watchlistTest
  */
 function selectPageTest( $count ) {
 
@@ -2279,13 +2241,11 @@ function selectPageTest( $count ) {
                case 37: return new profileInfo();
                case 38: return new specialCitePageTest();
                case 39: return new specialFilepathPageTest();
-               case 40: return new specialMakebot();
-               case 41: return new specialMakesysop();
-               case 42: return new specialRenameuserPageTest();
-               case 43: return new specialLinksearch();
-               case 44: return new specialCategoryTree();
-               case 45: return new api();
-               case 45: return new specialChemicalsourcesTest();
+               case 40: return new specialRenameuserPageTest();
+               case 41: return new specialLinksearch();
+               case 42: return new specialCategoryTree();
+               case 43: return new api();
+               case 44: return new specialChemicalsourcesTest();
                default: return new editPageTest();
        }
 }
@@ -2300,11 +2260,12 @@ function saveFile( $data, $name ) {
        file_put_contents( $name, $data );
 }
 
-
 /**
  ** Returns a test as an experimental GET-to-POST URL.
  **        This doesn't seem to always work though, and sometimes the output is too long
  **        to be a valid GET URL, so we also save in other formats.
+ * @param $test pageTest
+ * @return string
  */
 function getAsURL( pageTest $test ) {
        $used_question_mark = ( strpos( $test->getPagePath(), "?" ) !== false );
@@ -2356,11 +2317,12 @@ function saveTestAsPHP( pageTest $test, $filename ) {
        saveFile( $str, $filename );
 }
 
-
 /**
- ** Escapes a value so that it can be used on the command line by Curl.
- **        Specifically, "<" and "@" need to be escaped if they are the first character,
- **        otherwise  curl interprets these as meaning that we want to insert a file.
+ * Escapes a value so that it can be used on the command line by Curl.
+ *        Specifically, "<" and "@" need to be escaped if they are the first character,
+ *        otherwise  curl interprets these as meaning that we want to insert a file.
+ * @param $input_params array
+ * @return array
  */
 function escapeForCurl( array $input_params ) {
        $output_params = array();
@@ -2411,18 +2373,21 @@ function saveTest( pageTest $test, $testname ) {
        saveTestData  ( $test, $base_name . DATA_FILE );
 }
 
-
 // ////////////////// MEDIAWIKI OUTPUT /////////////////////////
 
 /**
- ** Asks MediaWiki for the HTML output of a test.
+ * Asks MediaWiki for the HTML output of a test.
+ * @param $test pageTest
+ * @return string
  */
 function wikiTestOutput( pageTest $test ) {
 
        $ch = curl_init();
 
        // specify the cookie, if required.
-       if ( $test->getCookie() ) curl_setopt( $ch, CURLOPT_COOKIE, $test->getCookie() );
+       if ( $test->getCookie() ) {
+               curl_setopt( $ch, CURLOPT_COOKIE, $test->getCookie() );
+       }
        curl_setopt( $ch, CURLOPT_POST, 1 );                          // save form using a POST
 
        $params = escapeForCurl( $test->getParams() );
@@ -2447,8 +2412,10 @@ function wikiTestOutput( pageTest $test ) {
 
 // ////////////////// HTML VALIDATION /////////////////////////
 
-/*
- ** Asks the validator whether this is valid HTML, or not.
+/**
+ * Asks the validator whether this is valid HTML, or not.
+ * @param $text string
+ * @return array
  */
 function validateHTML( $text ) {
 
@@ -2477,9 +2444,10 @@ function validateHTML( $text ) {
        return array( $valid, $result );
 }
 
-
 /**
- ** Get tidy to check for no HTML errors in the output file (e.g. unescaped strings).
+ * Get tidy to check for no HTML errors in the output file (e.g. unescaped strings).
+ * @param $name
+ * @return bool
  */
 function tidyCheckFile( $name ) {
        $file = DIRECTORY . "/" . $name;
@@ -2498,10 +2466,10 @@ function tidyCheckFile( $name ) {
        }
 }
 
-
 /**
  ** Returns whether or not an database error log file has changed in size since
  **        the last time this was run. This is used to tell if a test caused a DB error.
+ * @return bool
  */
 function dbErrorLogged() {
        static $filesize;
@@ -2529,8 +2497,12 @@ function dbErrorLogged() {
 // //////////////// TOP-LEVEL PROBLEM-FINDING FUNCTION ////////////////////////
 
 /**
- ** takes a page test, and runs it and tests it for problems in the output.
- **        Returns: False on finding a problem, or True on no problems being found.
+ * takes a page test, and runs it and tests it for problems in the output.
+ *        Returns: False on finding a problem, or True on no problems being found.
+ * @param $test pageTest
+ * @param $testname
+ * @param $can_overwrite bool
+ * @return bool
  */
 function runWikiTest( pageTest $test, &$testname, $can_overwrite = false ) {
 
@@ -2702,7 +2674,7 @@ if ( !is_dir( DIRECTORY ) ) {
        mkdir ( DIRECTORY, 0700 );
 }
 // otherwise, we first retest the things that we have found in previous runs
-else if ( RERUN_OLD_TESTS ) {
+elseif ( RERUN_OLD_TESTS ) {
        rerunPreviousTests();
 }
 
@@ -2750,7 +2722,7 @@ for ( $count = 0; true; $count++ ) {
                }
                saveTest( $test, $testname );
                $num_errors += 1;
-       } else if ( KEEP_PASSED_TESTS ) {
+       } elseif ( KEEP_PASSED_TESTS ) {
                // print current time, with microseconds (matches "strace" format), and the test name.
                print " " . date( "H:i:s." ) . substr( current( explode( " ", microtime() ) ), 2 ) . " " . $testname;
                saveTest( $test, $testname );