1 | <?php |
||
22 | class GetPreferences { |
||
23 | |||
24 | protected $user; |
||
25 | protected $language; |
||
26 | protected $preferences; |
||
27 | protected $configuration; |
||
28 | |||
29 | /** |
||
30 | * @since 1.0 |
||
31 | * |
||
32 | * @param User $user |
||
33 | * @param Language $language |
||
34 | * @param array &$preferences |
||
35 | */ |
||
36 | 4 | public function __construct( User $user, Language $language, array &$preferences ) { |
|
41 | |||
42 | /** |
||
43 | * @since 1.0 |
||
44 | * |
||
45 | * @param array $configuration |
||
46 | */ |
||
47 | 3 | public function setConfiguration( array $configuration ) { |
|
50 | |||
51 | /** |
||
52 | * @since 1.0 |
||
53 | * |
||
54 | * @return boolean |
||
55 | */ |
||
56 | 3 | public function execute() { |
|
57 | |||
58 | 3 | $groups = $this->getAllSwlGroups(); |
|
59 | |||
60 | 3 | if ( $this->configuration['egSWLEnableEmailNotify'] ) { |
|
61 | 1 | $this->preferences['swl_email'] = $this->addEmailNotificationPreference(); |
|
62 | 1 | } |
|
63 | |||
64 | 3 | if ( $this->configuration['egSWLEnableTopLink'] ) { |
|
65 | 1 | $this->preferences['swl_watchlisttoplink'] = $this->addTopLinkPreference(); |
|
66 | 1 | } |
|
67 | |||
68 | 3 | foreach ( $groups as /* SWLGroup */ $group ) { |
|
69 | 1 | $this->handleGroup( $group ); |
|
70 | 3 | } |
|
71 | |||
72 | 3 | return true; |
|
73 | } |
||
74 | |||
75 | 1 | private function handleGroup( SWLGroup $group ) { |
|
76 | 1 | $properties = $group->getProperties(); |
|
77 | |||
78 | 1 | if ( empty( $properties ) ) { |
|
79 | return; |
||
80 | } |
||
81 | |||
82 | 1 | switch ( true ) { |
|
83 | 1 | case count( $group->getCategories() ) > 0 : |
|
84 | 1 | $type = 'category'; |
|
85 | 1 | $name = $group->getCategories(); |
|
86 | 1 | $name = $name[0]; |
|
87 | 1 | break; |
|
88 | case count( $group->getNamespaces() ) > 0 : |
||
89 | $type = 'namespace'; |
||
90 | $name = $group->getNamespaces(); |
||
91 | $name = $name[0] == 0 ? wfMessage( 'main' )->text() : MWNamespace::getCanonicalName( $name[0] ); |
||
92 | break; |
||
93 | case count( $group->getConcepts() ) > 0 : |
||
94 | $type = 'concept'; |
||
95 | $name = $group->getConcepts(); |
||
96 | $name = $name[0]; |
||
97 | break; |
||
98 | default: |
||
99 | return; |
||
100 | } |
||
101 | |||
102 | 1 | foreach ( $properties as &$property ) { |
|
103 | 1 | $property = "''$property''"; |
|
104 | 1 | } |
|
105 | |||
106 | 1 | $this->preferences['swl_watchgroup_' . $group->getId()] = $this->addGoupPreference( |
|
107 | 1 | $type, |
|
108 | 1 | $group->getName(), |
|
109 | 1 | $name, |
|
110 | $properties |
||
111 | 1 | ); |
|
112 | 1 | } |
|
113 | |||
114 | protected function getAllSwlGroups() { |
||
117 | |||
118 | 1 | protected function addEmailNotificationPreference() { |
|
119 | return array( |
||
125 | |||
126 | 1 | protected function addTopLinkPreference() { |
|
133 | |||
134 | /** |
||
135 | * @search swl-prefs-category-label, swl-prefs-namespace-label, |
||
136 | * swl-prefs-concept-label |
||
137 | */ |
||
138 | 1 | protected function addGoupPreference( $type, $group, $name, $properties ) { |
|
151 | |||
152 | } |
||
153 |