24 public function __construct() {
25 parent::__construct();
26 $this->addDescription(
'Creates graphml xml file of language fallbacks.' );
29 public function execute() {
31<?xml version=
"1.0" encoding=
"UTF-8"?>
33 xmlns=
"http://graphml.graphdrawing.org/xmlns"
34 xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
35 xsi:schemaLocation=
"http://graphml.graphdrawing.org/xmlns
36 http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"
37 xmlns:y=
"http://www.yworks.com/xml/graphml">
39 <key
id=
"code" for=
"node" yfiles.type=
"nodegraphics"/>
40 <graph
id=
"G" edgedefault=
"directed">
47 $langs = MediaWikiServices::getInstance()
48 ->getLanguageNameUtils()
51 foreach ( $langs as $code => $name ) {
52 $fallbacks = Language::getFallbacksFor( $code, Language::STRICT_FALLBACKS );
53 if ( $fallbacks === [] ) {
57 $nodes[$code] = $this->createNode( $code );
60 foreach ( $fallbacks as $fb ) {
61 $nodes[$fb] = $this->createNode( $fb );
62 $edges[$fb . $prev] = Xml::element(
'edge', [
'source' => $prev,
'target' => $fb ] );
67 $output = array_merge( $nodes, $edges );
68 $output =
"\t\t" . implode(
"\n\t\t", $output );
69 echo str_replace(
'$1', $output, $template );
72 protected function createNode( $code ) {
73 return Xml::openElement(
'node', [
'id' => $code ] )
74 . Xml::openElement(
'data', [
'key' =>
'code' ] )
75 . Xml::openElement(
'y:Shapenode' )
78 [
'height' => 40,
'width' => max( 40, 20 * strlen( $code ) ) ],
81 . Xml::element(
'y:NodeLabel', [
'fontSize' =>
'24' ], $code )
82 . Xml::element(
'y:BorderStyle', [
'hasColor' =>
'false' ],
'' )
83 . Xml::element(
'y:Fill', [
'hasColor' =>
'false' ],
'' )
84 . Xml::closeElement(
'y:Shapenode' )
85 . Xml::closeElement(
'data' )
86 . Xml::closeElement(
'node' );