fallbacks-graph.php
Go to the documentation of this file.00001 <?php
00012
00013 if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
00014 $IP = getenv( 'MW_INSTALL_PATH' );
00015 } else {
00016 $dir = __DIR__;
00017 $IP = "$dir/../../..";
00018 }
00019 require_once "$IP/maintenance/Maintenance.php";
00020
00022 class FallbacksCompare extends Maintenance {
00023 public function __construct() {
00024 parent::__construct();
00025 $this->mDescription = 'Creates graphml xml file of language fallbacks.';
00026 }
00027
00028 public function execute() {
00029 $template = <<<XML
00030 <?xml version="1.0" encoding="UTF-8"?>
00031 <graphml
00032 xmlns="http://graphml.graphdrawing.org/xmlns"
00033 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
00034 xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
00035 http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"
00036 xmlns:y="http://www.yworks.com/xml/graphml">
00037
00038 <key id="code" for="node" yfiles.type="nodegraphics"/>
00039 <graph id="G" edgedefault="directed">
00040 $1
00041 </graph>
00042 </graphml>
00043
00044 XML;
00045
00046 $langs = Language::fetchLanguageNames( null, 'mw' );
00047 $nodes = $edges = array();
00048 foreach ( $langs as $code => $name ) {
00049
00050 $fallbacks = Language::getFallbacksFor( $code );
00051 if ( $fallbacks === array( 'en' ) ) {
00052 continue;
00053 }
00054
00055 $nodes[$code] = $this->createNode( $code );
00056
00057 $prev = $code;
00058 foreach ( $fallbacks as $fb ) {
00059 $nodes[$fb] = $this->createNode( $fb );
00060 $edges[$fb . $prev] = Xml::element( 'edge', array( 'source' => $prev, 'target' => $fb ) );
00061 $prev = $fb;
00062 }
00063 }
00064
00065 $output = array_merge( $nodes, $edges );
00066 $output = "\t\t" . implode( "\n\t\t", $output );
00067 echo str_replace( '$1', $output, $template );
00068 }
00069
00070 protected function createNode( $code ) {
00071 return
00072 Xml::openElement( 'node', array( 'id' => $code ) )
00073 . Xml::openElement( 'data', array( 'key' => "code" ) )
00074 . Xml::openElement( 'y:Shpapenode' )
00075 . Xml::element( 'y:NodeLabel', array(), $code )
00076 . Xml::closeElement( 'y:Shpapenode' )
00077 . Xml::closeElement( 'data' )
00078 . Xml::closeElement( 'node' );
00079 }
00080 }
00081
00082 $maintClass = 'FallbacksCompare';
00083 require_once DO_MAINTENANCE;