Index: trunk/extensions/SocialProfile/UserProfile/SpecialRemoveAvatar.php |
— | — | @@ -1,5 +1,10 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * A special page for privileged users to remove other users' avatars. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
4 | 9 | class RemoveAvatar extends SpecialPage { |
5 | 10 | |
6 | 11 | /** |
— | — | @@ -19,25 +24,25 @@ |
20 | 25 | |
21 | 26 | $this->title = SpecialPage::getTitleFor( 'RemoveAvatar' ); |
22 | 27 | |
23 | | - # If the user isn't logged in, display an error |
| 28 | + // If the user isn't logged in, display an error |
24 | 29 | if ( !$wgUser->isLoggedIn() ) { |
25 | 30 | $this->displayRestrictionError(); |
26 | 31 | return; |
27 | 32 | } |
28 | 33 | |
29 | | - # If the user doesn't have 'avatarremove' permission, display an error |
| 34 | + // If the user doesn't have 'avatarremove' permission, display an error |
30 | 35 | if ( !$wgUser->isAllowed( 'avatarremove' ) ) { |
31 | 36 | $this->displayRestrictionError(); |
32 | 37 | return; |
33 | 38 | } |
34 | 39 | |
35 | | - # Show a message if the database is in read-only mode |
| 40 | + // Show a message if the database is in read-only mode |
36 | 41 | if ( wfReadOnly() ) { |
37 | 42 | $wgOut->readOnlyPage(); |
38 | 43 | return; |
39 | 44 | } |
40 | 45 | |
41 | | - # If user is blocked, s/he doesn't need to access this page |
| 46 | + // If user is blocked, s/he doesn't need to access this page |
42 | 47 | if ( $wgUser->isBlocked() ) { |
43 | 48 | $wgOut->blockedPage(); |
44 | 49 | return; |
— | — | @@ -82,10 +87,11 @@ |
83 | 88 | |
84 | 89 | /** |
85 | 90 | * Show the form for retrieving a user's current avatar |
| 91 | + * @return HTML |
86 | 92 | */ |
87 | | - function showUserForm() { |
88 | | - $output = '<form method="get" name="avatar" action="">' |
89 | | - . Xml::hidden( 'title', $this->getTitle() ) . |
| 93 | + private function showUserForm() { |
| 94 | + $output = '<form method="get" name="avatar" action="">' . |
| 95 | + Xml::hidden( 'title', $this->getTitle() ) . |
90 | 96 | '<b>' . wfMsg( 'username' ) . '</b> |
91 | 97 | <input type="text" name="user" /> |
92 | 98 | <input type="submit" value="' . wfMsg( 'search' ) . '" /> |
— | — | @@ -95,8 +101,10 @@ |
96 | 102 | |
97 | 103 | /** |
98 | 104 | * Shows the requested user's current avatar and the button for deleting it |
| 105 | + * |
| 106 | + * @param $user_name String: name of the user whose avatars we want to delete |
99 | 107 | */ |
100 | | - function showUserAvatar( $user_name ) { |
| 108 | + private function showUserAvatar( $user_name ) { |
101 | 109 | $user_name = str_replace( '_', ' ', $user_name ); // replace underscores with spaces |
102 | 110 | $user_id = User::idFromName( $user_name ); |
103 | 111 | |
— | — | @@ -115,15 +123,17 @@ |
116 | 124 | /** |
117 | 125 | * Deletes all of the requested user's avatar images from the filesystem |
118 | 126 | * |
119 | | - * @param $id Int: user ID |
120 | | - * @param $size Int: size of the avatar image to delete (small, medium or large). |
| 127 | + * @param $id Integer: user ID |
| 128 | + * @param $size String: size of the avatar image to delete (small, medium or large). |
121 | 129 | * Doesn't really matter since we're just going to blast 'em all. |
122 | 130 | */ |
123 | | - function deleteImage( $id, $size ) { |
| 131 | + private function deleteImage( $id, $size ) { |
124 | 132 | global $wgUploadDirectory, $wgDBname, $wgMemc; |
125 | 133 | $avatar = new wAvatar( $id, $size ); |
126 | 134 | $files = glob( $wgUploadDirectory . '/avatars/' . $wgDBname . '_' . $id . '_' . $size . "*" ); |
| 135 | + wfSuppressWarnings(); |
127 | 136 | $img = basename( $files[0] ); |
| 137 | + wfRestoreWarnings(); |
128 | 138 | if ( $img && $img[0] ) { |
129 | 139 | unlink( $wgUploadDirectory . '/avatars/' . $img ); |
130 | 140 | } |