public function testDatabaseStorage() { $this->markTestSkipped('Needs I37b8e8018b3 <https://gerrit.wikimedia.org/r/#/c/270555/>'); // NOTE: database setup is expensive, so we only do // it once and run all the tests in one go. $dewiki = ['iw_prefix' => 'de', 'iw_url' => 'http://de.wikipedia.org/wiki/', 'iw_api' => 'http://de.wikipedia.org/w/api.php', 'iw_wikiid' => 'dewiki', 'iw_local' => 1, 'iw_trans' => 0]; $zzwiki = ['iw_prefix' => 'zz', 'iw_url' => 'http://zzwiki.org/wiki/', 'iw_api' => 'http://zzwiki.org/w/api.php', 'iw_wikiid' => 'zzwiki', 'iw_local' => 0, 'iw_trans' => 0]; $this->populateDB([$dewiki, $zzwiki]); $this->setWgInterwikiCache(false); $this->assertEquals([$dewiki, $zzwiki], Interwiki::getAllPrefixes(), 'getAllPrefixes()'); $this->assertEquals([$dewiki], Interwiki::getAllPrefixes(true), 'getAllPrefixes()'); $this->assertEquals([$zzwiki], Interwiki::getAllPrefixes(false), 'getAllPrefixes()'); $this->assertTrue(Interwiki::isValidInterwiki('de'), 'known prefix is valid'); $this->assertFalse(Interwiki::isValidInterwiki('xyz'), 'unknown prefix is valid'); $this->assertNull(Interwiki::fetch(null), 'no prefix'); $this->assertFalse(Interwiki::fetch('xyz'), 'unknown prefix'); $interwiki = Interwiki::fetch('de'); $this->assertInstanceOf('Interwiki', $interwiki); $this->assertSame($interwiki, Interwiki::fetch('de'), 'in-process caching'); $this->assertSame('http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL'); $this->assertSame('http://de.wikipedia.org/w/api.php', $interwiki->getAPI(), 'getAPI'); $this->assertSame('dewiki', $interwiki->getWikiID(), 'getWikiID'); $this->assertSame(true, $interwiki->isLocal(), 'isLocal'); $this->assertSame(false, $interwiki->isTranscludable(), 'isTranscludable'); Interwiki::invalidateCache('de'); $this->assertNotSame($interwiki, Interwiki::fetch('de'), 'invalidate cache'); }
function doSubmit() { global $wgContLang; $request = $this->getRequest(); $prefix = $request->getVal('wpInterwikiPrefix'); $do = $request->getVal('wpInterwikiAction'); // Show an error if the prefix is invalid (only when adding one). // Invalid characters for a title should also be invalid for a prefix. // Whitespace, ':', '&' and '=' are invalid, too. // (Bug 30599). global $wgLegalTitleChars; $validPrefixChars = preg_replace('/[ :&=]/', '', $wgLegalTitleChars); if (preg_match("/\\s|[^{$validPrefixChars}]/", $prefix) && $do === 'add') { $this->error('interwiki-badprefix', htmlspecialchars($prefix)); $this->showForm($do); return; } $reason = $request->getText('wpInterwikiReason'); $selfTitle = $this->getPageTitle(); $dbw = wfGetDB(DB_MASTER); switch ($do) { case 'delete': $dbw->delete('interwiki', array('iw_prefix' => $prefix), __METHOD__); if ($dbw->affectedRows() === 0) { $this->error('interwiki_delfailed', $prefix); $this->showForm($do); } else { $this->getOutput()->addWikiMsg('interwiki_deleted', $prefix); $log = new LogPage('interwiki'); $log->addEntry('iw_delete', $selfTitle, $reason, array($prefix)); Interwiki::invalidateCache($prefix); } break; case 'add': $prefix = $wgContLang->lc($prefix); // N.B.: no break! // N.B.: no break! case 'edit': $theurl = $request->getVal('wpInterwikiURL'); $local = $request->getCheck('wpInterwikiLocal') ? 1 : 0; $trans = $request->getCheck('wpInterwikiTrans') ? 1 : 0; $data = array('iw_prefix' => $prefix, 'iw_url' => $theurl, 'iw_local' => $local, 'iw_trans' => $trans); if ($prefix === '' || $theurl === '') { $this->error('interwiki-submit-empty'); $this->showForm($do); return; } // Simple URL validation: check that the protocol is one of // the supported protocols for this wiki. // (bug 30600) if (!wfParseUrl($theurl)) { $this->error('interwiki-submit-invalidurl'); $this->showForm($do); return; } if ($do === 'add') { $dbw->insert('interwiki', $data, __METHOD__, 'IGNORE'); } else { // $do === 'edit' $dbw->update('interwiki', $data, array('iw_prefix' => $prefix), __METHOD__, 'IGNORE'); } // used here: interwiki_addfailed, interwiki_added, interwiki_edited if ($dbw->affectedRows() === 0) { $this->error("interwiki_{$do}failed", $prefix); $this->showForm($do); } else { $this->getOutput()->addWikiMsg("interwiki_{$do}ed", $prefix); $log = new LogPage('interwiki'); $log->addEntry('iw_' . $do, $selfTitle, $reason, array($prefix, $theurl, $trans, $local)); Interwiki::invalidateCache($prefix); } break; } }