ApiTranslateUser.php

Go to the documentation of this file.
00001 <?php
00017 class ApiTranslateUser extends ApiBase {
00018     public function execute() {
00019         $output = array();
00020 
00021         $user = $this->getUser();
00022         $groups = $user->getOption( 'translate-recent-groups', '' );
00023         $output['recentgroups'] = array();
00024         if ( strval( $groups ) !== '' ) {
00025             $output['recentgroups'] = explode( '|', $groups );
00026             $this->getResult()->setIndexedTagName( $output['recentgroups'], 'group' );
00027         }
00028         $this->getResult()->addValue( null, $this->getModuleName(), $output );
00029     }
00030 
00031     public function getDescription() {
00032         return 'Translation related information about the user. Experimental.';
00033     }
00034 
00035     public function getExamples() {
00036         return array(
00037             'api.php?action=translateuser',
00038         );
00039     }
00040 
00041     public function getVersion() {
00042         return '2012-11-30';
00043     }
00044 
00048     public static function trackGroup( MessageGroup $group, User $user ) {
00049         if ( $user->isAnon() ) {
00050             return true;
00051         }
00052 
00053         $groups = $user->getOption( 'translate-recent-groups', '' );
00054 
00055         if ( $groups === '' ) {
00056             $groups = array();
00057         } else {
00058             $groups = explode( '|', $groups );
00059         }
00060 
00061         if ( isset( $groups[0] ) && $groups[0] === $group->getId() ) {
00062             return true;
00063         }
00064 
00065         array_unshift( $groups, $group->getId() );
00066         $groups = array_unique( $groups );
00067         $groups = array_slice( $groups, 0, 5 );
00068 
00069         $user->setOption( 'translate-recent-groups', implode( '|', $groups ) );
00070         $user->saveSettings();
00071 
00072         return true;
00073     }
00074 }
Generated on Tue Oct 29 00:00:23 2013 for MediaWiki Translate Extension by  doxygen 1.6.3