summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/TranslateUtils.php')
-rw-r--r--MLEB/Translate/TranslateUtils.php142
1 files changed, 53 insertions, 89 deletions
diff --git a/MLEB/Translate/TranslateUtils.php b/MLEB/Translate/TranslateUtils.php
index 546be5c7..3cb7ee5e 100644
--- a/MLEB/Translate/TranslateUtils.php
+++ b/MLEB/Translate/TranslateUtils.php
@@ -79,66 +79,43 @@ class TranslateUtils {
$dbr = wfGetDB( DB_REPLICA );
$revStore = MediaWikiServices::getInstance()->getRevisionStore();
$titleContents = [];
- if ( is_callable( [ $revStore, 'newRevisionsFromBatch' ] ) ) {
- $query = $revStore->getQueryInfo( [ 'page', 'user' ] );
- $rows = $dbr->select(
- $query['tables'],
- $query['fields'],
- [
- 'page_namespace' => $namespace,
- 'page_title' => $titles
- ],
- __METHOD__,
- [],
- $query['joins'] + [ 'JOIN', 'page_latest=rev_id' ]
- );
-
- $revisions = $revStore->newRevisionsFromBatch( $rows, [
- 'slots' => true,
- 'content' => true
- ] )->getValue();
- foreach ( $rows as $row ) {
- /** @var RevisionRecord|null $rev */
- $rev = $revisions[$row->rev_id];
- if ( $rev ) {
- /** @var TextContent $content */
- $content = $rev->getContent( SlotRecord::MAIN );
- if ( $content ) {
- $titleContents[$row->page_title] = [
- $content->getText(),
- $row->rev_user_text
- ];
- }
+
+ $query = $revStore->getQueryInfo( [ 'page', 'user' ] );
+ $rows = $dbr->select(
+ $query['tables'],
+ $query['fields'],
+ [
+ 'page_namespace' => $namespace,
+ 'page_title' => $titles,
+ 'page_latest=rev_id',
+ ],
+ __METHOD__,
+ [],
+ $query['joins']
+ );
+
+ $revisions = $revStore->newRevisionsFromBatch( $rows, [
+ 'slots' => true,
+ 'content' => true
+ ] )->getValue();
+
+ foreach ( $rows as $row ) {
+ /** @var RevisionRecord|null $rev */
+ $rev = $revisions[$row->rev_id];
+ if ( $rev ) {
+ /** @var TextContent $content */
+ $content = $rev->getContent( SlotRecord::MAIN );
+ if ( $content ) {
+ $titleContents[$row->page_title] = [
+ $content->getText(),
+ $row->rev_user_text
+ ];
}
}
- $rows->free();
- } else {
- // Pre 1.34 compatibility
- $actorQuery = ActorMigration::newMigration()->getJoin( 'rev_user' );
- $rows = $dbr->select( [ 'page', 'revision', 'text' ] + $actorQuery['tables'],
- [
- 'page_title', 'old_text', 'old_flags',
- 'rev_user_text' => $actorQuery['fields']['rev_user_text']
- ],
- [
- 'page_namespace' => $namespace,
- 'page_title' => $titles
- ],
- __METHOD__,
- [],
- [
- 'revision' => [ 'JOIN', 'page_latest=rev_id' ],
- 'text' => [ 'JOIN', 'rev_text_id=old_id' ],
- ] + $actorQuery['joins']
- );
- foreach ( $rows as $row ) {
- $titleContents[$row->page_title] = [
- Revision::getRevisionText( $row ),
- $row->rev_user_text
- ];
- }
- $rows->free();
}
+
+ $rows->free();
+
return $titleContents;
}
@@ -190,16 +167,6 @@ class TranslateUtils {
$dbr = wfGetDB( DB_REPLICA );
- if ( class_exists( ActorMigration::class ) ) {
- $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
- } else {
- $actorQuery = [
- 'tables' => [],
- 'fields' => [ 'rc_user_text' => 'rc_user_text' ],
- 'joins' => [],
- ];
- }
-
$hours = (int)$hours;
$cutoff_unixtime = time() - ( $hours * 3600 );
$cutoff = $dbr->timestamp( $cutoff_unixtime );
@@ -213,15 +180,15 @@ class TranslateUtils {
}
$res = $dbr->select(
- [ 'recentchanges' ] + $actorQuery['tables'],
+ [ 'recentchanges', 'actor' ],
array_merge( [
'rc_namespace', 'rc_title', 'rc_timestamp',
- 'rc_user_text' => $actorQuery['fields']['rc_user_text'],
+ 'rc_user_text' => 'actor_name',
], $extraFields ),
$conds,
__METHOD__,
[],
- $actorQuery['joins']
+ [ 'actor' => [ 'JOIN', 'actor_id=rc_actor' ] ]
);
$rows = iterator_to_array( $res );
@@ -451,12 +418,7 @@ class TranslateUtils {
$formats = [];
$filename = substr( $icon, 7 );
- if ( method_exists( MediaWikiServices::class, 'getRepoGroup' ) ) {
- // MediaWiki 1.34+
- $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $filename );
- } else {
- $file = wfFindFile( $filename );
- }
+ $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $filename );
if ( !$file ) {
wfWarn( "Unknown message group icon file $icon" );
@@ -498,7 +460,7 @@ class TranslateUtils {
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
$index = self::shouldReadFromMaster() ? DB_MASTER : DB_REPLICA;
- return $lb->getConnection( $index );
+ return $lb->getConnectionRef( $index );
}
/**
@@ -580,15 +542,8 @@ class TranslateUtils {
*/
public static function allowsSubpages( Title $title ): bool {
$mwInstance = MediaWikiServices::getInstance();
- if ( is_callable( [ $mwInstance, 'getNamespaceInfo' ] ) ) {
- $namespaceInfo = $mwInstance->getNamespaceInfo();
- return $namespaceInfo->hasSubpages( $title->getNamespace() );
- } else {
- // BC for MW 1.33
- global $wgNamespacesWithSubpages;
- return isset( $wgNamespacesWithSubpages[ $title->getNamespace() ] ) &&
- $wgNamespacesWithSubpages[ $title->getNamespace() ];
- }
+ $namespaceInfo = $mwInstance->getNamespaceInfo();
+ return $namespaceInfo->hasSubpages( $title->getNamespace() );
}
public static function isEditPage( WebRequest $request ): bool {
@@ -598,10 +553,19 @@ class TranslateUtils {
}
$action = $request->getVal( 'action' );
- if ( $action === 'edit' ) {
- return true;
+ return $action === 'edit';
+ }
+
+ /**
+ * Add support for <= 1.34. Wrapper method to fetch the the MW version
+ * @return string
+ */
+ public static function getMWVersion(): string {
+ if ( defined( 'MW_VERSION' ) ) {
+ return MW_VERSION;
}
- return false;
+ global $wgVersion;
+ return $wgVersion;
}
}