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