Index: trunk/extensions/Translate/SpecialSupportedLanguages.php |
— | — | @@ -0,0 +1,85 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @author Niklas Laxström |
| 5 | + * @copyright Copyright © 2010 Niklas Laxström |
| 6 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 7 | + */ |
| 8 | + |
| 9 | +$wgExtensionCredits['specialpage'][] = array( |
| 10 | + 'path' => __FILE__, |
| 11 | + 'name' => 'Translate: Supported Languages', |
| 12 | + 'version' => '2010-01-27', |
| 13 | + 'author' => 'Niklas Laxström', |
| 14 | + 'description' => '[[Special:Supported Languages|Special page]] for listing supported languages efficiently', |
| 15 | +); |
| 16 | + |
| 17 | +$wgSpecialPages['SupportedLanguages'] = 'SpecialSupportedLanguages'; |
| 18 | + |
| 19 | +class SpecialSupportedLanguages extends SpecialPage { |
| 20 | + |
| 21 | + public function __construct() { |
| 22 | + parent::__construct( 'SupportedLanguages' ); |
| 23 | + } |
| 24 | + |
| 25 | + public function execute( $par ) { |
| 26 | + global $wgLang, $wgOut; |
| 27 | + |
| 28 | + $locals = LanguageNames::getNames( $wgLang->getCode(), |
| 29 | + LanguageNames::FALLBACK_NORMAL, |
| 30 | + LanguageNames::LIST_MW_AND_CLDR |
| 31 | + ); |
| 32 | + $natives = Language::getLanguageNames( false ); |
| 33 | + ksort($natives); |
| 34 | + |
| 35 | + $titles = array(); |
| 36 | + foreach ( $natives as $code => $_ ) { |
| 37 | + $titles[] = Title::capitalize( $code, NS_PORTAL ) . '/translators'; |
| 38 | + } |
| 39 | + |
| 40 | + $dbr = wfGetDB( DB_SLAVE ); |
| 41 | + $tables = array( 'page', 'revision', 'text' ); |
| 42 | + $vars = array_merge(Revision::selectTextFields(), array( 'page_title', 'page_namespace' ), Revision::selectFields() ); |
| 43 | + $conds = array( |
| 44 | + 'page_latest = rev_id', |
| 45 | + 'rev_text_id = old_id', |
| 46 | + 'page_namespace' => NS_PORTAL, |
| 47 | + 'page_title' => $titles, |
| 48 | + ); |
| 49 | + |
| 50 | + $res = $dbr->select( $tables, $vars, $conds, __METHOD__ ); |
| 51 | + |
| 52 | + $users = array(); |
| 53 | + $lb = new LinkBatch; |
| 54 | + |
| 55 | + foreach ( $res as $row ) { |
| 56 | + $rev = new Revision($row); |
| 57 | + $text = $rev->getText(); |
| 58 | + $code = strtolower( preg_replace( '!/translators$!', '', $row->page_title ) ); |
| 59 | + preg_match_all( '!{{user\|([^}|]+)!', $text, $matches, PREG_SET_ORDER ); |
| 60 | + foreach( $matches as $match ) { |
| 61 | + $user = Title::capitalize( $match[1], NS_USER ); |
| 62 | + $lb->add( NS_USER, $user ); |
| 63 | + $lb->add( NS_USER_TALK, $user ); |
| 64 | + @$users[$code][] = $user; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + $lb->execute(); |
| 69 | + global $wgUser; |
| 70 | + $skin = $wgUser->getSkin(); |
| 71 | + foreach ( array_keys($users) as $code ) { |
| 72 | + $wgOut->addWikiText( "== [$code] {$locals[$code]} - {$natives[$code]} ==" ); |
| 73 | + |
| 74 | + foreach ( $users[$code] as $index => $username ) { |
| 75 | + $title = Title::makeTitleSafe( NS_USER, $username ); |
| 76 | + $users[$code][$index] = $skin->link( $title, $username ); |
| 77 | + } |
| 78 | + |
| 79 | + $wgOut->addHTML( $wgLang->listToText( $users[$code] ) ); |
| 80 | + } |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Translate/SpecialSupportedLanguages.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 87 | + native |