Index: trunk/extensions/Translate/SpecialImportTranslations.php |
— | — | @@ -11,6 +11,9 @@ |
12 | 12 | |
13 | 13 | class SpecialImportTranslations extends SpecialPage { |
14 | 14 | |
| 15 | + /** |
| 16 | + * Set up and fill some dependencies. |
| 17 | + */ |
15 | 18 | public function __construct() { |
16 | 19 | parent::__construct( 'ImportTranslations', 'translate-import' ); |
17 | 20 | global $wgUser, $wgOut, $wgRequest; |
— | — | @@ -19,11 +22,16 @@ |
20 | 23 | $this->request = $wgRequest; |
21 | 24 | } |
22 | 25 | |
| 26 | + // Dependencies |
23 | 27 | protected $user, $out, $request; |
24 | 28 | |
| 29 | + /** |
| 30 | + * Special page entry point. |
| 31 | + */ |
25 | 32 | public function execute( $parameters ) { |
26 | 33 | $this->setHeaders(); |
27 | 34 | |
| 35 | + // Security and validity checks |
28 | 36 | if ( !$this->userCanExecute( $this->user ) ) { |
29 | 37 | $this->displayRestrictionError(); |
30 | 38 | return; |
— | — | @@ -40,6 +48,7 @@ |
41 | 49 | return; |
42 | 50 | } |
43 | 51 | |
| 52 | + // Proceed to loading and parsing if possible |
44 | 53 | $file = null; |
45 | 54 | $msg = $this->loadFile( $file ); |
46 | 55 | if ( $this->checkError( $msg ) ) return; |
— | — | @@ -49,6 +58,11 @@ |
50 | 59 | |
51 | 60 | } |
52 | 61 | |
| 62 | + /** |
| 63 | + * Checks for error state from the return value of loadFile and parseFile |
| 64 | + * functions. Prints the error and the form and returns true if there is an |
| 65 | + * error. Returns false and does nothing if there is no error. |
| 66 | + */ |
53 | 67 | protected function checkError( $msg ) { |
54 | 68 | if ( $msg[0] !== 'ok' ) { |
55 | 69 | $errorWrap = "<div class='error'>\n$1\n</div>"; |
— | — | @@ -60,9 +74,11 @@ |
61 | 75 | return false; |
62 | 76 | } |
63 | 77 | |
| 78 | + /** |
| 79 | + * Constructs and outputs file input form with supported methods. |
| 80 | + */ |
64 | 81 | protected function outputForm() { |
65 | | - global $wgScriptPath; |
66 | | - $this->out->addScriptFile( "$wgScriptPath/extensions/Translate/js/import.js" ); |
| 82 | + $this->out->addScriptClass( 'TranslateImport' ); |
67 | 83 | |
68 | 84 | $this->out->addHTML( |
69 | 85 | |
— | — | @@ -115,6 +131,9 @@ |
116 | 132 | |
117 | 133 | } |
118 | 134 | |
| 135 | + /** |
| 136 | + * Try to get the file data from any of the supported methods. |
| 137 | + */ |
119 | 138 | protected function loadFile( &$filedata ) { |
120 | 139 | $source = $this->request->getText( 'upload-type' ); |
121 | 140 | |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | $wgHooks['SpecialRecentChangesPanel'][] = 'TranslateRcFilter::translationFilterForm'; |
68 | 68 | $wgHooks['SkinTemplateToolboxEnd'][] = 'TranslateToolbox::toolboxAllTranslations'; |
69 | 69 | |
70 | | -$wgJSAutoloadClasses['translate-import'] = "$dir/js/import.js"; |
| 70 | +$wgJSAutoloadClasses['TranslateImport'] = "extensions/Translate/js/import.js"; |
71 | 71 | |
72 | 72 | |
73 | 73 | $wgEnablePageTranslation = false; |