public function testNewObjFunction() { $arg1 = 'Foo'; $arg2 = 'Bar'; $arg3 = array('Baz'); $arg4 = new ExampleObject(); $args = array($arg1, $arg2, $arg3, $arg4); $newObject = new MWBlankClass($arg1, $arg2, $arg3, $arg4); $this->assertEquals(MWFunction::newObj('MWBlankClass', $args)->args, $newObject->args); }
/** * Find the object with a given name and return it (or NULL) * * @param $name String Special page name, may be localised and/or an alias * @return SpecialPage object or null if the page doesn't exist */ public static function getPage($name) { list($realName, ) = self::resolveAlias($name); if (property_exists(self::getList(), $realName)) { $rec = self::getList()->{$realName}; if (is_string($rec)) { $className = $rec; return new $className(); } elseif (is_array($rec)) { // @deprecated, officially since 1.18, unofficially since forever wfDebug("Array syntax for \$wgSpecialPages is deprecated, define a subclass of SpecialPage instead."); $className = array_shift($rec); self::getList()->{$realName} = MWFunction::newObj($className, $rec); } return self::getList()->{$realName}; } else { return null; } }
/** * Create a new object to replace this stub object. * @return object */ function _newObject() { return MWFunction::newObj($this->mClass, $this->mParams); }
define('MW_COMPILED', 1); } else { # Get the MWInit class require_once "{$IP}/includes/Init.php"; require_once "{$IP}/includes/AutoLoader.php"; } # Stub the profiler require_once MWInit::compiledPath('includes/profiler/Profiler.php'); // Some other requires if (!defined('MW_COMPILED')) { require_once "{$IP}/includes/Defines.php"; } require_once MWInit::compiledPath('includes/DefaultSettings.php'); if (defined('MW_CONFIG_CALLBACK')) { # Use a callback function to configure MediaWiki MWFunction::call(MW_CONFIG_CALLBACK); } elseif (file_exists("{$IP}/../wmf-config/wikimedia-mode")) { // Load settings, using wikimedia-mode if needed // @todo FIXME: Replace this hack with general farm-friendly code # @todo FIXME: Wikimedia-specific stuff needs to go away to an ext # Maybe a hook? global $cluster; $cluster = 'pmtpa'; require MWInit::interpretedPath('../wmf-config/wgConf.php'); $maintenance->loadWikimediaSettings(); require MWInit::interpretedPath('../wmf-config/CommonSettings.php'); } else { require_once $maintenance->loadSettings(); } if ($maintenance->getDbType() === Maintenance::DB_ADMIN && is_readable("{$IP}/AdminSettings.php")) { require MWInit::interpretedPath('AdminSettings.php');
/** * Create an object with a given name and an array of construct parameters * * @param $name String * @param $p Array: parameters * @deprecated since 1.18, warnings in 1.18, removal in 1.20 */ function wfCreateObject($name, $p) { wfDeprecated(__FUNCTION__); return MWFunction::newObj($name, $p); }
function testFallbackMbstringFunctions() { if (!extension_loaded('mbstring')) { $this->markTestSkipped("The mb_string functions must be installed to test the fallback functions"); } $sampleUTF = "Östergötland_coat_of_arms.png"; //mb_substr $substr_params = array(array(0, 0), array(5, -4), array(33), array(100, -5), array(-8, 10), array(1, 1), array(2, -1)); foreach ($substr_params as $param_set) { $old_param_set = $param_set; array_unshift($param_set, $sampleUTF); $this->assertEquals(MWFunction::callArray('mb_substr', $param_set), MWFunction::callArray('Fallback::mb_substr', $param_set), 'Fallback mb_substr with params ' . implode(', ', $old_param_set)); } //mb_strlen $this->assertEquals(mb_strlen($sampleUTF), Fallback::mb_strlen($sampleUTF), 'Fallback mb_strlen'); //mb_str(r?)pos $strpos_params = array(); foreach ($strpos_params as $param_set) { $old_param_set = $param_set; array_unshift($param_set, $sampleUTF); $this->assertEquals(MWFunction::callArray('mb_strpos', $param_set), MWFunction::callArray('Fallback::mb_strpos', $param_set), 'Fallback mb_strpos with params ' . implode(', ', $old_param_set)); $this->assertEquals(MWFunction::callArray('mb_strrpos', $param_set), MWFunction::callArray('Fallback::mb_strrpos', $param_set), 'Fallback mb_strrpos with params ' . implode(', ', $old_param_set)); } }
/** * @expectedException MWException */ function testCallingSelfFails() { MWFunction::call('self::foo'); }
/** * Create a new object to replace this stub object. * @return object */ public function _newObject() { return MWFunction::newObj($this->class, $this->params); }
/** * Find the object with a given name and return it (or NULL) * * @param string $name Special page name, may be localised and/or an alias * @return SpecialPage|null SpecialPage object or null if the page doesn't exist */ public static function getPage($name) { list($realName, ) = self::resolveAlias($name); $specialPageList = self::getPageList(); if (isset($specialPageList[$realName])) { $rec = $specialPageList[$realName]; if (is_callable($rec)) { // Use callback to instantiate the special page $page = call_user_func($rec); } elseif (is_string($rec)) { $className = $rec; $page = new $className(); } elseif (is_array($rec)) { $className = array_shift($rec); // @deprecated, officially since 1.18, unofficially since forever wfDeprecated("Array syntax for \$wgSpecialPages is deprecated ({$className}), " . "define a subclass of SpecialPage instead.", '1.18'); $page = MWFunction::newObj($className, $rec); } elseif ($rec instanceof SpecialPage) { $page = $rec; //XXX: we should deep clone here } else { $page = null; } if ($page instanceof SpecialPage) { return $page; } else { // It's not a classname, nor a callback, nor a legacy constructor array, // nor a special page object. Give up. wfLogWarning("Cannot instantiate special page {$realName}: bad spec!"); return null; } } else { return null; } }
/** * Find the object with a given name and return it (or NULL) * * @param string $name Special page name, may be localised and/or an alias * @return SpecialPage|null SpecialPage object or null if the page doesn't exist */ public static function getPage($name) { list($realName, ) = self::resolveAlias($name); $specialPageList = self::getList(); if (isset($specialPageList[$realName])) { $rec = $specialPageList[$realName]; if (is_string($rec)) { $className = $rec; return new $className(); } elseif (is_array($rec)) { $className = array_shift($rec); // @deprecated, officially since 1.18, unofficially since forever wfDeprecated("Array syntax for \$wgSpecialPages is deprecated ({$className}), " . "define a subclass of SpecialPage instead.", '1.18'); $specialPageList[$realName] = MWFunction::newObj($className, $rec); } return $specialPageList[$realName]; } else { return null; } }
/** * This function accepts multiple message keys and returns a message instance * for the first message which is non-empty. If all messages are empty then an * instance of the first message key is returned. * @param varargs: message keys * @return Message * @since 1.18 */ function wfMessageFallback() { $args = func_get_args(); return MWFunction::callArray('Message::newFallbackSequence', $args); }