Reedy has uploaded a new change for review.
https://gerrit.wikimedia.org/r/52956
Change subject: Always use $wgCentralDBname in wfGetDB
......................................................................
Always use $wgCentralDBname in wfGetDB
It seems the code expected it would only
apparently be run on metawiki, but this is so
not the case....
2013-03-09 01:21:30 mw1138 enwiki: #0
/usr/local/apache/common-local/php-1.21wmf10/includes/db/Database.php(984):
DatabaseBase->reportQueryError('Table 'enwiki.c...', 1146, 'SELECT *
FROM...', 'Campaign::campa...', false)
1 /usr/local/apache/common-local/php-1.21wmf10/includes/db/Database.php(1435):
DatabaseBase->query('SELECT * FROM...', 'Campaign::campa...')
2
/usr/local/apache/common-local/php-1.21wmf10/extensions/CentralNotice/includes/Campaign.php(769):
DatabaseBase->select('cn_notice_log', '*', Array, 'Campaign::campa...', Array)
3
/usr/local/apache/common-local/php-1.21wmf10/extensions/CentralNotice/api/ApiCentralNoticeLogs.php(22):
Campaign::campaignLogs(NULL, NULL, NULL, NULL, 50, 0)
4 /usr/local/apache/common-local/php-1.21wmf10/includes/api/ApiQuery.php(302):
ApiCentralNoticeLogs->execute()
5 /usr/local/apache/common-local/php-1.21wmf10/includes/api/ApiMain.php(833):
ApiQuery->execute()
6 /usr/local/apache/common-local/php-1.21wmf10/includes/api/ApiMain.php(373):
ApiMain->executeAction()
7 /usr/local/apache/common-local/php-1.21wmf10/includes/api/ApiMain.php(350):
ApiMain->executeActionWithErrorHandling()
8 /usr/local/apache/common-local/php-1.21wmf10/api.php(77): ApiMain->execute()
9 /usr/local/apache/common-local/live-1.5/api.php(3):
require('/usr/local/apac...')
10 {main}
Sat Mar 9 1:21:30 UTC 2013 mw1138 enwiki Campaign::campaignLogs
10.64.16.6 1146 Table 'enwiki.cn_notice_log' doesn't exist (10.64.16.6)
SELECT * FROM `cn_notice_log` ORDER BY notlog_timestamp DESC LIMIT 50
Change-Id: I5de9d1f66838094472a8268ef1678f9709aa9eb5
---
M CentralNotice.php
M CentralNoticePager.php
M TemplatePager.php
M includes/Banner.php
M includes/Campaign.php
M special/SpecialCentralNotice.php
M special/SpecialNoticeTemplate.php
7 files changed, 81 insertions(+), 52 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice
refs/changes/56/52956/1
diff --git a/CentralNotice.php b/CentralNotice.php
index 32d475a..79f33cc 100644
--- a/CentralNotice.php
+++ b/CentralNotice.php
@@ -589,7 +589,8 @@
* @return bool
*/
function efRegisterMessageGroups( &$list ) {
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
// Create the base aggregate group
$conf = array();
@@ -611,9 +612,9 @@
$res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
foreach ( $res as $r ) {
- $grp = new BannerMessageGroup( $r->page_namespace, $r->page_title );
- $id = $grp::getTranslateGroupName( $r->page_title );
- $list[$id] = $grp;
+ $grp = new BannerMessageGroup( $r->page_namespace,
$r->page_title );
+ $id = $grp::getTranslateGroupName( $r->page_title );
+ $list[$id] = $grp;
// Add the banner group to the aggregate group
$conf['GROUPS'][] = $id;
diff --git a/CentralNoticePager.php b/CentralNoticePager.php
index 9197854..e1ea7cc 100644
--- a/CentralNoticePager.php
+++ b/CentralNoticePager.php
@@ -13,7 +13,8 @@
* Pull banners from the database
*/
function getQueryInfo() {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBnames;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
// First we must construct the filter before we pull banners
// When the filter comes in it is space delimited, so break
that...
diff --git a/TemplatePager.php b/TemplatePager.php
index f71788f..6012756 100644
--- a/TemplatePager.php
+++ b/TemplatePager.php
@@ -29,7 +29,8 @@
* @return array of query settings
*/
function getQueryInfo() {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
// When the filter comes in it is space delimited, so break
that...
$likeArray = preg_split( '/\s/', $this->filter );
diff --git a/includes/Banner.php b/includes/Banner.php
index cec738b..81660da 100644
--- a/includes/Banner.php
+++ b/includes/Banner.php
@@ -69,11 +69,11 @@
}
static function removeTemplate( $name, $user ) {
- global $wgNoticeUseTranslateExtension;
+ global $wgNoticeUseTranslateExtension, $wgCentralDBname;
$bannerObj = new Banner( $name );
$id = $bannerObj->getId();
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$res = $dbr->select( 'cn_assignments', 'asn_id', array(
'tmp_id' => $id ), __METHOD__ );
if ( $dbr->numRows( $res ) > 0 ) {
@@ -85,7 +85,7 @@
$bannerObj->logBannerChange( 'removed', $user );
// Delete banner record from the CentralNotice
cn_templates table
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->begin();
$dbw->delete( 'cn_templates',
array( 'tmp_id' => $id ),
@@ -123,7 +123,8 @@
* @throws MWException
*/
static function addTag( $tag, $revisionId, $pageId, $value = null ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
if ( is_object( $revisionId ) ) {
throw new MWException( 'Got object, excepted id' );
@@ -150,7 +151,8 @@
* @throws MWException
*/
static protected function removeTag( $tag, $pageId ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$conds = array(
'rt_page' => $pageId,
@@ -165,8 +167,7 @@
* TODO js refresh, iframe
* live_target to other projects depending on ... something
*/
- function previewFieldSet( IContextSource $context, $lang )
- {
+ function previewFieldSet( IContextSource $context, $lang ) {
$render = new SpecialBannerLoader();
$render->siteName = 'Wikipedia'; //FIXME: translate?
$render->language = $lang;
@@ -434,7 +435,8 @@
}
static function getTemplateId( $templateName ) {
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$templateName = htmlspecialchars( $templateName );
$res = $dbr->select(
'cn_templates',
@@ -467,8 +469,6 @@
static function addTemplate( $name, $body, $user, $displayAnon,
$displayAccount, $fundraising = 0,
$autolink = 0, $landingPages = '',
$priorityLangs = array()
) {
- global $wgNoticeUseTranslateExtension;
-
if ( $body == '' || $name == '' ) {
return 'centralnotice-null-string';
}
@@ -476,7 +476,8 @@
// Format name so there are only letters, numbers, and
underscores
$name = preg_replace( '/[^A-Za-z0-9_]/', '', $name );
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$res = $dbr->select(
'cn_templates',
'tmp_name',
@@ -487,7 +488,7 @@
if ( $dbr->numRows( $res ) > 0 ) {
return 'centralnotice-template-exists';
} else {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->insert( 'cn_templates',
array(
'tmp_name' => $name,
@@ -584,7 +585,8 @@
}
}
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$log = array(
'tmplog_timestamp' => $dbw->timestamp(),
diff --git a/includes/Campaign.php b/includes/Campaign.php
index 8288f16..b0755bd 100644
--- a/includes/Campaign.php
+++ b/includes/Campaign.php
@@ -190,7 +190,8 @@
* @return array an array of campaign names
*/
static function getAllCampaignNames() {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$res = $dbr->select( 'cn_notices', 'not_name', null, __METHOD__
);
$notices = array();
foreach ( $res as $row ) {
@@ -229,7 +230,8 @@
$geo_countries = array();
}
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->begin();
$endTime = strtotime( '+1 hour', wfTimestamp( TS_UNIX, $startTs
) );
@@ -305,7 +307,8 @@
* @return bool|string True on success, string with message key for
error
*/
static function removeCampaign( $campaignName, $user ) {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$res = $dbr->select( 'cn_notices', 'not_name, not_locked',
array( 'not_name' => $campaignName )
@@ -328,7 +331,8 @@
$campaignId = Campaign::getNoticeId( $campaignName );
Campaign::logCampaignChange( 'removed', $campaignId, $user );
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->begin();
$dbw->delete( 'cn_assignments', array( 'not_id' => $campaignId
) );
$dbw->delete( 'cn_notices', array( 'not_name' => $campaignName
) );
@@ -346,7 +350,8 @@
* @return bool|string True on success, string with message key for
error
*/
static function addTemplateTo( $noticeName, $templateName, $weight ) {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$eNoticeName = htmlspecialchars( $noticeName );
$noticeId = Campaign::getNoticeId( $eNoticeName );
@@ -361,7 +366,7 @@
if ( $dbr->numRows( $res ) > 0 ) {
return 'centralnotice-template-already-exists';
}
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->begin();
$noticeId = Campaign::getNoticeId( $eNoticeName );
$dbw->insert( 'cn_assignments',
@@ -380,7 +385,8 @@
* Remove a banner assignment from a campaign
*/
static function removeTemplateFor( $noticeName, $templateName ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->begin();
$noticeId = Campaign::getNoticeId( $noticeName );
$templateId = Banner::getTemplateId( $templateName );
@@ -392,7 +398,8 @@
* Lookup the ID for a campaign based on the campaign name
*/
static function getNoticeId( $noticeName ) {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$eNoticeName = htmlspecialchars( $noticeName );
$row = $dbr->selectRow( 'cn_notices', 'not_id', array(
'not_name' => $eNoticeName ) );
if ( $row ) {
@@ -407,7 +414,8 @@
*/
static function getNoticeName( $noticeId ) {
// Read from the master database to avoid concurrency problems
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
if ( is_numeric( $noticeId ) ) {
$row = $dbr->selectRow( 'cn_notices', 'not_name',
array( 'not_id' => $noticeId ) );
if ( $row ) {
@@ -419,7 +427,8 @@
static function getNoticeProjects( $noticeName ) {
// Read from the master database to avoid concurrency problems
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$eNoticeName = htmlspecialchars( $noticeName );
$row = $dbr->selectRow( 'cn_notices', 'not_id', array(
'not_name' => $eNoticeName ) );
$projects = array();
@@ -435,7 +444,8 @@
static function getNoticeLanguages( $noticeName ) {
// Read from the master database to avoid concurrency problems
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$eNoticeName = htmlspecialchars( $noticeName );
$row = $dbr->selectRow( 'cn_notices', 'not_id', array(
'not_name' => $eNoticeName ) );
$languages = array();
@@ -451,7 +461,8 @@
static function getNoticeCountries( $noticeName ) {
// Read from the master database to avoid concurrency problems
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$eNoticeName = htmlspecialchars( $noticeName );
$row = $dbr->selectRow( 'cn_notices', 'not_id', array(
'not_name' => $eNoticeName ) );
$countries = array();
@@ -472,7 +483,8 @@
* @return bool|string True on success, string with message key for
error
*/
static function updateNoticeDate( $noticeName, $start, $end ) {
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
// Start/end don't line up
if ( $start > $end || $end < $start ) {
@@ -488,7 +500,7 @@
$startDate = $dbr->timestamp( $start );
$endDate = $dbr->timestamp( $end );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->update( 'cn_notices',
array(
'not_start' => $startDate,
@@ -513,7 +525,8 @@
return;
} else {
$settingName = strtolower( $settingName );
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->update( 'cn_notices',
array( 'not_' . $settingName => $settingValue ),
array( 'not_name' => $noticeName )
@@ -553,7 +566,8 @@
return;
} else {
$settingName = strtolower( $settingName );
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->update( 'cn_notices',
array( 'not_'.$settingName => $settingValue ),
array( 'not_name' => $noticeName )
@@ -569,7 +583,8 @@
* @param $weight New banner weight
*/
static function updateWeight( $noticeName, $templateId, $weight ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$noticeId = Campaign::getNoticeId( $noticeName );
$dbw->update( 'cn_assignments',
array( 'tmp_weight' => $weight ),
@@ -589,7 +604,8 @@
* @param $bucket New bucket number
*/
static function updateBucket( $noticeName, $templateId, $bucket ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$noticeId = Campaign::getNoticeId( $noticeName );
$dbw->update( 'cn_assignments',
array( 'asn_bucket' => $bucket ),
@@ -602,7 +618,8 @@
// @todo FIXME: Unused.
static function updateProjectName( $notice, $projectName ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->update( 'cn_notices',
array( 'not_project' => $projectName ),
array(
@@ -612,7 +629,8 @@
}
static function updateProjects( $notice, $newProjects ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->begin();
// Get the previously assigned projects
@@ -641,7 +659,8 @@
}
static function updateProjectLanguages( $notice, $newLanguages ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->begin();
// Get the previously assigned languages
@@ -670,7 +689,8 @@
}
static function updateCountries( $notice, $newCountries ) {
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
// Get the previously assigned languages
$oldCountries = Campaign::getNoticeCountries( $notice );
@@ -713,7 +733,8 @@
) {
// Only log the change if it is done by an actual user (rather
than a testing script)
if ( $user->getId() > 0 ) { // User::getID returns 0 for
anonymous or non-existant users
- $dbw = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$log = array(
'notlog_timestamp' => $dbw->timestamp(),
@@ -758,7 +779,8 @@
}
// Read from the master database to avoid concurrency problems
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$res = $dbr->select( 'cn_notice_log', '*', $conds,
__METHOD__,
array(
diff --git a/special/SpecialCentralNotice.php b/special/SpecialCentralNotice.php
index 21da53c..d4a7651 100644
--- a/special/SpecialCentralNotice.php
+++ b/special/SpecialCentralNotice.php
@@ -345,10 +345,10 @@
* Show all campaigns found in the database, show "Add a campaign" form
*/
function listNotices() {
- global $wgNoticeProjects;
+ global $wgNoticeProjects, $wgCentralDBname;
// Get connection
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
if ( $this->editable ) {
$readonly = array();
@@ -1046,9 +1046,9 @@
* Create form for managing banners assigned to a campaign
*/
function assignedTemplatesForm( $notice ) {
- global $wgLanguageCode, $wgNoticeNumberOfBuckets;
+ global $wgLanguageCode, $wgNoticeNumberOfBuckets,
$wgCentralDBnames;
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$res = $dbr->select(
// Aliases are needed to avoid problems with table
prefixes
array(
diff --git a/special/SpecialNoticeTemplate.php
b/special/SpecialNoticeTemplate.php
index 069431c..2a67df4 100644
--- a/special/SpecialNoticeTemplate.php
+++ b/special/SpecialNoticeTemplate.php
@@ -859,7 +859,8 @@
}
public function getBannerName( $bannerId ) {
- $dbr = wfGetDB( DB_MASTER );
+ global $wgCentralDBnames;
+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
if ( is_numeric( $bannerId ) ) {
$row = $dbr->selectRow( 'cn_templates', 'tmp_name',
array( 'tmp_id' => $bannerId ) );
if ( $row ) {
@@ -881,15 +882,15 @@
}
$initialBannerSettings = Banner::getBannerSettings( $name, true
);
-
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$res = $dbr->select( 'cn_templates', 'tmp_name',
array( 'tmp_name' => $name ),
__METHOD__
);
if ( $dbr->numRows( $res ) == 1 ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
$dbw->update( 'cn_templates',
array(
'tmp_display_anon' => $displayAnon,
@@ -937,7 +938,8 @@
$dest = preg_replace( '/[^A-Za-z0-9_]/', '', $dest );
// Pull banner settings from database
- $dbr = wfGetDB( DB_SLAVE );
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
$row = $dbr->selectRow( 'cn_templates',
array(
'tmp_display_anon',
--
To view, visit https://gerrit.wikimedia.org/r/52956
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5de9d1f66838094472a8268ef1678f9709aa9eb5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits