27 public function __construct() {
28 parent::__construct();
29 $this->addDescription(
'Creates graphml xml file of language fallbacks.' );
32 public function execute() {
35 <?xml version=
"1.0" encoding=
"UTF-8"?>
37 xmlns=
"http://graphml.graphdrawing.org/xmlns"
38 xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
39 xsi:schemaLocation=
"http://graphml.graphdrawing.org/xmlns
40 http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"
41 xmlns:y=
"http://www.yworks.com/xml/graphml">
43 <key
id=
"code" for=
"node" yfiles.type=
"nodegraphics"/>
44 <graph
id=
"G" edgedefault=
"directed">
51 $services = MediaWikiServices::getInstance();
53 ->getLanguageNameUtils()
55 $languageFallback = $services->getLanguageFallback();
57 foreach ( $langs as $code => $name ) {
58 $fallbacks = $languageFallback->getAll( $code, LanguageFallback::STRICT );
59 if ( $fallbacks === [] ) {
63 $nodes[$code] = $this->createNode( $code );
66 foreach ( $fallbacks as $fb ) {
67 $nodes[$fb] = $this->createNode( $fb );
68 $edges[$fb . $prev] = Xml::element(
'edge', [
'source' => $prev,
'target' => $fb ] );
73 $output = array_merge( $nodes, $edges );
74 $output =
"\t\t" . implode(
"\n\t\t", $output );
75 echo str_replace(
'$1', $output, $template );
78 protected function createNode( $code ) {
79 return Xml::openElement(
'node', [
'id' => $code ] )
80 . Xml::openElement(
'data', [
'key' =>
'code' ] )
81 . Xml::openElement(
'y:Shapenode' )
84 [
'height' => 40,
'width' => max( 40, 20 * strlen( $code ) ) ],
87 . Xml::element(
'y:NodeLabel', [
'fontSize' =>
'24' ], $code )
88 . Xml::element(
'y:BorderStyle', [
'hasColor' =>
'false' ],
'' )
89 . Xml::element(
'y:Fill', [
'hasColor' =>
'false' ],
'' )
90 . Xml::closeElement(
'y:Shapenode' )
91 . Xml::closeElement(
'data' )
92 . Xml::closeElement(
'node' );