*/
class MediaWiki {
- /**
- * Array of options which may or may not be used
- * FIXME: this seems currently to be a messy halfway-house between globals
- * and a config object. Pick one and run with it
- * @var array
- */
- private $params = array();
-
/**
* TODO: fold $output, etc, into this
* @var RequestContext
*/
private $context;
- /**
- * Stores key/value pairs to circumvent global variables
- * Note that keys are case-insensitive!
- *
- * @param $key String: key to store
- * @param $value Mixed: value to put for the key
- */
- public function setVal( $key, &$value ) {
- $key = strtolower( $key );
- $this->params[$key] =& $value;
- }
-
- /**
- * Retrieves key/value pairs to circumvent global variables
- * Note that keys are case-insensitive!
- *
- * @param $key String: key to get
- * @param $default string default value, defaults to empty string
- * @return $default Mixed: default value if if the key doesn't exist
- */
- public function getVal( $key, $default = '' ) {
- $key = strtolower( $key );
- if ( isset( $this->params[$key] ) ) {
- return $this->params[$key];
- }
- return $default;
- }
-
public function request( WebRequest $x = null ){
return wfSetVar( $this->context->request, $x );
}
* @return bool true if the request is already executed
*/
private function handleSpecialCases() {
+ global $wgServer, $wgUsePathInfo;
+
wfProfileIn( __METHOD__ );
// Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
$url = $this->context->title->getFullURL( $query );
}
// Check for a redirect loop
- if ( !preg_match( '/^' . preg_quote( $this->getVal( 'Server' ), '/' ) . '/', $url ) && $this->context->title->isLocal() ) {
+ if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $this->context->title->isLocal() ) {
// 301 so google et al report the target as the actual url.
$this->context->output->redirect( $url, 301 );
} else {
"requested; this sometimes happens when moving a wiki " .
"to a new server or changing the server configuration.\n\n";
- if ( $this->getVal( 'UsePathInfo' ) ) {
+ if ( $wgUsePathInfo ) {
$message .= "The wiki is trying to interpret the page " .
"title from the URL path portion (PATH_INFO), which " .
"sometimes fails depending on the web server. Try " .
* @return mixed an Article, or a string to redirect to another URL
*/
private function initializeArticle() {
+ global $wgDisableHardRedirects;
+
wfProfileIn( __METHOD__ );
$action = $this->context->request->getVal( 'action', 'view' );
// Is the target already set by an extension?
$target = $target ? $target : $article->followRedirect();
if ( is_string( $target ) ) {
- if ( !$this->getVal( 'DisableHardRedirects' ) ) {
+ if ( !$wgDisableHardRedirects ) {
// we'll need to redirect
wfProfileOut( __METHOD__ );
return $target;
* @param $article Article
*/
private function performAction( $article ) {
+ global $wgSquidMaxage, $wgUseExternalEditor,
+ $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
+
wfProfileIn( __METHOD__ );
if ( !wfRunHooks( 'MediaWikiPerformAction', array(
switch( $act ) {
case 'view':
- $this->context->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
+ $this->context->output->setSquidMaxage( $wgSquidMaxage );
$article->view();
break;
case 'raw': // includes JS/CSS
$article->$act();
break;
case 'dublincore':
- if ( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
+ if ( !$wgEnableDublinCoreRdf ) {
wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
} else {
$rdf = new DublinCoreRdf( $article );
}
break;
case 'creativecommons':
- if ( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
+ if ( !$wgEnableCreativeCommonsRdf ) {
wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
} else {
$rdf = new CreativeCommonsRdf( $article );
$external = $this->context->request->getVal( 'externaledit' );
$section = $this->context->request->getVal( 'section' );
$oldid = $this->context->request->getVal( 'oldid' );
- if ( !$this->getVal( 'UseExternalEditor' ) || $act == 'submit' || $internal ||
+ if ( !$wgUseExternalEditor || $act == 'submit' || $internal ||
$section || $oldid || ( !$this->context->user->getOption( 'externaleditor' ) && !$external ) ) {
$editor = new EditPage( $article );
$editor->submit();
- } elseif ( $this->getVal( 'UseExternalEditor' ) && ( $external || $this->context->user->getOption( 'externaleditor' ) ) ) {
+ } elseif ( $wgUseExternalEditor && ( $external || $this->context->user->getOption( 'externaleditor' ) ) ) {
$mode = $this->context->request->getVal( 'mode' );
$extedit = new ExternalEdit( $article, $mode );
$extedit->edit();
break;
case 'history':
if ( $this->context->request->getFullRequestURL() == $this->context->title->getInternalURL( 'action=history' ) ) {
- $this->context->output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
+ $this->context->output->setSquidMaxage( $wgSquidMaxage );
}
$history = new HistoryPage( $article );
$history->history();
$this->object = NULL;
}
- /**
- * Test case insentiveness for get / set
- */
- public function testSetGetValKeyInsentiveness() {
-
- // set with lower case key
- $value = 'SomeValue';
- $this->object->setVal( 'foobar', $value );
-
- $this->assertEquals(
- $this->object->getVal( 'foobar' ), 'SomeValue',
- 'lower case key set, getting lower case key'
- );
- $this->assertEquals(
- $this->object->getVal( 'FOOBAR' ), 'SomeValue',
- 'lower case key set, getting upper case key'
- );
-
- // set with Mixed case key
- $value = 'SomeValue2';
- $this->object->setVal( 'FooBar', $value );
-
- $this->assertEquals(
- $this->object->getVal( 'foobar' ), 'SomeValue2',
- 'mixed case key set, getting lower case key'
- );
- $this->assertEquals(
- $this->object->getVal( 'FOOBAR' ), 'SomeValue2',
- 'mixed case key set, getting upper case key'
- );
- }
-
- public function testGetValWithDefault() {
- $this->assertEmpty(
- $this->object->getVal( 'NonExistent' ),
- 'Non existent key return empty string'
- );
- $this->assertEquals(
- $this->object->getVal( 'NonExistent2', 'Default Value' ), 'Default Value',
- 'Non existent key with default given, should give default'
- );
- }
-
/**
* @todo Implement testPerformRequestForTitle().
*/