WikiPageMessageGroup.php

Go to the documentation of this file.
00001 <?php
00015 class WikiPageMessageGroup extends WikiMessageGroup {
00017     protected $title;
00018 
00019     public function __construct( $id, $source ) {
00020         $this->id = $id;
00021         $this->title = $source;
00022         $this->namespace = NS_TRANSLATIONS;
00023     }
00024 
00025     public function getSourceLanguage() {
00026         return $this->getTitle()->getPageLanguage()->getCode();
00027     }
00028 
00032     public function getTitle() {
00033         if ( is_string( $this->title ) ) {
00034             $this->title = Title::newFromText( $this->title );
00035         }
00036 
00037         return $this->title;
00038     }
00039 
00044     protected $definitions;
00045 
00049     public function getDefinitions() {
00050         if ( is_array( $this->definitions ) ) {
00051             return $this->definitions;
00052         }
00053 
00054         // Avoid replication issues
00055         $dbr = wfGetDB( DB_MASTER );
00056         $tables = 'translate_sections';
00057         $vars = array( 'trs_key', 'trs_text' );
00058         $conds = array( 'trs_page' => $this->getTitle()->getArticleID() );
00059         $options = array( 'ORDER BY' => 'trs_order' );
00060         $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
00061 
00062         $defs = array();
00063         $prefix = $this->getTitle()->getPrefixedDBKey() . '/';
00064         $re = '~<tvar\|([^>]+)>(.*?)</>~u';
00065 
00066         foreach ( $res as $r ) {
00068             $text = $r->trs_text;
00069             $text = preg_replace( $re, '$\1', $text );
00070             $defs[$r->trs_key] = $text;
00071         }
00072 
00073         $new_defs = array();
00074         foreach ( $defs as $k => $v ) {
00075             $k = str_replace( ' ', '_', $k );
00076             $new_defs[$prefix . $k] = $v;
00077         }
00078 
00079         return $this->definitions = $new_defs;
00080     }
00081 
00082     public function load( $code ) {
00083         if ( $this->isSourceLanguage( $code ) ) {
00084             return $this->getDefinitions();
00085         }
00086 
00087         return array();
00088     }
00089 
00098     public function getMessage( $key, $code ) {
00099         if ( $this->isSourceLanguage( $code ) ) {
00100             $stuff = $this->load( $code );
00101 
00102             return isset( $stuff[$key] ) ? $stuff[$key] : null;
00103         }
00104 
00105         $title = Title::makeTitleSafe( $this->getNamespace(), "$key/$code" );
00106 
00107         // BC for MW 1.19 and older
00108         if ( defined( 'Revision::READ_LATEST' ) ) {
00109             $rev = Revision::newFromTitle( $title, false, Revision::READ_LATEST );
00110         } else {
00111             $rev = Revision::newFromTitle( $title );
00112         }
00113 
00114         if ( !$rev ) {
00115             return null;
00116         }
00117 
00118         return $rev->getText();
00119     }
00120 
00124     public function getChecker() {
00125         $checker = new MediaWikiMessageChecker( $this );
00126         $checker->setChecks( array(
00127             array( $checker, 'pluralCheck' ),
00128             array( $checker, 'XhtmlCheck' ),
00129             array( $checker, 'braceBalanceCheck' ),
00130             array( $checker, 'pagenameMessagesCheck' ),
00131             array( $checker, 'miscMWChecks' )
00132         ) );
00133 
00134         return $checker;
00135     }
00136 
00137     public function getDescription( IContextSource $context = null ) {
00138         $title = $this->getTitle()->getPrefixedText();
00139         $target = ":$title";
00140 
00141         // Allow for adding a custom group description by using
00142         // "MediaWiki:Tp-custom-<group ID>".
00143         $customText = '';
00144         $msg = wfMessage( 'tp-custom-' . $this->id );
00145         self::addContext( $msg, $context );
00146         if ( $msg->exists() ) {
00147             $customText = $msg->plain();
00148         }
00149 
00150         $msg = wfMessage( 'translate-tag-page-desc', $title, $target );
00151         self::addContext( $msg, $context );
00152 
00153         return $msg->plain() . $customText;
00154     }
00155 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3