Index: trunk/extensions/WikiLove/WikiLove.hooks.php |
— | — | @@ -1,18 +1,20 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Hooks for WikiLove extension |
5 | | - * |
| 5 | + * |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
8 | 8 | */ |
9 | 9 | |
10 | 10 | class WikiLoveHooks { |
11 | 11 | private static $recipient = ''; |
12 | | - |
| 12 | + |
13 | 13 | /** |
14 | 14 | * LoadExtensionSchemaUpdates hook |
15 | 15 | * |
16 | 16 | * @param $updater DatabaseUpdater |
| 17 | + * |
| 18 | + * @return true |
17 | 19 | */ |
18 | 20 | public static function loadExtensionSchemaUpdates( $updater = null ) { |
19 | 21 | if ( $updater === null ) { |
— | — | @@ -22,16 +24,18 @@ |
23 | 25 | } else { |
24 | 26 | $updater->addExtensionUpdate( array( 'addTable', 'wikilove_log', |
25 | 27 | dirname( __FILE__ ) . '/patches/WikiLoveLog.sql', true ) ); |
26 | | - $updater->addExtensionUpdate( array( 'addTable', 'wikilove_image_log', |
| 28 | + $updater->addExtensionUpdate( array( 'addTable', 'wikilove_image_log', |
27 | 29 | dirname( __FILE__ ) . '/patches/WikiLoveImageLog.sql', true ) ); |
28 | 30 | } |
29 | 31 | return true; |
30 | 32 | } |
31 | | - |
| 33 | + |
32 | 34 | /** |
33 | 35 | * Add the preference in the user preferences with the GetPreferences hook. |
34 | 36 | * @param $user User |
35 | | - * @param $preferences |
| 37 | + * @param $preferences array |
| 38 | + * |
| 39 | + * @return true |
36 | 40 | */ |
37 | 41 | public static function getPreferences( $user, &$preferences ) { |
38 | 42 | global $wgWikiLoveGlobal; |
— | — | @@ -44,19 +48,21 @@ |
45 | 49 | } |
46 | 50 | return true; |
47 | 51 | } |
48 | | - |
| 52 | + |
49 | 53 | /** |
50 | 54 | * Adds the required module if we are on a user (talk) page. |
51 | 55 | * |
52 | | - * @param $output |
| 56 | + * @param $out OutputPage |
53 | 57 | * @param $skin Skin |
| 58 | + * |
| 59 | + * @return true |
54 | 60 | */ |
55 | 61 | public static function beforePageDisplay( $out, $skin ) { |
56 | 62 | global $wgWikiLoveGlobal, $wgUser; |
57 | 63 | if ( !$wgWikiLoveGlobal && !$wgUser->getOption( 'wikilove-enabled' ) ) { |
58 | 64 | return true; |
59 | 65 | } |
60 | | - |
| 66 | + |
61 | 67 | $title = self::getUserTalkPage( $skin->getTitle() ); |
62 | 68 | if ( !is_null( $title ) ) { |
63 | 69 | $out->addModules( array( 'ext.wikiLove.icon', 'ext.wikiLove.init' ) ); |
— | — | @@ -64,15 +70,19 @@ |
65 | 71 | } |
66 | 72 | return true; |
67 | 73 | } |
68 | | - |
| 74 | + |
69 | 75 | /** |
70 | 76 | * Exports wikilove-recipient and edittoken variables to JS |
| 77 | + * |
| 78 | + * @param $vars array |
| 79 | + * |
| 80 | + * @return true |
71 | 81 | */ |
72 | 82 | public static function makeGlobalVariablesScript( &$vars ) { |
73 | 83 | global $wgUser; |
74 | 84 | $vars['wikilove-recipient'] = self::$recipient; |
75 | 85 | $vars['wikilove-edittoken'] = $wgUser->edittoken(); |
76 | | - |
| 86 | + |
77 | 87 | $vars['wikilove-anon'] = 0; |
78 | 88 | if ( self::$recipient !== '' ) { |
79 | 89 | $receiver = User::newFromName( self::$recipient ); |
— | — | @@ -80,7 +90,7 @@ |
81 | 91 | } |
82 | 92 | return true; |
83 | 93 | } |
84 | | - |
| 94 | + |
85 | 95 | /** |
86 | 96 | * Adds a tab the old way (before MW 1.18) |
87 | 97 | */ |
— | — | @@ -88,27 +98,26 @@ |
89 | 99 | self::skinConfigViewsLinks( $skin, $contentActions ); |
90 | 100 | return true; |
91 | 101 | } |
92 | | - |
| 102 | + |
93 | 103 | /** |
94 | 104 | * Adds a tab or an icon the new way (MW >1.18) |
95 | 105 | */ |
96 | 106 | public static function skinTemplateNavigation( &$skin, &$links ) { |
97 | 107 | if ( self::showIcon( $skin ) ) { |
98 | 108 | self::skinConfigViewsLinks( $skin, $links['views']); |
99 | | - } |
100 | | - else { |
| 109 | + } else { |
101 | 110 | self::skinConfigViewsLinks( $skin, $links['actions']); |
102 | 111 | } |
103 | 112 | return true; |
104 | 113 | } |
105 | | - |
| 114 | + |
106 | 115 | /** |
107 | 116 | * Configure views links. |
108 | 117 | * Helper function for SkinTemplateTabs and SkinTemplateNavigation hooks |
109 | 118 | * to configure views links. |
110 | 119 | * |
111 | 120 | * @param $skin Skin |
112 | | - * @param $views |
| 121 | + * @param $views array |
113 | 122 | */ |
114 | 123 | private static function skinConfigViewsLinks( $skin, &$views ) { |
115 | 124 | global $wgWikiLoveGlobal, $wgUser; |
— | — | @@ -117,7 +126,7 @@ |
118 | 127 | if ( !$wgWikiLoveGlobal && !$wgUser->getOption( 'wikilove-enabled' ) ) { |
119 | 128 | return true; |
120 | 129 | } |
121 | | - |
| 130 | + |
122 | 131 | if ( !is_null( self::getUserTalkPage( $skin->getTitle() ) ) ) { |
123 | 132 | $views['wikilove'] = array( |
124 | 133 | 'text' => wfMsg( 'wikilove-tab-text' ), |
— | — | @@ -129,17 +138,19 @@ |
130 | 139 | } |
131 | 140 | } |
132 | 141 | } |
133 | | - |
| 142 | + |
134 | 143 | /** |
135 | 144 | * Only show an icon when the global preference is enabled and the current skin is Vector. |
136 | 145 | * |
137 | 146 | * @param $skin Skin |
| 147 | + * |
| 148 | + * @return bool |
138 | 149 | */ |
139 | 150 | private static function showIcon( $skin ) { |
140 | 151 | global $wgWikiLoveTabIcon; |
141 | 152 | return $wgWikiLoveTabIcon && $skin->getSkinName() == 'vector'; |
142 | 153 | } |
143 | | - |
| 154 | + |
144 | 155 | /** |
145 | 156 | * Find the editable talk page of the user we're looking at, or null |
146 | 157 | * if such page does not exist. |
— | — | @@ -153,15 +164,15 @@ |
154 | 165 | if ( !$wgUser->isLoggedIn() ) { |
155 | 166 | return null; |
156 | 167 | } |
157 | | - |
| 168 | + |
158 | 169 | $ns = $title->getNamespace(); |
159 | 170 | // return quickly if we're in the wrong namespace anyway |
160 | 171 | if ( $ns != NS_USER && $ns != NS_USER_TALK ) { |
161 | 172 | return null; |
162 | 173 | } |
163 | | - |
| 174 | + |
164 | 175 | $baseTitle = Title::newFromText( $title->getBaseText(), $ns ); |
165 | | - |
| 176 | + |
166 | 177 | if ( $ns == NS_USER_TALK && $baseTitle->quickUserCan( 'edit' ) ) { |
167 | 178 | return $baseTitle; |
168 | 179 | } elseif ( $ns == NS_USER ) { |
— | — | @@ -172,4 +183,4 @@ |
173 | 184 | } |
174 | 185 | return null; |
175 | 186 | } |
176 | | -} |
\ No newline at end of file |
| 187 | +} |