RecentMessageGroup.php

Go to the documentation of this file.
00001 <?php
00016 class RecentMessageGroup extends WikiMessageGroup {
00017     /*
00018      * Yes this is very ugly hack and should not be removed.
00019      * @see MessageCollection::getPages()
00020      */
00021     protected $namespace = false;
00022 
00023     protected $language;
00024 
00029     public function __construct() {
00030     }
00031 
00032     public function setLanguage( $code ) {
00033         $this->language = $code;
00034     }
00035 
00036     public function getId() {
00037         return '!recent';
00038     }
00039 
00040     public function getLabel( IContextSource $context = null ) {
00041         $msg = wfMessage( 'translate-dynagroup-recent-label' );
00042         $msg = self::addContext( $msg, $context );
00043 
00044         return $msg->plain();
00045     }
00046 
00047     public function getDescription( IContextSource $context = null ) {
00048         $msg = wfMessage( 'translate-dynagroup-recent-desc' );
00049         $msg = self::addContext( $msg, $context );
00050 
00051         return $msg->plain();
00052     }
00053 
00054     protected function getRCCutoff() {
00055         $db = wfGetDB( DB_SLAVE );
00056         $tables = 'recentchanges';
00057         $max = $db->selectField( $tables, 'MAX(rc_id)', array(), __METHOD__ );
00058 
00059         return max( 0, $max - 50000 );
00060     }
00061 
00065     protected function getQueryConditions() {
00066         global $wgTranslateMessageNamespaces;
00067         $db = wfGetDB( DB_SLAVE );
00068         $conds = array(
00069             'rc_title ' . $db->buildLike( $db->anyString(), '/' . $this->language ),
00070             'rc_namespace' => $wgTranslateMessageNamespaces,
00071             'rc_type != ' . RC_LOG,
00072             'rc_id > ' . $this->getRCCutoff(),
00073         );
00074 
00075         return $conds;
00076     }
00077 
00084     protected function matchingMessage( MessageHandle $msg ) {
00085         return true;
00086     }
00087 
00088     public function getDefinitions() {
00089         if ( !$this->language ) {
00090             throw new MWException( "Language not set" );
00091         }
00092 
00093         $db = wfGetDB( DB_SLAVE );
00094         $tables = 'recentchanges';
00095         $fields = array( 'rc_namespace', 'rc_title' );
00096         $conds = $this->getQueryConditions();
00097         $options = array(
00098             'ORDER BY' => 'rc_id DESC',
00099             'LIMIT' => 5000
00100         );
00101         $res = $db->select( $tables, $fields, $conds, __METHOD__, $options );
00102 
00103         $defs = array();
00104         foreach ( $res as $row ) {
00105             $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
00106             $handle = new MessageHandle( $title );
00107 
00108             if ( !$handle->isValid() || !$this->matchingMessage( $handle ) ) {
00109                 continue;
00110             }
00111 
00112             $messageKey = $handle->getKey();
00113             $fullKey = $row->rc_namespace . ':' . $messageKey;
00114 
00115             /* Note: due to bugs, getMessage might return null even for
00116              * known messages. These negatives are not cached, but that
00117              * should be rare enough case to not affect performance. */
00118             if ( !isset( $defs[$fullKey] ) ) {
00119                 $group = $handle->getGroup();
00120                 $msg = $group->getMessage( $messageKey, $group->getSourceLanguage() );
00121 
00122                 if ( $msg !== null ) {
00123                     $defs[$fullKey] = $msg;
00124                 }
00125             }
00126         }
00127 
00128         return $defs;
00129     }
00130 
00131     public function getChecker() {
00132         return null;
00133     }
00134 
00138     public function getMessageContent( MessageHandle $handle ) {
00139         $groupId = MessageIndex::getPrimaryGroupId( $handle );
00140         $group = MessageGroups::getGroup( $groupId );
00141         if ( $group ) {
00142             return $group->getMessage( $handle->getKey(), $group->getSourceLanguage() );
00143         }
00144 
00145         throw new MWException( 'Could not find group for ' . $handle->getKey() );
00146     }
00147 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3