http://www.mediawiki.org/wiki/Special:Code/MediaWiki/58257

Revision: 58257
Author:   nikerabbit
Date:     2009-10-28 15:09:53 +0000 (Wed, 28 Oct 2009)

Log Message:
-----------
Make more generic

Modified Paths:
--------------
    trunk/extensions/Translate/MessageGroups.php
    trunk/extensions/Translate/groups/MediaWikiExtensions.php

Modified: trunk/extensions/Translate/MessageGroups.php
===================================================================
--- trunk/extensions/Translate/MessageGroups.php        2009-10-28 14:10:19 UTC 
(rev 58256)
+++ trunk/extensions/Translate/MessageGroups.php        2009-10-28 15:09:53 UTC 
(rev 58257)
@@ -318,6 +318,9 @@
         * Name of the array where all messages are stored, if applicable.
         */
        protected $arrName      = 'messages';
+
+       protected $path         = null;
+
        public function getVariableName() { return $this->arrName; }
        public function setVariableName( $value ) { $this->arrName = $value; }
 
@@ -369,10 +372,17 @@
        }
 
        public function getPath() {
-               global $wgTranslateExtensionDirectory;
-               return $wgTranslateExtensionDirectory;
+               if ( $this->path === null ) {
+                       global $wgTranslateExtensionDirectory;
+                       return $wgTranslateExtensionDirectory; // BC
+               }
+               return $this->path;
        }
 
+       public function setPath( $path ) {
+               $this->path = $path;
+       }
+
        public function getReader( $code ) {
                $reader = new WikiExtensionFormatReader( 
$this->getMessageFileWithPath( $code ) );
                $reader->variableName = $this->getVariableName();

Modified: trunk/extensions/Translate/groups/MediaWikiExtensions.php
===================================================================
--- trunk/extensions/Translate/groups/MediaWikiExtensions.php   2009-10-28 
14:10:19 UTC (rev 58256)
+++ trunk/extensions/Translate/groups/MediaWikiExtensions.php   2009-10-28 
15:09:53 UTC (rev 58257)
@@ -2,7 +2,17 @@
 
 class PremadeMediawikiExtensionGroups {
        protected $groups;
+       protected $definitionFile = null;
+       protected $useConfigure = true;
+       protected $idPrefix = 'ext-';
 
+       public function __construct() {
+               global $wgTranslateExtensionDirectory;
+               $dir = dirname( __FILE__ );
+               $this->definitionFile = $dir . '/mediawiki-defines.txt';
+               $this->path = $wgTranslateExtensionDirectory;
+       }
+
        public function init() {
                if ( $this->groups !== null ) return;
 
@@ -11,17 +21,15 @@
                        $wgConfigureExtDir = "$IP/extensions/";
                }
                $wgAutoloadClasses['TxtDef'] = $wgConfigureExtDir . 
"Configure/TxtDef.php";
-               if ( class_exists( 'TxtDef' ) ) {
+               if ( $this->useConfigure && class_exists( 'TxtDef' ) ) {
                        $tmp = TxtDef::loadFromFile( $wgConfigureExtDir . 
"Configure/Configure.settings-ext.txt" );
                        $configureData = array_combine( array_map( array( 
__CLASS__, 'foldId' ), array_keys($tmp)), array_values($tmp) );
                } else {
                        $configureData = array();
                }
 
+               $defines = file_get_contents( $this->definitionFile );
 
-               $dir = dirname( __FILE__ );
-               $defines = file_get_contents( $dir . '/mediawiki-defines.txt' );
-
                $linefeed = '(\r\n|\n)';
 
                $sections = array_map( 'trim', preg_split( "/$linefeed{2,}/", 
$defines, - 1, PREG_SPLIT_NO_EMPTY ) );
@@ -33,7 +41,7 @@
                        $newgroup = array();
 
                        foreach ( $lines as $line ) {
-                               if ( $line === '' ) continue;
+                               if ( $line === '' || $line[0] === '#' ) 
continue;
 
                                if ( strpos( $line, '=' ) === false ) {
                                        if ( empty( $newgroup['name'] ) ) {
@@ -98,7 +106,7 @@
                        if ( isset( $g['id'] ) ) {
                                $id = $g['id'];
                        } else {
-                               $id = 'ext-' . preg_replace( '/\s+/', '', 
strtolower( $name ) );
+                               $id = $this->idPrefix . preg_replace( '/\s+/', 
'', strtolower( $name ) );
                        }
 
                        if ( isset( $g['file'] ) ) {
@@ -110,7 +118,7 @@
                        if ( isset( $g['descmsg'] ) ) {
                                $descmsg = $g['descmsg'];
                        } else {
-                               $descmsg = str_replace( 'ext-', '', $id ) . 
'-desc';
+                               $descmsg = str_replace( $this->idPrefix, '', 
$id ) . '-desc';
                        }
 
                        $configureId = self::foldId( $name );
@@ -148,6 +156,7 @@
                global $wgTranslateAC, $wgTranslateEC;
                $this->init();
 
+               var_dump( $this->groups );
                if ( !count( $this->groups ) ) return;
 
                foreach ( $this->groups as $id => $g ) {
@@ -155,6 +164,12 @@
                        $wgTranslateEC[] = $id;
                }
 
+               $this->addAllMeta();
+       }
+
+       protected function addAllMeta() {
+               global $wgTranslateAC, $wgTranslateEC;
+
                $meta = array(
                        'ext-0-all'               => 
'AllMediawikiExtensionsGroup',
                        'ext-0-wikia'             => 'AllWikiaExtensionsGroup',
@@ -177,10 +192,10 @@
        }
 
        public function factory( $id ) {
-
                $info = $this->groups[$id];
                $group = ExtensionMessageGroup::factory( $info['name'], $id );
                $group->setMessageFile( $info['file'] );
+               $group->setPath( $this->path );
 
                if ( isset( $info['prefix'] ) ) {
                        $mangler = new StringMatcher( $info['prefix'], 
$info['mangle'] );
@@ -199,8 +214,6 @@
                        $group->setDescriptionMsg( $info['descmsg'], 
$info['url'] );
                }
 
-               global $wgTranslateExtensionDirectory;
-
                if ( isset($info['aliasfile']) ) $group->setAliasFile( 
$info['aliasfile'] );
                if ( isset($info['magicfile']) ) $group->setMagicFile( 
$info['magicfile'] );
 



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to