Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
TranslateReplaceTitle.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageProcessing;
5
8use MediaWiki\MediaWikiServices;
9use MediaWiki\Title\Title;
10use MediaWiki\Title\TitleArrayFromResult;
11
25 public static function getTitlesForMove(
26 MessageHandle $sourceMessageHandle, string $replacement
27 ): array {
28 $titlesForMove = [];
29 $namespace = $sourceMessageHandle->getTitle()->getNamespace();
30
31 $titles = self::getMatchingTitles( $sourceMessageHandle );
32
33 foreach ( $titles as $title ) {
34 $handle = new MessageHandle( $title );
35 // This takes care of situations where we have two different titles
36 // foo and foo/bar, both will be matched and fetched but the slash
37 // does not represent a language separator
38 if ( $handle->getKey() !== $sourceMessageHandle->getKey() ) {
39 continue;
40 }
41 $targetTitle = Title::makeTitle(
42 $namespace,
43 Utilities::title( $replacement, $handle->getCode(), $namespace )
44 );
45 $titlesForMove[] = [ $title, $targetTitle ];
46 }
47
48 return $titlesForMove;
49 }
50
51 private static function getMatchingTitles( MessageHandle $handle ): TitleArrayFromResult {
52 $dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_PRIMARY );
53 $result = $dbr->newSelectQueryBuilder()
54 ->select( [ 'page_title', 'page_namespace', 'page_id' ] )
55 ->from( 'page' )
56 ->where( [
57 'page_namespace' => $handle->getTitle()->getNamespace(),
58 'page_title ' . $dbr->buildLike(
59 $handle->getTitleForBase()->getDBkey(), '/', $dbr->anyString()
60 ),
61 ] )
62 ->caller( __METHOD__ )
63 ->fetchResultSet();
64
65 return new TitleArrayFromResult( $result );
66 }
67}
Class for pointing to messages, like Title class is for titles.
getKey()
Returns the identified or guessed message key.
Helper class that contains utility methods to help with identifying and replace titles.
static getTitlesForMove(MessageHandle $sourceMessageHandle, string $replacement)
Returns two lists: a set of message handles that would be moved/renamed by the current text replaceme...
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:31