// In a perfect world this wouldn't be necessary
$wgTitle = Title::makeTitle( NS_MAIN, 'API' );
-/* Construct an ApiMain with the arguments passed via the URL. What we get back
- * is some form of an ApiMain, possibly even one that produces an error message,
- * but we don't care here, as that is handled by the ctor.
- */
-$processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI );
-
-// Last chance hook before executing the API
try {
+ /* Construct an ApiMain with the arguments passed via the URL. What we get back
+ * is some form of an ApiMain, possibly even one that produces an error message,
+ * but we don't care here, as that is handled by the ctor.
+ */
+ $processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI );
+
+ // Last chance hook before executing the API
wfRunHooks( 'ApiBeforeMain', array( &$processor ) );
if ( !$processor instanceof ApiMain ) {
throw new MWException( 'ApiBeforMain hook set $processor to a non-ApiMain class' );
$limit : maximum number of results to return
&$results : out param: array of page names (strings)
+'PrefixSearchExtractNamespace': Called if core was not able to extract a
+namespace from the search string so that extensions can attempt it.
+$namespaces : array of int namespace keys to search in (change this if you can
+extract namespaces)
+$search : search term (replace this with term without the namespace if you can
+extract one)
+
'PrefsEmailAudit': Called when user changes their email address.
$user: User (object) changing his email address
$oldaddr: old email address (string)
$title = Title::newFromText( $search );
if ( $title && !$title->isExternal() ) {
$ns = array( $title->getNamespace() );
+ $search = $title->getText();
if ( $ns[0] == NS_MAIN ) {
$ns = $namespaces; // no explicit prefix, use default namespaces
+ wfRunHooks( 'PrefixSearchExtractNamespace', array( &$ns, &$search ) );
}
- return $this->searchBackend( $ns, $title->getText(), $limit );
+ return $this->searchBackend( $ns, $search, $limit );
}
// Is this a namespace prefix?
{
$namespaces = array( $title->getNamespace() );
$search = '';
+ } else {
+ wfRunHooks( 'PrefixSearchExtractNamespace', array( &$namespaces, &$search ) );
}
return $this->searchBackend( $namespaces, $search, $limit );
$pageInfo['header-basic'][] = array( $langDisp,
Language::fetchLanguageName( $pageLang, $lang->getCode() )
- . ' ' . $this->msg( 'parentheses', $pageLang ) );
+ . ' ' . $this->msg( 'parentheses', $pageLang )->escaped() );
// Content model of the page
$pageInfo['header-basic'][] = array(
$this->getContext()->setLanguage( $code );
if ( !$this->mInternalMode ) {
global $wgLang;
- $wgLang = RequestContext::getMain()->getLanguage();
+ $wgLang = $this->getContext()->getLanguage();
+ RequestContext::getMain()->setLanguage( $wgLang );
}
$config = $this->getConfig();
// Destructive buttons
//
- // Use destructive buttons for actions which result in the destruction of data.
- // e.g. deleting a page.
+ // Use destructive buttons for actions that remove or limit, such as deleting a page or blocking a user.
// This should not be used for cancel buttons.
//
// Markup:
public function testGetPageViewLanguage( $expected, $titleText, $contLang,
$lang, $variant, $msg = ''
) {
- global $wgLanguageCode, $wgContLang, $wgLang, $wgDefaultLanguageVariant, $wgAllowUserJs;
-
// Setup environnement for this test
- $wgLanguageCode = $contLang;
- $wgContLang = Language::factory( $contLang );
- $wgLang = Language::factory( $lang );
- $wgDefaultLanguageVariant = $variant;
- $wgAllowUserJs = true;
+ $this->setMwGlobals( array(
+ 'wgLanguageCode' => $contLang,
+ 'wgContLang' => Language::factory( $contLang ),
+ 'wgLang' => Language::factory( $lang ),
+ 'wgDefaultLanguageVariant' => $variant,
+ 'wgAllowUserJs' => true,
+ ) );
$title = Title::newFromText( $titleText );
$this->assertInstanceOf( 'Title', $title,
* @covers User::getPasswordExpired()
*/
public function testPasswordExpire() {
- global $wgPasswordExpireGrace;
- $wgTemp = $wgPasswordExpireGrace;
- $wgPasswordExpireGrace = 3600 * 24 * 7; // 7 days
+ $this->setMwGlobals( 'wgPasswordExpireGrace', 3600 * 24 * 7 ); // 7 days
$user = User::newFromName( 'UnitTestUser' );
$user->loadDefaults( 'UnitTestUser' );
$ts = time() - ( 3600 * 24 * 10 ); // 10 days ago
$user->expirePassword( $ts );
$this->assertEquals( 'hard', $user->getPasswordExpired() );
-
- $wgPasswordExpireGrace = $wgTemp;
}
/**
/** @var DerivativeContext */
private $mContext;
- private $mOldGetPreferencesHooks;
-
private static $Success = array( 'options' => 'success' );
protected function setUp() {
$this->mTested = new ApiOptions( $main, 'options' );
- global $wgHooks;
- if ( !isset( $wgHooks['GetPreferences'] ) ) {
- $wgHooks['GetPreferences'] = array();
- }
- $this->mOldGetPreferencesHooks = $wgHooks['GetPreferences'];
- $wgHooks['GetPreferences'][] = array( $this, 'hookGetPreferences' );
- }
-
- protected function tearDown() {
- global $wgHooks;
-
- $wgHooks['GetPreferences'] = $this->mOldGetPreferencesHooks;
- $this->mOldGetPreferencesHooks = false;
-
- parent::tearDown();
+ $this->mergeMwGlobalArrayValue( 'wgHooks', array(
+ 'GetPreferences' => array(
+ array( $this, 'hookGetPreferences' )
+ )
+ ) );
}
public function hookGetPreferences( $user, &$preferences ) {
* @covers ApiQuery
*/
class ApiQueryTest extends ApiTestCase {
- /**
- * @var array Storage for $wgHooks
- */
- protected $hooks;
-
protected function setUp() {
- global $wgHooks;
-
parent::setUp();
$this->doLogin();
- // Setup en: as interwiki prefix
- $this->hooks = $wgHooks;
- $wgHooks['InterwikiLoadPrefix'][] = function ( $prefix, &$data ) {
- if ( $prefix == 'apiquerytestiw' ) {
- $data = array( 'iw_url' => 'wikipedia' );
- }
- return false;
- };
- }
-
- protected function tearDown() {
- global $wgHooks;
- $wgHooks = $this->hooks;
-
- parent::tearDown();
+ // Setup apiquerytestiw: as interwiki prefix
+ $this->setMwGlobals( 'wgHooks', array(
+ 'InterwikiLoadPrefix' => array(
+ function ( $prefix, &$data ) {
+ if ( $prefix == 'apiquerytestiw' ) {
+ $data = array( 'iw_url' => 'wikipedia' );
+ }
+ return false;
+ }
+ )
+ ) );
}
public function testTitlesGetNormalized() {
}
public function testRecacheFallbacksWithHooks() {
- global $wgHooks;
-
// Use hook to provide updates for messages. This is what the
// LocalisationUpdate extension does. See bug 68781.
- $wgHooks['LocalisationCacheRecacheFallback'][] = function (
- LocalisationCache $lc,
- $code,
- array &$cache
- ) {
- if ( $code === 'ru' ) {
- $cache['messages']['present-uk'] = 'ru-override';
- $cache['messages']['present-ru'] = 'ru-override';
- $cache['messages']['present-en'] = 'ru-override';
- }
- };
+ $this->mergeMwGlobalArrayValue( 'wgHooks', array(
+ 'LocalisationCacheRecacheFallback' => array(
+ function (
+ LocalisationCache $lc,
+ $code,
+ array &$cache
+ ) {
+ if ( $code === 'ru' ) {
+ $cache['messages']['present-uk'] = 'ru-override';
+ $cache['messages']['present-ru'] = 'ru-override';
+ $cache['messages']['present-en'] = 'ru-override';
+ }
+ }
+ )
+ ) );
$lc = new LocalisationCache( array( 'store' => 'detect' ) );
$lc->recache( 'uk' );
*/
class TextContentTest extends MediaWikiLangTestCase {
protected $context;
- protected $savedContentGetParserOutput;
protected function setUp() {
- global $wgHooks;
-
parent::setUp();
// Anon user
'wgUseTidy' => false,
'wgAlwaysUseTidy' => false,
'wgCapitalLinks' => true,
+ 'wgHooks' => array(), // bypass hook ContentGetParserOutput that force custom rendering
) );
-
- // bypass hooks that force custom rendering
- if ( isset( $wgHooks['ContentGetParserOutput'] ) ) {
- $this->savedContentGetParserOutput = $wgHooks['ContentGetParserOutput'];
- unset( $wgHooks['ContentGetParserOutput'] );
- }
- }
-
- public function teardown() {
- global $wgHooks;
-
- // restore hooks that force custom rendering
- if ( $this->savedContentGetParserOutput !== null ) {
- $wgHooks['ContentGetParserOutput'] = $this->savedContentGetParserOutput;
- }
-
- parent::teardown();
}
public function newContent( $text ) {
class AutoLoaderTest extends MediaWikiTestCase {
protected function setUp() {
- global $wgAutoloadLocalClasses, $wgAutoloadClasses;
-
parent::setUp();
// Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower
- $this->testLocalClasses = array(
- 'TestAutoloadedLocalClass' => __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
- 'TestAutoloadedCamlClass' => __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
+ $this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', array(
+ 'TestAutoloadedLocalClass' =>
+ __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php',
+ 'TestAutoloadedCamlClass' =>
+ __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php',
'TestAutoloadedSerializedClass' =>
__DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php',
- );
- $this->setMwGlobals(
- 'wgAutoloadLocalClasses',
- $this->testLocalClasses + $wgAutoloadLocalClasses
- );
+ ) );
AutoLoader::resetAutoloadLocalClassesLower();
- $this->testExtensionClasses = array(
+ $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', array(
'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php',
- );
- $this->setMwGlobals( 'wgAutoloadClasses', $this->testExtensionClasses + $wgAutoloadClasses );
+ ) );
}
/**