tosfos has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/161362

Change subject: initial commit
......................................................................

initial commit

Change-Id: I476316318acc5c2d711375daf681f65991764955
---
A .gitignore
A DebugMode.class.php
A DebugMode.php
A DebugMode.utils.php
A README
A VarSetters/GlobalVarSetter.php
A VarSetters/PhpFunctionVarSetter.php
A VarSetters/PhpIniVarSetter.php
A VarSetters/VarSetter.php
A i18n/en.json
A i18n/qqq.json
11 files changed, 514 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DebugMode 
refs/changes/62/161362/1

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1ea3dda
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+## NetBeans
+nbproject*
+project.index
+.jshintrc
diff --git a/DebugMode.class.php b/DebugMode.class.php
new file mode 100644
index 0000000..8bc7ed1
--- /dev/null
+++ b/DebugMode.class.php
@@ -0,0 +1,199 @@
+<?php
+/*
+ * Copyright (C) 2014 Ike Hecht
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * Puts wiki into debug mode
+ *
+ * @author Ike Hecht
+ */
+class DebugMode {
+       /* Debug levels */
+       const DEBUG_MODE_NONE = 0;
+       const DEBUG_MODE_INI = 1;
+       const DEBUG_MODE_PHP = 2;
+       const DEBUG_MODE_VERBOSE = 4; //Settings which change page output even 
without any errors
+       const DEBUG_MODE_CACHE = 8;
+       const DEBUG_MODE_RESOURCE_LOADER = 16;
+       const DEBUG_MODE_INSECURE = 32;/** @todo label appropriately and 
display warning if set */
+       const DEBUG_MODE_ALL = 63;
+       /**
+        * Which debug modes are set
+        *
+        * @var int
+        */
+       private $mode;
+
+       /**
+        * Array of variable settings to be ignored
+        * These can be variable settings of any type - ini, php, global
+        *
+        * @var array
+        */
+       private $ignoreVars;
+
+       public function getMode() {
+               return $this->mode;
+       }
+
+       public function getIgnoreVars() {
+               return $this->ignoreVars;
+       }
+
+       public function setMode( $mode ) {
+               $this->mode = $mode;
+       }
+
+       public function setIgnoreVars( $ignoreVars ) {
+               $this->ignoreVars = $ignoreVars;
+       }
+
+       public function __construct( $mode, $ignoreVars ) {
+               $this->mode = $mode;
+               $this->ignoreVars = $ignoreVars;
+       }
+
+       /**
+        * Set all settings
+        */
+       public function setAll() {
+               /** @todo Move all variables and mode requirements to an array 
*/
+               if ( $this->getMode() == self::DEBUG_MODE_NONE ) {
+                       return;
+               }
+               if ( $this->isModeSet( self::DEBUG_MODE_INI ) ) {
+                       $this->setPhpIniVars();
+               }
+               if ( $this->isModeSet( self::DEBUG_MODE_PHP ) ) {
+                       $this->setPhpFunctionVars();
+               }
+               $this->setGlobalVars();
+       }
+
+       /**
+        * Set php.ini variables
+        */
+       private function setPhpIniVars() {
+               $phpIniVarSetter = new PhpIniVarSetter( $this->getIgnoreVars() 
);
+               $phpIniVarSetter->setVars( $this->getPhpIniVars() );
+       }
+
+       /**
+        * Get an array of ini variables with desired settings
+        *
+        * @return array
+        */
+       private function getPhpIniVars() {
+               return array( 'display_errors' => 1 );
+       }
+
+       /**
+        * Set php settings using a php function
+        */
+       public function setPhpFunctionVars() {
+               $phpFunctionVarSetter = new PhpFunctionVarSetter( 
$this->getIgnoreVars() );
+               $phpFunctionVarSetter->setVars( $this->getPhpFunctionVars() );
+       }
+
+       /**
+        * Get an array of php setting functions and parameters
+        *
+        * @return array
+        */
+       private function getPhpFunctionVars() {
+               return array( 'error_reporting' => -1 );
+       }
+
+       /**
+        * Set MediaWiki globals
+        */
+       private function setGlobalVars() {
+               $trueVars = $this->getTrueGlobalVars();
+               $globalVarSetter = new GlobalVarSetter( $this->getIgnoreVars() 
);
+               $globalVarSetter->setVarsTo( $trueVars, true );
+
+               $falseVars = $this->getFalseGlobalVars();
+               $globalVarSetter->setVarsTo( $falseVars, false );
+
+               $otherVars = $this->getOtherGlobalVars();
+               $globalVarSetter->setVars( $otherVars );
+       }
+
+       /**
+        * Get an array of all MediaWiki globals that should be set to true
+        *
+        * @return array
+        */
+       private function getTrueGlobalVars() {
+               $varArray = array();
+
+               if ( $this->isModeSet( self::DEBUG_MODE_VERBOSE ) ) {
+                       $varArray = array_merge( $varArray, array( 
'wgShowDebug' ) );
+               }
+               if ( $this->isModeSet( self::DEBUG_MODE_RESOURCE_LOADER ) ) {
+                       $varArray = array_merge( $varArray, array( 
'wgResourceLoaderDebug' ) );
+               }
+               $varArray = array_merge( $varArray,
+                       array( 'wgColorErrors', 'wgDebugAPI', 
'wgDebugComments', 'wgDebugDBTransactions',
+                       'wgDebugDumpSql', 'wgDebugFunctionEntry', 
'wgDebugPrintHttpHeaders', 'wgDebugTimestamps',
+                       'wgDebugToolbar', 'wgDevelopmentWarnings', 
'wgLogExceptionBacktrace', 'wgShowDBErrorBacktrace',
+                       'wgShowExceptionDetails', 'wgShowSQLErrors' ) );
+
+               return $varArray;
+       }
+
+       /**
+        * Get an array of all MediaWiki globals that should be set to false
+        *
+        * @return array
+        */
+       private function getFalseGlobalVars() {
+               $varArray = array();
+               if ( $this->isModeSet( self::DEBUG_MODE_CACHE ) ) {
+                       $varArray = array_merge( $varArray,
+                               array( 'wgCachePages', 
'wgDeprecationReleaseLimit', 'wgEnableParserCache' ) );
+               }
+               return $varArray;
+       }
+
+       /**
+        * Get an array of all MediaWiki globals and what they should be set to
+        *
+        * @return array GlobalVar => Value
+        */
+       private function getOtherGlobalVars() {
+               $varArray = array();
+
+               if ( $this->isModeSet( self::DEBUG_MODE_RESOURCE_LOADER ) ) {
+                       $varArray['wgResourceLoaderMaxage'] = 1;
+               }
+               $varArray['wgProfileLimit'] = 0.0;
+
+               return $varArray;
+       }
+
+       /**
+        * Check if this mode has been set
+        *
+        * @param int $mode
+        * @return boolean
+        */
+       private function isModeSet( $mode ) {
+               return $this->getMode() & $mode;
+       }
+}
diff --git a/DebugMode.php b/DebugMode.php
new file mode 100644
index 0000000..71dcc8c
--- /dev/null
+++ b/DebugMode.php
@@ -0,0 +1,66 @@
+<?php
+/*
+ * Copyright (C) 2014 Ike Hecht
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * DebugMode extension - Puts wiki into debug mode
+ *
+ * For more info see http://mediawiki.org/wiki/Extension:DebugMode
+ *
+ * @file
+ * @ingroup Extensions
+ * @author Ike Hecht
+ * @license GNU General Public License 2.0 or later
+ */
+$wgExtensionCredits['other'][] = array(
+       'path' => __FILE__,
+       'name' => 'DebugMode',
+       'author' => 'Ike Hecht',
+       'version' => '0.1.0 beta',
+       'url' => 'https://www.mediawiki.org/wiki/Extension:DebugMode',
+       'descriptionmsg' => 'debugmode-desc',
+       'license-name' => 'GPL-2.0+'
+);
+
+$wgMessagesDirs['DebugMode'] = __DIR__ . '/i18n';
+$wgAutoloadClasses['DebugMode'] = __DIR__ . '/DebugMode.class.php';
+$wgAutoloadClasses['DebugModeUtils'] = __DIR__ . '/DebugMode.utils.php';
+
+$wgAutoloadClasses['VarSetter'] = __DIR__ . '/VarSetters/VarSetter.php';
+$wgAutoloadClasses['GlobalVarSetter'] = __DIR__ . 
'/VarSetters/GlobalVarSetter.php';
+$wgAutoloadClasses['PhpFunctionVarSetter'] = __DIR__ . 
'/VarSetters/PhpFunctionVarSetter.php';
+$wgAutoloadClasses['PhpIniVarSetter'] = __DIR__ . 
'/VarSetters/PhpIniVarSetter.php';
+
+$wgExtensionFunctions[] = 'DebugModeUtils::setup';
+
+/* Configuration */
+
+/**
+ * Should be set using named constants in the DebugMode class using bitwise 
operators.
+ * Can be set to true to enable all debugging or false to do nothing.
+ * Note: Setting to false does not turn debugging off! It just leaves the 
existing settings alone.
+ */
+$wgDebugMode = DebugModeUtils::getDefault();
+
+/**
+ * An array of variables that should be ignored by the extension. Can be used 
for more fine-tuning
+ * of variables than allowed by $wgDebugMode.
+ * These vars can be any named variables known to the extension, including 
MediaWiki globals and
+ * php settings.
+ */
+$wgDebugModeIgnoreVars = array();
diff --git a/DebugMode.utils.php b/DebugMode.utils.php
new file mode 100644
index 0000000..d5d8805
--- /dev/null
+++ b/DebugMode.utils.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ * Copyright (C) 2014 Ike Hecht
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * Utilities for DebugMode
+ *
+ * @author Ike Hecht
+ */
+class DebugModeUtils {
+
+       /**
+        * Returns the default debug mode
+        *
+        * @return int Debug mode
+        */
+       public static function getDefault() {
+               return ( DebugMode::DEBUG_MODE_ALL ^ 
DebugMode::DEBUG_MODE_VERBOSE );
+       }
+
+       /**
+        * Set up DebugMode and set all settings
+        *
+        * @global boolean|int $wgDebugMode
+        * @global array $wgDebugModeIgnoreVars
+        */
+       public static function setup() {
+               global $wgDebugMode, $wgDebugModeIgnoreVars;
+
+               /* allow true or false, for convenience */
+               if ( $wgDebugMode === false ) {
+                       $wgDebugMode = DebugMode::DEBUG_MODE_NONE;
+               } elseif ( $wgDebugMode === true ) {
+                       $wgDebugMode = DebugMode::DEBUG_MODE_ALL;
+               }
+
+               if ( $wgDebugMode == DebugMode::DEBUG_MODE_NONE ) {
+                       return;
+               }
+
+               $debugMode = new DebugMode( $wgDebugMode, 
$wgDebugModeIgnoreVars );
+               $debugMode->setAll();
+       }
+}
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README
diff --git a/VarSetters/GlobalVarSetter.php b/VarSetters/GlobalVarSetter.php
new file mode 100644
index 0000000..79e1bb4
--- /dev/null
+++ b/VarSetters/GlobalVarSetter.php
@@ -0,0 +1,30 @@
+<?php
+/*
+ * Copyright (C) 2014 Ike Hecht
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * Sets MediaWiki globals
+ *
+ * @author Ike Hecht
+ */
+class GlobalVarSetter extends VarSetter {
+
+       protected function reallySetVar( $var, $value ) {
+               $GLOBALS[$var] = $value;
+       }
+}
diff --git a/VarSetters/PhpFunctionVarSetter.php 
b/VarSetters/PhpFunctionVarSetter.php
new file mode 100644
index 0000000..6b51072
--- /dev/null
+++ b/VarSetters/PhpFunctionVarSetter.php
@@ -0,0 +1,30 @@
+<?php
+/*
+ * Copyright (C) 2014 Ike Hecht
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * Sets php settings that are set with a function
+ *
+ * @author Ike Hecht
+ */
+class PhpFunctionVarSetter extends VarSetter {
+
+       protected function reallySetVar( $function, $value ) {
+               $function( $value );
+       }
+}
diff --git a/VarSetters/PhpIniVarSetter.php b/VarSetters/PhpIniVarSetter.php
new file mode 100644
index 0000000..0386b24
--- /dev/null
+++ b/VarSetters/PhpIniVarSetter.php
@@ -0,0 +1,30 @@
+<?php
+/*
+ * Copyright (C) 2014 Ike Hecht
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * Sets php.ini settings
+ *
+ * @author Ike Hecht
+ */
+class PhpIniVarSetter extends VarSetter {
+
+       protected function reallySetVar( $var, $value ) {
+               ini_set( $var, $value );
+       }
+}
diff --git a/VarSetters/VarSetter.php b/VarSetters/VarSetter.php
new file mode 100644
index 0000000..08b0163
--- /dev/null
+++ b/VarSetters/VarSetter.php
@@ -0,0 +1,80 @@
+<?php
+/*
+ * Copyright (C) 2014 Ike Hecht
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * Set variables
+ *
+ * @author Ike Hecht
+ */
+abstract class VarSetter {
+       private $ignoreVars;
+
+       function getIgnoreVars() {
+               return $this->ignoreVars;
+       }
+
+       function setIgnoreVars( $ignoreVars ) {
+               $this->ignoreVars = $ignoreVars;
+       }
+
+       public function __construct( array $ignoreVars ) {
+               $this->ignoreVars = $ignoreVars;
+       }
+
+       /**
+        * Brains of the class
+        * Inheritors use this function to set the var to equal value
+        */
+       abstract protected function reallySetVar( $var, $value );
+
+       /**
+        * Set a var, but only if it is not supposed to be ignored by the class
+        *
+        * @param string $var
+        * @param mixed $value
+        */
+       final public function setVar( $var, $value ) {
+               if ( !in_array( $var, $this->getIgnoreVars() ) ) {
+                       $this->reallySetVar( $var, $value );
+               }
+       }
+
+       /**
+        * Set an array of vars where Var => Value
+        *
+        * @param array $varArray
+        */
+       final public function setVars( $varArray ) {
+               foreach ( $varArray as $var => $value ) {
+                       $this->setVar( $var, $value );
+               }
+       }
+
+       /**
+        * Set each var in the array to the same value
+        *
+        * @param array $varArray
+        * @param mixed $value
+        */
+       final public function setVarsTo( $varArray, $value ) {
+               foreach ( $varArray as $var ) {
+                       $this->setVar( $var, $value );
+               }
+       }
+}
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..e9e9582
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,8 @@
+{
+    "@metadata": {
+        "authors": [
+            "Ike Hecht"
+        ]
+    },
+    "debugmode-desc": "Puts the wiki into debug mode"
+}
\ No newline at end of file
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..bb3da6f
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,8 @@
+{
+    "@metadata": {
+        "authors": [
+            "Ike Hecht"
+        ]
+    },
+    "debugmode-desc": 
"{{desc|name=DebugMode|url=http://www.mediawiki.org/wiki/Extension:DebugMode}}";
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/161362
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I476316318acc5c2d711375daf681f65991764955
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DebugMode
Gerrit-Branch: master
Gerrit-Owner: tosfos <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to