Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UploadFormBeforeProcessing | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
handle | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
process | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace NSFileRepo\Hooks; |
4 | |
5 | class UploadFormBeforeProcessing { |
6 | |
7 | /** |
8 | * |
9 | * @var \Config |
10 | */ |
11 | protected $config = null; |
12 | |
13 | /** |
14 | * |
15 | * @var \IContextSource |
16 | */ |
17 | protected $context = null; |
18 | |
19 | /** |
20 | * |
21 | * @var \SpecialUpload |
22 | */ |
23 | protected $uploadForm = null; |
24 | |
25 | /** |
26 | * Check for Namespace in Title line |
27 | * @param SpecialPage $uploadForm |
28 | * @return boolean |
29 | */ |
30 | public static function handle( &$uploadForm ) { |
31 | $instance = new self( |
32 | \RequestContext::getMain(), |
33 | new \NSFileRepo\Config(), |
34 | $uploadForm |
35 | ); |
36 | |
37 | return $instance->process(); |
38 | } |
39 | |
40 | /** |
41 | * See static method "handle" |
42 | * @param \IContextSource $context |
43 | * @param \Config $config |
44 | * @param \SpecialPage $uploadForm 'Extension:PageForms' fires this hook with \PFUploadWindow as parameter |
45 | */ |
46 | public function __construct( \IContextSource $context, \Config $config, \SpecialPage $uploadForm ) { |
47 | $this->context = $context; |
48 | $this->config = $config; |
49 | $this->uploadForm = $uploadForm; |
50 | } |
51 | |
52 | public function process() { |
53 | $title = \Title::newFromText( $this->uploadForm->mDesiredDestName ); |
54 | if( $title === null ) { |
55 | return true; |
56 | } |
57 | if ( $title->getNamespace() < $this->config->get( 'NamespaceThreshold' ) ) { |
58 | $this->uploadForm->mDesiredDestName = preg_replace( "/:/", '-', $this->uploadForm->mDesiredDestName ); |
59 | } else { |
60 | $bits = explode( ':', $this->uploadForm->mDesiredDestName ); |
61 | $ns = array_shift( $bits ); |
62 | $this->uploadForm->mDesiredDestName = $ns.":" . implode( "-", $bits ); |
63 | } |
64 | return true; |
65 | } |
66 | } |