Completed
Push — master ( 2ed9e0...86f4fe )
by Toni Hermoso
38:59 queued 18:56
created

SpecialSDImport   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 112
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getKeyOptionsWithBlank() 0 15 2
B execute() 0 68 1
A processCSV() 0 5 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if (!defined('MEDIAWIKI')) { die(-1); } 
3
 
4
 
5
# Our SpecialPage
6
class SpecialSDImport extends SpecialPage {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
	
8
	
9
	/**
10
	 * Constructor : initialise object
11
	 * Get data POSTed through the form and assign them to the object
12
	 * @param $request WebRequest : data posted.
13
	 */
14
	
15
	public function __construct($request = null) {
16
		parent::__construct('SDImport');   #The first argument must be the name of your special page
17
	
18
19
	}
20
	
21
	private static function getKeyOptionsWithBlank( $keys ) {
22
		
23
		global $wgContLang;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
24
		
25
		$list_namespaces = array( "" => "" );
26
		
27
		foreach ( $keys as $key ) {
28
			
29
			$keyName = $wgContLang->getNsText( $key );
30
			
31
			$list_namespaces[ $keyName ] = $key;
32
		}
33
		
34
		return $list_namespaces;
35
	}
36
37
	
38
	/**
39
	 * Special page entry point
40
	 */
41
	public function execute($par) {
42
		global $wgOut;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
43
		
44
		global $wgSDImportDataPage; // Configuration options
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
45
	
46
		$list_namespaces = self::getKeyOptionsWithBlank( array_keys( $wgSDImportDataPage ) );
47
	
48
		$wgOut->addModules( 'ext.sdimport' );
49
		$this->setHeaders();
50
	
51
		// TODO: We should handle request in the form in a better way. $wgRequest Check examples here: involved http://www.mediawiki.org/wiki/Category:Special_page_extensions
52
	
53
		# A formDescriptor for uploading stuff
54
		$formDescriptor = array(
55
	
56
			'fileupload' => array(
57
				'section' => 'upload',
58
				'label' => 'Upload file',
59
                'class' => 'HTMLTextField',
60
				'type' => 'file'
61
			),
62
			'separator' => array(
63
				'section' => 'upload',
64
				'type' => 'select',
65
				'label' => 'Separator',
66
				'options' => array(  "," => ",","{TAB}" => "{TAB}", ";" => ";" )
67
			),
68
			'delimiter' => array(
69
				'section' => 'upload',
70
				'type' => 'select',
71
				'label' => 'Delimiter',
72
				'options' => array( "\"" => "\"" , "'" => "'" )
73
			),
74
			'namespace' => array(
75
				'section' => 'upload',
76
				'type' => 'select',
77
				'label' => 'Namespace',
78
				'options' => $list_namespaces
79
			),
80
			'single' => [
81
				'section' => 'upload',
82
				'class' => 'HTMLCheckField',
83
				'label' => 'Single row mode',
84
				'default' => false,
85
			]		
86
87
		);
88
89
	
90
		$htmlForm = new HTMLForm( $formDescriptor, 'sdimport-form' );
91
	
92
		$htmlForm->setSubmitText( wfMessage('sdimport-form-submit-button')->text() ); # What text does the submit button display
93
		$htmlForm->setTitle( $this->getTitle() ); # You must call setTitle() on an HTMLForm
94
	
95
		/* We set a callback function */
96
		$htmlForm->setSubmitCallback( array( 'SpecialSDImport', 'processCSV' ) );
97
	
98
		$htmlForm->suppressReset(false); # Get back reset button
99
	
100
		$wgOut->addHTML( "<div id='sdintro' class='sdimport_section'>" );
101
		$wgOut->addHTML( wfMessage('sdimport-form-intro')->text() );			
102
		$wgOut->addHTML( "</div>" );
103
		$wgOut->addHTML( "<div id='sdform' class='sdimport_section'>" );
104
		$htmlForm->show(); # Displaying the form
105
		$wgOut->addHTML( "</div>" );
106
		$wgOut->addHTML( "<div id='sdpreview' class='hot handsontable htColumnHeaders sdimport_section'></div>" );
107
		//$wgOut->addHTML( "<div id='sdpreview' class='hot handsontable htColumnHeaders'></div>");
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
108
	}
109
	
110
	
111
	static function processCSV( $formData ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
112
113
		// Everything handled via Javascript. Nothing done here...
114
		return true;
115
	}
116
	
117
}
118