Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 74 additions & 65 deletions src/ChangeSet.php

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions src/CustomTexts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*/
namespace SWL;

use SMWDIProperty;
use MediaWiki\MediaWikiServices;
use SMW\DIProperty;

class CustomTexts {

Expand Down Expand Up @@ -49,7 +50,9 @@ private function initCustomTexts() {
return;
}
$this->customTexts = array();
$dbr = wfGetDB( DB_REPLICA );
$dbr = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_REPLICA );
$row = $dbr->selectRow(
'swl_groups',
'group_custom_texts',
Expand Down Expand Up @@ -79,12 +82,12 @@ private function initCustomTexts() {
*
* @since 0.2
*
* @param SMWDIProperty $property
* @param DIProperty $property
* @param String $newValue
*
* @return String or false
*/
public function getPropertyCustomText( SMWDIProperty $property, $newValue ) {
public function getPropertyCustomText( DIProperty $property, $newValue ) {
$this->initCustomTexts();
if( array_key_exists( $property->getLabel(), $this->customTexts ) && array_key_exists( $newValue, $this->customTexts[$property->getLabel()] ) ) {
return $this->customTexts[$property->getLabel()][$newValue];
Expand Down
27 changes: 18 additions & 9 deletions src/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class Edit {
* @return Edit
*/
public static function newFromId( $id ) {
$dbr = wfGetDB( DB_REPLICA );
$dbr = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_REPLICA );

return self::newFromDBResult( $dbr->select(
'swl_edits',
Expand All @@ -75,7 +77,8 @@ public static function newFromId( $id ) {
'edit_page_id',
'edit_time'
),
array( 'edit_id' => $id )
array( 'edit_id' => $id ),
__METHOD__
) );
}

Expand Down Expand Up @@ -134,16 +137,19 @@ public function writeToDB() {
* @return boolean Success indicator
*/
private function updateInDB() {
$dbr = wfGetDB( DB_PRIMARY );
$dbw = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_PRIMARY );

return $dbr->update(
return $dbw->update(
'swl_edits',
array(
'edit_user_name' => $this->userName,
'edit_page_id' => $this->pageId,
'edit_time' => $this->time
),
array( 'edit_id' => $this->id )
array( 'edit_id' => $this->id ),
__METHOD__
);
}

Expand All @@ -158,18 +164,21 @@ private function insertIntoDB() {
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
$hookContainer->run( 'SWLBeforeEditInsert', array( &$this ) );

$dbr = wfGetDB( DB_PRIMARY );
$dbw = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_PRIMARY );

$result = $dbr->insert(
$result = $dbw->insert(
'swl_edits',
array(
'edit_user_name' => $this->userName,
'edit_page_id' => $this->pageId,
'edit_time' => $this->time
)
),
__METHOD__
);

$this->id = $dbr->insertId();
$this->id = $dbw->insertId();

$hookContainer->run( 'SWLAfterEditInsert', array( &$this ) );

Expand Down
6 changes: 3 additions & 3 deletions src/Emailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use User;
use UserMailer;
use MailAddress;
use SMWDataValueFactory;
use SMW\DataValueFactory;
use SMW\DIProperty;

final class Emailer {
Expand Down Expand Up @@ -118,10 +118,10 @@ private static function getPropertyHTML( DIProperty $property, array $changes, C
}
if( !$justCustomMessage ) {
if ( !is_null( $change->getOldValue() ) ) {
$deletions[] = SMWDataValueFactory::newDataItemValue( $change->getOldValue(), $property )->getShortHTMLText();
$deletions[] = DataValueFactory::newDataItemValue( $change->getOldValue(), $property )->getShortHTMLText();
}
if ( !is_null( $change->getNewValue() ) ) {
$insertions[] = SMWDataValueFactory::newDataItemValue( $change->getNewValue(), $property )->getShortHTMLText();
$insertions[] = DataValueFactory::newDataItemValue( $change->getNewValue(), $property )->getShortHTMLText();
}
}
}
Expand Down
39 changes: 24 additions & 15 deletions src/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
use SMW\Query\Language\ConceptDescription;
use SMW\Query\Language\Conjunction;
use SMW\Query\Language\ValueDescription;
use SMWDIProperty;
use SMW\DIProperty;
use SMWQuery;
use SMWValueDescription;
use Title;
use User;

Expand Down Expand Up @@ -186,8 +185,11 @@ public function writeToDB() {
* @return boolean Success indicator
*/
private function updateInDB() {
$dbr = wfGetDB( DB_PRIMARY );
return $dbr->update(
$dbw = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_PRIMARY );

return $dbw->update(
'swl_groups',
array(
'group_name' => $this->name,
Expand All @@ -197,7 +199,8 @@ private function updateInDB() {
'group_concepts' => implode( '|', $this->concepts ),
'group_custom_texts' => implode( '|', $this->getSerializedCustomTexts() ),
),
array( 'group_id' => $this->id )
array( 'group_id' => $this->id ),
__METHOD__
);
}

Expand All @@ -209,9 +212,11 @@ private function updateInDB() {
* @return boolean Success indicator
*/
private function insertIntoDB() {
$dbr = wfGetDB( DB_PRIMARY );
$dbw = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_PRIMARY );

$result = $dbr->insert(
$result = $dbw->insert(
'swl_groups',
array(
'group_name' => $this->name,
Expand All @@ -220,10 +225,11 @@ private function insertIntoDB() {
'group_namespaces' => implode( '|', $this->namespaces ),
'group_concepts' => implode( '|', $this->concepts ),
'group_custom_texts' => implode( '|', $this->getSerializedCustomTexts() ),
)
),
__METHOD__
);

$this->id = $dbr->insertId();
$this->id = $dbw->insertId();

return $result;
}
Expand Down Expand Up @@ -251,7 +257,7 @@ public function getNamespaces() {
}

/**
* Returns the properties specified by the group as strings (serializations of SMWDIProperty).
* Returns the properties specified by the group as strings (serializations of DIProperty).
*
* @since 0.1
*
Expand All @@ -262,17 +268,17 @@ public function getProperties() {
}

/**
* Returns the properties specified by the group as SMWDIProperty objects.
* Returns the properties specified by the group as DIProperty objects.
*
* @since 0.1
*
* @return array[SMWDIProperty]
* @return array[DIProperty]
*/
public function getPropertyObjects() {
$properties = array();

foreach ( $this->properties as $property ) {
$properties[] = SMWDIProperty::newFromSerialization( $property );
$properties[] = DIProperty::newFromSerialization( $property );
}

return $properties;
Expand Down Expand Up @@ -481,7 +487,9 @@ public function conceptsCoverPage( Title $title ) {
*/
public function getWatchingUsers() {
if ( $this->watchingUsers == false ) {
$dbr = wfGetDB( DB_REPLICA );
$dbr = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_REPLICA );

$users = $dbr->select(
'swl_users_per_group',
Expand All @@ -490,7 +498,8 @@ public function getWatchingUsers() {
),
array(
'upg_group_id' => $this->getId()
)
),
__METHOD__
);

$userIds = array();
Expand Down
30 changes: 19 additions & 11 deletions src/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
namespace SWL;

use MediaWiki\MediaWikiServices;
use Title;
use User;

Expand All @@ -36,17 +37,24 @@ public static function getAll() {
if ( self::$groups === false ) {
self::$groups = array();

$dbr = wfGetDB( DB_REPLICA );

$groups = $dbr->select( 'swl_groups', array(
'group_id',
'group_name',
'group_categories',
'group_namespaces',
'group_properties',
'group_concepts',
'group_custom_texts'
) );
$dbr = MediaWikiServices::getInstance()
->getDBLoadBalancer()
->getConnection( DB_REPLICA );

$groups = $dbr->select(
'swl_groups',
array(
'group_id',
'group_name',
'group_categories',
'group_namespaces',
'group_properties',
'group_concepts',
'group_custom_texts',
),
[],
__METHOD__
);

foreach ( $groups as $group ) {
self::$groups[] = Group::newFromDBResult( $group );
Expand Down
Loading