Index: trunk/extensions/FanBoxes/SpecialTopFanBoxes.php |
— | — | @@ -0,0 +1,489 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A special page to show either the most popular userboxes (default) or |
| 5 | + * alternatively, the newest userboxes. |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
| 10 | +class TopFanBoxes extends SpecialPage { |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructor |
| 14 | + */ |
| 15 | + public function __construct() { |
| 16 | + parent::__construct( 'TopUserboxes' ); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Show the special page |
| 21 | + * |
| 22 | + * @param $par Mixed: parameter passed to the page or null |
| 23 | + */ |
| 24 | + public function execute( $par ) { |
| 25 | + global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgFanBoxScripts; |
| 26 | + |
| 27 | + // Add CSS & JS |
| 28 | + $wgOut->addExtensionStyle( $wgFanBoxScripts . '/FanBoxes.css' ); |
| 29 | + $wgOut->addScriptFile( $wgFanBoxScripts . '/FanBoxes.js' ); |
| 30 | + |
| 31 | + $topfanboxId = $wgRequest->getVal( 'id' ); |
| 32 | + $topfanboxCategory = $wgRequest->getVal( 'cat' ); |
| 33 | + |
| 34 | + if( $topfanboxId == 'fantag_date' ) { |
| 35 | + $wgOut->setPageTitle( wfMsg( 'most-recent-fanboxes-link' ) ); |
| 36 | + $topfanboxes = $this->getTopFanboxes( 'fantag_date' ); |
| 37 | + } else { |
| 38 | + $wgOut->setPageTitle( wfMsg( 'topuserboxes' ) ); |
| 39 | + $topfanboxes = $this->getTopFanboxes( 'fantag_count' ); |
| 40 | + } |
| 41 | + |
| 42 | + $output = ''; |
| 43 | + |
| 44 | + // Make top right nav bar |
| 45 | + $output .= '<div class="fanbox-nav"> |
| 46 | + <h2>' . wfMsg( 'fanbox-nav-header' ) . "</h2> |
| 47 | + <p><a href=\"{$this->getTitle()->escapeFullURL()}\">" . |
| 48 | + wfMsg( 'top-fanboxes-link' ) . '</a></p> |
| 49 | + <p><a href="' . $this->getTitle()->escapeFullURL( 'id=fantag_date' ) . '">' . |
| 50 | + wfMsg( 'most-recent-fanboxes-link' ) . '</a></p> |
| 51 | + </div>'; |
| 52 | + |
| 53 | + // Nothing? That means that no userboxes have been created yet...so |
| 54 | + // show a message to the user about that, prompting them to create some |
| 55 | + // userboxes |
| 56 | + if ( empty( $topfanboxes ) ) { |
| 57 | + $output .= wfMsgExt( 'fanbox-top-list-is-empty', 'parse' ); |
| 58 | + } |
| 59 | + |
| 60 | + if( !$topfanboxCategory ) { |
| 61 | + $x = 1; |
| 62 | + |
| 63 | + $output .= '<div class="top-fanboxes">'; |
| 64 | + |
| 65 | + $tagParser = new Parser(); |
| 66 | + |
| 67 | + foreach( $topfanboxes as $topfanbox ) { |
| 68 | + $check_user_fanbox = $this->checkIfUserHasFanbox( $topfanbox['fantag_id'] ); |
| 69 | + |
| 70 | + if( $topfanbox['fantag_image_name'] ) { |
| 71 | + $fantag_image_width = 45; |
| 72 | + $fantag_image_height = 53; |
| 73 | + $fantag_image = wfFindFile( $topfanbox['fantag_image_name'] ); |
| 74 | + $fantag_image_url = ''; |
| 75 | + if ( is_object( $fantag_image ) ) { |
| 76 | + $fantag_image_url = $fantag_image->createThumb( |
| 77 | + $fantag_image_width, |
| 78 | + $fantag_image_height |
| 79 | + ); |
| 80 | + } |
| 81 | + $fantag_image_tag = '<img alt="" src="' . $fantag_image_url . '"/>'; |
| 82 | + } |
| 83 | + |
| 84 | + if( $topfanbox['fantag_left_text'] == '' ) { |
| 85 | + $fantag_leftside = $fantag_image_tag; |
| 86 | + } else { |
| 87 | + $fantag_leftside = $topfanbox['fantag_left_text']; |
| 88 | + $fantag_leftside = $tagParser->parse( |
| 89 | + $fantag_leftside, $wgTitle, |
| 90 | + $wgOut->parserOptions(), false |
| 91 | + ); |
| 92 | + $fantag_leftside = $fantag_leftside->getText(); |
| 93 | + } |
| 94 | + |
| 95 | + if( $topfanbox['fantag_left_textsize'] == 'mediumfont' ) { |
| 96 | + $leftfontsize = '14px'; |
| 97 | + } |
| 98 | + if( $topfanbox['fantag_left_textsize'] == 'bigfont' ) { |
| 99 | + $leftfontsize = '20px'; |
| 100 | + } |
| 101 | + |
| 102 | + if( $topfanbox['fantag_right_textsize'] == 'smallfont' ) { |
| 103 | + $rightfontsize = '12px'; |
| 104 | + } |
| 105 | + if( $topfanbox['fantag_right_textsize'] == 'mediumfont' ) { |
| 106 | + $rightfontsize = '14px'; |
| 107 | + } |
| 108 | + |
| 109 | + // Get permalink |
| 110 | + $fantag_title = Title::makeTitle( NS_FANTAG, $topfanbox['fantag_title'] ); |
| 111 | + |
| 112 | + // Get creator |
| 113 | + $userftusername = $topfanbox['fantag_user_name']; |
| 114 | + $userftuserid = $topfanbox['fantag_user_id']; |
| 115 | + $user_title = Title::makeTitle( NS_USER, $topfanbox['fantag_user_name'] ); |
| 116 | + $avatar = new wAvatar( $topfanbox['fantag_user_id'], 'm' ); |
| 117 | + |
| 118 | + $right_text = $topfanbox['fantag_right_text']; |
| 119 | + $right_text = $tagParser->parse( |
| 120 | + $right_text, $wgTitle, $wgOut->parserOptions(), false |
| 121 | + ); |
| 122 | + $right_text = $right_text->getText(); |
| 123 | + |
| 124 | + $output .= " |
| 125 | + <div class=\"top-fanbox-row\"> |
| 126 | + <span class=\"top-fanbox-num\">{$x}.</span><span class=\"top-fanbox\"> |
| 127 | + |
| 128 | + <div class=\"fanbox-item\"> |
| 129 | + |
| 130 | + <div class=\"individual-fanbox\" id=\"individualFanbox" . $topfanbox['fantag_id'] . "\"> |
| 131 | + <div class=\"show-message-container\" id=\"show-message-container" . $topfanbox['fantag_id'] . "\"> |
| 132 | + <div class=\"permalink-container\"> |
| 133 | + <a class=\"perma\" style=\"font-size:8px; color:" . $topfanbox['fantag_right_textcolor'] . "\" href=\"" . $fantag_title->escapeFullURL() . "\" title=\"{$topfanbox['fantag_title']}\">" . wfMsg( 'fanbox-perma' ) . "</a> |
| 134 | + <table class=\"fanBoxTable\" onclick=\"javascript:FanBoxes.openFanBoxPopup('fanboxPopUpBox{$topfanbox['fantag_id']}', 'individualFanbox{$topfanbox['fantag_id']}')\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> |
| 135 | + <tr> |
| 136 | + <td id=\"fanBoxLeftSideOutput\" style=\"color:" . $topfanbox['fantag_left_textcolor'] . "; font-size:$leftfontsize\" bgcolor=\"" . $topfanbox['fantag_left_bgcolor'] . "\">" . $fantag_leftside . "</td> |
| 137 | + <td id=\"fanBoxRightSideOutput\" style=\"color:" . $topfanbox['fantag_right_textcolor'] . "; font-size:$rightfontsize\" bgcolor=\"" . $topfanbox['fantag_right_bgcolor'] . "\">" . $right_text . "</td> |
| 138 | + </tr> |
| 139 | + </table> |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + </div>"; |
| 143 | + |
| 144 | + if( $wgUser->isLoggedIn() ) { |
| 145 | + if( $check_user_fanbox == 0 ) { |
| 146 | + $output .= " |
| 147 | + <div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $topfanbox['fantag_id'] . "\"> |
| 148 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 149 | + <tr> |
| 150 | + <td align=\"center\">" . wfMsg( 'fanbox-add-fanbox' ) . "</td> |
| 151 | + </tr> |
| 152 | + <tr> |
| 153 | + <td align=\"center\"> |
| 154 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-add' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$topfanbox['fantag_id']}', 'individualFanbox{$topfanbox['fantag_id']}'); FanBoxes.showAddRemoveMessageUserPage(1, {$topfanbox['fantag_id']}, 'show-addremove-message')\" /> |
| 155 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$topfanbox['fantag_id']}', 'individualFanbox{$topfanbox['fantag_id']}')\" /> |
| 156 | + </td> |
| 157 | + </tr> |
| 158 | + </table> |
| 159 | + </div>"; |
| 160 | + } else { |
| 161 | + $output .= " |
| 162 | + <div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $topfanbox['fantag_id'] . "\"> |
| 163 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 164 | + <tr> |
| 165 | + <td align=\"center\">" . wfMsg( 'fanbox-remove-fanbox' ) . "</td> |
| 166 | + </tr> |
| 167 | + <tr> |
| 168 | + <td align=\"center\"> |
| 169 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-remove' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$topfanbox['fantag_id']}', 'individualFanbox{$topfanbox['fantag_id']}'); FanBoxes.showAddRemoveMessageUserPage(2, {$topfanbox['fantag_id']}, 'show-addremove-message')\" /> |
| 170 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$topfanbox['fantag_id']}', 'individualFanbox{$topfanbox['fantag_id']}')\" /> |
| 171 | + </td> |
| 172 | + </tr> |
| 173 | + </table> |
| 174 | + </div>"; |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + if( $wgUser->getID() == 0 ) { |
| 179 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 180 | + $output .= "<div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $topfanbox['fantag_id'] . "\"> |
| 181 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 182 | + <tr> |
| 183 | + <td align=\"center\">" . wfMsg( 'fanbox-add-fanbox-login' ) . |
| 184 | + " <a href=\"{$login->getFullURL()}\">" . wfMsg( 'fanbox-login' ) . "</a> |
| 185 | + </td> |
| 186 | + </tr> |
| 187 | + <tr> |
| 188 | + <td align=\"center\"> |
| 189 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$topfanbox['fantag_id']}', 'individualFanbox{$topfanbox['fantag_id']}')\" /> |
| 190 | + </td> |
| 191 | + </tr> |
| 192 | + </table> |
| 193 | + </div>"; |
| 194 | + } |
| 195 | + |
| 196 | + $output .= '</div></span>'; |
| 197 | + $output .= '<div class="top-fanbox-users"> |
| 198 | + <table> |
| 199 | + <tr> |
| 200 | + <td class="centerheight"> |
| 201 | + <b><a href="' . $fantag_title->escapeFullURL() . '">' . |
| 202 | + wfMsgExt( |
| 203 | + 'fanbox-members', |
| 204 | + 'parsemag', |
| 205 | + $topfanbox['fantag_count'] |
| 206 | + ) . |
| 207 | + '</a></b> |
| 208 | + </td> |
| 209 | + </tr> |
| 210 | + </table> |
| 211 | + </div>'; |
| 212 | + $output .= '<div class="cleared"></div>'; |
| 213 | + $output .= '</div>'; |
| 214 | + |
| 215 | + $x++; |
| 216 | + |
| 217 | + } |
| 218 | + $output .= '</div><div class="cleared"></div>'; |
| 219 | + } |
| 220 | + |
| 221 | + if( $topfanboxCategory ) { |
| 222 | + $x = 1; |
| 223 | + |
| 224 | + $output .= '<div class="top-fanboxes">'; |
| 225 | + |
| 226 | + // This variable wasn't originally defined, I'm not sure that this |
| 227 | + // is 100% correct, but... |
| 228 | + $categoryfanboxes = $this->getFanBoxByCategory( $topfanboxCategory ); |
| 229 | + |
| 230 | + foreach( $categoryfanboxes as $categoryfanbox ) { |
| 231 | + $check_user_fanbox = $this->checkIfUserHasFanbox( $categoryfanbox['fantag_id'] ); |
| 232 | + |
| 233 | + if( $categoryfanbox['fantag_image_name'] ) { |
| 234 | + $fantag_image_width = 45; |
| 235 | + $fantag_image_height = 53; |
| 236 | + $fantag_image = wfFindFile( $categoryfanbox['fantag_image_name'] ); |
| 237 | + $fantag_image_url = ''; |
| 238 | + if ( is_object( $fantag_image ) ) { |
| 239 | + $fantag_image_url = $fantag_image->createThumb( |
| 240 | + $fantag_image_width, |
| 241 | + $fantag_image_height |
| 242 | + ); |
| 243 | + } |
| 244 | + $fantag_image_tag = '<img alt="" src="' . $fantag_image_url . '"/>'; |
| 245 | + } |
| 246 | + |
| 247 | + if( $categoryfanbox['fantag_left_text'] == '' ) { |
| 248 | + $fantag_leftside = $fantag_image_tag; |
| 249 | + } else { |
| 250 | + $fantag_leftside = $categoryfanbox['fantag_left_text']; |
| 251 | + } |
| 252 | + |
| 253 | + if( $categoryfanbox['fantag_left_textsize'] == 'mediumfont' ) { |
| 254 | + $leftfontsize = '14px'; |
| 255 | + } |
| 256 | + if( $categoryfanbox['fantag_left_textsize'] == 'bigfont' ) { |
| 257 | + $leftfontsize = '20px'; |
| 258 | + } |
| 259 | + |
| 260 | + if( $categoryfanbox['fantag_right_textsize'] == 'smallfont' ) { |
| 261 | + $rightfontsize = '12px'; |
| 262 | + } |
| 263 | + if( $categoryfanbox['fantag_right_textsize'] == 'mediumfont' ) { |
| 264 | + $rightfontsize = '14px'; |
| 265 | + } |
| 266 | + |
| 267 | + // Get permalink |
| 268 | + $fantag_title = Title::makeTitle( NS_FANTAG, $categoryfanbox['fantag_title'] ); |
| 269 | + |
| 270 | + // Get creator |
| 271 | + $userftusername = $categoryfanbox['fantag_user_name']; |
| 272 | + $userftuserid = $categoryfanbox['fantag_user_id']; |
| 273 | + $user_title = Title::makeTitle( NS_USER, $categoryfanbox['fantag_user_name'] ); |
| 274 | + $avatar = new wAvatar( $categoryfanbox['fantag_user_id'], 'm' ); |
| 275 | + |
| 276 | + $output .= " |
| 277 | + <div class=\"top-fanbox-row\"> |
| 278 | + <span class=\"top-fanbox-num\">{$x}.</span><div class=\"top-fanbox\"> |
| 279 | + |
| 280 | + <div class=\"fanbox-item\"> |
| 281 | + |
| 282 | + <div class=\"individual-fanbox\" id=\"individualFanbox" . $categoryfanbox['fantag_id'] . "\"> |
| 283 | + <div class=\"show-message-container\" id=\"show-message-container" . $categoryfanbox['fantag_id'] . "\"> |
| 284 | + <div class=\"permalink-container\"> |
| 285 | + <a class=\"perma\" style=\"font-size:8px; color:" . $categoryfanbox['fantag_right_textcolor'] . "\" href=\"" . $fantag_title->escapeFullURL() . "\" title=\"{$categoryfanbox['fantag_title']}\">" . wfMsg( 'fanbox-perma' ) . "</a> |
| 286 | + <table class=\"fanBoxTable\" onclick=\"javascript:FanBoxes.openFanBoxPopup('fanboxPopUpBox{$categoryfanbox['fantag_id']}', 'individualFanbox{$categoryfanbox['fantag_id']}')\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> |
| 287 | + <tr> |
| 288 | + <td id=\"fanBoxLeftSideOutput\" style=\"color:" . $categoryfanbox['fantag_left_textcolor'] . "; font-size:$leftfontsize\" bgcolor=\"" . $categoryfanbox['fantag_left_bgcolor'] . "\">" . $fantag_leftside . "</td> |
| 289 | + <td id=\"fanBoxRightSideOutput\" style=\"color:" . $categoryfanbox['fantag_right_textcolor'] . "; font-size:$rightfontsize\" bgcolor=\"" . $categoryfanbox['fantag_right_bgcolor'] . "\">" . $categoryfanbox['fantag_right_text'] . '</td> |
| 290 | + </tr> |
| 291 | + </table> |
| 292 | + </div> |
| 293 | + </div> |
| 294 | + </div>'; |
| 295 | + |
| 296 | + if( $wgUser->isLoggedIn() ) { |
| 297 | + if( $check_user_fanbox == 0 ) { |
| 298 | + $output .= " |
| 299 | + <div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $categoryfanbox['fantag_id'] . "\"> |
| 300 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 301 | + <tr> |
| 302 | + <td align=\"center\">" . wfMsg( 'fanbox-add-fanbox' ) . "</td> |
| 303 | + </tr> |
| 304 | + <tr> |
| 305 | + <td align=\"center\"> |
| 306 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-add' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$categoryfanbox["fantag_id"]}', 'individualFanbox{$categoryfanbox["fantag_id"]}'); FanBoxes.showAddRemoveMessageUserPage(1, {$categoryfanbox["fantag_id"]}, 'show-addremove-message')\" /> |
| 307 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$categoryfanbox["fantag_id"]}', 'individualFanbox{$categoryfanbox["fantag_id"]}')\" /> |
| 308 | + </td> |
| 309 | + </tr> |
| 310 | + </table> |
| 311 | + </div>"; |
| 312 | + } else { |
| 313 | + $output .= " |
| 314 | + <div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $categoryfanbox['fantag_id'] . "\"> |
| 315 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 316 | + <tr> |
| 317 | + <td align=\"center\">" . wfMsg( 'fanbox-remove-fanbox' ) . "</td> |
| 318 | + </tr> |
| 319 | + <tr> |
| 320 | + <td align=\"center\"> |
| 321 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-remove' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$categoryfanbox['fantag_id']}', 'individualFanbox{$categoryfanbox['fantag_id']}'); FanBoxes.showAddRemoveMessageUserPage(2, {$categoryfanbox['fantag_id']}, 'show-addremove-message')\" /> |
| 322 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$categoryfanbox['fantag_id']}', 'individualFanbox{$categoryfanbox['fantag_id']}')\" /> |
| 323 | + </td> |
| 324 | + </tr> |
| 325 | + </table> |
| 326 | + </div>"; |
| 327 | + } |
| 328 | + } |
| 329 | + |
| 330 | + if( $wgUser->getID() == 0 ) { |
| 331 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 332 | + $output .= "<div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $categoryfanbox['fantag_id'] . "\"> |
| 333 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 334 | + <tr> |
| 335 | + <td align=\"center\">" . wfMsg( 'fanbox-add-fanbox-login' ) . |
| 336 | + " <a href=\"{$login->getFullURL()}\">" . wfMsg( 'fanbox-login' ) . "</a> |
| 337 | + </td> |
| 338 | + </tr> |
| 339 | + <tr> |
| 340 | + <td align=\"center\"> |
| 341 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$categoryfanbox['fantag_id']}', 'individualFanbox{$categoryfanbox['fantag_id']}')\" /> |
| 342 | + </td> |
| 343 | + </tr> |
| 344 | + </table> |
| 345 | + </div>"; |
| 346 | + } |
| 347 | + |
| 348 | + $output .= '</div></div>'; |
| 349 | + $output .= '<div class="top-fanbox-creator"> |
| 350 | + <table> |
| 351 | + <tr> |
| 352 | + <td class="centerheight"> <b> ' . wfMsg( 'fanbox-created-by' ) . ' <b> </td> |
| 353 | + <td class="centerheight"> <b> <a href="' . $user_title->escapeFullURL() . "\"> |
| 354 | + {$avatar->getAvatarURL()} |
| 355 | + </a></b> |
| 356 | + </td> |
| 357 | + </tr> |
| 358 | + </table> |
| 359 | + </div>"; |
| 360 | + $output .= '<div class="top-fanbox-users"> |
| 361 | + <table> |
| 362 | + <tr> |
| 363 | + <td class="centerheight"> |
| 364 | + <b><a href="' . $fantag_title->escapeFullURL() . '">' . |
| 365 | + wfMsg( 'fanbox-members', $categoryfanbox['fantag_count'] ). |
| 366 | + '</a></b> |
| 367 | + </td> |
| 368 | + </tr> |
| 369 | + </table> |
| 370 | + </div>'; |
| 371 | + $output .= '<div class="cleared"></div>'; |
| 372 | + $output .= '</div>'; |
| 373 | + |
| 374 | + $x++; |
| 375 | + |
| 376 | + } |
| 377 | + $output .= '</div><div class="cleared"></div>'; |
| 378 | + |
| 379 | + } |
| 380 | + $wgOut->addHTML( $output ); |
| 381 | + |
| 382 | + } |
| 383 | + |
| 384 | + function getTopFanboxes( $orderBy ) { |
| 385 | + $dbr = wfGetDB( DB_MASTER ); |
| 386 | + |
| 387 | + $res = $dbr->select( |
| 388 | + 'fantag', |
| 389 | + array( |
| 390 | + 'fantag_id', 'fantag_title', 'fantag_pg_id', 'fantag_left_text', |
| 391 | + 'fantag_left_textcolor', 'fantag_left_bgcolor', |
| 392 | + 'fantag_right_text', 'fantag_right_textcolor', |
| 393 | + 'fantag_right_bgcolor', 'fantag_image_name', |
| 394 | + 'fantag_left_textsize', 'fantag_right_textsize', 'fantag_count', |
| 395 | + 'fantag_user_id', 'fantag_user_name', 'fantag_date' |
| 396 | + ), |
| 397 | + array(), |
| 398 | + __METHOD__, |
| 399 | + array( 'ORDER BY' => "$orderBy DESC", 'LIMIT' => 50 ) |
| 400 | + ); |
| 401 | + |
| 402 | + $topFanboxes = array(); |
| 403 | + foreach( $res as $row ) { |
| 404 | + $topFanboxes[] = array( |
| 405 | + 'fantag_id' => $row->fantag_id, |
| 406 | + 'fantag_title' => $row->fantag_title, |
| 407 | + 'fantag_pg_id' => $row->fantag_pg_id, |
| 408 | + 'fantag_left_text' => $row->fantag_left_text, |
| 409 | + 'fantag_left_textcolor' => $row->fantag_left_textcolor, |
| 410 | + 'fantag_left_bgcolor' => $row->fantag_left_bgcolor, |
| 411 | + 'fantag_right_text' => $row->fantag_right_text, |
| 412 | + 'fantag_right_textcolor' => $row->fantag_right_textcolor, |
| 413 | + 'fantag_right_bgcolor' => $row->fantag_right_bgcolor, |
| 414 | + 'fantag_image_name' => $row->fantag_image_name, |
| 415 | + 'fantag_left_textsize' => $row->fantag_left_textsize, |
| 416 | + 'fantag_right_textsize' => $row->fantag_right_textsize, |
| 417 | + 'fantag_count' => $row->fantag_count, |
| 418 | + 'fantag_user_id' => $row->fantag_user_id, |
| 419 | + 'fantag_user_name' => $row->fantag_user_name, |
| 420 | + 'fantag_date' => $row->fantag_date, |
| 421 | + ); |
| 422 | + } |
| 423 | + |
| 424 | + return $topFanboxes; |
| 425 | + } |
| 426 | + |
| 427 | + function checkIfUserHasFanbox( $userft_fantag_id ) { |
| 428 | + global $wgUser; |
| 429 | + $dbr = wfGetDB( DB_SLAVE ); |
| 430 | + $res = $dbr->select( |
| 431 | + 'user_fantag', |
| 432 | + array( 'COUNT(*) AS count' ), |
| 433 | + array( |
| 434 | + 'userft_user_name' => $wgUser->getName(), |
| 435 | + 'userft_fantag_id' => intval( $userft_fantag_id ) |
| 436 | + ), |
| 437 | + __METHOD__ |
| 438 | + ); |
| 439 | + $row = $dbr->fetchObject( $res ); |
| 440 | + $check_fanbox_count = 0; |
| 441 | + if( $row ) { |
| 442 | + $check_fanbox_count = $row->count; |
| 443 | + } |
| 444 | + return $check_fanbox_count; |
| 445 | + } |
| 446 | + |
| 447 | + public function getFanBoxByCategory( $category ) { |
| 448 | + $dbr = wfGetDB( DB_MASTER ); |
| 449 | + |
| 450 | + $res = $dbr->select( |
| 451 | + array( 'fantag', 'categorylinks' ), |
| 452 | + array( |
| 453 | + 'fantag_id', 'fantag_title', 'fantag_pg_id', |
| 454 | + 'fantag_left_text', 'fantag_left_textcolor', |
| 455 | + 'fantag_left_bgcolor', 'fantag_right_text', |
| 456 | + 'fantag_right_textcolor', 'fantag_right_bgcolor', |
| 457 | + 'fantag_image_name', 'fantag_left_textsize', |
| 458 | + 'fantag_right_textsize', 'fantag_count', |
| 459 | + 'fantag_user_id', 'fantag_user_name' |
| 460 | + ), |
| 461 | + array( 'cl_to' => $category ), |
| 462 | + __METHOD__, |
| 463 | + array( 'ORDER BY' => 'fantag_count DESC' ), |
| 464 | + array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = fantag_pg_id' ) ) |
| 465 | + ); |
| 466 | + |
| 467 | + $categoryFanboxes = array(); |
| 468 | + foreach( $res as $row ) { |
| 469 | + $categoryFanboxes[] = array( |
| 470 | + 'fantag_id' => $row->fantag_id, |
| 471 | + 'fantag_title' => $row->fantag_title, |
| 472 | + 'fantag_pg_id' => $row->fantag_pg_id, |
| 473 | + 'fantag_left_text' => $row->fantag_left_text, |
| 474 | + 'fantag_left_textcolor' => $row->fantag_left_textcolor, |
| 475 | + 'fantag_left_bgcolor' => $row->fantag_left_bgcolor, |
| 476 | + 'fantag_right_text' => $row->fantag_right_text, |
| 477 | + 'fantag_right_textcolor' => $row->fantag_right_textcolor, |
| 478 | + 'fantag_right_bgcolor' => $row->fantag_right_bgcolor, |
| 479 | + 'fantag_image_name' => $row->fantag_image_name, |
| 480 | + 'fantag_left_textsize' => $row->fantag_left_textsize, |
| 481 | + 'fantag_right_textsize' => $row->fantag_right_textsize, |
| 482 | + 'fantag_count' => $row->fantag_count, |
| 483 | + 'fantag_user_id' => $row->fantag_user_id, |
| 484 | + 'fantag_user_name' => $row->fantag_user_name, |
| 485 | + ); |
| 486 | + } |
| 487 | + |
| 488 | + return $categoryFanboxes; |
| 489 | + } |
| 490 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/SpecialTopFanBoxes.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 491 | + native |
Index: trunk/extensions/FanBoxes/FanBoxes.js |
— | — | @@ -0,0 +1,269 @@ |
| 2 | +var FanBoxes = { |
| 3 | + // Display right side of fanbox as user inputs info |
| 4 | + displayRightSide: function() { |
| 5 | + var rightSideOutput = document.form1.inputRightSide.value; |
| 6 | + document.getElementById( 'fanBoxRightSideOutput2' ).innerHTML = rightSideOutput; |
| 7 | + }, |
| 8 | + |
| 9 | + /** |
| 10 | + * Display left side as user inputs info and sets imagename value to empty |
| 11 | + * (just in case he previously uploaded an image) |
| 12 | + */ |
| 13 | + displayLeftSide: function() { |
| 14 | + var leftSideOutput = document.form1.inputLeftSide.value; |
| 15 | + document.getElementById( 'fanBoxLeftSideOutput2' ).innerHTML = leftSideOutput; |
| 16 | + document.getElementById( 'fantag_image_name' ).value = ''; |
| 17 | + }, |
| 18 | + |
| 19 | + /** |
| 20 | + * If user uploaded image, and then typed in text, and now wants to insert |
| 21 | + * image again, he can just click it |
| 22 | + */ |
| 23 | + insertImageToLeft: function() { |
| 24 | + var imageElement = document.getElementById( 'fanbox_image' ); |
| 25 | + document.getElementById( 'fantag_image_name' ).value = imageElement.value; |
| 26 | + document.getElementById( 'fanBoxLeftSideOutput2' ).innerHTML = imageElement.innerHTML; |
| 27 | + document.getElementById( 'inputLeftSide' ).value = ''; |
| 28 | + }, |
| 29 | + |
| 30 | + // Countdown as user types characters |
| 31 | + limitText: function( limitField, limitCount, limitNum ) { |
| 32 | + if( limitField.value.length > limitNum ) { |
| 33 | + limitField.value = limitField.value.substring( 0, limitNum ); |
| 34 | + } else { |
| 35 | + limitCount.value = limitNum - limitField.value.length; |
| 36 | + } |
| 37 | + }, |
| 38 | + |
| 39 | + // Limits the left side fanbox so user can't type in tons of characters without a space |
| 40 | + leftSideFanBoxFormat: function() { |
| 41 | + var str_left_side = document.form1.inputLeftSide.value; |
| 42 | + var str_left_side_length = document.form1.inputLeftSide.value.length; |
| 43 | + var space_position = str_left_side.substring( |
| 44 | + str_left_side_length - 5, str_left_side_length ).search( ' ' ); |
| 45 | + if( str_left_side.length < 6 ) { |
| 46 | + document.form1.inputLeftSide.maxLength = 11; |
| 47 | + } |
| 48 | + if( space_position == -1 && str_left_side.length > 6 ) { |
| 49 | + document.form1.inputLeftSide.maxLength = str_left_side.length; |
| 50 | + } |
| 51 | + if( space_position == -1 && str_left_side.length == 6 ) { |
| 52 | + document.form1.inputLeftSide.value = |
| 53 | + document.form1.inputLeftSide.value.substring( 0, 5 ) + ' ' + |
| 54 | + document.form1.inputLeftSide.value.substring( 5, 6 ); |
| 55 | + document.getElementById( 'fanBoxLeftSideOutput2' ).innerHTML = |
| 56 | + document.form1.inputLeftSide.value.substring( 0, 5 ) + ' ' + |
| 57 | + document.form1.inputLeftSide.value.substring( 5, 7 ); |
| 58 | + } |
| 59 | + if( str_left_side.length >= 5 ) { |
| 60 | + document.getElementById( 'fanBoxLeftSideOutput2' ).style.fontSize = '14px'; |
| 61 | + document.getElementById( 'textSizeLeftSide' ).value = 'mediumfont'; |
| 62 | + } else { |
| 63 | + document.getElementById( 'fanBoxLeftSideOutput2' ).style.fontSize = '20px'; |
| 64 | + document.getElementById( 'textSizeLeftSide' ).value = 'bigfont'; |
| 65 | + } |
| 66 | + }, |
| 67 | + |
| 68 | + /** |
| 69 | + * Limits right side so user can't type in tons of characters without a |
| 70 | + * space |
| 71 | + */ |
| 72 | + rightSideFanBoxFormat: function() { |
| 73 | + var str_right_side = document.form1.inputRightSide.value; |
| 74 | + var str_right_side_length = document.form1.inputRightSide.value.length; |
| 75 | + var space_position = str_right_side.substring( |
| 76 | + str_right_side_length - 17, str_right_side_length ).search( ' ' ); |
| 77 | + if( str_right_side.length < 18 ) { |
| 78 | + document.form1.inputRightSide.maxLength = 70; |
| 79 | + } |
| 80 | + if( space_position == -1 && str_right_side.length > 18 ) { |
| 81 | + document.form1.inputRightSide.maxLength = str_right_side.length; |
| 82 | + } |
| 83 | + if( space_position == -1 && str_right_side.length == 18 ) { |
| 84 | + document.form1.inputRightSide.value = |
| 85 | + document.form1.inputRightSide.value.substring( 0, 17 ) + ' ' + |
| 86 | + document.form1.inputRightSide.value.substring( 17, 18 ); |
| 87 | + document.getElementById( 'fanBoxRightSideOutput2' ).innerHTML = |
| 88 | + document.form1.inputRightSide.value.substring( 0, 17 ) + ' ' + |
| 89 | + document.form1.inputRightSide.value.substring( 17, 19 ); |
| 90 | + } |
| 91 | + |
| 92 | + if( str_right_side.length >= 52 ) { |
| 93 | + document.getElementById( 'fanBoxRightSideOutput2' ).style.fontSize = '12px'; |
| 94 | + document.getElementById( 'textSizeRightSide' ).value = 'smallfont'; |
| 95 | + } else { |
| 96 | + document.getElementById( 'fanBoxRightSideOutput2' ).style.fontSize = '14px'; |
| 97 | + document.getElementById( 'textSizeRightSide' ).value = 'mediumfont'; |
| 98 | + } |
| 99 | + }, |
| 100 | + |
| 101 | + /** |
| 102 | + * The below 3 functions are used to open, add/remove, and close the fanbox |
| 103 | + * popup box when you click on it |
| 104 | + */ |
| 105 | + openFanBoxPopup: function( popupBox, fanBox ) { |
| 106 | + popupBox = document.getElementById( popupBox ); |
| 107 | + fanBox = document.getElementById( fanBox ); |
| 108 | + popupBox.style.display = ( popupBox.style.display == 'block' ) ? 'none' : 'block'; |
| 109 | + fanBox.style.display = ( fanBox.style.display == 'none' ) ? 'block' : 'none'; |
| 110 | + }, |
| 111 | + |
| 112 | + closeFanboxAdd: function( popupBox, fanBox ) { |
| 113 | + popupBox = document.getElementById( popupBox ); |
| 114 | + fanBox = document.getElementById( fanBox ); |
| 115 | + popupBox.style.display = 'none'; |
| 116 | + fanBox.style.display = 'block'; |
| 117 | + }, |
| 118 | + |
| 119 | + /** |
| 120 | + * Display image box |
| 121 | + */ |
| 122 | + displayAddImage: function( el, el2, el3 ) { |
| 123 | + el = document.getElementById( el ); |
| 124 | + el.style.display = ( el.style.display == 'block' ) ? 'none' : 'block'; |
| 125 | + el2 = document.getElementById( el2 ); |
| 126 | + el3 = document.getElementById( el3 ); |
| 127 | + el2.style.display = 'none'; |
| 128 | + el3.style.display = 'inline'; |
| 129 | + }, |
| 130 | + |
| 131 | + /** |
| 132 | + * Insert a tag (category) from the category cloud into the inputbox below |
| 133 | + * it on Special:UserBoxes |
| 134 | + * |
| 135 | + * @param tagname String: category name |
| 136 | + * @param tagnumber Integer |
| 137 | + */ |
| 138 | + insertTag: function( tagname, tagnumber ) { |
| 139 | + document.getElementById( 'tag-' + tagnumber ).style.color = '#CCCCCC'; |
| 140 | + document.getElementById( 'tag-' + tagnumber ).innerHTML = tagname; |
| 141 | + // Funny...if you move this getElementById call into a variable and use |
| 142 | + // that variable here, this won't work as intended |
| 143 | + document.getElementById( 'pageCtg' ).value += ( ( document.getElementById( 'pageCtg' ).value ) ? ', ' : '' ) + tagname; |
| 144 | + }, |
| 145 | + |
| 146 | + showMessage: function( addRemove, title, fantagId ) { |
| 147 | + document.getElementById( 'show-message-container' + fantagId ).style.display = 'none'; |
| 148 | + document.getElementById( 'show-message-container' + fantagId ).style.visibility = 'hidden'; |
| 149 | + sajax_request_type = 'POST'; |
| 150 | + sajax_do_call( 'wfFanBoxShowaddRemoveMessage', [ addRemove, title, fantagId ], function( request ) { |
| 151 | + document.getElementById( 'show-message-container' + fantagId ).innerHTML = request.responseText; |
| 152 | + jQuery( '#show-message-container' + fantagId ).fadeIn( 2000 ); |
| 153 | + document.getElementById( 'show-message-container' + fantagId ).style.display = 'block'; |
| 154 | + document.getElementById( 'show-message-container' + fantagId ).style.visibility = 'visible'; |
| 155 | + }); |
| 156 | + }, |
| 157 | + |
| 158 | + showAddRemoveMessageUserPage: function( addRemove, id, style ) { |
| 159 | + document.getElementById( 'show-message-container' + id ).style.display = 'none'; |
| 160 | + document.getElementById( 'show-message-container' + id ).style.visibility = 'hidden'; |
| 161 | + sajax_request_type = 'POST'; |
| 162 | + sajax_do_call( 'wfMessageAddRemoveUserPage', [ addRemove, id, style ], function( request ) { |
| 163 | + document.getElementById( 'show-message-container' + id ).innerHTML = request.responseText; |
| 164 | + jQuery( '#show-message-container' + id ).fadeIn( 2000 ); |
| 165 | + document.getElementById( 'show-message-container' + id ).style.display = 'block'; |
| 166 | + document.getElementById( 'show-message-container' + id ).style.visibility = 'visible'; |
| 167 | + }); |
| 168 | + }, |
| 169 | + |
| 170 | + /** |
| 171 | + * Create a fantag, performing various checks before submitting the |
| 172 | + * document. |
| 173 | + * |
| 174 | + * Moved from SpecialFanBoxes.php |
| 175 | + */ |
| 176 | + createFantag: function() { |
| 177 | + if( !document.getElementById( 'inputRightSide' ).value ) { |
| 178 | + alert( __FANBOX_MUSTENTER_RIGHT_OR__ ); |
| 179 | + return ''; |
| 180 | + } |
| 181 | + |
| 182 | + if( |
| 183 | + !document.getElementById( 'inputLeftSide' ).value && |
| 184 | + !document.getElementById( 'fantag_image_name' ).value |
| 185 | + ) |
| 186 | + { |
| 187 | + alert( __FANBOX_MUSTENTER_LEFT__ ); |
| 188 | + return ''; |
| 189 | + } |
| 190 | + |
| 191 | + var title = document.getElementById( 'wpTitle' ).value; |
| 192 | + if( !title ) { |
| 193 | + alert( __FANBOX_MUSTENTER_TITLE__ ); |
| 194 | + return ''; |
| 195 | + } |
| 196 | + |
| 197 | + if( title.indexOf( '#' ) > -1 ) { |
| 198 | + alert( __FANBOX_HASH__ ); |
| 199 | + return ''; |
| 200 | + } |
| 201 | + |
| 202 | + // Encode ampersands |
| 203 | + title = title.replace( '&', '%26' ); |
| 204 | + |
| 205 | + sajax_request_type = 'POST'; |
| 206 | + sajax_do_call( |
| 207 | + 'wfFanBoxesTitleExists', |
| 208 | + [ encodeURIComponent( document.getElementById( 'wpTitle' ) ) ], |
| 209 | + function( req ) { |
| 210 | + if( req.responseText.indexOf( 'OK' ) >= 0 ) { |
| 211 | + document.form1.submit(); |
| 212 | + } else { |
| 213 | + alert( __FANBOX_CHOOSE_ANOTHER__ ); |
| 214 | + } |
| 215 | + } |
| 216 | + ); |
| 217 | + }, |
| 218 | + |
| 219 | + /** |
| 220 | + * Simpler version of FanBoxes.createFantag(); this one checks that the |
| 221 | + * right side input has something and that the left side input has |
| 222 | + * something and then submits the form. |
| 223 | + */ |
| 224 | + createFantagSimple: function() { |
| 225 | + if( !document.getElementById( 'inputRightSide' ).value ) { |
| 226 | + alert( __FANBOX_MUSTENTER_RIGHT__ ); |
| 227 | + return ''; |
| 228 | + } |
| 229 | + |
| 230 | + if( |
| 231 | + !document.getElementById( 'inputLeftSide' ).value && |
| 232 | + !document.getElementById( 'fantag_image_name' ).value |
| 233 | + ) |
| 234 | + { |
| 235 | + alert( __FANBOX_MUSTENTER_LEFT__ ); |
| 236 | + return ''; |
| 237 | + } |
| 238 | + |
| 239 | + document.form1.submit(); |
| 240 | + }, |
| 241 | + |
| 242 | + resetUpload: function() { |
| 243 | + var frame = document.getElementById( 'imageUpload-frame' ); |
| 244 | + frame.src = wgScriptPath + '/index.php?title=Special:FanBoxAjaxUpload'; |
| 245 | + frame.style.display = 'block'; |
| 246 | + frame.style.visibility = 'visible'; |
| 247 | + }, |
| 248 | + |
| 249 | + completeImageUpload: function() { |
| 250 | + var html = '<div style="margin:0px 0px 10px 0px;"><img height="30" width="30" src="' + |
| 251 | + wgScriptPath + '/extensions/FanBoxes/ajax-loader-white.gif" alt="" /></div>'; |
| 252 | + document.getElementById( 'fanbox_image' ).innerHTML = html; |
| 253 | + document.getElementById( 'fanBoxLeftSideOutput2' ).innerHTML = html; |
| 254 | + }, |
| 255 | + |
| 256 | + uploadComplete: function( img_tag, img_name ) { |
| 257 | + document.getElementById( 'fanbox_image' ).innerHTML = img_tag; |
| 258 | + document.getElementById( 'fanbox_image2' ).innerHTML = |
| 259 | + '<p><a href="javascript:FanBoxes.resetUpload();">' + |
| 260 | + __FANBOX_UPLOAD_NEW_IMAGE__ + '</a></p>'; |
| 261 | + document.getElementById( 'fanbox_image' ).value = img_name; |
| 262 | + |
| 263 | + document.getElementById( 'fanBoxLeftSideOutput2' ).innerHTML = img_tag; |
| 264 | + document.getElementById( 'fantag_image_name' ).value = img_name; |
| 265 | + |
| 266 | + document.getElementById( 'inputLeftSide' ).value = ''; |
| 267 | + document.getElementById( 'imageUpload-frame' ).style.display = 'none'; |
| 268 | + document.getElementById( 'imageUpload-frame' ).style.visibility = 'hidden'; |
| 269 | + } |
| 270 | +}; |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBoxes.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 271 | + native |
Index: trunk/extensions/FanBoxes/FanBox.i18n.php |
— | — | @@ -0,0 +1,185 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization file for the FanBox extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Aaron Wright <aaron.wright@gmail.com> |
| 14 | + * @author David Pean <david.pean@gmail.com> |
| 15 | + */ |
| 16 | +$messages['en'] = array( |
| 17 | + 'fanbox-add' => 'Add', |
| 18 | + 'fanbox-addtext' => 'Add Text', |
| 19 | + 'fanbox-categories-help' => 'Categories help organize information on the site. To add multiple categories seperate them by commas.', |
| 20 | + 'fanbox-categories-label' => 'Categories', |
| 21 | + 'fanbox-choose-another' => 'Please choose another title', |
| 22 | + 'fanbox-create-button' => 'Create', |
| 23 | + 'fanbox-created-by' => 'created by:', |
| 24 | + 'fanbox-hash' => '# is an invalid character for the title.', |
| 25 | + 'fanbox-members' => '{{PLURAL:$1|one member|$1 members}}', |
| 26 | + 'fanbox-mustenter-left' => 'You must enter either text or an image for the left side', |
| 27 | + 'fanbox-mustenter-right' => 'You must enter text for the right side', |
| 28 | + 'fanbox-mustenter-right-or' => 'You must enter text for the right side', |
| 29 | + 'fanbox-mustenter-title' => 'You must enter a title', |
| 30 | + 'fanbox-perma' => 'perma', |
| 31 | + 'fanbox-prev' => 'Prev', |
| 32 | + 'fanbox-next' => 'Next', |
| 33 | + 'fan-addfan-title' => 'Create a userbox', |
| 34 | + 'fan-createfor' => 'Create a userbox for $1', |
| 35 | + 'fan-createfannotloggedin'=> 'You must log-in to create a userbox.', |
| 36 | + 'fan-updatefan' => 'Edit Userbox for "$1"', |
| 37 | + 'fanbox-instructions' => 'Choose a title for the userbox, add text (or an image) and color to the left and right side and press create! It\'s that easy!', |
| 38 | + 'fanbox-title' => 'Title', |
| 39 | + 'fanbox-leftsidetext' => 'Left Side', |
| 40 | + 'fanbox-display-image'=> ' (add an image)', |
| 41 | + 'fanbox-close-image'=> ' (close image box)', |
| 42 | + 'fanbox-leftsideinstructions' => '(Maximum characters: 10; 5 per line)', |
| 43 | + 'fanbox-rightsidetext' => 'Right Side', |
| 44 | + 'fanbox-rightsideinstructions' => '(Maximum characters: 70)', |
| 45 | + 'fanbox-charsleft' => '(you have $1 characters left)', |
| 46 | + 'fanbox-leftbg-color' => 'Left Background', |
| 47 | + 'fanbox-lefttext-color' => 'Left Text', |
| 48 | + 'fanbox-rightbg-color' => 'Right Background', |
| 49 | + 'fanbox-righttext-color' => 'Right Text', |
| 50 | + 'fanbox-leftsideimage' => 'Add an Image', |
| 51 | + 'fanbox-leftsideimageinstructions' => '(instead of text, you can add an image to left side)', |
| 52 | + 'fanboxes-maxchars-sixty' => 'Maximum characters: 60', |
| 53 | + 'fanbox-upload-image-button' => 'Upload', |
| 54 | + 'fanbox-upload-new-image' => 'Upload New Image', |
| 55 | + 'fanbox-update-button' => 'Edit', |
| 56 | + 'fanbox-userdoesnotexist' => 'The user you are trying to view does not exist.', |
| 57 | + 'fanbox-woops' => 'Woops, you took a wrong turn!', |
| 58 | + 'fanbox-userbox-category' => 'Userboxes', # default category where all userboxes will be put into |
| 59 | + 'fanbox-summary-new' => 'new userbox', |
| 60 | + 'fanbox-summary-update' => 'update userbox', |
| 61 | + 'fan-addfan-exists' => 'The title for your userbox already exists. Please choose another title for the userbox.', |
| 62 | + 'f-list-title' => "$1's Userbox List", |
| 63 | + 'f-back-link' => '< Back to $1\'s Page', |
| 64 | + 'f-count' => '$1 has $2 {{PLURAL:$2|userbox|userboxes}}.', |
| 65 | + 'fan-embed' => 'Embed', |
| 66 | + 'fan-add-colors' => 'Add Colors', |
| 67 | + 'fanbox-remove' => 'Remove', |
| 68 | + 'fanbox-remove-fanbox' => 'Remove this box from your userpage?', |
| 69 | + 'fanbox-add-fanbox' => 'Add this box to your userpage?', |
| 70 | + 'fanbox-add-fanbox-login' => 'Want to add this to your userpage?', |
| 71 | + 'fanbox-login' => 'Login.', |
| 72 | + 'fanbox-nav-header' => 'Userboxes', |
| 73 | + 'top-fanboxes-link' => 'Top Userboxes', |
| 74 | + 'most-recent-fanboxes-link' => 'Most Recent Userboxes', |
| 75 | + 'fanbox-successful-add' => 'You have successfully added this userbox to your userpage.', |
| 76 | + 'fanbox-successful-remove' => 'You have successfully removed this userbox from your userpage.', |
| 77 | + 'fanbox-users-with-fanbox' => 'Fans with this Userbox', |
| 78 | + 'fanbox-users-with-fanbox-message' => 'Other people interested in the same stuff', |
| 79 | + 'fanbox-woops-title' => 'Woops!', |
| 80 | + 'user-fanbox-title' => 'Userboxes', |
| 81 | + 'topuserboxes' => 'Top UserBoxes', |
| 82 | + 'viewuserboxes' => 'View UserBoxes', |
| 83 | + 'userboxes' => 'Create a Userbox', |
| 84 | + 'userboxes-instructions' => '<!-- Put instructions or stuff here -->', # do not translate this |
| 85 | + 'fanbox-top-list-is-empty' => 'There are no top userboxes yet. [[Special:UserBoxes|Create a userbox!]]', |
| 86 | +); |
| 87 | + |
| 88 | +/** Finnish (Suomi) |
| 89 | + * @author Jack Phoenix <jack@countervandalism.net> |
| 90 | + */ |
| 91 | +$messages['fi'] = array( |
| 92 | + 'fanbox-add' => 'Lisää', |
| 93 | + 'fanbox-addtext' => 'Lisää tekstiä', |
| 94 | + 'fanbox-categories-help' => 'Luokat auttavat järjestämään tietoa tässä wikissä. Lisätäksesi useita luokkia, erottele ne pilkuin.', |
| 95 | + 'fanbox-categories-label' => 'Luokat', |
| 96 | + 'fanbox-choose-another' => 'Ole hyvä ja valitse toinen otsikko', |
| 97 | + 'fanbox-create-button' => 'Luo', |
| 98 | + 'fanbox-created-by' => 'luonut:', |
| 99 | + 'fanbox-hash' => '# on merkki, joka ei kelpaa otsikkoon.', |
| 100 | + 'fanbox-members' => '{{PLURAL:$1|yksi jäsen|$1 jäsentä}}', |
| 101 | + 'fanbox-mustenter-left' => 'Sinun tulee antaa joko tekstiä tai kuva vasemmalle puolelle', |
| 102 | + 'fanbox-mustenter-right' => 'Sinun tulee antaa tekstiä oikealle puolelle', |
| 103 | + 'fanbox-mustenter-right-or' => 'Sinun tulee antaa tekstiä oikealle puolelle', |
| 104 | + 'fanbox-mustenter-title' => 'Sinun tulee antaa otsikko', |
| 105 | + 'fanbox-perma' => 'ikilinkki', |
| 106 | + 'fanbox-prev' => 'edell.', |
| 107 | + 'fanbox-next' => 'seur.', |
| 108 | + 'fan-addfan-title' => 'Luo käyttäjälaatikko', |
| 109 | + 'fan-createfor' => 'Luo käyttäjälaatikko $1', |
| 110 | + 'fan-createfannotloggedin'=> 'Sinun tulee kirjautua sisään voidaksesi luoda käyttäjälaatikon.', |
| 111 | + 'fan-updatefan' => 'Päivitä käyttäjälaatikko "$1"', |
| 112 | + 'fanbox-instructions' => 'Valitse otsikko käyttäjälaatikollesi, lisää tekstiä (tai kuva) ja väriä vasemmalle puolelle ja oikealle puolelle ja paina "Luo"-nappia. Se on niin helppoa!', |
| 113 | + 'fanbox-title' => 'Otsikko', |
| 114 | + 'fanbox-leftsidetext' => 'Vasen puoli', |
| 115 | + 'fanbox-display-image'=> ' (lisää kuva)', |
| 116 | + 'fanbox-close-image'=> ' (sulje kuvalaatikko)', |
| 117 | + 'fanbox-leftsideinstructions' => '(Suurin merkkimäärä: 10; 5 riviä kohden)', |
| 118 | + 'fanbox-rightsidetext' => 'Oikea puoli', |
| 119 | + 'fanbox-rightsideinstructions' => '(Suurin merkkimäärä: 70)', |
| 120 | + 'fanbox-charsleft' => '(sinulla on $1 merkkiä jäljellä)', |
| 121 | + 'fanbox-leftbg-color' => 'Vasen tausta', |
| 122 | + 'fanbox-lefttext-color' => 'Vasen teksti', |
| 123 | + 'fanbox-rightbg-color' => 'Oikea tausta', |
| 124 | + 'fanbox-righttext-color' => 'Oikea teksti', |
| 125 | + 'fanbox-leftsideimage' => 'Lisää kuva', |
| 126 | + 'fanbox-leftsideimageinstructions' => '(tekstin sijaan voit lisätä kuvan vasemmalle puolelle)', |
| 127 | + 'fanboxes-maxchars-sixty' => 'Suurin merkkimäärä: 60', |
| 128 | + 'fanbox-upload-image-button' => 'Tallenna', |
| 129 | + 'fanbox-upload-new-image' => 'Tallenna uusi kuva', |
| 130 | + 'fanbox-update-button' => 'Muokkaa', |
| 131 | + 'fanbox-userdoesnotexist' => 'Käyttäjää, jota koitat katsoa, ei ole olemassa', |
| 132 | + 'fanbox-woops' => 'Hups, astuit harhaan!', |
| 133 | + 'fanbox-userbox-category' => 'Käyttäjälaatikot', |
| 134 | + 'fanbox-summary-new' => 'uusi käyttäjälaatikko', |
| 135 | + 'fanbox-summary-update' => 'käyttäjälaatikko päivitetty', |
| 136 | + 'fan-addfan-exists' => 'Käyttäjälaatikkosi otsikko on jo olemassa. Ole hyvä ja valitse toinen otsiko käyttäjälaatikollesi.', |
| 137 | + 'f-list-title' => 'Käyttäjän $1 käyttäjälaatikkolista', |
| 138 | + 'f-back-link' => '< Takaisin käyttäjän $1 sivulle', |
| 139 | + 'f-count' => 'Käyttäjällä $1 on $2 {{PLURAL:$2|käyttäjälaatikko|käyttäjälaatikkoa}}.', |
| 140 | + 'fan-embed' => 'Upota', |
| 141 | + 'fan-add-colors' => 'Lisää värejä', |
| 142 | + 'fanbox-remove' => 'Poista', |
| 143 | + 'fanbox-remove-fanbox' => 'Poista tämä laatikko käyttäjäsivultasi?', |
| 144 | + 'fanbox-add-fanbox' => 'Lisää tämä laatikko käyttäjäsivullesi?', |
| 145 | + 'fanbox-add-fanbox-login' => 'Haluatko lisätä tämän käyttäjäsivullesi?', |
| 146 | + 'fanbox-login' => 'Kirjaudu sisään.', |
| 147 | + 'fanbox-nav-header' => 'Käyttäjälaatikot', |
| 148 | + 'top-fanboxes-link' => 'Parhaimmat käyttäjälaatikot', |
| 149 | + 'most-recent-fanboxes-link' => 'Tuoreimmat käyttäjälaatikot', |
| 150 | + 'fanbox-successful-add' => 'Olet onnistuneesti lisännyt tämän käyttäjälaatikon käyttäjäsivullesi.', |
| 151 | + 'fanbox-successful-remove' => 'Olet onnistuneesti poistanut tämän käyttäjälaatikon käyttäjäsivultasi.', |
| 152 | + 'fanbox-users-with-fanbox' => 'Fanit, joilla on tämä käyttäjälaatikko', |
| 153 | + 'fanbox-users-with-fanbox-message' => 'Muut ihmiset, jotka ovat kiinnostuneet samoista asioista', |
| 154 | + 'fanbox-woops-title' => 'Ups!', |
| 155 | + 'user-fanbox-title' => 'Käyttäjälaatikot', |
| 156 | + 'topuserboxes' => 'Parhaimmat käyttäjälaatikot', |
| 157 | + 'viewuserboxes' => 'Katso käyttäjälaatikkoja', |
| 158 | + 'userboxes' => 'Luo käyttäjälaatikko', |
| 159 | +); |
| 160 | + |
| 161 | +/** French (Français) |
| 162 | + * @author Jack Phoenix <jack@countervandalism.net> |
| 163 | + */ |
| 164 | +$messages['fr'] = array( |
| 165 | + 'fanbox-add' => 'Ajouter', |
| 166 | + 'fanbox-addtext' => 'Ajouter le texte', |
| 167 | + 'fanbox-categories-label' => 'Catégories', |
| 168 | + 'fanbox-create-button' => 'Créer', |
| 169 | + 'fanbox-members' => '{{PLURAL:$1|un membre|$1 membres}}', |
| 170 | + 'fanbox-perma' => 'lien permanent', |
| 171 | + 'fan-addfan-title' => 'Créer une boîte utilisateur', |
| 172 | + 'fan-createfor' => 'Créer une boîte utilisateur pour $1', |
| 173 | + 'fan-createfannotloggedin'=> 'Vous devez vous connecter pour créer une boîte utilisateur.', |
| 174 | + 'fan-updatefan' => 'Modifier boîte utilisateur pour $1', |
| 175 | + 'fanbox-title' => 'Titre', |
| 176 | + 'fanbox-upload-image-button' => 'Téléverser', |
| 177 | + 'fanbox-upload-new-image' => 'Téléverser une nouvelle image', |
| 178 | + 'fanbox-update-button' => 'Modifier', |
| 179 | + 'fanbox-userbox-category' => 'Boîtes utilisateur', |
| 180 | + 'fanbox-summary-new' => 'nouvelle boîte utilisateur', |
| 181 | + 'f-count' => '$1 a $2 {{PLURAL:$2|boîte utilisateur|boîtes utilisateur}}.', |
| 182 | + 'fan-add-colors' => 'Ajouter coleurs', |
| 183 | + 'fanbox-nav-header' => 'Boîtes utilisateur', |
| 184 | + 'user-fanbox-title' => 'Boîtes utilisateur', |
| 185 | + 'userboxes' => 'Créer une boîte utilisateur', |
| 186 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBox.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 187 | + native |
Index: trunk/extensions/FanBoxes/FanBox.namespaces.php |
— | — | @@ -0,0 +1,35 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Translations of the UserBox namespace. |
| 5 | + * |
| 6 | + * @file |
| 7 | + */ |
| 8 | + |
| 9 | +$namespaceNames = array(); |
| 10 | + |
| 11 | +// For wikis where the FanBoxes extension is not installed. |
| 12 | +if( !defined( 'NS_FANTAG' ) ) { |
| 13 | + define( 'NS_FANTAG', 600 ); |
| 14 | +} |
| 15 | + |
| 16 | +if( !defined( 'NS_FANTAG_TALK' ) ) { |
| 17 | + define( 'NS_FANTAG_TALK', 601 ); |
| 18 | +} |
| 19 | + |
| 20 | +/** English */ |
| 21 | +$namespaceNames['en'] = array( |
| 22 | + NS_FANTAG => 'UserBox', |
| 23 | + NS_FANTAG_TALK => 'UserBox_talk', |
| 24 | +); |
| 25 | + |
| 26 | +/** Finnish (Suomi) */ |
| 27 | +$namespaceNames['fi'] = array( |
| 28 | + NS_FANTAG => 'Käyttäjälaatikko', |
| 29 | + NS_FANTAG_TALK => 'Keskustelu_käyttäjälaatikosta', |
| 30 | +); |
| 31 | + |
| 32 | +/** Dutch (Nederlands) */ |
| 33 | +$namespaceNames['nl'] = array( |
| 34 | + NS_FANTAG => 'Gebruikers_box', |
| 35 | + NS_FANTAG_TALK => 'Overleg_gebruikers_box', |
| 36 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBox.namespaces.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 37 | + native |
Index: trunk/extensions/FanBoxes/FanBoxesClass.php |
— | — | @@ -0,0 +1,143 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * @todo document |
| 6 | + */ |
| 7 | +class UserFanBoxes { |
| 8 | + |
| 9 | + var $user_id; # Text form (spaces not underscores) of the main part |
| 10 | + var $user_name; # Text form (spaces not underscores) of the main part |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructor |
| 14 | + * @todo FIXME: we could, in theory, drop this function and the private |
| 15 | + * class member variables as they are unused in here, we'd |
| 16 | + * just need to fix all the callers |
| 17 | + * @private |
| 18 | + */ |
| 19 | + /* private */ function __construct( $username ) { |
| 20 | + $title1 = Title::newFromDBkey( $username ); |
| 21 | + $this->user_name = $title1->getText(); |
| 22 | + $this->user_id = User::idFromName( $this->user_name ); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Used on SpecialViewFanBoxes page to get all the user's fanboxes |
| 27 | + * |
| 28 | + * @param $type Integer: unused |
| 29 | + * @param $limit Integer: LIMIT for the SQL query |
| 30 | + * @param $page Integer: the current page; used to build pagination links |
| 31 | + * and also used here to calculate the OFFSET for the |
| 32 | + * SQL query |
| 33 | + * @return Array |
| 34 | + */ |
| 35 | + public function getUserFanboxes( $type, $limit = 0, $page = 0 ) { |
| 36 | + $dbr = wfGetDB( DB_SLAVE ); |
| 37 | + |
| 38 | + $params['ORDER BY'] = 'userft_date DESC'; |
| 39 | + //$limit_sql = ''; |
| 40 | + if( $limit > 0 ) { |
| 41 | + $limitvalue = 0; |
| 42 | + if( $page ) { |
| 43 | + $limitvalue = $page * $limit - ( $limit ); |
| 44 | + } |
| 45 | + $params['LIMIT'] = $limit; |
| 46 | + $params['OFFSET'] = $limitvalue; |
| 47 | + //$limit_sql = " LIMIT {$limitvalue},{$limit} "; |
| 48 | + } |
| 49 | + |
| 50 | + $res = $dbr->select( |
| 51 | + array( 'fantag', 'user_fantag' ), |
| 52 | + array( |
| 53 | + 'fantag_id', |
| 54 | + 'fantag_title', |
| 55 | + 'fantag_left_text', |
| 56 | + 'fantag_left_textcolor', |
| 57 | + 'fantag_left_bgcolor', |
| 58 | + 'fantag_right_text', |
| 59 | + 'fantag_right_textcolor', |
| 60 | + 'fantag_right_bgcolor', |
| 61 | + 'userft_date', |
| 62 | + 'fantag_image_name', |
| 63 | + 'fantag_left_textsize', |
| 64 | + 'fantag_right_textsize' |
| 65 | + ), |
| 66 | + array( 'userft_user_id' => $this->user_id ), |
| 67 | + __METHOD__, |
| 68 | + $params, |
| 69 | + array( 'user_fantag' => array( 'INNER JOIN', 'userft_fantag_id = fantag_id' ) ) |
| 70 | + ); |
| 71 | + |
| 72 | + $userFanboxes = array(); |
| 73 | + foreach ( $res as $row ) { |
| 74 | + $userFanboxes[] = array( |
| 75 | + 'fantag_id' => $row->fantag_id, |
| 76 | + 'fantag_title' => $row->fantag_title, |
| 77 | + 'fantag_left_text' => $row->fantag_left_text, |
| 78 | + 'fantag_left_textcolor' => $row->fantag_left_textcolor, |
| 79 | + 'fantag_left_bgcolor' => $row->fantag_left_bgcolor, |
| 80 | + 'fantag_right_text' => $row->fantag_right_text, |
| 81 | + 'fantag_right_textcolor' => $row->fantag_right_textcolor, |
| 82 | + 'fantag_right_bgcolor' => $row->fantag_right_bgcolor, |
| 83 | + 'fantag_image_name' => $row->fantag_image_name, |
| 84 | + 'fantag_left_textsize' => $row->fantag_left_textsize, |
| 85 | + 'fantag_right_textsize' => $row->fantag_right_textsize |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + return $userFanboxes; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Used on Special:ViewFanBoxes page to get the count of a user's fanboxes |
| 94 | + * so we can build the prev/next bar |
| 95 | + * |
| 96 | + * @param $user_name String: name of the user whose fanbox count we want to |
| 97 | + * get |
| 98 | + * @return Integer: amount of fanboxes the user has, or 0 if they have none |
| 99 | + */ |
| 100 | + static function getFanBoxCountByUsername( $user_name ) { |
| 101 | + $dbw = wfGetDB( DB_MASTER ); |
| 102 | + $res = $dbw->select( |
| 103 | + 'user_fantag', |
| 104 | + array( 'COUNT(*) AS count' ), |
| 105 | + array( 'userft_user_name' => $user_name ), |
| 106 | + __METHOD__, |
| 107 | + array( 'LIMIT' => 1 ) |
| 108 | + ); |
| 109 | + $row = $dbw->fetchObject( $res ); |
| 110 | + $user_fanbox_count = 0; |
| 111 | + if( $row ) { |
| 112 | + $user_fanbox_count = $row->count; |
| 113 | + } |
| 114 | + return $user_fanbox_count; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Used on Special:ViewFanBoxes to know whether popup box should be Add or |
| 119 | + * Remove fanbox |
| 120 | + * |
| 121 | + * @param $userft_fantag_id Integer: user ID number |
| 122 | + * @return Integer: |
| 123 | + */ |
| 124 | + public function checkIfUserHasFanbox( $userft_fantag_id ) { |
| 125 | + global $wgUser; |
| 126 | + $dbw = wfGetDB( DB_MASTER ); |
| 127 | + $res = $dbw->select( |
| 128 | + 'user_fantag', |
| 129 | + array( 'COUNT(*) AS count' ), |
| 130 | + array( |
| 131 | + 'userft_user_name' => $wgUser->getName(), |
| 132 | + 'userft_fantag_id' => intval( $userft_fantag_id ) |
| 133 | + ), |
| 134 | + __METHOD__ |
| 135 | + ); |
| 136 | + $row = $dbw->fetchObject( $res ); |
| 137 | + $check_fanbox_count = 0; |
| 138 | + if( $row ) { |
| 139 | + $check_fanbox_count = $row->count; |
| 140 | + } |
| 141 | + return $check_fanbox_count; |
| 142 | + } |
| 143 | + |
| 144 | +} |
Property changes on: trunk/extensions/FanBoxes/FanBoxesClass.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 145 | + native |
Index: trunk/extensions/FanBoxes/UserBoxesHook.php |
— | — | @@ -0,0 +1,204 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * <userboxes> parser hook extension -- allows displaying your own userboxes in |
| 5 | + * a wiki page |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
| 10 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 11 | + die( "Not a valid entry point.\n" ); |
| 12 | +} |
| 13 | + |
| 14 | +$wgHooks['ParserFirstCallInit'][] = 'wfUserBoxesHook'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Register the <userboxes> tag with the Parser. |
| 18 | + * |
| 19 | + * @param $parser Object: instance of Parser (not necessarily $wgParser) |
| 20 | + * @return Boolean: true |
| 21 | + */ |
| 22 | +function wfUserBoxesHook( &$parser ) { |
| 23 | + $parser->setHook( 'userboxes', 'UserBoxesHook' ); |
| 24 | + return true; |
| 25 | +} |
| 26 | + |
| 27 | +function UserBoxesHook( $input, $args, $parser ) { |
| 28 | + global $wgOut, $wgUser, $wgTitle, $wgMemc, $wgFanBoxScripts; |
| 29 | + |
| 30 | + $parser->disableCache(); |
| 31 | + |
| 32 | + $wgOut->addScriptFile( $wgFanBoxScripts . '/FanBoxes.js' ); |
| 33 | + $wgOut->addExtensionStyle( $wgFanBoxScripts . '/FanBoxes.css' ); |
| 34 | + |
| 35 | + $user_name = ( isset( $args['user'] ) ? $args['user'] : $wgUser->getName() ); |
| 36 | + |
| 37 | + $limit = 10; |
| 38 | + if ( isset( $args['limit'] ) && is_numeric( $args['limit'] ) ) { |
| 39 | + $limit = intval( $args['limit'] ); |
| 40 | + } |
| 41 | + |
| 42 | + $f = new UserFanBoxes( $user_name ); |
| 43 | + |
| 44 | + // Try cache |
| 45 | + //$key = wfMemcKey( 'user', 'profile', 'fanboxes', $f->user_id ); |
| 46 | + //$data = $wgMemc->get( $key ); |
| 47 | + |
| 48 | + //if( !$data ) { |
| 49 | + // wfDebug( "Got profile fanboxes for user {$user_name} from DB\n" ); |
| 50 | + // $fanboxes = $f->getUserFanboxes( 0, $limit ); |
| 51 | + // $wgMemc->set( $key, $fanboxes ); |
| 52 | + //} else { |
| 53 | + // wfDebug( "Got profile fanboxes for user {$user_name} from cache\n" ); |
| 54 | + // $fanboxes = $data; |
| 55 | + //} |
| 56 | + |
| 57 | + $fanboxes = $f->getUserFanboxes( 0, $limit ); |
| 58 | + |
| 59 | + $fanbox_count = $f->getFanBoxCountByUsername( $user_name ); |
| 60 | + $fanbox_link = SpecialPage::getTitleFor( 'ViewUserBoxes' ); |
| 61 | + $per_row = 1; |
| 62 | + $output = ''; |
| 63 | + |
| 64 | + if( $fanboxes ) { |
| 65 | + $output .= '<div class="clearfix"><div class="user-fanbox-container">'; |
| 66 | + |
| 67 | + $x = 1; |
| 68 | + $tagParser = new Parser(); |
| 69 | + |
| 70 | + foreach( $fanboxes as $fanbox ) { |
| 71 | + $check_user_fanbox = $f->checkIfUserHasFanbox( $fanbox['fantag_id'] ); |
| 72 | + |
| 73 | + if( $fanbox['fantag_image_name'] ) { |
| 74 | + $fantag_image_width = 45; |
| 75 | + $fantag_image_height = 53; |
| 76 | + $fantag_image = wfFindFile( $fanbox['fantag_image_name'] ); |
| 77 | + $fantag_image_url = ''; |
| 78 | + if ( is_object( $fantag_image ) ) { |
| 79 | + $fantag_image_url = $fantag_image->createThumb( |
| 80 | + $fantag_image_width, |
| 81 | + $fantag_image_height |
| 82 | + ); |
| 83 | + } |
| 84 | + $fantag_image_tag = '<img alt="" src="' . $fantag_image_url . '" />'; |
| 85 | + } |
| 86 | + |
| 87 | + if( $fanbox['fantag_left_text'] == '' ) { |
| 88 | + $fantag_leftside = $fantag_image_tag; |
| 89 | + } else { |
| 90 | + $fantag_leftside = $fanbox['fantag_left_text']; |
| 91 | + $fantag_leftside = $tagParser->parse( |
| 92 | + $fantag_leftside, |
| 93 | + $wgTitle, |
| 94 | + $wgOut->parserOptions(), |
| 95 | + false |
| 96 | + ); |
| 97 | + $fantag_leftside = $fantag_leftside->getText(); |
| 98 | + } |
| 99 | + |
| 100 | + $leftfontsize = '10px'; |
| 101 | + if( $fanbox['fantag_left_textsize'] == 'mediumfont' ) { |
| 102 | + $leftfontsize = '11px'; |
| 103 | + } |
| 104 | + if( $fanbox['fantag_left_textsize'] == 'bigfont' ) { |
| 105 | + $leftfontsize = '15px'; |
| 106 | + } |
| 107 | + $rightfontsize = '10px'; |
| 108 | + if( $fanbox['fantag_right_textsize'] == 'smallfont' ) { |
| 109 | + $rightfontsize = '10px'; |
| 110 | + } |
| 111 | + if( $fanbox['fantag_right_textsize'] == 'mediumfont' ) { |
| 112 | + $rightfontsize = '11px'; |
| 113 | + } |
| 114 | + |
| 115 | + // Get permalink |
| 116 | + $fantag_title = Title::makeTitle( NS_FANTAG, $fanbox['fantag_title'] ); |
| 117 | + |
| 118 | + $right_text = $fanbox['fantag_right_text']; |
| 119 | + $right_text = $tagParser->parse( |
| 120 | + $right_text, |
| 121 | + $wgTitle, |
| 122 | + $wgOut->parserOptions(), |
| 123 | + false |
| 124 | + ); |
| 125 | + $right_text = $right_text->getText(); |
| 126 | + |
| 127 | + // Output fanboxes |
| 128 | + $output .= "<span class=\"top-fanbox\"><div class=\"fanbox-item\"> |
| 129 | + <div class=\"individual-fanbox\" id=\"individualFanbox" . $fanbox['fantag_id'] . "\"> |
| 130 | + <div class=\"show-message-container-profile\" id=\"show-message-container" . $fanbox['fantag_id'] . "\"> |
| 131 | + <div class=\"relativeposition\"> |
| 132 | + <a class=\"perma\" style=\"font-size:8px; color:" . $fanbox['fantag_right_textcolor'] . "\" href=\"" . $fantag_title->escapeFullURL() . "\" title=\"{$fanbox['fantag_title']}\">" . wfMsg( 'fanbox-perma' ) . "</a> |
| 133 | + <table class=\"fanBoxTableProfile\" onclick=\"javascript:FanBoxes.openFanBoxPopup('fanboxPopUpBox{$fanbox['fantag_id']}', 'individualFanbox{$fanbox['fantag_id']}')\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> |
| 134 | + <tr> |
| 135 | + <td id=\"fanBoxLeftSideOutputProfile\" style=\"color:" . $fanbox['fantag_left_textcolor'] . "; font-size:$leftfontsize\" bgcolor=\"" . $fanbox['fantag_left_bgcolor'] . "\">" . $fantag_leftside . "</td> |
| 136 | + <td id=\"fanBoxRightSideOutputProfile\" style=\"color:" . $fanbox['fantag_right_textcolor'] . "; font-size:$rightfontsize\" bgcolor=\"" . $fanbox['fantag_right_bgcolor'] . "\">" . $right_text . "</td> |
| 137 | + </tr> |
| 138 | + </table> |
| 139 | + </div> |
| 140 | + </div> |
| 141 | + </div>"; |
| 142 | + |
| 143 | + if( $wgUser->isLoggedIn() ) { |
| 144 | + if( $check_user_fanbox == 0 ) { |
| 145 | + $output .= " |
| 146 | + <div class=\"fanbox-pop-up-box-profile\" id=\"fanboxPopUpBox" . $fanbox['fantag_id'] . "\"> |
| 147 | + <table cellpadding=\"0\" cellspacing=\"0\"> |
| 148 | + <tr> |
| 149 | + <td style=\"font-size:10px\" align=\"center\">" . wfMsg( 'fanbox-add-fanbox' ) . "</td> |
| 150 | + </tr> |
| 151 | + <tr> |
| 152 | + <td align=\"center\"> |
| 153 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-add' ) . "\" size=\"10\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$fanbox['fantag_id']}', 'individualFanbox{$fanbox['fantag_id']}'); FanBoxes.showAddRemoveMessageUserPage(1, {$fanbox['fantag_id']}, 'show-addremove-message-half')\" /> |
| 154 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"10\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$fanbox['fantag_id']}', 'individualFanbox{$fanbox['fantag_id']}')\" /> |
| 155 | + </td> |
| 156 | + </tr> |
| 157 | + </table> |
| 158 | + </div>"; |
| 159 | + } else { |
| 160 | + $output .= " |
| 161 | + <div class=\"fanbox-pop-up-box-profile\" id=\"fanboxPopUpBox" . $fanbox['fantag_id'] . "\"> |
| 162 | + <table cellpadding=\"0\" cellspacing=\"0\"> |
| 163 | + <tr> |
| 164 | + <td style=\"font-size:10px\" align=\"center\">" . wfMsg( 'fanbox-remove-fanbox' ) . "</td> |
| 165 | + </tr> |
| 166 | + <tr> |
| 167 | + <td align=\"center\"> |
| 168 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-remove' ) . "\" size=\"10\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$fanbox['fantag_id']}', 'individualFanbox{$fanbox['fantag_id']}'); FanBoxes.showAddRemoveMessageUserPage(2, {$fanbox['fantag_id']}, 'show-addremove-message-half')\" /> |
| 169 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"10\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$fanbox['fantag_id']}', 'individualFanbox{$fanbox['fantag_id']}')\" /> |
| 170 | + </td> |
| 171 | + </tr> |
| 172 | + </table> |
| 173 | + </div>"; |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + if( $wgUser->getID() == 0 ) { |
| 178 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 179 | + $output .= '<div class="fanbox-pop-up-box-profile" id="fanboxPopUpBox' . $fanbox['fantag_id'] . '"> |
| 180 | + <table cellpadding="0" cellspacing="0"> |
| 181 | + <tr> |
| 182 | + <td style="font-size: 10px" align="center">' . |
| 183 | + wfMsg( 'fanbox-add-fanbox-login' ) . |
| 184 | + "<a href=\"{$login->getFullURL()}\">" . |
| 185 | + wfMsg( 'fanbox-login' ) . '</a> |
| 186 | + </td> |
| 187 | + <tr> |
| 188 | + <td align="center"> |
| 189 | + <input type="button" value="' . wfMsg( 'cancel' ) . "\" size=\"10\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$fanbox['fantag_id']}', 'individualFanbox{$fanbox['fantag_id']}')\" /> |
| 190 | + </td> |
| 191 | + </tr> |
| 192 | + </table> |
| 193 | + </div>"; |
| 194 | + } |
| 195 | + |
| 196 | + $output .= '</div></span><div class="cleared"></div>'; |
| 197 | + //if( $x == count( $fanboxes ) || $x != 1 && $x % $per_row == 0 ) $output .= '<div class="cleared"></div>'; |
| 198 | + $x++; |
| 199 | + } |
| 200 | + |
| 201 | + $output .= '</div></div>'; |
| 202 | + } |
| 203 | + |
| 204 | + return $output; |
| 205 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/UserBoxesHook.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 206 | + native |
Index: trunk/extensions/FanBoxes/SpecialViewFanBoxes.php |
— | — | @@ -0,0 +1,264 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A special page for viewing the fanboxes of a user, either someone else or |
| 5 | + * yourself. |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
| 10 | +class ViewFanBoxes extends SpecialPage { |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructor |
| 14 | + */ |
| 15 | + public function __construct() { |
| 16 | + parent::__construct( 'ViewUserBoxes' ); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Show the special page |
| 21 | + * |
| 22 | + * @param $par Mixed: parameter passed to the page or null |
| 23 | + */ |
| 24 | + public function execute( $par ) { |
| 25 | + global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgFanBoxScripts; |
| 26 | + |
| 27 | + // Redirect Non-logged in users to Login Page |
| 28 | + if( $wgUser->getID() == 0 && $user_name == '' ) { |
| 29 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 30 | + $wgOut->redirect( $login->escapeFullURL( 'returnto=Special:ViewUserBoxes' ) ); |
| 31 | + return false; |
| 32 | + } |
| 33 | + |
| 34 | + $tagParser = new Parser(); |
| 35 | + $wgOut->addScriptFile( $wgFanBoxScripts . '/FanBoxes.js' ); |
| 36 | + $wgOut->addExtensionStyle( $wgFanBoxScripts . '/FanBoxes.css' ); |
| 37 | + |
| 38 | + $wgOut->setPageTitle( wfMsgHtml( 'fanbox-nav-header' ) ); |
| 39 | + |
| 40 | + // Code for viewing fanboxes for each user |
| 41 | + $output = ''; |
| 42 | + $user_name = $wgRequest->getVal( 'user', $par ); |
| 43 | + $page = $wgRequest->getInt( 'page', 1 ); |
| 44 | + |
| 45 | + // If no user is set in the URL, we assume it's the current user |
| 46 | + if( !$user_name ) { |
| 47 | + $user_name = $wgUser->getName(); |
| 48 | + } |
| 49 | + $user_id = User::idFromName( $user_name ); |
| 50 | + $user = Title::makeTitle( NS_USER, $user_name ); |
| 51 | + |
| 52 | + // Error message for username that does not exist (from URL) |
| 53 | + if( $user_id == 0 ) { |
| 54 | + $wgOut->setPageTitle( wfMsg( 'fanbox-woops' ) ); |
| 55 | + $wgOut->addHTML( wfMsg( 'fanbox-userdoesnotexist' ) ); |
| 56 | + return false; |
| 57 | + } |
| 58 | + |
| 59 | + // Config for the page |
| 60 | + $per_page = 30; |
| 61 | + |
| 62 | + // Get all FanBoxes for this user into the array |
| 63 | + // Calls the FanBoxesClass file |
| 64 | + $userfan = new UserFanBoxes( $user_name ); |
| 65 | + $userFanboxes = $userfan->getUserFanboxes( 0, $per_page, $page ); |
| 66 | + $total = $userfan->getFanBoxCountByUsername( $user_name ); |
| 67 | + $per_row = 3; |
| 68 | + |
| 69 | + // Page title and top part |
| 70 | + $wgOut->setPageTitle( wfMsgHtml( 'f-list-title', $userfan->user_name ) ); |
| 71 | + $output .= '<div class="back-links"> |
| 72 | + <a href="' . $user->getFullURL() . '">' . |
| 73 | + wfMsgHtml( 'f-back-link', $userfan->user_name ) . |
| 74 | + '</a> |
| 75 | + </div> |
| 76 | + <div class="fanbox-count">' . |
| 77 | + wfMsgExt( 'f-count', 'parsemag', $userfan->user_name, $total ) . |
| 78 | + '</div> |
| 79 | + |
| 80 | + <div class="view-fanboxes-container clearfix">'; |
| 81 | + |
| 82 | + if( $userFanboxes ) { |
| 83 | + $x = 1; |
| 84 | + |
| 85 | + foreach( $userFanboxes as $userfanbox ) { |
| 86 | + $check_user_fanbox = $userfan->checkIfUserHasFanbox( $userfanbox['fantag_id'] ); |
| 87 | + |
| 88 | + if( $userfanbox['fantag_image_name'] ) { |
| 89 | + $fantag_image_width = 45; |
| 90 | + $fantag_image_height = 53; |
| 91 | + $fantag_image = wfFindFile( $userfanbox['fantag_image_name'] ); |
| 92 | + $fantag_image_url = ''; |
| 93 | + if ( is_object( $fantag_image ) ) { |
| 94 | + $fantag_image_url = $fantag_image->createThumb( |
| 95 | + $fantag_image_width, |
| 96 | + $fantag_image_height |
| 97 | + ); |
| 98 | + } |
| 99 | + $fantag_image_tag = '<img alt="" src="' . $fantag_image_url . '" />'; |
| 100 | + } |
| 101 | + |
| 102 | + if( $userfanbox['fantag_left_text'] == '' ) { |
| 103 | + $fantag_leftside = $fantag_image_tag; |
| 104 | + } else { |
| 105 | + $fantag_leftside = $userfanbox['fantag_left_text']; |
| 106 | + $fantag_leftside = $tagParser->parse( |
| 107 | + $fantag_leftside, $wgTitle, |
| 108 | + $wgOut->parserOptions(), false |
| 109 | + ); |
| 110 | + $fantag_leftside = $fantag_leftside->getText(); |
| 111 | + } |
| 112 | + |
| 113 | + $leftfontsize = '12px'; |
| 114 | + if( $userfanbox['fantag_left_textsize'] == 'mediumfont' ) { |
| 115 | + $leftfontsize = '14px'; |
| 116 | + } |
| 117 | + if( $userfanbox['fantag_left_textsize'] == 'bigfont' ) { |
| 118 | + $leftfontsize = '20px'; |
| 119 | + } |
| 120 | + |
| 121 | + $rightfontsize = '10px'; |
| 122 | + if( $userfanbox['fantag_right_textsize'] == 'smallfont' ) { |
| 123 | + $rightfontsize = '12px'; |
| 124 | + } |
| 125 | + if( $userfanbox['fantag_right_textsize'] == 'mediumfont' ) { |
| 126 | + $rightfontsize = '14px'; |
| 127 | + } |
| 128 | + |
| 129 | + // Get permalink |
| 130 | + $fantag_title = Title::makeTitle( NS_FANTAG, $userfanbox['fantag_title'] ); |
| 131 | + |
| 132 | + $right_text = $userfanbox['fantag_right_text']; |
| 133 | + $right_text = $tagParser->parse( |
| 134 | + $right_text, |
| 135 | + $wgTitle, |
| 136 | + $wgOut->parserOptions(), |
| 137 | + false |
| 138 | + ); |
| 139 | + $right_text = $right_text->getText(); |
| 140 | + |
| 141 | + // Output fanboxes |
| 142 | + $output .= '<span class="top-fanbox"> |
| 143 | + <div class="fanbox-item"> |
| 144 | + <div class="individual-fanboxtest" id="individualFanbox' . $userfanbox['fantag_id'] . '"> |
| 145 | + <div class="show-message-container" id="show-message-container' . $userfanbox['fantag_id'] . '"> |
| 146 | + <div class="permalink-container"> |
| 147 | + <a class="perma" style="font-size:8px; color:' . $userfanbox['fantag_right_textcolor'] . '" href="' . $fantag_title->escapeFullURL() . "\" title=\"{$userfanbox['fantag_title']}\">" . wfMsg( 'fanbox-perma' ) . "</a> |
| 148 | + <table class=\"fanBoxTable\" onclick=\"javascript:FanBoxes.openFanBoxPopup('fanboxPopUpBox{$userfanbox['fantag_id']}', 'individualFanbox{$userfanbox['fantag_id']}')\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> |
| 149 | + <tr> |
| 150 | + <td id=\"fanBoxLeftSideOutput\" style=\"color:" . $userfanbox['fantag_left_textcolor'] . "; font-size:$leftfontsize\" bgcolor=\"" . $userfanbox['fantag_left_bgcolor'] . '">' . $fantag_leftside . "</td> |
| 151 | + <td id=\"fanBoxRightSideOutput\" style=\"color:" . $userfanbox['fantag_right_textcolor'] . "; font-size:$rightfontsize\" bgcolor=\"" . $userfanbox['fantag_right_bgcolor'] . '">' . $right_text . '</td> |
| 152 | + </tr> |
| 153 | + </table> |
| 154 | + </div> |
| 155 | + </div> |
| 156 | + </div>'; |
| 157 | + |
| 158 | + if( $wgUser->isLoggedIn() ) { |
| 159 | + if( $check_user_fanbox == 0 ) { |
| 160 | + $output .= ' |
| 161 | + <div class="fanbox-pop-up-box" id="fanboxPopUpBox' . $userfanbox['fantag_id'] . '"> |
| 162 | + <table cellpadding="0" cellspacing="0" width="258px"> |
| 163 | + <tr> |
| 164 | + <td align="center">' . wfMsg( 'fanbox-add-fanbox' ) . '</td> |
| 165 | + </tr> |
| 166 | + <tr> |
| 167 | + <td align="center"> |
| 168 | + <input type="button" value="' . wfMsg( 'fanbox-add' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$userfanbox['fantag_id']}', 'individualFanbox{$userfanbox['fantag_id']}'); FanBoxes.showAddRemoveMessageUserPage(1, {$userfanbox['fantag_id']}, 'show-addremove-message')\" /> |
| 169 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$userfanbox['fantag_id']}', 'individualFanbox{$userfanbox['fantag_id']}')\" /> |
| 170 | + </td> |
| 171 | + </tr> |
| 172 | + </table> |
| 173 | + </div>"; |
| 174 | + } else { |
| 175 | + $output .= ' |
| 176 | + <div class="fanbox-pop-up-box" id="fanboxPopUpBox' . $userfanbox['fantag_id'] . '"> |
| 177 | + <table cellpadding="0" cellspacing="0" width="258px"> |
| 178 | + <tr> |
| 179 | + <td align="center">' . wfMsg( 'fanbox-remove-fanbox' ) . '</td> |
| 180 | + </tr> |
| 181 | + <tr> |
| 182 | + <td align="center"> |
| 183 | + <input type="button" value="' . wfMsg( 'fanbox-remove' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$userfanbox['fantag_id']}', 'individualFanbox{$userfanbox['fantag_id']}'); FanBoxes.showAddRemoveMessageUserPage(2, {$userfanbox['fantag_id']}, 'show-addremove-message')\" /> |
| 184 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$userfanbox['fantag_id']}', 'individualFanbox{$userfanbox['fantag_id']}')\" /> |
| 185 | + </td> |
| 186 | + </tr> |
| 187 | + </table> |
| 188 | + </div>"; |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + if( $wgUser->getID() == 0 ) { |
| 193 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 194 | + $output .= '<div class="fanbox-pop-up-box" id="fanboxPopUpBox' . $userfanbox['fantag_id'] . '"> |
| 195 | + <table cellpadding="0" cellspacing="0" width="258px"> |
| 196 | + <tr> |
| 197 | + <td align="center">' . |
| 198 | + wfMsg( 'fanbox-add-fanbox-login' ) . |
| 199 | + "<a href=\"{$login->getFullURL()}\">" . |
| 200 | + wfMsg( 'fanbox-login' ) . '</a></td> |
| 201 | + </tr> |
| 202 | + <tr> |
| 203 | + <td align="center"> |
| 204 | + <input type="button" value="' . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$userfanbox['fantag_id']}', 'individualFanbox{$userfanbox['fantag_id']}')\" /> |
| 205 | + </td> |
| 206 | + </tr> |
| 207 | + </table> |
| 208 | + </div>"; |
| 209 | + } |
| 210 | + |
| 211 | + $output .= '</div></span>'; |
| 212 | + |
| 213 | + if( $x == count( $userFanboxes ) || $x != 1 && $x % $per_row == 0 ) { |
| 214 | + $output .= '<div class="cleared"></div>'; |
| 215 | + } |
| 216 | + $x++; |
| 217 | + } |
| 218 | + } |
| 219 | + |
| 220 | + $output .= '</div>'; |
| 221 | + |
| 222 | + // Build next/prev nav |
| 223 | + $numofpages = $total / $per_page; |
| 224 | + |
| 225 | + if( $numofpages > 1 ) { |
| 226 | + $output .= '<div class="page-nav">'; |
| 227 | + if( $page > 1 ) { |
| 228 | + $output .= '<a href="' . $this->getTitle()->escapeFullURL( |
| 229 | + array( 'user' => $user_name, 'page' => ( $page - 1 ) ) ) . |
| 230 | + '">' . wfMsg( 'fanbox-prev' ) . '</a> '; |
| 231 | + } |
| 232 | + |
| 233 | + if( ( $total % $per_page ) != 0 ) { |
| 234 | + $numofpages++; |
| 235 | + } |
| 236 | + if( $numofpages >= 9 && $page < $total ) { |
| 237 | + $numofpages = 9 + $page; |
| 238 | + } |
| 239 | + if( $numofpages >= ( $total / $per_page ) ) { |
| 240 | + $numofpages = ( $total / $per_page ) + 1; |
| 241 | + } |
| 242 | + |
| 243 | + for( $i = 1; $i <= $numofpages; $i++ ) { |
| 244 | + if( $i == $page ) { |
| 245 | + $output .= ( $i . ' ' ); |
| 246 | + } else { |
| 247 | + $output .= '<a href="' . $this->getTitle()->escapeFullURL( |
| 248 | + array( 'user' => $user_name, 'page' => $i ) ) . |
| 249 | + "\">$i</a> "; |
| 250 | + } |
| 251 | + } |
| 252 | + |
| 253 | + if( ( $total - ( $per_page * $page ) ) > 0 ) { |
| 254 | + $output .= ' <a href="' . $this->getTitle()->escapeFullURL( |
| 255 | + array( 'user' => $user_name, 'page' => ( $page + 1 ) ) ) . |
| 256 | + '">' . wfMsg( 'fanbox-next' ) . '</a>'; |
| 257 | + } |
| 258 | + $output .= '</div>'; |
| 259 | + } |
| 260 | + |
| 261 | + // Output everything |
| 262 | + $wgOut->addHTML( $output ); |
| 263 | + } |
| 264 | + |
| 265 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/SpecialViewFanBoxes.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 266 | + native |
Index: trunk/extensions/FanBoxes/FanBoxClass.php |
— | — | @@ -0,0 +1,704 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * FanBox class |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @todo document |
| 8 | + */ |
| 9 | +class FanBox { |
| 10 | + |
| 11 | + var $name, |
| 12 | + $title, |
| 13 | + $exists, |
| 14 | + $create_date, |
| 15 | + $type, |
| 16 | + $fantag_id, |
| 17 | + $fantag_title, |
| 18 | + $user_name, |
| 19 | + $left_text, |
| 20 | + $left_textcolor, |
| 21 | + $left_bgcolor, |
| 22 | + $left_textsize, |
| 23 | + $right_text, |
| 24 | + $right_textcolor, |
| 25 | + $right_bgcolor, |
| 26 | + $right_textsize, |
| 27 | + $fantag_left_text, |
| 28 | + $fantag_left_textcolor, |
| 29 | + $fantag_left_bgcolor, |
| 30 | + $fantag_right_text, |
| 31 | + $fantag_right_textcolor, |
| 32 | + $fantag_right_bgcolor, |
| 33 | + $fantag_image_name, |
| 34 | + $fantag_left_textsize, |
| 35 | + $fantag_right_textsize, |
| 36 | + $userft_fantag_id; |
| 37 | + |
| 38 | + /** |
| 39 | + * Constructor |
| 40 | + */ |
| 41 | + public function __construct( $title ) { |
| 42 | + if( !is_object( $title ) ) { |
| 43 | + throw new MWException( 'FanBox constructor given bogus title.' ); |
| 44 | + } |
| 45 | + $this->title =& $title; |
| 46 | + $this->name = $title->getDBkey(); |
| 47 | + $this->dataLoaded = false; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Create a Fantag object from a fantag name |
| 52 | + * |
| 53 | + * @param $name String: name of the fanbox, used to create a title object |
| 54 | + * using Title::makeTitleSafe |
| 55 | + * @return Mixed: new instance of FanBox for the constructed title or null |
| 56 | + */ |
| 57 | + public static function newFromName( $name ) { |
| 58 | + $title = Title::makeTitleSafe( NS_FANTAG, $name ); |
| 59 | + |
| 60 | + if ( is_object( $title ) ) { |
| 61 | + return new FanBox( $title ); |
| 62 | + } else { |
| 63 | + return null; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Insert info into fantag table in the database when user creates fantag |
| 69 | + */ |
| 70 | + public function addFan( $fantag_left_text, $fantag_left_textcolor, |
| 71 | + $fantag_left_bgcolor, $fantag_right_text, |
| 72 | + $fantag_right_textcolor, $fantag_right_bgcolor, $fantag_image_name, |
| 73 | + $fantag_left_textsize, $fantag_right_textsize, $categories |
| 74 | + ) { |
| 75 | + global $wgUser, $wgContLang; |
| 76 | + |
| 77 | + $dbw = wfGetDB( DB_MASTER ); |
| 78 | + |
| 79 | + $descTitle = $this->getTitle(); |
| 80 | + $desc = wfMsgForContent( 'fanbox-summary-new' ); |
| 81 | + $article = new Article( $descTitle ); |
| 82 | + |
| 83 | + $categories_wiki = ''; |
| 84 | + if( $categories ) { |
| 85 | + $categories_a = explode( ',', $categories ); |
| 86 | + foreach( $categories_a as $category ) { |
| 87 | + $categories_wiki .= '[[' . |
| 88 | + $wgContLang->getNsText( NS_CATEGORY ) . ':' . |
| 89 | + trim( $category ) . "]]\n"; |
| 90 | + } |
| 91 | + } |
| 92 | + $article = new Article( $this->title ); |
| 93 | + |
| 94 | + $article_content = $this->buildWikiText() . "\n\n" . |
| 95 | + $this->getBaseCategories() . "\n" . $categories_wiki . |
| 96 | + "\n__NOEDITSECTION__"; |
| 97 | + |
| 98 | + if( $descTitle->exists() ) { |
| 99 | + # Invalidate the cache for the description page |
| 100 | + $descTitle->invalidateCache(); |
| 101 | + $descTitle->purgeSquid(); |
| 102 | + } else { |
| 103 | + // New fantag; create the description page. |
| 104 | + $article->doEdit( $this->buildWikiText() . "\n\n" . $article_content, $desc ); |
| 105 | + } |
| 106 | + |
| 107 | + # Test to see if the row exists using INSERT IGNORE |
| 108 | + # This avoids race conditions by locking the row until the commit, and also |
| 109 | + # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition. |
| 110 | + $dbw->insert( 'fantag', |
| 111 | + array( |
| 112 | + 'fantag_title' => $this->getName(), |
| 113 | + 'fantag_left_text' => $fantag_left_text, |
| 114 | + 'fantag_left_textcolor' => $fantag_left_textcolor, |
| 115 | + 'fantag_left_bgcolor' => $fantag_left_bgcolor, |
| 116 | + 'fantag_right_text' => $fantag_right_text, |
| 117 | + 'fantag_right_textcolor' => $fantag_right_textcolor, |
| 118 | + 'fantag_right_bgcolor' => $fantag_right_bgcolor, |
| 119 | + 'fantag_date' => date( 'Y-m-d H:i:s' ), |
| 120 | + 'fantag_pg_id' => $article->getID(), |
| 121 | + 'fantag_user_id' => $wgUser->getID(), |
| 122 | + 'fantag_user_name' => $wgUser->getName(), |
| 123 | + 'fantag_image_name' => $fantag_image_name, |
| 124 | + 'fantag_left_textsize' => $fantag_left_textsize, |
| 125 | + 'fantag_right_textsize' => $fantag_right_textsize, |
| 126 | + ), |
| 127 | + __METHOD__, |
| 128 | + 'IGNORE' |
| 129 | + ); |
| 130 | + return $dbw->insertId(); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * Insert info into user_fantag table when user creates fantag or grabs it |
| 135 | + * |
| 136 | + * @param $userft_fantag_id Integer: fantag ID number |
| 137 | + */ |
| 138 | + public function addUserFan( $userft_fantag_id ) { |
| 139 | + global $wgUser; |
| 140 | + |
| 141 | + $dbw = wfGetDB( DB_MASTER ); |
| 142 | + $dbw->insert( |
| 143 | + 'user_fantag', |
| 144 | + array( |
| 145 | + 'userft_fantag_id' => intval( $userft_fantag_id ), |
| 146 | + 'userft_user_id' => $wgUser->getID(), |
| 147 | + 'userft_user_name' => $wgUser->getName(), |
| 148 | + 'userft_date' => date( 'Y-m-d H:i:s' ), |
| 149 | + ), |
| 150 | + __METHOD__ |
| 151 | + ); |
| 152 | + } |
| 153 | + |
| 154 | + public function buildWikiText() { |
| 155 | + $output = ''; |
| 156 | + $output .= "left_text:{$this->getFanBoxLeftText()}\n"; |
| 157 | + $output .= "left_textcolor:{$this->getFanBoxLeftTextColor()}\n"; |
| 158 | + $output .= "left_bgcolor:{$this->getFanBoxLeftBgColor()}\n"; |
| 159 | + $output .= "right_text:{$this->getFanBoxRightText()}\n"; |
| 160 | + $output .= "right_textcolor:{$this->getFanBoxRightTextColor()}\n"; |
| 161 | + $output .= "right_bgcolor:{$this->getFanBoxRightBgColor()}\n"; |
| 162 | + $output .= "left_textsize:{$this->getFanBoxLeftTextSize()}\n"; |
| 163 | + $output .= "right_textsize:{$this->getFanBoxRightTextSize()}\n"; |
| 164 | + |
| 165 | + $output = "<!--{$output}-->"; |
| 166 | + return $output; |
| 167 | + } |
| 168 | + |
| 169 | + public function getBaseCategories() { |
| 170 | + global $wgUser, $wgContLang; |
| 171 | + $creator = $this->getUserName(); |
| 172 | + if( !$creator ) { |
| 173 | + $creator = $wgUser->getName(); |
| 174 | + } |
| 175 | + $ctg = '{{DEFAULTSORT:{{PAGENAME}}}}'; |
| 176 | + $ctg .= '[[' . $wgContLang->getNsText( NS_CATEGORY ) . ':' . |
| 177 | + wfMsgForContent( 'fanbox-userbox-category' ) . "]]\n"; |
| 178 | + return $ctg; |
| 179 | + } |
| 180 | + |
| 181 | + // Update fan |
| 182 | + public function updateFan( $fantag_left_text, $fantag_left_textcolor, |
| 183 | + $fantag_left_bgcolor, $fantag_right_text, $fantag_right_textcolor, |
| 184 | + $fantag_right_bgcolor, $fantag_image_name, $fantag_left_textsize, |
| 185 | + $fantag_right_textsize, $fanboxId, $categories |
| 186 | + ) { |
| 187 | + global $wgUser, $wgMemc, $wgContLang; |
| 188 | + |
| 189 | + $dbw = wfGetDB( DB_MASTER ); |
| 190 | + |
| 191 | + $dbw->update( |
| 192 | + 'fantag', |
| 193 | + array( |
| 194 | + 'fantag_left_text' => $fantag_left_text, |
| 195 | + 'fantag_left_textcolor' => $fantag_left_textcolor, |
| 196 | + 'fantag_left_bgcolor' => $fantag_left_bgcolor, |
| 197 | + 'fantag_right_text' => $fantag_right_text, |
| 198 | + 'fantag_right_textcolor' => $fantag_right_textcolor, |
| 199 | + 'fantag_right_bgcolor' => $fantag_right_bgcolor, |
| 200 | + 'fantag_image_name' => $fantag_image_name, |
| 201 | + 'fantag_left_textsize' => $fantag_left_textsize, |
| 202 | + 'fantag_right_textsize' => $fantag_right_textsize, |
| 203 | + ), |
| 204 | + array( 'fantag_pg_id' => intval( $fanboxId ) ), |
| 205 | + __METHOD__ |
| 206 | + ); |
| 207 | + $key = wfMemcKey( 'fantag', 'page', $this->name ); |
| 208 | + $wgMemc->delete( $key ); |
| 209 | + |
| 210 | + $categories_wiki = ''; |
| 211 | + if( $categories ) { |
| 212 | + $categories_a = explode( ',', $categories ); |
| 213 | + foreach( $categories_a as $category ) { |
| 214 | + $categories_wiki .= '[[' . $wgContLang->getNsText( NS_CATEGORY ) . |
| 215 | + ':' . trim( $category ) . "]]\n"; |
| 216 | + } |
| 217 | + } |
| 218 | + $article = new Article( $this->title ); |
| 219 | + |
| 220 | + $article_content = $this->buildWikiText() . "\n" . |
| 221 | + $this->getBaseCategories() . "\n" . $categories_wiki . |
| 222 | + "\n__NOEDITSECTION__"; |
| 223 | + |
| 224 | + $article->doEdit( $article_content, wfMsgForContent( 'fanbox-summary-update' ) ); |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * Remove fantag from user_fantag table when user removes it |
| 229 | + * |
| 230 | + * @param $userft_fantag_id Integer: fantag ID number |
| 231 | + */ |
| 232 | + function removeUserFanBox( $userft_fantag_id ) { |
| 233 | + global $wgUser; |
| 234 | + $dbw = wfGetDB( DB_MASTER ); |
| 235 | + $dbw->delete( |
| 236 | + 'user_fantag', |
| 237 | + array( |
| 238 | + 'userft_user_name' => $wgUser->getName(), |
| 239 | + 'userft_fantag_id' => intval( $userft_fantag_id ) |
| 240 | + ), |
| 241 | + __METHOD__ |
| 242 | + ); |
| 243 | + $dbw->commit(); |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * Change count of fantag when user adds or removes it |
| 248 | + * |
| 249 | + * @param $fanBoxId Integer: fantag ID number |
| 250 | + * @param $number Integer |
| 251 | + */ |
| 252 | + function changeCount( $fanBoxId, $number ) { |
| 253 | + $dbw = wfGetDB( DB_MASTER ); |
| 254 | + |
| 255 | + $count = (int)$dbw->selectField( |
| 256 | + 'fantag', |
| 257 | + 'fantag_count', |
| 258 | + array( 'fantag_id' => intval( $fanBoxId ) ), |
| 259 | + __METHOD__ |
| 260 | + ); |
| 261 | + |
| 262 | + $res = $dbw->update( |
| 263 | + 'fantag', |
| 264 | + array( 'fantag_count' => "{$count}+{$number}" ), |
| 265 | + array( 'fantag_id' => intval( $fanBoxId ) ), |
| 266 | + __METHOD__ |
| 267 | + ); |
| 268 | + } |
| 269 | + |
| 270 | + /** |
| 271 | + * Try to load fan metadata from memcached. |
| 272 | + * |
| 273 | + * @return Boolean: true on success. |
| 274 | + */ |
| 275 | + private function loadFromCache() { |
| 276 | + global $wgMemc; |
| 277 | + |
| 278 | + wfProfileIn( __METHOD__ ); |
| 279 | + $this->dataLoaded = false; |
| 280 | + |
| 281 | + $key = wfMemcKey( 'fantag', 'page', $this->name ); |
| 282 | + $data = $wgMemc->get( $key ); |
| 283 | + |
| 284 | + if( !empty( $data ) && is_array( $data ) ) { |
| 285 | + $this->id = $data['id']; |
| 286 | + $this->left_text = $data['lefttext']; |
| 287 | + $this->left_textcolor = $data['lefttextcolor']; |
| 288 | + $this->left_bgcolor = $data['leftbgcolor']; |
| 289 | + $this->right_text = $data['righttext']; |
| 290 | + $this->right_textcolor = $data['righttextcolor']; |
| 291 | + $this->right_bgcolor = $data['rightbgcolor']; |
| 292 | + $this->fantag_image = $data['fantagimage']; |
| 293 | + $this->left_textsize = $data['lefttextsize']; |
| 294 | + $this->right_textsize = $data['righttextsize']; |
| 295 | + $this->pg_id = $data['pgid']; |
| 296 | + $this->user_id = $data['userid']; |
| 297 | + $this->user_name = $data['username']; |
| 298 | + $this->dataLoaded = true; |
| 299 | + $this->exists = true; |
| 300 | + } |
| 301 | + |
| 302 | + if ( $this->dataLoaded ) { |
| 303 | + wfDebug( "loaded Fan:{$this->name} from cache\n" ); |
| 304 | + wfIncrStats( 'fantag_cache_hit' ); |
| 305 | + } else { |
| 306 | + wfIncrStats( 'fantag_cache_miss' ); |
| 307 | + } |
| 308 | + |
| 309 | + wfProfileOut( __METHOD__ ); |
| 310 | + return $this->dataLoaded; |
| 311 | + } |
| 312 | + |
| 313 | + /** |
| 314 | + * Save the fan data to memcached |
| 315 | + */ |
| 316 | + private function saveToCache() { |
| 317 | + global $wgMemc; |
| 318 | + |
| 319 | + $key = wfMemcKey( 'fantag', 'page', $this->name ); |
| 320 | + if ( $this->exists() ) { |
| 321 | + $cachedValues = array( |
| 322 | + 'id' => $this->id, |
| 323 | + 'lefttext' => $this->left_text, |
| 324 | + 'lefttextcolor' => $this->left_textcolor, |
| 325 | + 'leftbgcolor' => $this->left_bgcolor, |
| 326 | + 'righttext' => $this->right_text, |
| 327 | + 'righttextcolor' => $this->right_textcolor, |
| 328 | + 'rightbgcolor' => $this->right_bgcolor, |
| 329 | + 'fantagimage' => $this->fantag_image, |
| 330 | + 'lefttextsize' => $this->left_textsize, |
| 331 | + 'righttextsize' => $this->right_textsize, |
| 332 | + 'userid' => $this->user_id, |
| 333 | + 'username' => $this->user_name, |
| 334 | + 'pgid' => $this->pg_id |
| 335 | + ); |
| 336 | + $wgMemc->set( $key, $cachedValues, 60 * 60 * 24 * 7 ); // A week |
| 337 | + } else { |
| 338 | + // However we should clear them, so they aren't leftover |
| 339 | + // if we've deleted the file. |
| 340 | + $wgMemc->delete( $key ); |
| 341 | + } |
| 342 | + } |
| 343 | + |
| 344 | + function loadFromDB() { |
| 345 | + wfProfileIn( __METHOD__ ); |
| 346 | + |
| 347 | + $dbw = wfGetDB( DB_MASTER ); |
| 348 | + |
| 349 | + $row = $dbw->selectRow( |
| 350 | + 'fantag', |
| 351 | + array( |
| 352 | + 'fantag_id', 'fantag_left_text', |
| 353 | + 'fantag_left_textcolor', 'fantag_left_bgcolor', |
| 354 | + 'fantag_user_id', 'fantag_user_name', |
| 355 | + 'fantag_right_text', 'fantag_right_textcolor', |
| 356 | + 'fantag_right_bgcolor', 'fantag_image_name', |
| 357 | + 'fantag_left_textsize', 'fantag_right_textsize', 'fantag_pg_id' |
| 358 | + ), |
| 359 | + array( 'fantag_title' => $this->name ), |
| 360 | + __METHOD__ |
| 361 | + ); |
| 362 | + if ( $row ) { |
| 363 | + $this->id = $row->fantag_id; |
| 364 | + $this->left_text = $row->fantag_left_text; |
| 365 | + $this->exists = true; |
| 366 | + $this->left_textcolor = $row->fantag_left_textcolor; |
| 367 | + $this->left_bgcolor = $row->fantag_left_bgcolor; |
| 368 | + $this->right_text = $row->fantag_right_text; |
| 369 | + $this->right_textcolor = $row->fantag_right_textcolor; |
| 370 | + $this->right_bgcolor = $row->fantag_right_bgcolor; |
| 371 | + $this->fantag_image = $row->fantag_image_name; |
| 372 | + $this->left_textsize = $row->fantag_left_textsize; |
| 373 | + $this->right_textsize = $row->fantag_right_textsize; |
| 374 | + $this->pg_id = $row->fantag_pg_id; |
| 375 | + $this->user_id = $row->fantag_user_id; |
| 376 | + $this->user_name = $row->fantag_user_name; |
| 377 | + } |
| 378 | + |
| 379 | + # Unconditionally set loaded=true, we don't want the accessors constantly rechecking |
| 380 | + $this->dataLoaded = true; |
| 381 | + wfProfileOut( __METHOD__ ); |
| 382 | + } |
| 383 | + |
| 384 | + /** |
| 385 | + * Load fanbox metadata from cache or DB, unless already loaded |
| 386 | + */ |
| 387 | + function load() { |
| 388 | + if ( !$this->dataLoaded ) { |
| 389 | + if ( !$this->loadFromCache() ) { |
| 390 | + $this->loadFromDB(); |
| 391 | + $this->saveToCache(); |
| 392 | + } |
| 393 | + $this->dataLoaded = true; |
| 394 | + } |
| 395 | + } |
| 396 | + |
| 397 | + public function outputFanBox() { |
| 398 | + global $wgTitle, $wgOut; |
| 399 | + |
| 400 | + $tagParser = new Parser(); |
| 401 | + |
| 402 | + if( $this->getFanBoxImage() ) { |
| 403 | + $fantag_image_width = 45; |
| 404 | + $fantag_image_height = 53; |
| 405 | + $fantag_image = wfFindFile( $this->getFanBoxImage() ); |
| 406 | + $fantag_image_url = ''; |
| 407 | + if ( is_object( $fantag_image ) ) { |
| 408 | + $fantag_image_url = $fantag_image->createThumb( |
| 409 | + $fantag_image_width, |
| 410 | + $fantag_image_height |
| 411 | + ); |
| 412 | + } |
| 413 | + $fantag_image_tag = '<img alt="" src="' . $fantag_image_url . '"/>'; |
| 414 | + } |
| 415 | + |
| 416 | + if( $this->getFanBoxLeftText() == '' ) { |
| 417 | + $fantag_leftside = $fantag_image_tag; |
| 418 | + } else { |
| 419 | + $fantag_leftside = $this->getFanBoxLeftText(); |
| 420 | + $fantag_leftside = $tagParser->parse( |
| 421 | + $fantag_leftside, |
| 422 | + $wgTitle, |
| 423 | + $wgOut->parserOptions(), |
| 424 | + false |
| 425 | + ); |
| 426 | + $fantag_leftside = $fantag_leftside->getText(); |
| 427 | + } |
| 428 | + |
| 429 | + $fantag_title = Title::makeTitle( NS_FANTAG, $this->name ); |
| 430 | + $individual_fantag_id = $this->getFanBoxId(); |
| 431 | + |
| 432 | + if( $this->getFanBoxPageID() == $wgTitle->getArticleID() ) { |
| 433 | + $fantag_perma = ''; |
| 434 | + } else { |
| 435 | + $fantag_perma = "<a class=\"perma\" style=\"font-size:8px; color:" . |
| 436 | + $this->getFanBoxRightTextColor() . "\" href=\"" . |
| 437 | + $fantag_title->escapeFullURL() . "\" title=\"{$this->name}\">" . |
| 438 | + wfMsg( 'fanbox-perma' ) . '</a>'; |
| 439 | + } |
| 440 | + |
| 441 | + $leftfontsize = '12px'; |
| 442 | + if( $this->getFanBoxLeftTextSize() == 'mediumfont' ) { |
| 443 | + $leftfontsize = '14px'; |
| 444 | + } |
| 445 | + if( $this->getFanBoxLeftTextSize() == 'bigfont' ) { |
| 446 | + $leftfontsize = '20px'; |
| 447 | + } |
| 448 | + |
| 449 | + if( $this->getFanBoxRightTextSize() == 'smallfont' ) { |
| 450 | + $rightfontsize = '12px'; |
| 451 | + } |
| 452 | + if( $this->getFanBoxRightTextSize() == 'mediumfont' ) { |
| 453 | + $rightfontsize = '14px'; |
| 454 | + } |
| 455 | + |
| 456 | + $right_text = $this->getFanBoxRightText(); |
| 457 | + $right_text = $tagParser->parse( |
| 458 | + $right_text, $wgTitle, $wgOut->parserOptions(), false |
| 459 | + ); |
| 460 | + $right_text = $right_text->getText(); |
| 461 | + |
| 462 | + $output = '<input type="hidden" name="individualFantagId" value="' . $this->getFanBoxId() . '" /> |
| 463 | + <div class="individual-fanbox" id="individualFanbox' . $individual_fantag_id . "\"> |
| 464 | + <div class=\"permalink-container\"> |
| 465 | + $fantag_perma |
| 466 | + </div> |
| 467 | + <table class=\"fanBoxTable\" onclick=\"javascript:FanBoxes.openFanBoxPopup('fanboxPopUpBox{$individual_fantag_id}','individualFanbox{$individual_fantag_id}')\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> |
| 468 | + <tr> |
| 469 | + <td id=\"fanBoxLeftSideOutput\" style=\"color:" . $this->getFanBoxLeftTextColor() . "; font-size:$leftfontsize\" bgcolor=\"" . $this->getFanBoxLeftBgColor() . "\">" . $fantag_leftside . "</td> |
| 470 | + <td id=\"fanBoxRightSideOutput\" style=\"color:" . $this->getFanBoxRightTextColor() . "; font-size:$rightfontsize\" bgcolor=\"" . $this->getFanBoxRightBgColor() . "\">" . $right_text . "</td> |
| 471 | + </tr> |
| 472 | + </table> |
| 473 | + </div>"; |
| 474 | + |
| 475 | + return $output; |
| 476 | + } |
| 477 | + |
| 478 | + /** |
| 479 | + * Check if user has fanbox and output the right (add vs. remove) popup box |
| 480 | + */ |
| 481 | + public function checkIfUserHasFanBox() { |
| 482 | + global $wgUser; |
| 483 | + |
| 484 | + $dbw = wfGetDB( DB_MASTER ); |
| 485 | + /*$check_fanbox_count = $dbw->selectField( |
| 486 | + 'user_fantag', |
| 487 | + array( 'COUNT(*) AS count' ), |
| 488 | + array( |
| 489 | + 'userft_user_name' => $wgUser->getName(), |
| 490 | + 'userft_fantag_id' => $this->getFanBoxId() |
| 491 | + ), |
| 492 | + __METHOD__ |
| 493 | + );*/ |
| 494 | + $sql = "SELECT COUNT(*) AS count |
| 495 | + FROM {$dbw->tableName( 'user_fantag' )} |
| 496 | + WHERE userft_user_name = '{$wgUser->getName()}' && userft_fantag_id = '{$this->getFanBoxId()}'"; |
| 497 | + $res = $dbw->query( $sql, __METHOD__ ); |
| 498 | + $row = $dbw->fetchObject( $res ); |
| 499 | + $check_fanbox_count = 0; |
| 500 | + if( $row ) { |
| 501 | + $check_fanbox_count = $row->count; |
| 502 | + } |
| 503 | + return $check_fanbox_count; |
| 504 | + } |
| 505 | + |
| 506 | + public function outputIfUserHasFanBox() { |
| 507 | + $fanboxtitle = $this->getTitle(); |
| 508 | + $fanboxtitle = $fanboxtitle->getText(); |
| 509 | + $individual_fantag_id = $this->getFanBoxId(); |
| 510 | + |
| 511 | + $output = " |
| 512 | + <div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $individual_fantag_id . "\"> |
| 513 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 514 | + <tr> |
| 515 | + <td align=\"center\">" . wfMsg( 'fanbox-remove-fanbox' ) ."</td> |
| 516 | + <tr> |
| 517 | + <td align=\"center\"> |
| 518 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-remove' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$individual_fantag_id}','individualFanbox{$individual_fantag_id}'); FanBoxes.showMessage(2, '$fanboxtitle', $individual_fantag_id) \" /> |
| 519 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$individual_fantag_id}','individualFanbox{$individual_fantag_id}')\" /> |
| 520 | + </td> |
| 521 | + </table> |
| 522 | + </div>"; |
| 523 | + |
| 524 | + return $output; |
| 525 | + } |
| 526 | + |
| 527 | + public function outputIfUserDoesntHaveFanBox() { |
| 528 | + $fanboxtitle = $this->getTitle(); |
| 529 | + $fanboxtitle = $fanboxtitle->getText(); |
| 530 | + $individual_fantag_id = $this->getFanBoxId(); |
| 531 | + |
| 532 | + $output = " |
| 533 | + <div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $individual_fantag_id . "\"> |
| 534 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 535 | + <tr> |
| 536 | + <td align=\"center\">" . wfMsg( 'fanbox-add-fanbox' ) . "</td> |
| 537 | + </tr> |
| 538 | + <tr> |
| 539 | + <td align=\"center\"> |
| 540 | + <input type=\"button\" value=\"" . wfMsg( 'fanbox-add' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$individual_fantag_id}','individualFanbox{$individual_fantag_id}'); FanBoxes.showMessage(1, '$fanboxtitle', $individual_fantag_id) \"/> |
| 541 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.closeFanboxAdd('fanboxPopUpBox{$individual_fantag_id}','individualFanbox{$individual_fantag_id}')\" /> |
| 542 | + </td> |
| 543 | + </tr> |
| 544 | + </table> |
| 545 | + </div>"; |
| 546 | + |
| 547 | + return $output; |
| 548 | + } |
| 549 | + |
| 550 | + public function outputIfUserNotLoggedIn() { |
| 551 | + // The fantag ID in the div element is needed for the "login" popup |
| 552 | + // to work properly |
| 553 | + $individual_fantag_id = $this->getFanBoxId(); |
| 554 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 555 | + $output = "<div class=\"fanbox-pop-up-box\" id=\"fanboxPopUpBox" . $individual_fantag_id . "\"> |
| 556 | + <table cellpadding=\"0\" cellspacing=\"0\" width=\"258px\"> |
| 557 | + <tr> |
| 558 | + <td align=\"center\">" . wfMsg( 'fanbox-add-fanbox-login' ) . |
| 559 | + " <a href=\"{$login->getFullURL()}\">" . wfMsg( 'fanbox-login' ) . "</a></td> |
| 560 | + </tr> |
| 561 | + <tr> |
| 562 | + <td align=\"center\"> |
| 563 | + <input type=\"button\" value=\"" . wfMsg( 'cancel' ) . "\" size=\"20\" onclick=\"FanBoxes.openFanBoxPopup('fanboxPopUpBox{$individual_fantag_id}','individualFanbox{$individual_fantag_id}')\" /> |
| 564 | + </td> |
| 565 | + </tr> |
| 566 | + </table> |
| 567 | + </div>"; |
| 568 | + return $output; |
| 569 | + } |
| 570 | + |
| 571 | + /** |
| 572 | + * @return String: the name of this fanbox |
| 573 | + */ |
| 574 | + public function getName() { |
| 575 | + return $this->name; |
| 576 | + } |
| 577 | + |
| 578 | + /** |
| 579 | + * @return Object: the associated Title object |
| 580 | + */ |
| 581 | + public function getTitle() { |
| 582 | + return $this->title; |
| 583 | + } |
| 584 | + |
| 585 | + /** |
| 586 | + * @return Integer: the ID number of the fanbox |
| 587 | + */ |
| 588 | + public function getFanBoxId() { |
| 589 | + $this->load(); |
| 590 | + return $this->id; |
| 591 | + } |
| 592 | + |
| 593 | + /** |
| 594 | + * @return String: left-hand text of the fanbox |
| 595 | + */ |
| 596 | + public function getFanBoxLeftText() { |
| 597 | + $this->load(); |
| 598 | + return $this->left_text; |
| 599 | + } |
| 600 | + |
| 601 | + /** |
| 602 | + * @return String: the color of the left-side text |
| 603 | + */ |
| 604 | + public function getFanBoxLeftTextColor() { |
| 605 | + $this->load(); |
| 606 | + return $this->left_textcolor; |
| 607 | + } |
| 608 | + |
| 609 | + /** |
| 610 | + * @return String: background color of the left side |
| 611 | + */ |
| 612 | + public function getFanBoxLeftBgColor() { |
| 613 | + $this->load(); |
| 614 | + return $this->left_bgcolor; |
| 615 | + } |
| 616 | + |
| 617 | + /** |
| 618 | + * @return String: right-hand text of the fanbox |
| 619 | + */ |
| 620 | + public function getFanBoxRightText() { |
| 621 | + $this->load(); |
| 622 | + return $this->right_text; |
| 623 | + } |
| 624 | + |
| 625 | + /** |
| 626 | + * @return String: text color of the right side text |
| 627 | + */ |
| 628 | + public function getFanBoxRightTextColor() { |
| 629 | + $this->load(); |
| 630 | + return $this->right_textcolor; |
| 631 | + } |
| 632 | + |
| 633 | + /** |
| 634 | + * @return String: background color of the right side |
| 635 | + */ |
| 636 | + public function getFanBoxRightBgColor() { |
| 637 | + $this->load(); |
| 638 | + return $this->right_bgcolor; |
| 639 | + } |
| 640 | + |
| 641 | + /** |
| 642 | + * @return String: URL to the fanbox image (if any), I think |
| 643 | + */ |
| 644 | + public function getFanBoxImage() { |
| 645 | + $this->load(); |
| 646 | + return $this->fantag_image; |
| 647 | + } |
| 648 | + |
| 649 | + /** |
| 650 | + * @return String: size of the left-hand text |
| 651 | + */ |
| 652 | + public function getFanBoxLeftTextSize() { |
| 653 | + $this->load(); |
| 654 | + return $this->left_textsize; |
| 655 | + } |
| 656 | + |
| 657 | + /** |
| 658 | + * @return String: size of the right-hand text |
| 659 | + */ |
| 660 | + public function getFanBoxRightTextSize() { |
| 661 | + $this->load(); |
| 662 | + return $this->right_textsize; |
| 663 | + } |
| 664 | + |
| 665 | + /** |
| 666 | + * @return Integer: page ID for the current page |
| 667 | + */ |
| 668 | + public function getFanBoxPageID() { |
| 669 | + $this->load(); |
| 670 | + return $this->pg_id; |
| 671 | + } |
| 672 | + |
| 673 | + /** |
| 674 | + * @return Integer: user ID of the user who created this FanBox |
| 675 | + */ |
| 676 | + public function getUserID() { |
| 677 | + $this->load(); |
| 678 | + return $this->user_id; |
| 679 | + } |
| 680 | + |
| 681 | + /** |
| 682 | + * @return String: name of the user who created this FanBox |
| 683 | + */ |
| 684 | + public function getUserName() { |
| 685 | + $this->load(); |
| 686 | + return $this->user_name; |
| 687 | + } |
| 688 | + |
| 689 | + /** |
| 690 | + * @return Boolean: true if the FanBox exists, else false |
| 691 | + */ |
| 692 | + public function exists() { |
| 693 | + $this->load(); |
| 694 | + return $this->exists; |
| 695 | + } |
| 696 | + |
| 697 | + /** |
| 698 | + * @return String: the embed code for the current fanbox |
| 699 | + */ |
| 700 | + public function getEmbedThisCode() { |
| 701 | + $embedtitle = Title::makeTitle( NS_FANTAG, $this->getName() )->getPrefixedDBkey(); |
| 702 | + return "[[$embedtitle]]"; |
| 703 | + } |
| 704 | + |
| 705 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBoxClass.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 706 | + native |
Index: trunk/extensions/FanBoxes/FanBox.alias.php |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for the FanBoxes extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$aliases = array(); |
| 11 | + |
| 12 | +/** English */ |
| 13 | +$aliases['en'] = array( |
| 14 | + 'FanBoxAjaxUpload' => array( 'FanBoxAjaxUpload' ), |
| 15 | + 'UserBoxes' => array( 'UserBoxes' ), |
| 16 | + 'TopUserboxes' => array( 'TopUserboxes' ), |
| 17 | + 'ViewUserBoxes' => array( 'ViewUserBoxes' ), |
| 18 | +); |
| 19 | + |
| 20 | +/** Finnish (Suomi) */ |
| 21 | +$aliases['fi'] = array( |
| 22 | + 'UserBoxes' => array( 'Käyttäjälaatikot' ), |
| 23 | + 'TopUserboxes' => array( 'Suosituimmat käyttäjälaatikot' ), |
| 24 | + 'ViewUserBoxes' => array( 'Katso käyttäjälaatikkoja' ), |
| 25 | +); |
| 26 | + |
| 27 | +/** Dutch (Nederlands) */ |
| 28 | +$aliases['nl'] = array( |
| 29 | + 'UserBoxes' => array( 'Gebruikers boxen' ), |
| 30 | + 'TopUserboxes' => array( 'Top gebruikers boxen' ), |
| 31 | + 'ViewUserBoxes' => array( 'Bekijk gebruikers boxen' ), |
| 32 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBox.alias.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 33 | + native |
Index: trunk/extensions/FanBoxes/MiniAjaxUpload.php |
— | — | @@ -0,0 +1,567 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * New version of that fucking AJAX upload form, 1.16-compatible. |
| 5 | + * |
| 6 | + * wpThumbWidth is the width of the thumbnail that will be returned |
| 7 | + * Also, to prevent overwriting uploads of files with popular names i.e. |
| 8 | + * Image.jpg all the uploaded files are prepended with the current timestamp. |
| 9 | + * |
| 10 | + * @file |
| 11 | + * @ingroup SpecialPage |
| 12 | + * @ingroup Upload |
| 13 | + * @author Jack Phoenix <jack@countervandalism.net> |
| 14 | + * @date 26 June 2011 |
| 15 | + * @note Based on 1.16 core SpecialUpload.php (GPL-licensed) by Bryan et al. |
| 16 | + */ |
| 17 | +class SpecialFanBoxAjaxUpload extends SpecialUpload { |
| 18 | + /** |
| 19 | + * Constructor: initialise object |
| 20 | + * Get data POSTed through the form and assign them to the object |
| 21 | + * @param WebRequest $request Data posted. |
| 22 | + */ |
| 23 | + public function __construct( $request = null ) { |
| 24 | + global $wgRequest; |
| 25 | + |
| 26 | + SpecialPage::__construct( 'FanBoxAjaxUpload', 'upload', false ); |
| 27 | + |
| 28 | + $this->loadRequest( is_null( $request ) ? $wgRequest : $request ); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * apparently you don't need to (re)declare the protected/public class |
| 33 | + * member variables here, so I removed them. |
| 34 | + */ |
| 35 | + |
| 36 | + /** |
| 37 | + * Initialize instance variables from request and create an Upload handler |
| 38 | + * |
| 39 | + * What was changed here: $this->mIgnoreWarning is now unconditionally true |
| 40 | + * and we use our own handler for $this->mUpload instead of UploadBase |
| 41 | + * |
| 42 | + * @param WebRequest $request The request to extract variables from |
| 43 | + */ |
| 44 | + protected function loadRequest( $request ) { |
| 45 | + global $wgUser; |
| 46 | + |
| 47 | + $this->mRequest = $request; |
| 48 | + $this->mSourceType = $request->getVal( 'wpSourceType', 'file' ); |
| 49 | + $this->mUpload = FanBoxUpload::createFromRequest( $request ); |
| 50 | + $this->mUploadClicked = $request->wasPosted() |
| 51 | + && ( $request->getCheck( 'wpUpload' ) |
| 52 | + || $request->getCheck( 'wpUploadIgnoreWarning' ) ); |
| 53 | + |
| 54 | + // Guess the desired name from the filename if not provided |
| 55 | + $this->mDesiredDestName = $request->getText( 'wpDestFile' ); |
| 56 | + if( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) { |
| 57 | + $this->mDesiredDestName = $request->getFileName( 'wpUploadFile' ); |
| 58 | + } |
| 59 | + $this->mComment = $request->getText( 'wpUploadDescription' ); |
| 60 | + $this->mLicense = $request->getText( 'wpLicense' ); |
| 61 | + |
| 62 | + $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' ); |
| 63 | + $this->mIgnoreWarning = true;//$request->getCheck( 'wpIgnoreWarning' ) || $request->getCheck( 'wpUploadIgnoreWarning' ); |
| 64 | + $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $wgUser->isLoggedIn(); |
| 65 | + $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' ); |
| 66 | + $this->mCopyrightSource = $request->getText( 'wpUploadSource' ); |
| 67 | + |
| 68 | + $this->mForReUpload = $request->getBool( 'wpForReUpload' ); // updating a file |
| 69 | + $this->mCancelUpload = $request->getCheck( 'wpCancelUpload' ) |
| 70 | + || $request->getCheck( 'wpReUpload' ); // b/w compat |
| 71 | + |
| 72 | + // If it was posted check for the token (no remote POST'ing with user credentials) |
| 73 | + $token = $request->getVal( 'wpEditToken' ); |
| 74 | + if( $this->mSourceType == 'file' && $token == null ) { |
| 75 | + // Skip token check for file uploads as that can't be faked via JS... |
| 76 | + // Some client-side tools don't expect to need to send wpEditToken |
| 77 | + // with their submissions, as that's new in 1.16. |
| 78 | + $this->mTokenOk = true; |
| 79 | + } else { |
| 80 | + $this->mTokenOk = $wgUser->matchEditToken( $token ); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Special page entry point |
| 86 | + * |
| 87 | + * What was changed here: the setArticleBodyOnly() line below was added, |
| 88 | + * and some bits of code were entirely removed. |
| 89 | + */ |
| 90 | + public function execute( $par ) { |
| 91 | + global $wgUser, $wgOut, $wgRequest; |
| 92 | + |
| 93 | + // Disable the skin etc. |
| 94 | + $wgOut->setArticleBodyOnly( true ); |
| 95 | + |
| 96 | + # Check uploading enabled |
| 97 | + if( !UploadBase::isEnabled() ) { |
| 98 | + $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' ); |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + # Check permissions |
| 103 | + global $wgGroupPermissions; |
| 104 | + if( !$wgUser->isAllowed( 'upload' ) ) { |
| 105 | + if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload'] |
| 106 | + || $wgGroupPermissions['autoconfirmed']['upload'] ) ) { |
| 107 | + // Custom message if logged-in users without any special rights can upload |
| 108 | + $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); |
| 109 | + } else { |
| 110 | + $wgOut->permissionRequired( 'upload' ); |
| 111 | + } |
| 112 | + return; |
| 113 | + } |
| 114 | + |
| 115 | + # Check blocks |
| 116 | + if( $wgUser->isBlocked() ) { |
| 117 | + $wgOut->blockedPage(); |
| 118 | + return; |
| 119 | + } |
| 120 | + |
| 121 | + # Check whether we actually want to allow changing stuff |
| 122 | + if( wfReadOnly() ) { |
| 123 | + $wgOut->readOnlyPage(); |
| 124 | + return; |
| 125 | + } |
| 126 | + |
| 127 | + # Unsave the temporary file in case this was a cancelled upload |
| 128 | + if ( $this->mCancelUpload ) { |
| 129 | + if ( !$this->unsaveUploadedFile() ) { |
| 130 | + # Something went wrong, so unsaveUploadedFile showed a warning |
| 131 | + return; |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + # Process upload or show a form |
| 136 | + if ( $this->mTokenOk && !$this->mCancelUpload && ( $this->mUpload && $this->mUploadClicked ) ) { |
| 137 | + $this->processUpload(); |
| 138 | + } else { |
| 139 | + $this->showUploadForm( $this->getUploadForm() ); |
| 140 | + } |
| 141 | + |
| 142 | + # Cleanup |
| 143 | + if ( $this->mUpload ) { |
| 144 | + $this->mUpload->cleanupTempFile(); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Get an UploadForm instance with title and text properly set. |
| 150 | + * |
| 151 | + * @param string $message HTML string to add to the form |
| 152 | + * @param string $sessionKey Session key in case this is a stashed upload |
| 153 | + * @return UploadForm |
| 154 | + */ |
| 155 | + protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) { |
| 156 | + # Initialize form |
| 157 | + $form = new FanBoxAjaxUploadForm( array( |
| 158 | + 'watch' => $this->getWatchCheck(), |
| 159 | + 'forreupload' => $this->mForReUpload, |
| 160 | + 'sessionkey' => $sessionKey, |
| 161 | + 'hideignorewarning' => $hideIgnoreWarning, |
| 162 | + 'destwarningack' => (bool)$this->mDestWarningAck, |
| 163 | + 'destfile' => $this->mDesiredDestName, |
| 164 | + ) ); |
| 165 | + $form->setTitle( $this->getTitle() ); |
| 166 | + |
| 167 | + # Check the token, but only if necessary |
| 168 | + if( !$this->mTokenOk && !$this->mCancelUpload |
| 169 | + && ( $this->mUpload && $this->mUploadClicked ) ) { |
| 170 | + $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) ); |
| 171 | + } |
| 172 | + |
| 173 | + # Add upload error message |
| 174 | + $form->addPreText( $message ); |
| 175 | + |
| 176 | + return $form; |
| 177 | + } |
| 178 | + |
| 179 | + /** |
| 180 | + * Stashes the upload and shows the main upload form. |
| 181 | + * |
| 182 | + * Note: only errors that can be handled by changing the name or |
| 183 | + * description should be redirected here. It should be assumed that the |
| 184 | + * file itself is sane and has passed UploadBase::verifyFile. This |
| 185 | + * essentially means that UploadBase::VERIFICATION_ERROR and |
| 186 | + * UploadBase::EMPTY_FILE should not be passed here. |
| 187 | + * |
| 188 | + * @param $message String: HTML message to be passed to mainUploadForm |
| 189 | + */ |
| 190 | + protected function showRecoverableUploadError( $message ) { |
| 191 | + $sessionKey = $this->mUpload->stashSession(); |
| 192 | + $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" . |
| 193 | + '<div class="error">' . $message . "</div>\n"; |
| 194 | + |
| 195 | + $form = $this->getUploadForm( $message, $sessionKey ); |
| 196 | + $form->setSubmitText( wfMsg( 'upload-tryagain' ) ); |
| 197 | + $this->showUploadForm( $form ); |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * Show the upload form with error message, but do not stash the file. |
| 202 | + * |
| 203 | + * @param $message String: error message to show |
| 204 | + */ |
| 205 | + protected function showUploadError( $message ) { |
| 206 | + $message = addslashes( $message ); |
| 207 | + $output = "<script language=\"javascript\"> |
| 208 | + /*<![CDATA[*/ |
| 209 | + window.parent.uploadError( '{$message}' ); |
| 210 | + /*]]>*/</script>"; |
| 211 | + $this->showUploadForm( $this->getUploadForm( $output ) ); |
| 212 | + } |
| 213 | + |
| 214 | + /** |
| 215 | + * Do the upload. |
| 216 | + * Checks are made in SpecialFanBoxAjaxUpload::execute() |
| 217 | + * |
| 218 | + * What was changed here: $wgRequest was added as a global, one hook and |
| 219 | + * the post-upload redirect were removed in favor of the code below |
| 220 | + * the $this->mUploadSuccessful = true; line |
| 221 | + */ |
| 222 | + protected function processUpload() { |
| 223 | + global $wgUser, $wgOut, $wgRequest; |
| 224 | + |
| 225 | + // Verify permissions |
| 226 | + $permErrors = $this->mUpload->verifyPermissions( $wgUser ); |
| 227 | + if( $permErrors !== true ) { |
| 228 | + $wgOut->showPermissionsErrorPage( $permErrors ); |
| 229 | + return; |
| 230 | + } |
| 231 | + |
| 232 | + // Fetch the file if required |
| 233 | + $status = $this->mUpload->fetchFile(); |
| 234 | + if( !$status->isOK() ) { |
| 235 | + $this->showUploadForm( |
| 236 | + $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) |
| 237 | + ); |
| 238 | + return; |
| 239 | + } |
| 240 | + |
| 241 | + // Upload verification |
| 242 | + $details = $this->mUpload->verifyUpload(); |
| 243 | + if ( $details['status'] != UploadBase::OK ) { |
| 244 | + $this->processVerificationError( $details ); |
| 245 | + return; |
| 246 | + } |
| 247 | + |
| 248 | + $this->mLocalFile = $this->mUpload->getLocalFile(); |
| 249 | + |
| 250 | + // Get the page text if this is not a reupload |
| 251 | + if( !$this->mForReUpload ) { |
| 252 | + $pageText = self::getInitialPageText( |
| 253 | + $this->mComment, $this->mLicense, |
| 254 | + $this->mCopyrightStatus, $this->mCopyrightSource ); |
| 255 | + } else { |
| 256 | + $pageText = false; |
| 257 | + } |
| 258 | + |
| 259 | + $status = $this->mUpload->performUpload( |
| 260 | + $this->mComment, $pageText, $this->mWatchthis, $wgUser |
| 261 | + ); |
| 262 | + |
| 263 | + if ( !$status->isGood() ) { |
| 264 | + $this->showUploadError( $wgOut->parse( $status->getWikiText() ) ); |
| 265 | + return; |
| 266 | + } |
| 267 | + |
| 268 | + // Success, redirect to description page |
| 269 | + $this->mUploadSuccessful = true; |
| 270 | + |
| 271 | + $wgOut->setArticleBodyOnly( true ); |
| 272 | + $wgOut->clearHTML(); |
| 273 | + |
| 274 | + $thumbWidth = $wgRequest->getInt( 'wpThumbWidth', 75 ); |
| 275 | + |
| 276 | + // The old version below, which initially used $this->mDesiredDestName |
| 277 | + // instead of that getTitle() caused plenty o' fatals...the new version |
| 278 | + // seems to be OK...I think. |
| 279 | + //$img = wfFindFile( $this->mUpload->getTitle() ); |
| 280 | + $img = $this->mLocalFile; |
| 281 | + |
| 282 | + if ( !$img ) { |
| 283 | + // This should NOT be happening...the getThumbnail() call below |
| 284 | + // will cause a fatal error if $img is not an object |
| 285 | + error_log( |
| 286 | + 'FanBox/MiniAjaxUpload FATAL! $this->mUpload is:' . |
| 287 | + print_r( $this->mUpload, true ) |
| 288 | + ); |
| 289 | + } |
| 290 | + |
| 291 | + $thumb = $img->getThumbnail( $thumbWidth ); |
| 292 | + $img_tag = $thumb->toHtml(); |
| 293 | + $slashedImgTag = addslashes( $img_tag ); |
| 294 | + |
| 295 | + // $this->mDesiredDestName doesn't include the timestamp so we can't |
| 296 | + // use it as the second param to the JS function... |
| 297 | + // @see extensions/QuizGame/QuestionGameUpload.php, |
| 298 | + // SpecialQuestionGameUpload::processUpload() for a detailed |
| 299 | + // description of wtf's going on in here |
| 300 | + $imgName = $img->getTitle()->getDBkey(); |
| 301 | + echo "<script language=\"javascript\"> |
| 302 | + /*<![CDATA[*/ |
| 303 | + window.parent.FanBoxes.uploadComplete(\"{$slashedImgTag}\", \"{$imgName}\", ''); |
| 304 | + /*]]>*/</script>"; |
| 305 | + } |
| 306 | +} |
| 307 | + |
| 308 | +class FanBoxAjaxUploadForm extends UploadForm { |
| 309 | + protected $mWatch; |
| 310 | + protected $mForReUpload; |
| 311 | + protected $mSessionKey; |
| 312 | + protected $mHideIgnoreWarning; |
| 313 | + protected $mDestWarningAck; |
| 314 | + protected $mDestFile; |
| 315 | + |
| 316 | + protected $mSourceIds; |
| 317 | + |
| 318 | + public function __construct( $options = array() ) { |
| 319 | + $this->mWatch = !empty( $options['watch'] ); |
| 320 | + $this->mForReUpload = !empty( $options['forreupload'] ); |
| 321 | + $this->mSessionKey = isset( $options['sessionkey'] ) |
| 322 | + ? $options['sessionkey'] : ''; |
| 323 | + $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] ); |
| 324 | + $this->mDestWarningAck = !empty( $options['destwarningack'] ); |
| 325 | + |
| 326 | + $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : ''; |
| 327 | + |
| 328 | + $sourceDescriptor = $this->getSourceSection(); |
| 329 | + $descriptor = $sourceDescriptor |
| 330 | + + $this->getDescriptionSection() |
| 331 | + + $this->getOptionsSection(); |
| 332 | + |
| 333 | + //wfRunHooks( 'UploadFormInitDescriptor', array( &$descriptor ) ); |
| 334 | + HTMLForm::__construct( $descriptor, 'upload' ); |
| 335 | + |
| 336 | + # Set some form properties |
| 337 | + $this->setSubmitText( wfMsg( 'uploadbtn' ) ); |
| 338 | + $this->setSubmitName( 'wpUpload' ); |
| 339 | + $this->setSubmitTooltip( 'upload' ); |
| 340 | + $this->setId( 'mw-upload-form' ); |
| 341 | + |
| 342 | + # Build a list of IDs for JavaScript insertion |
| 343 | + $this->mSourceIds = array(); |
| 344 | + foreach ( $sourceDescriptor as $key => $field ) { |
| 345 | + if ( !empty( $field['id'] ) ) { |
| 346 | + $this->mSourceIds[] = $field['id']; |
| 347 | + } |
| 348 | + } |
| 349 | + } |
| 350 | + |
| 351 | + function displayForm( $submitResult ) { |
| 352 | + global $wgOut; |
| 353 | + parent::displayForm( $submitResult ); |
| 354 | + if ( method_exists( $wgOut, 'allowClickjacking' ) ) { |
| 355 | + $wgOut->allowClickjacking(); |
| 356 | + } |
| 357 | + } |
| 358 | + |
| 359 | + /** |
| 360 | + * Wrap the form innards in an actual <form> element |
| 361 | + * This is here because HTMLForm's default wrapForm() is so stupid that it |
| 362 | + * doesn't let us add the onsubmit attribute...oh yeah, and because using |
| 363 | + * $wgOut->addInlineScript in that addUploadJS() function doesn't work, |
| 364 | + * either |
| 365 | + * |
| 366 | + * @param $html String: HTML contents to wrap. |
| 367 | + * @return String: wrapped HTML. |
| 368 | + */ |
| 369 | + function wrapForm( $html ) { |
| 370 | + # Include a <fieldset> wrapper for style, if requested. |
| 371 | + if ( $this->mWrapperLegend !== false ) { |
| 372 | + $html = Xml::fieldset( $this->mWrapperLegend, $html ); |
| 373 | + } |
| 374 | + # Use multipart/form-data |
| 375 | + $encType = $this->mUseMultipart |
| 376 | + ? 'multipart/form-data' |
| 377 | + : 'application/x-www-form-urlencoded'; |
| 378 | + # Attributes |
| 379 | + $attribs = array( |
| 380 | + 'action' => $this->getTitle()->getFullURL(), |
| 381 | + 'method' => 'post', |
| 382 | + 'class' => 'visualClear', |
| 383 | + 'enctype' => $encType, |
| 384 | + 'onsubmit' => 'submitForm()' // changed |
| 385 | + ); |
| 386 | + if ( !empty( $this->mId ) ) { |
| 387 | + $attribs['id'] = $this->mId; |
| 388 | + } |
| 389 | + |
| 390 | + // fucking newlines... |
| 391 | + return "<script type=\"text/javascript\"> |
| 392 | + function submitForm() { |
| 393 | + if ( document.getElementById( 'wpUploadFile' ).value != '' ) { |
| 394 | + window.parent.FanBoxes.completeImageUpload(); |
| 395 | + return true; |
| 396 | + } else { |
| 397 | + alert( '" . str_replace( "\n", ' ', wfMsg( 'emptyfile' ) ) . "' ); |
| 398 | + return false; |
| 399 | + } |
| 400 | + } |
| 401 | +</script>\n" . Html::rawElement( 'form', $attribs, $html ); |
| 402 | + } |
| 403 | + |
| 404 | + /** |
| 405 | + * Get the descriptor of the fieldset that contains the file source |
| 406 | + * selection. The section is 'source' |
| 407 | + * |
| 408 | + * @return array Descriptor array |
| 409 | + */ |
| 410 | + protected function getSourceSection() { |
| 411 | + global $wgUser, $wgRequest; |
| 412 | + |
| 413 | + if ( $this->mSessionKey ) { |
| 414 | + return array( |
| 415 | + 'wpSessionKey' => array( |
| 416 | + 'type' => 'hidden', |
| 417 | + 'default' => $this->mSessionKey, |
| 418 | + ), |
| 419 | + 'wpSourceType' => array( |
| 420 | + 'type' => 'hidden', |
| 421 | + 'default' => 'Stash', |
| 422 | + ), |
| 423 | + ); |
| 424 | + } |
| 425 | + |
| 426 | + $canUploadByUrl = UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ); |
| 427 | + $radio = $canUploadByUrl; |
| 428 | + $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) ); |
| 429 | + |
| 430 | + $descriptor = array(); |
| 431 | + $descriptor['UploadFile'] = array( |
| 432 | + 'class' => 'UploadSourceField', |
| 433 | + 'section' => 'source', |
| 434 | + 'type' => 'file', |
| 435 | + 'id' => 'wpUploadFile', |
| 436 | + 'label-message' => 'sourcefilename', |
| 437 | + 'upload-type' => 'File', |
| 438 | + 'radio' => &$radio, |
| 439 | + // help removed, we don't need any tl,dr on this mini-upload form |
| 440 | + 'checked' => $selectedSourceType == 'file', |
| 441 | + ); |
| 442 | + if ( $canUploadByUrl ) { |
| 443 | + $descriptor['UploadFileURL'] = array( |
| 444 | + 'class' => 'UploadSourceField', |
| 445 | + 'section' => 'source', |
| 446 | + 'id' => 'wpUploadFileURL', |
| 447 | + 'label-message' => 'sourceurl', |
| 448 | + 'upload-type' => 'url', |
| 449 | + 'radio' => &$radio, |
| 450 | + 'checked' => $selectedSourceType == 'url', |
| 451 | + ); |
| 452 | + } |
| 453 | + |
| 454 | + return $descriptor; |
| 455 | + } |
| 456 | + |
| 457 | + /** |
| 458 | + * Get the descriptor of the fieldset that contains the file description |
| 459 | + * input. The section is 'description' |
| 460 | + * |
| 461 | + * @note I thought that adding the time() call to the 'default' and/or |
| 462 | + * 'nodata' keys would do what I assumed, i.e. prepend the file name w/ |
| 463 | + * the timestamp, but it did nothing. @see wrapForm() instead |
| 464 | + * |
| 465 | + * @return array Descriptor array |
| 466 | + */ |
| 467 | + protected function getDescriptionSection() { |
| 468 | + $descriptor = array( |
| 469 | + 'DestFile' => array( |
| 470 | + 'type' => 'hidden', |
| 471 | + 'id' => 'wpDestFile', |
| 472 | + 'size' => 60, |
| 473 | + 'default' => $this->mDestFile, |
| 474 | + # FIXME: hack to work around poor handling of the 'default' option in HTMLForm |
| 475 | + 'nodata' => strval( $this->mDestFile ) !== '', |
| 476 | + 'readonly' => true // users do not need to change the file name; normally this is true only when reuploading |
| 477 | + ) |
| 478 | + ); |
| 479 | + |
| 480 | + global $wgUseCopyrightUpload; |
| 481 | + if ( $wgUseCopyrightUpload ) { |
| 482 | + $descriptor['UploadCopyStatus'] = array( |
| 483 | + 'type' => 'text', |
| 484 | + 'section' => 'description', |
| 485 | + 'id' => 'wpUploadCopyStatus', |
| 486 | + 'label-message' => 'filestatus', |
| 487 | + ); |
| 488 | + $descriptor['UploadSource'] = array( |
| 489 | + 'type' => 'text', |
| 490 | + 'section' => 'description', |
| 491 | + 'id' => 'wpUploadSource', |
| 492 | + 'label-message' => 'filesource', |
| 493 | + ); |
| 494 | + } |
| 495 | + |
| 496 | + return $descriptor; |
| 497 | + } |
| 498 | + |
| 499 | + /** |
| 500 | + * Get the descriptor of the fieldset that contains the upload options, |
| 501 | + * such as "watch this file". The section is 'options' |
| 502 | + * |
| 503 | + * @return array Descriptor array |
| 504 | + */ |
| 505 | + protected function getOptionsSection() { |
| 506 | + $descriptor = array(); |
| 507 | + |
| 508 | + $descriptor['wpDestFileWarningAck'] = array( |
| 509 | + 'type' => 'hidden', |
| 510 | + 'id' => 'wpDestFileWarningAck', |
| 511 | + 'default' => $this->mDestWarningAck ? '1' : '', |
| 512 | + ); |
| 513 | + |
| 514 | + if ( $this->mForReUpload ) { |
| 515 | + $descriptor['wpForReUpload'] = array( |
| 516 | + 'type' => 'hidden', |
| 517 | + 'id' => 'wpForReUpload', |
| 518 | + 'default' => '1', |
| 519 | + ); |
| 520 | + } |
| 521 | + |
| 522 | + return $descriptor; |
| 523 | + } |
| 524 | + |
| 525 | + /** |
| 526 | + * Add the upload JS and show the form. |
| 527 | + */ |
| 528 | + public function show() { |
| 529 | + HTMLForm::show(); |
| 530 | + } |
| 531 | + |
| 532 | + /** |
| 533 | + * Empty function; submission is handled elsewhere. |
| 534 | + * |
| 535 | + * @return bool false |
| 536 | + */ |
| 537 | + function trySubmit() { |
| 538 | + return false; |
| 539 | + } |
| 540 | +} |
| 541 | + |
| 542 | +/** |
| 543 | + * Quick helper class for SpecialFanBoxAjaxUpload::loadRequest; this prefixes |
| 544 | + * the filename with the timestamp. Yes, another class is needed for it. *sigh* |
| 545 | + */ |
| 546 | +class FanBoxUpload extends UploadFromFile { |
| 547 | + /** |
| 548 | + * Create a form of UploadBase depending on wpSourceType and initializes it |
| 549 | + */ |
| 550 | + public static function createFromRequest( &$request, $type = null ) { |
| 551 | + $handler = new self; |
| 552 | + $handler->initializeFromRequest( $request ); |
| 553 | + return $handler; |
| 554 | + } |
| 555 | + |
| 556 | + function initializeFromRequest( &$request ) { |
| 557 | + $desiredDestName = $request->getText( 'wpDestFile' ); |
| 558 | + if( !$desiredDestName ) { |
| 559 | + $desiredDestName = $request->getFileName( 'wpUploadFile' ); |
| 560 | + } |
| 561 | + $desiredDestName = time() . '-' . $desiredDestName; |
| 562 | + return $this->initializePathInfo( |
| 563 | + $desiredDestName, |
| 564 | + $request->getFileTempName( 'wpUploadFile' ), |
| 565 | + $request->getFileSize( 'wpUploadFile' ) |
| 566 | + ); |
| 567 | + } |
| 568 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/MiniAjaxUpload.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 569 | + native |
Index: trunk/extensions/FanBoxes/FanBoxes.css |
— | — | @@ -0,0 +1,457 @@ |
| 2 | +/* CSS for FanBoxes extension */ |
| 3 | +/* Create Form */ |
| 4 | +.create-fanbox-text-and-color { |
| 5 | + width: 550px; |
| 6 | + margin-bottom: 10px; |
| 7 | +} |
| 8 | + |
| 9 | +h3 { |
| 10 | + margin-top: 5px; |
| 11 | + margin-bottom: 5px; |
| 12 | + font-size: 14px; |
| 13 | +} |
| 14 | + |
| 15 | +.create-fanbox-title { |
| 16 | + margin-bottom: 10px; |
| 17 | + width: 550px; |
| 18 | +} |
| 19 | + |
| 20 | +.create-fanbox-text { |
| 21 | + width: 550px; |
| 22 | +} |
| 23 | + |
| 24 | +.category-section { |
| 25 | + width: 550px; |
| 26 | +} |
| 27 | + |
| 28 | +h1 { |
| 29 | + font-size: 16px; |
| 30 | + margin: 10px 0px 10px 0px !important; |
| 31 | + border-bottom: none; |
| 32 | + font-weight: bold; |
| 33 | +} |
| 34 | + |
| 35 | +#addImage { |
| 36 | + font-size: 9px; |
| 37 | + color: #285C98; |
| 38 | + cursor: pointer; |
| 39 | + display: inline; |
| 40 | +} |
| 41 | + |
| 42 | +#closeImage { |
| 43 | + font-size: 9px; |
| 44 | + color: #285C98; |
| 45 | + cursor: pointer; |
| 46 | + display: none; |
| 47 | +} |
| 48 | + |
| 49 | +.create-fanbox-image { |
| 50 | + display: none; |
| 51 | +} |
| 52 | + |
| 53 | +#countdownbox { |
| 54 | + padding-left: 10px; |
| 55 | +} |
| 56 | + |
| 57 | +#fanbox-left-text { |
| 58 | + float: left; |
| 59 | + width: 180px; |
| 60 | + padding-right: 10px; |
| 61 | +} |
| 62 | + |
| 63 | +#fanbox-right-text { |
| 64 | + float: right; |
| 65 | + width: 350px; |
| 66 | +} |
| 67 | + |
| 68 | +#add-colors-left { |
| 69 | + width: 150px; |
| 70 | + margin: 0px 2px 0px 0px; |
| 71 | + float: left; |
| 72 | +} |
| 73 | + |
| 74 | +#colorpickerholder { |
| 75 | + position: relative; |
| 76 | + padding: 6px; |
| 77 | + background-color: #eeeeee; |
| 78 | + width: 370px; |
| 79 | + height: 190px; |
| 80 | + float: left; |
| 81 | +} |
| 82 | + |
| 83 | +.imageUpload-frame { |
| 84 | + height: 90px; |
| 85 | +} |
| 86 | + |
| 87 | +.fanBoxTable { |
| 88 | + cursor: pointer; |
| 89 | + height: 65px; |
| 90 | + width: 270px; |
| 91 | +} |
| 92 | + |
| 93 | +#fanBoxLeftSideOutput { |
| 94 | + width: 45px; |
| 95 | + height: 57px; |
| 96 | + font-size: 20px; |
| 97 | + text-align: center; |
| 98 | + padding: 3px 5px 3px 5px; |
| 99 | + border-bottom: 1px #000000 solid; |
| 100 | + border-top: 1px #000000 solid; |
| 101 | + border-left: 1px #000000 solid; |
| 102 | + border-right: 1px #000000 solid; |
| 103 | +} |
| 104 | + |
| 105 | +#fanBoxLeftSideContainer { |
| 106 | + width: 55px; |
| 107 | + height: 63px; |
| 108 | + text-align: center; |
| 109 | + border-bottom: 1px #000000 solid; |
| 110 | + border-top: 1px #000000 solid; |
| 111 | + border-left: 1px #000000 solid; |
| 112 | + border-right: 1px #000000 solid; |
| 113 | +} |
| 114 | + |
| 115 | +#fanBoxLeftSideOutput2 { |
| 116 | + width: 45px; |
| 117 | + height: 57px; |
| 118 | + font-size: 20px; |
| 119 | + text-align: center; |
| 120 | + padding: 3px 5px 3px 5px; |
| 121 | +} |
| 122 | + |
| 123 | +#fanBoxRightSideOutput { |
| 124 | + width: 202px; |
| 125 | + height: 57px; |
| 126 | + font-size: 14px; |
| 127 | + padding: 3px 5px 3px 5px; |
| 128 | + border-bottom: 1px #000000 solid; |
| 129 | + border-top: 1px #000000 solid; |
| 130 | + border-right: 1px #000000 solid; |
| 131 | +} |
| 132 | + |
| 133 | +#fanBoxRightSideContainer { |
| 134 | + width: 212px; |
| 135 | + height: 63px; |
| 136 | + border-bottom: 1px #000000 solid; |
| 137 | + border-top: 1px #000000 solid; |
| 138 | + border-right: 1px #000000 solid; |
| 139 | +} |
| 140 | + |
| 141 | +#fanBoxRightSideOutput2 { |
| 142 | + width: 202px; |
| 143 | + height: 57px; |
| 144 | + font-size: 14px; |
| 145 | + padding: 3px 5px 3px 5px; |
| 146 | +} |
| 147 | + |
| 148 | +#fanBoxLeftSideOutputProfile { |
| 149 | + width: 35px; |
| 150 | + height: 52px; |
| 151 | + font-size: 20px; |
| 152 | + text-align: center; |
| 153 | + padding: 0px 5px 0px 5px; |
| 154 | + border-bottom: 1px #000000 solid; |
| 155 | + border-top: 1px #000000 solid; |
| 156 | + border-left: 1px #000000 solid; |
| 157 | + border-right: 1px #000000 solid; |
| 158 | +} |
| 159 | + |
| 160 | +#fanBoxRightSideOutputProfile { |
| 161 | + width: 150px; |
| 162 | + height: 52px; |
| 163 | + font-size: 14px; |
| 164 | + padding: 0px 5px 0px 5px; |
| 165 | + border-bottom: 1px #000000 solid; |
| 166 | + border-top: 1px #000000 solid; |
| 167 | + border-right: 1px #000000 solid; |
| 168 | +} |
| 169 | + |
| 170 | +.categorytext { |
| 171 | + width: 700px; |
| 172 | +} |
| 173 | + |
| 174 | +.lr-left { |
| 175 | + float: left; |
| 176 | + width: 55%; |
| 177 | +} |
| 178 | + |
| 179 | +.lr-right { |
| 180 | + float: right; |
| 181 | + border-left: 1px solid #DCDCDC; |
| 182 | + float: right; |
| 183 | + padding: 0px 0px 0px 20px; |
| 184 | + margin: 0px 0px 20px 0px; |
| 185 | + width: 40%; |
| 186 | +} |
| 187 | + |
| 188 | +/* End of Create Form */ |
| 189 | + |
| 190 | +.fantag-image { |
| 191 | + margin: 0px 0px 24px 0px; |
| 192 | +} |
| 193 | + |
| 194 | +.fanbox-item { |
| 195 | + width: 270px; |
| 196 | + height: 100%; |
| 197 | + margin: 0px 0px 5px 0px; |
| 198 | +} |
| 199 | + |
| 200 | +.individual-fanbox { |
| 201 | + display: block; |
| 202 | + width: 270px; |
| 203 | + height: 100%; |
| 204 | +} |
| 205 | + |
| 206 | +.individual-fanboxtest { |
| 207 | + display: block; |
| 208 | +} |
| 209 | + |
| 210 | +.fanbox-pop-up-box { |
| 211 | + width: 258px; |
| 212 | + display: none; |
| 213 | + padding: 5px; |
| 214 | + border: 1px solid #dcdcdc; |
| 215 | + height: 53px; |
| 216 | +} |
| 217 | + |
| 218 | +.fanbox-pop-up-box-profile { |
| 219 | + width: 201px; |
| 220 | + height: 50px; |
| 221 | + display: none; |
| 222 | + border: 1px solid #dcdcdc; |
| 223 | +} |
| 224 | + |
| 225 | +.fanBoxTableProfile { |
| 226 | + cursor: pointer; |
| 227 | + width: 100%; |
| 228 | + height: 100%; |
| 229 | + line-height: 1; |
| 230 | +} |
| 231 | + |
| 232 | +.show-message-container { |
| 233 | + position: relative; |
| 234 | +} |
| 235 | + |
| 236 | +.show-message-container-profile { |
| 237 | + width: 75%; |
| 238 | + height: 75%; |
| 239 | + position: relative; |
| 240 | +} |
| 241 | + |
| 242 | +.fanboxpopup-container { |
| 243 | + width: 270px; |
| 244 | + height: 100%; |
| 245 | +} |
| 246 | + |
| 247 | +.permalink-container { |
| 248 | + position: relative; |
| 249 | +} |
| 250 | + |
| 251 | +.relativeposition { |
| 252 | + position: relative; |
| 253 | +} |
| 254 | + |
| 255 | +.75percent { |
| 256 | + width: 75%; |
| 257 | + height: 75%; |
| 258 | +} |
| 259 | + |
| 260 | +a.perma { |
| 261 | + position: absolute; |
| 262 | + bottom: 0.3em; |
| 263 | + right: 0.3em; |
| 264 | + display: block; |
| 265 | + z-index: 1; |
| 266 | +} |
| 267 | + |
| 268 | +.show-addremove-message { |
| 269 | + color: red; |
| 270 | + font-weight: bold; |
| 271 | + text-align: center; |
| 272 | + height: 63px; |
| 273 | + width: 268px; |
| 274 | + border-bottom: 1px #000000 solid; |
| 275 | + border-top: 1px #000000 solid; |
| 276 | + border-left: 1px #000000 solid; |
| 277 | + border-right: 1px #000000 solid; |
| 278 | +} |
| 279 | + |
| 280 | +.show-addremove-message-half { |
| 281 | + color: red; |
| 282 | + font-weight: bold; |
| 283 | + text-align: center; |
| 284 | + height: 43px; |
| 285 | + width: 190px; |
| 286 | + padding: 5px; |
| 287 | + border-bottom: 1px #000000 solid; |
| 288 | + border-top: 1px #000000 solid; |
| 289 | + border-left: 1px #000000 solid; |
| 290 | + border-right: 1px #000000 solid; |
| 291 | +} |
| 292 | + |
| 293 | +.show-individual-addremove-message { |
| 294 | + color: red; |
| 295 | + font-weight: bold; |
| 296 | + padding-top: 10px; |
| 297 | +} |
| 298 | + |
| 299 | +.verticalalign { |
| 300 | + vertical-align: middle; |
| 301 | +} |
| 302 | + |
| 303 | +#messageforaddremove { |
| 304 | + display: none; |
| 305 | +} |
| 306 | + |
| 307 | +.fan-error { |
| 308 | + color: #ff0000; |
| 309 | + font-size: 16px; |
| 310 | + font-weight: bold; |
| 311 | +} |
| 312 | + |
| 313 | +.back-links { |
| 314 | + margin: 0px 0px 10px 0px; |
| 315 | +} |
| 316 | + |
| 317 | +.back-links a { |
| 318 | + text-decoration: none; |
| 319 | + font-weight: bold; |
| 320 | +} |
| 321 | + |
| 322 | +.fanbox-count { |
| 323 | + margin: 0px 0px 0px 0px; |
| 324 | +} |
| 325 | + |
| 326 | +.page-nav a { |
| 327 | + font-weight: bold; |
| 328 | +} |
| 329 | + |
| 330 | +.top-fanbox-num { |
| 331 | + font-weight: bold; |
| 332 | + font-size: 18px; |
| 333 | + color: #dcdcdc; |
| 334 | + width: 45px; |
| 335 | + padding: 5px 0px 0px 0px; |
| 336 | + margin: 0px 0px 0px 5px; |
| 337 | + float: left; |
| 338 | +} |
| 339 | + |
| 340 | +.top-fanbox-users { |
| 341 | + font-size: 13px; |
| 342 | + color: #797979; |
| 343 | + height: 65px; |
| 344 | + width: 100px; |
| 345 | + float: left; |
| 346 | +} |
| 347 | + |
| 348 | +.top-fanbox-creator { |
| 349 | + font-size: 13px; |
| 350 | + color: #797979; |
| 351 | + height: 65px; |
| 352 | + width: 150px; |
| 353 | + padding-left: 10px; |
| 354 | + float: left; |
| 355 | +} |
| 356 | + |
| 357 | +.centerheight { |
| 358 | + text-align: center; |
| 359 | + height: 65px; |
| 360 | +} |
| 361 | + |
| 362 | +.top-fan { |
| 363 | + padding-right: 10px; |
| 364 | + float: left; |
| 365 | +} |
| 366 | + |
| 367 | +.fanbox-nav { |
| 368 | + float: right; |
| 369 | + margin: 10px 0px 0px 0px; |
| 370 | + width: 200px; |
| 371 | + padding: 5px; |
| 372 | +} |
| 373 | + |
| 374 | +.fanbox-nav h2 { |
| 375 | + font-size: 16px; |
| 376 | + color: #333333; |
| 377 | + padding: 0px 0px 3px 0px; |
| 378 | + border-bottom: 1px solid #dcdcdc; |
| 379 | + margin:0px 0px 10px 0px !important; |
| 380 | +} |
| 381 | + |
| 382 | +.fanbox-nav a { |
| 383 | + font-weight: bold; |
| 384 | + text-decoration: none; |
| 385 | +} |
| 386 | + |
| 387 | +.top-fanboxes { |
| 388 | + float: left; |
| 389 | + margin: 10px 0px 0px 0px; |
| 390 | + position: relative; |
| 391 | + overflow: hidden; |
| 392 | +} |
| 393 | + |
| 394 | +.top-fanbox-row { |
| 395 | + clear: both; |
| 396 | +} |
| 397 | + |
| 398 | +.top-fanbox { |
| 399 | + padding-right: 10px; |
| 400 | + float: left; |
| 401 | +} |
| 402 | + |
| 403 | +.view-fanboxes-container{ |
| 404 | + padding: 0px 0px 25px 0px; |
| 405 | + position: relative; |
| 406 | +} |
| 407 | + |
| 408 | +.fanboxitem-container{ |
| 409 | + padding-right: 10px; |
| 410 | + float: left; |
| 411 | +} |
| 412 | + |
| 413 | +.fa-item { |
| 414 | + border: 1px solid #D7DEE8; |
| 415 | + padding: 7px; |
| 416 | + float: left; |
| 417 | + margin: 0px 15px 15px 0px; |
| 418 | + width: 350px; |
| 419 | +} |
| 420 | + |
| 421 | +.user-embed-tag { |
| 422 | + margin: 20px 0 10px 0; |
| 423 | +} |
| 424 | + |
| 425 | +.fanbox-page-container { |
| 426 | + padding: 5px 0 0 0; |
| 427 | +} |
| 428 | + |
| 429 | +.user-embed-tag input { |
| 430 | + width: 40%; |
| 431 | +} |
| 432 | + |
| 433 | +.users-with-fanbox h2 { |
| 434 | + border-bottom: none; |
| 435 | + font-size: 14px; |
| 436 | + font-weight: bold; |
| 437 | + color: #777; |
| 438 | + margin: 0px 0 3px 0 !important; |
| 439 | + padding: 0; |
| 440 | +} |
| 441 | + |
| 442 | +.users-with-fanbox-message { |
| 443 | + font-size: 9px; |
| 444 | + margin: 0px 0px 5px; |
| 445 | +} |
| 446 | + |
| 447 | +.users-with-fanbox img { |
| 448 | + border: 1px solid #dcdcdc; |
| 449 | + padding: 2px; |
| 450 | + background-color: #fff; |
| 451 | + margin: 0px 2px 0px; |
| 452 | +} |
| 453 | + |
| 454 | +.fanbox-right-text-message { |
| 455 | + font-size: 10px !important; |
| 456 | + font-weight: normal; |
| 457 | + margin: 0px 0px 0px 10px; |
| 458 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBoxes.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 459 | + native |
Index: trunk/extensions/FanBoxes/SpecialFanBoxes.php |
— | — | @@ -0,0 +1,477 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A special page for creating new social userboxes (a.k.a fanboxes a.k.a |
| 5 | + * fantags). |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
| 10 | +class FanBoxes extends SpecialPage { |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructor |
| 14 | + */ |
| 15 | + public function __construct() { |
| 16 | + parent::__construct( 'UserBoxes' ); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Show the special page |
| 21 | + * |
| 22 | + * @param $par Mixed: parameter passed to the page or null |
| 23 | + */ |
| 24 | + public function execute( $par ) { |
| 25 | + global $wgOut, $wgUser, $wgRequest, $wgHooks, $wgFanBoxScripts; |
| 26 | + |
| 27 | + // Set it up so that you must be logged in to create a userbox |
| 28 | + if( $wgUser->getID() == 0 ) { |
| 29 | + $wgOut->setPageTitle( wfMsgHtml( 'fanbox-woops-title' ) ); |
| 30 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 31 | + $wgOut->redirect( $login->getFullURL( 'returnto=Special:UserBoxes' ) ); |
| 32 | + return false; |
| 33 | + } |
| 34 | + |
| 35 | + // Don't allow blocked users (RT #12589) |
| 36 | + if( $wgUser->isBlocked() ) { |
| 37 | + $wgOut->blockedPage(); |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + // If the database is in read-only mode, bail out |
| 42 | + if( wfReadOnly() ) { |
| 43 | + $wgOut->readOnlyPage(); |
| 44 | + return true; |
| 45 | + } |
| 46 | + |
| 47 | + // Extension's CSS & JS |
| 48 | + $wgOut->addScriptFile( $wgFanBoxScripts . '/FanBoxes.js' ); |
| 49 | + $wgOut->addExtensionStyle( $wgFanBoxScripts . '/FanBoxes.css' ); |
| 50 | + |
| 51 | + // colorpicker |
| 52 | + $wgOut->addScript( "<script type=\"text/javascript\" src=\"http://yui.yahooapis.com/2.5.2/build/utilities/utilities.js\"></script>\n" ); |
| 53 | + $wgOut->addScript( "<script type=\"text/javascript\" src=\"http://yui.yahooapis.com/2.5.2/build/slider/slider-min.js\"></script>\n" ); |
| 54 | + $wgOut->addScript( "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://yui.yahooapis.com/2.5.2/build/colorpicker/assets/skins/sam/colorpicker.css\"/>\n" ); |
| 55 | + $wgOut->addScript( "<script type=\"text/javascript\" src=\"http://yui.yahooapis.com/2.5.2/build/colorpicker/colorpicker-min.js\"></script>\n" ); |
| 56 | + |
| 57 | + // Add i18n messages as JS globals (this can be removed once we require |
| 58 | + // ResourceLoader/MW 1.17+) |
| 59 | + $wgHooks['MakeGlobalVariablesScript'][] = 'FanBoxes::addJSGlobals'; |
| 60 | + |
| 61 | + $output = ''; |
| 62 | + $title = str_replace( '#', '', $wgRequest->getVal( 'wpTitle' ) ); |
| 63 | + $fanboxId = $wgRequest->getInt( 'id' ); |
| 64 | + $categories = ''; |
| 65 | + |
| 66 | + // Set up the edit fanbox part |
| 67 | + if( $fanboxId ) { |
| 68 | + $title = Title::newFromID( $fanboxId ); |
| 69 | + $update_fan = new FanBox( $title ); |
| 70 | + |
| 71 | + // Get categories |
| 72 | + $dbr = wfGetDB( DB_SLAVE ); |
| 73 | + $res = $dbr->select( |
| 74 | + 'categorylinks', |
| 75 | + 'cl_to', |
| 76 | + array( 'cl_from' => intval( $fanboxId ) ), |
| 77 | + __METHOD__ |
| 78 | + ); |
| 79 | + |
| 80 | + $fanboxCategory = wfMsgForContent( 'fanbox-userbox-category' ); |
| 81 | + foreach( $res as $row ) { |
| 82 | + if( |
| 83 | + $row->cl_to != $fanboxCategory && |
| 84 | + // @todo FIXME: i18n |
| 85 | + strpos( $row->cl_to, 'Userboxes_by_User_' ) === false |
| 86 | + ) |
| 87 | + { |
| 88 | + $categories .= ( ( $categories ) ? ', ' : '' ) . $row->cl_to; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + $output .= " |
| 93 | + <form action=\"\" method=\"post\" name=\"form1\"> |
| 94 | + <input type=\"hidden\" name=\"fantag_image_name\" id=\"fantag_image_name\" value=\"{$update_fan->getFanBoxImage()}\"> |
| 95 | + <input type=\"hidden\" name=\"textSizeRightSide\" id=\"textSizeRightSide\" value=\"{$update_fan->getFanBoxRightTextSize()}\" > |
| 96 | + <input type=\"hidden\" name=\"textSizeLeftSide\" id=\"textSizeLeftSide\" value=\"{$update_fan->getFanBoxLeftTextSize()}\"> |
| 97 | + <input type=\"hidden\" name=\"bgColorLeftSideColor\" id=\"bgColorLeftSideColor\" value=\"{$update_fan->getFanBoxLeftBgColor()}\"> |
| 98 | + <input type=\"hidden\" name=\"textColorLeftSideColor\" id=\"textColorLeftSideColor\" value=\"{$update_fan->getFanBoxLeftTextColor()}\"> |
| 99 | + <input type=\"hidden\" name=\"bgColorRightSideColor\" id=\"bgColorRightSideColor\" value=\"{$update_fan->getFanBoxRightBgColor()}\"> |
| 100 | + <input type=\"hidden\" name=\"textColorRightSideColor\" id=\"textColorRightSideColor\" value=\"{$update_fan->getFanBoxRightTextColor()}\">"; |
| 101 | + |
| 102 | + if( $update_fan->getFanBoxImage() ) { |
| 103 | + $fantag_image_width = 45; |
| 104 | + $fantag_image_height = 53; |
| 105 | + $fantag_image = wfFindFile( $update_fan->getFanBoxImage() ); |
| 106 | + $fantag_image_url = ''; |
| 107 | + if ( is_object( $fantag_image ) ) { |
| 108 | + $fantag_image_url = $fantag_image->createThumb( |
| 109 | + $fantag_image_width, |
| 110 | + $fantag_image_height |
| 111 | + ); |
| 112 | + } |
| 113 | + $fantag_image_tag = '<img alt="" src="' . $fantag_image_url . '" />'; |
| 114 | + } |
| 115 | + |
| 116 | + if( $update_fan->getFanBoxLeftText() == '' ) { |
| 117 | + $fantag_leftside = $fantag_image_tag; |
| 118 | + $fantag_imageholder = $fantag_image_tag; |
| 119 | + } else { |
| 120 | + $fantag_leftside = $update_fan->getFanBoxLeftText(); |
| 121 | + $fantag_imageholder = ''; |
| 122 | + } |
| 123 | + |
| 124 | + $leftfontsize = $rightfontsize = ''; |
| 125 | + if( $update_fan->getFanBoxLeftTextSize() == 'mediumfont' ) { |
| 126 | + $leftfontsize = '14px'; |
| 127 | + } |
| 128 | + if( $update_fan->getFanBoxLeftTextSize() == 'bigfont' ) { |
| 129 | + $leftfontsize = '20px'; |
| 130 | + } |
| 131 | + |
| 132 | + if( $update_fan->getFanBoxRightTextSize() == 'smallfont' ) { |
| 133 | + $rightfontsize = '12px'; |
| 134 | + } |
| 135 | + if( $update_fan->getFanBoxRightTextSize() == 'mediumfont' ) { |
| 136 | + $rightfontsize = '14px'; |
| 137 | + } |
| 138 | + |
| 139 | + $output .= "\n" . '<table class="fanBoxTable" border="0" cellpadding="0" cellspacing="0"> |
| 140 | + <tr> |
| 141 | + <td id="fanBoxLeftSideContainer" bgcolor="' . $update_fan->getFanBoxLeftBgColor() . '"> |
| 142 | + <table cellspacing="0" width="55px" height="63px"> |
| 143 | + <tr> |
| 144 | + <td id="fanBoxLeftSideOutput2" style="color:' . |
| 145 | + $update_fan->getFanBoxLeftTextColor() . |
| 146 | + '; font-size:' . $leftfontsize . '">' . |
| 147 | + $fantag_leftside . |
| 148 | + '</td> |
| 149 | + </table> |
| 150 | + </td> |
| 151 | + <td id="fanBoxRightSideContainer" bgcolor="' . $update_fan->getFanBoxRightBgColor() . '"> |
| 152 | + <table cellspacing="0"> |
| 153 | + <tr> |
| 154 | + <td id="fanBoxRightSideOutput2" style="color:' . |
| 155 | + $update_fan->getFanBoxRightTextColor() . |
| 156 | + '; font-size:' . $rightfontsize . '">' . |
| 157 | + $update_fan->getFanBoxRightText() . |
| 158 | + '</td> |
| 159 | + </table> |
| 160 | + </td> |
| 161 | + </table>'; |
| 162 | + |
| 163 | + $output .= '<h1>' . wfMsg( 'fanbox-addtext' ) . '</h1> |
| 164 | + <div class="create-fanbox-text"> |
| 165 | + <div id="fanbox-left-text"> |
| 166 | + <h3>' . wfMsg( 'fanbox-leftsidetext' ) . "<span id=\"addImage\" onclick=\"FanBoxes.displayAddImage('create-fanbox-image', 'addImage', 'closeImage')\">" . |
| 167 | + wfMsg( 'fanbox-display-image' ) . "</span> <span id=\"closeImage\" onclick=\"FanBoxes.displayAddImage('create-fanbox-image', 'closeImage', 'addImage')\">" . |
| 168 | + wfMsg( 'fanbox-close-image' ) . "</span></h3> |
| 169 | + <input type=\"text\" name=\"inputLeftSide\" id=\"inputLeftSide\" value=\"{$update_fan->getFanBoxLeftText()}\" oninput=\"FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()\" onkeyup=\"FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()\" onkeydown=\"FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()\" onpaste=\"FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()\" onkeypress=\"FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()\" maxlength=\"11\"><br /> |
| 170 | + <font size=\"1\">" . wfMsg( 'fanbox-leftsideinstructions' ) . '</font> |
| 171 | + </div> |
| 172 | + <div id="fanbox-right-text"> |
| 173 | + <h3>' . wfMsg( 'fanbox-rightsidetext' ) . '<span class="fanbox-right-text-message">' . wfMsg( 'fanbox-charsleft', '<input readonly="readonly" type="text" name="countdown" style="width:20px; height:15px;" value="70" /> ' ) . "</span></h3> |
| 174 | + <input type=\"text\" name=\"inputRightSide\" id=\"inputRightSide\" style=\"width:350px\" value=\"{$update_fan->getFanBoxRightText()}\" oninput=\"FanBoxes.displayRightSide(); |
| 175 | + rightSideFanBoxFormat()\" |
| 176 | + onkeydown=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\" |
| 177 | + onkeyup=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\" |
| 178 | + onpaste=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\" |
| 179 | + onkeypress=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\" |
| 180 | + maxlength=\"70\" /><br /> |
| 181 | + <font size=\"1\">" . wfMsg( 'fanbox-rightsideinstructions' ) . '</font> |
| 182 | + </div> |
| 183 | + </form> |
| 184 | + </div>'; |
| 185 | + |
| 186 | + $output .= ' |
| 187 | + <div id="create-fanbox-image" class="create-fanbox-image"> |
| 188 | + <h1>' . wfMsg( 'fanbox-leftsideimage' ) . ' <font size="1">' . wfMsg( 'fanbox-leftsideimageinstructions' ) . " </font></h1> |
| 189 | + <div id=\"fanbox_image\" onclick=\"FanBoxes.insertImageToLeft()\">$fantag_imageholder</div> |
| 190 | + <div id=\"fanbox_image2\"> </div> |
| 191 | + <div id=\"real-form\" style=\"display:block;height:70px;\"> |
| 192 | + <iframe id=\"imageUpload-frame\" class=\"imageUpload-frame\" width=\"700\" |
| 193 | + scrolling=\"no\" frameborder=\"0\" src=\"" . |
| 194 | + SpecialPage::getTitleFor( 'FanBoxAjaxUpload' )->escapeFullURL() . '"> |
| 195 | + </iframe> |
| 196 | + </div> |
| 197 | + </div>'; |
| 198 | + |
| 199 | + $output .= $this->colorPickerAndCategoryCloud( $categories ); |
| 200 | + |
| 201 | + $output .= '<div class="create-fanbox-buttons"> |
| 202 | + <input type="button" class="site-button" value="' . |
| 203 | + wfMsg( 'fanbox-update-button' ) . |
| 204 | + '" size="20" onclick="FanBoxes.createFantagSimple()" /> |
| 205 | + </div>'; |
| 206 | + } |
| 207 | + |
| 208 | + // Set it up so that the page title includes the title of the red link that the user clicks on |
| 209 | + $destination = $wgRequest->getVal( 'destName' ); |
| 210 | + $page_title = wfMsg( 'fan-addfan-title' ); |
| 211 | + if( $destination ) { |
| 212 | + $page_title = wfMsg( 'fan-createfor', str_replace( '_', ' ', $destination ) ); |
| 213 | + } |
| 214 | + if( $fanboxId ) { |
| 215 | + $page_title = wfMsg( 'fan-updatefan', str_replace( '_', ' ', $update_fan->getName() ) ); |
| 216 | + } |
| 217 | + |
| 218 | + $wgOut->setPageTitle( $page_title ); |
| 219 | + |
| 220 | + // Set it up so that the title of the page the user creates using the create form ends |
| 221 | + // up being the title of the red link he clicked on to get to the create form |
| 222 | + if( $destination ) { |
| 223 | + $title = $destination; |
| 224 | + } |
| 225 | + |
| 226 | + if( !$fanboxId ) { |
| 227 | + $output .= '<div class="lr-right">' . |
| 228 | + wfMsgExt( 'userboxes-instructions', 'parse' ) . |
| 229 | + '</div> |
| 230 | + |
| 231 | + <form action="" method="post" name="form1"> |
| 232 | + <input type="hidden" name="fantag_image_name" id="fantag_image_name" /> |
| 233 | + <input type="hidden" name="fantag_imgname" id="fantag_imgname" /> |
| 234 | + <input type="hidden" name="fantag_imgtag" id="fantag_imgtag" /> |
| 235 | + <input type="hidden" name="textSizeRightSide" id="textSizeRightSide" /> |
| 236 | + <input type="hidden" name="textSizeLeftSide" id="textSizeLeftSide" /> |
| 237 | + <input type="hidden" name="bgColorLeftSideColor" id="bgColorLeftSideColor" value="" /> |
| 238 | + <input type="hidden" name="textColorLeftSideColor" id="textColorLeftSideColor" value="" /> |
| 239 | + <input type="hidden" name="bgColorRightSideColor" id="bgColorRightSideColor" value="" /> |
| 240 | + <input type="hidden" name="textColorRightSideColor" id="textColorRightSideColor" value="" />'; |
| 241 | + |
| 242 | + if( !$destination ) { |
| 243 | + $output .= '<h1>' . wfMsg( 'fanbox-title' ) . '</h1> |
| 244 | + <div class="create-fanbox-title"> |
| 245 | + <input type="text" name="wpTitle" id="wpTitle" value="' . |
| 246 | + $wgRequest->getVal( 'wpTitle' ) . |
| 247 | + '" style="width:350px" maxlength="60" /><br /> |
| 248 | + <font size="1">(' . wfMsg( 'fanboxes-maxchars-sixty' ) . ')</font><br /> |
| 249 | + </div>'; |
| 250 | + } else { |
| 251 | + $output .= Html::hidden( 'wpTitle', $destination, array( 'id' => 'wpTitle' ) ); |
| 252 | + } |
| 253 | + |
| 254 | + $output .= '<table class="fanBoxTable" border="0" cellpadding="0" cellspacing="0"> |
| 255 | + <tr> |
| 256 | + <td id="fanBoxLeftSideContainer"> |
| 257 | + <table cellspacing="0" width="55px" height="63px"> |
| 258 | + <tr> |
| 259 | + <td id="fanBoxLeftSideOutput2"></td> |
| 260 | + </tr> |
| 261 | + </table> |
| 262 | + </td> |
| 263 | + <td id="fanBoxRightSideContainer"> |
| 264 | + <table cellspacing="0" width="212px" height="63px"> |
| 265 | + <tr> |
| 266 | + <td id="fanBoxRightSideOutput2"></td> |
| 267 | + </tr> |
| 268 | + </table> |
| 269 | + </td> |
| 270 | + </tr> |
| 271 | + </table>' . "\n"; |
| 272 | + |
| 273 | + $output.= '<h1>' . wfMsg( 'fanbox-addtext' ) . '</h1> |
| 274 | + <div class="create-fanbox-text"> |
| 275 | + <div id="fanbox-left-text"> |
| 276 | + <h3>' . wfMsg( 'fanbox-leftsidetext' ) . "<span id=\"addImage\" onclick=\"FanBoxes.displayAddImage('create-fanbox-image', 'addImage', 'closeImage')\">" . wfMsg( 'fanbox-display-image' ) . "</span> <span id=\"closeImage\" onclick=\"FanBoxes.displayAddImage('create-fanbox-image', 'closeImage', 'addImage')\">" . wfMsg( 'fanbox-close-image' ) . '</span></h3> |
| 277 | + <input type="text" name="inputLeftSide" id="inputLeftSide" oninput="FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()" onkeyup="FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()" onkeydown="FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()" onpaste="FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()" onkeypress="FanBoxes.displayLeftSide(); FanBoxes.leftSideFanBoxFormat()" |
| 278 | + maxlength="11" /><br /> |
| 279 | + <font size="1">' . wfMsgForContent( 'fanbox-leftsideinstructions' ) . '</font> |
| 280 | + </div> |
| 281 | + <div id="fanbox-right-text"> |
| 282 | + <h3>' . wfMsgForContent( 'fanbox-rightsidetext' ) . '<span id="countdownbox"> <span class="fanbox-right-text-message">' |
| 283 | + . wfMsg( 'fanbox-charsleft', '<input readonly="readonly" type="text" name="countdown" style="width:20px; height:15px;" value="70" />' ) . '</span></span></h3> |
| 284 | + <input type="text" name="inputRightSide" id="inputRightSide" style="width:350px" oninput="FanBoxes.displayRightSide(); |
| 285 | + FanBoxes.rightSideFanBoxFormat()" |
| 286 | + onkeydown="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()" |
| 287 | + onkeyup="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()" |
| 288 | + onpaste="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()" |
| 289 | + onkeypress="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()" |
| 290 | + maxlength="70" /><br /> |
| 291 | + <font size="1">' . wfMsg( 'fanbox-rightsideinstructions' ) . '</font> |
| 292 | + </div> |
| 293 | + <div class="cleared"></div> |
| 294 | + </form> |
| 295 | + </div>'; |
| 296 | + |
| 297 | + $output .= '<div id="create-fanbox-image" class="create-fanbox-image"> |
| 298 | + <h1>' . wfMsg( 'fanbox-leftsideimage' ) . |
| 299 | + ' <font size="1">' . |
| 300 | + wfMsgForContent( 'fanbox-leftsideimageinstructions' ) . |
| 301 | + ' </font></h1> |
| 302 | + <div id="fanbox_image" onclick="FanBoxes.insertImageToLeft()"></div> |
| 303 | + <div id="fanbox_image2"></div> |
| 304 | + |
| 305 | + <div id="real-form" style="display: block; height: 70px;"> |
| 306 | + <iframe id="imageUpload-frame" class="imageUpload-frame" width="700" |
| 307 | + scrolling="no" frameborder="0" src="' . SpecialPage::getTitleFor( 'FanBoxAjaxUpload' )->escapeFullURL() . '"> |
| 308 | + </iframe> |
| 309 | + </div> |
| 310 | + </div>'; |
| 311 | + |
| 312 | + $output .= $this->colorPickerAndCategoryCloud( $categories ); |
| 313 | + |
| 314 | + $output .= '<div class="create-fanbox-buttons"> |
| 315 | + <input type="button" class="site-button" value="' . wfMsg( 'fanbox-create-button' ) . '" size="20" onclick="FanBoxes.createFantag()" /> |
| 316 | + </div>'; |
| 317 | + } |
| 318 | + |
| 319 | + $wgOut->addHTML( $output ); |
| 320 | + |
| 321 | + // Send values to database and create fantag page when form is submitted |
| 322 | + if( $wgRequest->wasPosted() ) { |
| 323 | + if( !$fanboxId ) { |
| 324 | + $fan = FanBox::newFromName( $title ); |
| 325 | + $fantagId = $fan->addFan( |
| 326 | + $wgRequest->getVal( 'inputLeftSide' ), |
| 327 | + $wgRequest->getVal( 'textColorLeftSideColor' ), |
| 328 | + $wgRequest->getVal( 'bgColorLeftSideColor' ), |
| 329 | + $wgRequest->getVal( 'inputRightSide' ), |
| 330 | + $wgRequest->getVal( 'textColorRightSideColor' ), |
| 331 | + $wgRequest->getVal( 'bgColorRightSideColor' ), |
| 332 | + $wgRequest->getVal( 'fantag_image_name' ), |
| 333 | + $wgRequest->getVal( 'textSizeLeftSide' ), |
| 334 | + $wgRequest->getVal( 'textSizeRightSide' ), |
| 335 | + $wgRequest->getVal( 'pageCtg' ) |
| 336 | + ); |
| 337 | + $fan->addUserFan( $fantagId ); |
| 338 | + $wgOut->redirect( $fan->title->getFullURL() ); |
| 339 | + } |
| 340 | + if( $fanboxId ) { |
| 341 | + $title = Title::newFromID( $fanboxId ); |
| 342 | + $update_fan = new FanBox( $title ); |
| 343 | + $update_fan->updateFan( |
| 344 | + $wgRequest->getVal( 'inputLeftSide' ), |
| 345 | + $wgRequest->getVal( 'textColorLeftSideColor' ), |
| 346 | + $wgRequest->getVal( 'bgColorLeftSideColor' ), |
| 347 | + $wgRequest->getVal( 'inputRightSide' ), |
| 348 | + $wgRequest->getVal( 'textColorRightSideColor' ), |
| 349 | + $wgRequest->getVal( 'bgColorRightSideColor' ), |
| 350 | + $wgRequest->getVal( 'fantag_image_name' ), |
| 351 | + $wgRequest->getVal( 'textSizeLeftSide' ), |
| 352 | + $wgRequest->getVal( 'textSizeRightSide' ), |
| 353 | + $fanboxId, |
| 354 | + $wgRequest->getVal( 'pageCtg' ) |
| 355 | + ); |
| 356 | + $wgOut->redirect( $update_fan->title->getFullURL() ); |
| 357 | + } |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + function colorPickerAndCategoryCloud( $categories ) { |
| 362 | + $output = '<div class="add-colors"> |
| 363 | + <h1>' . wfMsg( 'fan-add-colors' ) . '</h1> |
| 364 | + <div id="add-colors-left"> |
| 365 | + <form name="colorpickerradio" action=""> |
| 366 | + <input type="radio" name="colorpickerchoice" value="leftBG" checked="checked" />' . |
| 367 | + wfMsg( 'fanbox-leftbg-color' ) . |
| 368 | + '<br /> |
| 369 | + <input type="radio" name="colorpickerchoice" value="leftText" />' . |
| 370 | + wfMsg( 'fanbox-lefttext-color' ) . |
| 371 | + '<br /> |
| 372 | + <input type="radio" name="colorpickerchoice" value="rightBG" />' . |
| 373 | + wfMsg( 'fanbox-rightbg-color' ) . |
| 374 | + '<br /> |
| 375 | + <input type="radio" name="colorpickerchoice" value="rightText" />' . |
| 376 | + wfMsg( 'fanbox-righttext-color' ) . " |
| 377 | + </form> |
| 378 | + </div> |
| 379 | + |
| 380 | + <div id=\"add-colors-right\"> |
| 381 | + <div id=\"colorpickerholder\"></div> |
| 382 | + </div> |
| 383 | + |
| 384 | + <script type=\"text/javascript\"> |
| 385 | + var colorPickerTest = new YAHOO.widget.ColorPicker( 'colorpickerholder', { |
| 386 | + showhsvcontrols: true, |
| 387 | + showhexcontrols: true, |
| 388 | + images: { |
| 389 | + PICKER_THUMB: 'http://developer.yahoo.com/yui/build/colorpicker/assets/picker_thumb.png', |
| 390 | + HUE_THUMB: 'http://developer.yahoo.com/yui/build/colorpicker/assets/hue_thumb.png' |
| 391 | + } |
| 392 | + }); |
| 393 | + |
| 394 | + colorPickerTest.on( 'rgbChange', function( p_oEvent ) { |
| 395 | + var sColor = '#' + this.get( 'hex' ); |
| 396 | + |
| 397 | + if( document.colorpickerradio.colorpickerchoice[0].checked ) { |
| 398 | + document.getElementById( 'fanBoxLeftSideOutput2' ).style.backgroundColor = sColor; |
| 399 | + // The commented-out line below is the original NYC code but I noticed that it doesn't work |
| 400 | + //document.getElementById( 'fanBoxLeftSideContainer' ).style.backgroundColor = sColor; |
| 401 | + document.getElementById( 'bgColorLeftSideColor' ).value = sColor; |
| 402 | + } |
| 403 | + |
| 404 | + if( document.colorpickerradio.colorpickerchoice[1].checked ) { |
| 405 | + document.getElementById( 'fanBoxLeftSideOutput2' ).style.color = sColor; |
| 406 | + document.getElementById( 'textColorLeftSideColor' ).value = sColor; |
| 407 | + } |
| 408 | + |
| 409 | + if( document.colorpickerradio.colorpickerchoice[2].checked ) { |
| 410 | + document.getElementById( 'fanBoxRightSideOutput2' ).style.backgroundColor = sColor; |
| 411 | + // The commented-out line below is the original NYC code but I noticed that it doesn't work |
| 412 | + //document.getElementById( 'fanBoxRightSideContainer' ).style.backgroundColor = sColor; |
| 413 | + document.getElementById( 'bgColorRightSideColor' ).value = sColor; |
| 414 | + } |
| 415 | + |
| 416 | + if( document.colorpickerradio.colorpickerchoice[3].checked ) { |
| 417 | + document.getElementById( 'fanBoxRightSideOutput2' ).style.color = sColor; |
| 418 | + document.getElementById( 'textColorRightSideColor' ).value = sColor; |
| 419 | + } |
| 420 | + }); |
| 421 | + </script> |
| 422 | + <div class=\"cleared\"></div> |
| 423 | + </div>"; |
| 424 | + |
| 425 | + // Category cloud stuff |
| 426 | + $cloud = new TagCloud( 10 ); |
| 427 | + $categoriesLabel = wfMsg( 'fanbox-categories-label' ); |
| 428 | + $categoriesHelpText = wfMsg( 'fanbox-categories-help' ); |
| 429 | + |
| 430 | + $output .= '<div class="category-section">'; |
| 431 | + $tagcloud = '<div id="create-tagcloud" style="line-height: 25pt; width: 600px; padding-bottom: 15px;">'; |
| 432 | + $tagnumber = 0; |
| 433 | + $tabcounter = 1; |
| 434 | + foreach( $cloud->tags as $tag => $att ) { |
| 435 | + $tag = str_replace( 'Fans', '', $tag ); |
| 436 | + $tag = trim( $tag ); |
| 437 | + $slashedTag = $tag; // define variable |
| 438 | + // Fix for categories that contain an apostrophe |
| 439 | + if ( strpos( $tag, "'" ) ) { |
| 440 | + $slashedTag = str_replace( "'", "\'", $tag ); |
| 441 | + } |
| 442 | + $tagcloud .= " <span id=\"tag-{$tagnumber}\" style=\"font-size:{$cloud->tags[$tag]['size']}{$cloud->tags_size_type}\"> |
| 443 | + <a style='cursor:hand;cursor:pointer;text-decoration:underline' onclick=\"javascript:FanBoxes.insertTag('" . $slashedTag . "',{$tagnumber});\">{$tag}</a> |
| 444 | + </span>\n"; |
| 445 | + $tagnumber++; |
| 446 | + } |
| 447 | + |
| 448 | + $tagcloud .= '</div>'; |
| 449 | + $output .= '<div class="create-category-title">'; |
| 450 | + $output .= "<h1>$categoriesLabel</h1>"; |
| 451 | + $output .= '</div>'; |
| 452 | + $output .= "<div class=\"categorytext\">$categoriesHelpText</div>"; |
| 453 | + $output .= $tagcloud; |
| 454 | + $output .= '<textarea class="createbox" tabindex="' . $tabcounter . '" accesskey="," name="pageCtg" id="pageCtg" rows="2" cols="80">' . |
| 455 | + $categories . '</textarea><br /><br />'; |
| 456 | + $output .= '</div>'; |
| 457 | + |
| 458 | + return $output; |
| 459 | + } |
| 460 | + |
| 461 | + /** |
| 462 | + * Add some new JS globals into the page output. This can be replaced by |
| 463 | + * ResourceLoader in the future. |
| 464 | + * |
| 465 | + * @param $vars Array: array of pre-existing JS globals |
| 466 | + * @return Boolean: true |
| 467 | + */ |
| 468 | + public static function addJSGlobals( $vars ) { |
| 469 | + $vars['__FANBOX_MUSTENTER_LEFT__'] = wfMsg( 'fanbox-mustenter-left' ); |
| 470 | + $vars['__FANBOX_MUSTENTER_RIGHT__'] = wfMsg( 'fanbox-mustenter-right' ); |
| 471 | + $vars['__FANBOX_MUSTENTER_RIGHT_OR__'] = wfMsg( 'fanbox-mustenter-right-or' ); |
| 472 | + $vars['__FANBOX_MUSTENTER_TITLE__'] = wfMsg( 'fanbox-mustenter-title' ); |
| 473 | + $vars['__FANBOX_HASH__'] = wfMsg( 'fanbox-hash' ); |
| 474 | + $vars['__FANBOX_CHOOSE_ANOTHER__'] = wfMsg( 'fanbox-choose-another' ); |
| 475 | + $vars['__FANBOX_UPLOAD_NEW_IMAGE__'] = wfMsg( 'fanbox-upload-new-image' ); |
| 476 | + return true; |
| 477 | + } |
| 478 | +} |
Property changes on: trunk/extensions/FanBoxes/SpecialFanBoxes.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 479 | + native |
Index: trunk/extensions/FanBoxes/fantag.sql |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +CREATE TABLE /*_*/fantag ( |
| 3 | + `fantag_id` int(11) NOT NULL auto_increment PRIMARY KEY, |
| 4 | + `fantag_title` varchar(100) NOT NULL, |
| 5 | + `fantag_pg_id` int(11) NOT NULL, |
| 6 | + `fantag_left_text` varchar(20) default NULL, |
| 7 | + `fantag_left_textcolor` varchar(20) default NULL, |
| 8 | + `fantag_left_bgcolor` varchar(20) default NULL, |
| 9 | + `fantag_right_text` varchar(90) NOT NULL, |
| 10 | + `fantag_right_textcolor` varchar(20) default NULL, |
| 11 | + `fantag_right_bgcolor` varchar(20) default NULL, |
| 12 | + `fantag_user_id` int(11) NOT NULL, |
| 13 | + `fantag_user_name` varchar(50) NOT NULL, |
| 14 | + `fantag_date` datetime NOT NULL, |
| 15 | + `fantag_count` int(11) NOT NULL default '1', |
| 16 | + `fantag_image_name` varchar(255) default NULL, |
| 17 | + `fantag_left_textsize` varchar(20) default NULL, |
| 18 | + `fantag_right_textsize` varchar(20) default NULL |
| 19 | +) /*$wgDBTableOptions*/; |
| 20 | + |
| 21 | +CREATE INDEX /*i*/fantag_user_id ON /*_*/fantag (fantag_user_id); |
| 22 | +CREATE INDEX /*i*/fantag_pg_id ON /*_*/fantag (fantag_pg_id); |
| 23 | + |
| 24 | +CREATE TABLE /*_*/user_fantag ( |
| 25 | + `userft_id` int(11) NOT NULL auto_increment PRIMARY KEY, |
| 26 | + `userft_fantag_id` int(11) NOT NULL, |
| 27 | + `userft_user_id` int(11) NOT NULL, |
| 28 | + `userft_user_name` varchar(50) NOT NULL, |
| 29 | + `userft_date` datetime NOT NULL, |
| 30 | + `userft_order` int(11) NOT NULL |
| 31 | +) /*$wgDBTableOptions*/; |
| 32 | + |
| 33 | +CREATE INDEX /*i*/userft_fantag_id ON /*_*/user_fantag (userft_fantag_id); |
| 34 | +CREATE INDEX /*i*/userft_user_id ON /*_*/user_fantag (userft_user_id); |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/fantag.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 35 | + native |
Index: trunk/extensions/FanBoxes/FanBox_AjaxFunctions.php |
— | — | @@ -0,0 +1,131 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * AJAX functions used by FanBoxes extension. |
| 5 | + */ |
| 6 | + |
| 7 | +$wgAjaxExportList[] = 'wfFanBoxShowaddRemoveMessage'; |
| 8 | +function wfFanBoxShowaddRemoveMessage( $addremove, $title, $individual_fantag_id ) { |
| 9 | + global $wgUser; |
| 10 | + $out = ''; |
| 11 | + |
| 12 | + $fanbox = FanBox::newFromName( $title ); |
| 13 | + |
| 14 | + if( $addremove == 1 ) { |
| 15 | + $fanbox->changeCount( $individual_fantag_id, +1 ); |
| 16 | + $fanbox->addUserFan( $individual_fantag_id ); |
| 17 | + |
| 18 | + if( $wgUser->isLoggedIn() ) { |
| 19 | + $check = $fanbox->checkIfUserHasFanBox(); |
| 20 | + if( $check == 0 ) { |
| 21 | + $out .= $fanbox->outputIfUserDoesntHaveFanBox(); |
| 22 | + } else { |
| 23 | + $out .= $fanbox->outputIfUserHasFanBox(); |
| 24 | + } |
| 25 | + } else { |
| 26 | + $out .= $fanbox->outputIfUserNotLoggedIn(); |
| 27 | + } |
| 28 | + |
| 29 | + $out.= '<div class="show-individual-addremove-message">' . |
| 30 | + wfMsg( 'fanbox-successful-add' ) . |
| 31 | + '</div>'; |
| 32 | + } |
| 33 | + |
| 34 | + if( $addremove == 2 ) { |
| 35 | + $fanbox->changeCount( $individual_fantag_id, -1 ); |
| 36 | + $fanbox->removeUserFanBox( $individual_fantag_id ); |
| 37 | + |
| 38 | + if( $wgUser->isLoggedIn() ) { |
| 39 | + $check = $fanbox->checkIfUserHasFanBox(); |
| 40 | + if( $check == 0 ) { |
| 41 | + $out .= $fanbox->outputIfUserDoesntHaveFanBox(); |
| 42 | + } else { |
| 43 | + $out .= $fanbox->outputIfUserHasFanBox(); |
| 44 | + } |
| 45 | + } else { |
| 46 | + $out .= $fanbox->outputIfUserNotLoggedIn(); |
| 47 | + } |
| 48 | + |
| 49 | + $out.= '<div class="show-individual-addremove-message">' . |
| 50 | + wfMsg( 'fanbox-successful-remove' ) . |
| 51 | + '</div>'; |
| 52 | + } |
| 53 | + |
| 54 | + return $out; |
| 55 | +} |
| 56 | + |
| 57 | +$wgAjaxExportList[] = 'wfMessageAddRemoveUserPage'; |
| 58 | +function wfMessageAddRemoveUserPage( $addRemove, $id, $style ) { |
| 59 | + global $wgUser; |
| 60 | + $out = ''; |
| 61 | + |
| 62 | + if( $addRemove == 1 ) { |
| 63 | + $number = +1; |
| 64 | + |
| 65 | + $dbw = wfGetDB( DB_MASTER ); |
| 66 | + $dbw->insert( |
| 67 | + 'user_fantag', |
| 68 | + array( |
| 69 | + 'userft_fantag_id' => $id, |
| 70 | + 'userft_user_id' => $wgUser->getID(), |
| 71 | + 'userft_user_name' => $wgUser->getName(), |
| 72 | + 'userft_date' => date( 'Y-m-d H:i:s' ), |
| 73 | + ), |
| 74 | + __METHOD__ |
| 75 | + ); |
| 76 | + $dbw->commit(); |
| 77 | + |
| 78 | + $out .= "<div class=\"$style\">" . wfMsg( 'fanbox-successful-add' ) . |
| 79 | + '</div>'; |
| 80 | + } |
| 81 | + |
| 82 | + if( $addRemove == 2 ) { |
| 83 | + $number = -1; |
| 84 | + |
| 85 | + $dbw = wfGetDB( DB_MASTER ); |
| 86 | + $dbw->delete( |
| 87 | + 'user_fantag', |
| 88 | + array( |
| 89 | + 'userft_user_id' => $wgUser->getID(), |
| 90 | + 'userft_fantag_id' => $id |
| 91 | + ), |
| 92 | + __METHOD__ |
| 93 | + ); |
| 94 | + $dbw->commit(); |
| 95 | + |
| 96 | + $out.= "<div class=\"$style\">" . wfMsg( 'fanbox-successful-remove' ) . |
| 97 | + '</div>'; |
| 98 | + } |
| 99 | + |
| 100 | + $dbw->update( |
| 101 | + 'fantag', |
| 102 | + /* SET */array( "fantag_count=fantag_count+{$number}" ), |
| 103 | + /* WHERE */array( 'fantag_id' => $id ), |
| 104 | + __METHOD__ |
| 105 | + ); |
| 106 | + |
| 107 | + $dbw->commit(); |
| 108 | + |
| 109 | + return $out; |
| 110 | +} |
| 111 | + |
| 112 | +$wgAjaxExportList[] = 'wfFanBoxesTitleExists'; |
| 113 | +function wfFanBoxesTitleExists( $page_name ) { |
| 114 | + // Construct page title object to convert to Database Key |
| 115 | + $pageTitle = Title::makeTitle( NS_MAIN, urldecode( $page_name ) ); |
| 116 | + $dbKey = $pageTitle->getDBkey(); |
| 117 | + |
| 118 | + // Database key would be in page title if the page already exists |
| 119 | + $dbw = wfGetDB( DB_MASTER ); |
| 120 | + $s = $dbw->selectRow( |
| 121 | + 'page', |
| 122 | + array( 'page_id' ), |
| 123 | + array( 'page_title' => $dbKey, 'page_namespace' => NS_FANTAG ), |
| 124 | + __METHOD__ |
| 125 | + ); |
| 126 | + |
| 127 | + if ( $s !== false ) { |
| 128 | + return 'Page exists'; |
| 129 | + } else { |
| 130 | + return 'OK'; |
| 131 | + } |
| 132 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBox_AjaxFunctions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 133 | + native |
Index: trunk/extensions/FanBoxes/FanBoxPage.php |
— | — | @@ -0,0 +1,165 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * This class handles the views of UserBox: pages. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | +class FanBoxPage extends Article { |
| 10 | + |
| 11 | + var $title = null; |
| 12 | + var $authors = array(); |
| 13 | + |
| 14 | + /** |
| 15 | + * @var Object: instance of FanBox for the current Title |
| 16 | + */ |
| 17 | + var $fan; |
| 18 | + |
| 19 | + function __construct( Title $title ) { |
| 20 | + parent::__construct( $title ); |
| 21 | + } |
| 22 | + |
| 23 | + function view() { |
| 24 | + global $wgOut, $wgUser, $wgTitle, $wgFanBoxScripts; |
| 25 | + |
| 26 | + $wgOut->addScriptFile( $wgFanBoxScripts . '/FanBoxes.js' ); |
| 27 | + |
| 28 | + $wgOut->setHTMLTitle( $wgTitle->getText() ); |
| 29 | + $wgOut->setPageTitle( $wgTitle->getText() ); |
| 30 | + |
| 31 | + $this->fan = new FanBox( $this->getTitle() ); |
| 32 | + $fanboxTitle = Title::makeTitle( NS_FANTAG, $this->fan->getName() ); |
| 33 | + |
| 34 | + // Don't throw a bunch of E_NOTICEs when we're viewing the page of a |
| 35 | + // nonexistent fanbox |
| 36 | + if ( !$this->getID() ) { |
| 37 | + parent::view(); |
| 38 | + return ''; |
| 39 | + } |
| 40 | + |
| 41 | + $output = ''; |
| 42 | + $output .= "<h1 class=\"firstHeading\">{$fanboxTitle->getPrefixedText()}</h1>"; |
| 43 | + |
| 44 | + $output .= '<div class="fanbox-page-container clearfix">' . |
| 45 | + $this->fan->outputFanBox(); |
| 46 | + $fantag_id = $this->fan->getFanBoxId(); |
| 47 | + |
| 48 | + $output .= '<div id="show-message-container' . $fantag_id . '">'; |
| 49 | + |
| 50 | + if( $wgUser->isLoggedIn() ) { |
| 51 | + $check = $this->fan->checkIfUserHasFanBox(); |
| 52 | + if( $check == 0 ) { |
| 53 | + $output .= $this->fan->outputIfUserDoesntHaveFanBox(); |
| 54 | + } else { |
| 55 | + $output .= $this->fan->outputIfUserHasFanBox(); |
| 56 | + } |
| 57 | + } else { |
| 58 | + $output .= $this->fan->outputIfUserNotLoggedIn(); |
| 59 | + } |
| 60 | + |
| 61 | + $output .= '</div> |
| 62 | + <div class="user-embed-tag">' . |
| 63 | + $this->getEmbedThisTag() . |
| 64 | + '</div> |
| 65 | + <div class="users-with-fanbox"> |
| 66 | + <h2>' . wfMsg( 'fanbox-users-with-fanbox' ) . '</h2> |
| 67 | + <div class="users-with-fanbox-message">' . |
| 68 | + wfMsg( 'fanbox-users-with-fanbox-message' ) . |
| 69 | + '</div>' . |
| 70 | + $this->fanBoxHolders() . "\n" . |
| 71 | + '</div> |
| 72 | + </div>'; |
| 73 | + |
| 74 | + $wgOut->addHTML( $output ); |
| 75 | + |
| 76 | + global $wgFanBoxPageDisplay; |
| 77 | + // Display comments, if we want to display those. |
| 78 | + if( $wgFanBoxPageDisplay['comments'] ) { |
| 79 | + $wgOut->addWikiText( '<comments/>' ); |
| 80 | + } |
| 81 | + |
| 82 | + parent::view(); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Get the users who have the current fanbox. |
| 87 | + * |
| 88 | + * @return Array: array containing the users' names and IDs or an empty |
| 89 | + * array |
| 90 | + */ |
| 91 | + function getFanBoxHolders() { |
| 92 | + global $wgTitle; |
| 93 | + |
| 94 | + $pageTitleId = $wgTitle->getArticleID(); |
| 95 | + |
| 96 | + $dbr = wfGetDB( DB_SLAVE ); |
| 97 | + /* I don't know how the Database class handles the DISTINCT keyword, |
| 98 | + but it won't do a join without the ON part, sadly; see |
| 99 | + DatabaseBase::tableNamesWithUseIndexOrJOIN() which is where it forces |
| 100 | + the ON crap on us (pun not intended, I swear) |
| 101 | + $res = $dbr->select( |
| 102 | + array( 'user_fantag', 'fantag' ), |
| 103 | + array( 'DISTINCT userft_user_name', 'userft_user_id' ), |
| 104 | + array( |
| 105 | + 'userft_fantag_id = fantag_id', |
| 106 | + 'fantag_pg_id' => $pageTitleId |
| 107 | + ), |
| 108 | + __METHOD__, |
| 109 | + array(), |
| 110 | + array( 'fantag' => array( 'INNER JOIN' ) ) |
| 111 | + ); |
| 112 | + */ |
| 113 | + $sql = "SELECT DISTINCT userft_user_name, userft_user_id |
| 114 | + FROM {$dbr->tableName( 'user_fantag' )} INNER JOIN {$dbr->tableName( 'fantag' )} |
| 115 | + WHERE user_fantag.userft_fantag_id = fantag.fantag_id AND fantag.fantag_pg_id = {$pageTitleId}"; |
| 116 | + $res = $dbr->query( $sql, __METHOD__ ); |
| 117 | + |
| 118 | + $fanboxHolders = array(); |
| 119 | + |
| 120 | + foreach( $res as $row ) { |
| 121 | + $fanboxHolders[] = array( |
| 122 | + 'userft_user_name' => $row->userft_user_name, |
| 123 | + 'userft_user_id' => $row->userft_user_id |
| 124 | + ); |
| 125 | + }; |
| 126 | + |
| 127 | + return $fanboxHolders; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Get the users who have the current fanbox from the database and output |
| 132 | + * their avatars. |
| 133 | + * |
| 134 | + * @return String: HTML |
| 135 | + */ |
| 136 | + function fanBoxHolders() { |
| 137 | + $output = ''; |
| 138 | + $fanboxHolders = $this->getFanBoxHolders(); |
| 139 | + |
| 140 | + foreach( $fanboxHolders as $fanboxHolder ) { |
| 141 | + $userftusername = $fanboxHolder['userft_user_name']; |
| 142 | + $userftuserid = $fanboxHolder['userft_user_id']; |
| 143 | + $userTitle = Title::makeTitle( NS_USER, $fanboxHolder['userft_user_name'] ); |
| 144 | + $avatar = new wAvatar( $fanboxHolder['userft_user_id'], 'ml' ); |
| 145 | + $output .= "<a href=\"" . $userTitle->escapeFullURL() . "\"> |
| 146 | + {$avatar->getAvatarURL()} |
| 147 | + </a>"; |
| 148 | + } |
| 149 | + |
| 150 | + return $output; |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Get the wikitext code for embedding this fanbox on a wiki page. |
| 155 | + * |
| 156 | + * @return String: HTML |
| 157 | + */ |
| 158 | + public function getEmbedThisTag() { |
| 159 | + $code = $this->fan->getEmbedThisCode(); |
| 160 | + $code = preg_replace( '/[\n\r\t]/', '', $code ); // remove any non-space whitespace |
| 161 | + $code = str_replace( '_', ' ', $code ); // replace underscores with spaces |
| 162 | + return '<form name="embed_fan" action="">' . wfMsg( 'fan-embed' ) . |
| 163 | + " <input name='embed_code' type='text' value='{$code}' onclick='javascript:document.embed_fan.embed_code.focus();document.embed_fan.embed_code.select();' readonly='readonly' /></form>"; |
| 164 | + } |
| 165 | + |
| 166 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBoxPage.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 167 | + native |
Index: trunk/extensions/FanBoxes/FanBox.php |
— | — | @@ -0,0 +1,99 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * FanBox extension |
| 5 | + * Defines a new namespace for fanboxes (NS_FANTAG, the namespace number is 600 |
| 6 | + * by default) and some new special pages to add/view fanboxes. |
| 7 | + * |
| 8 | + * @file |
| 9 | + * @ingroup Extensions |
| 10 | + * @version 2.0 |
| 11 | + * @author Aaron Wright <aaron.wright@gmail.com> |
| 12 | + * @author David Pean <david.pean@gmail.com> |
| 13 | + * @author Robert Lefkowitz |
| 14 | + * @author Jack Phoenix <jack@countervandalism.net> |
| 15 | + * @link http://www.mediawiki.org/wiki/Extension:FanBox Documentation |
| 16 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 17 | + */ |
| 18 | + |
| 19 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 20 | + die( 'This is not a valid entry point to MediaWiki.' ); |
| 21 | +} |
| 22 | + |
| 23 | +// Extension credits that show up on Special:Version |
| 24 | +$wgExtensionCredits['other'][] = array( |
| 25 | + 'name' => 'FanBox', |
| 26 | + 'version' => '2.0', |
| 27 | + 'author' => array( 'Aaron Wright', 'David Pean', 'Robert Lefkowitz', 'Jack Phoenix' ), |
| 28 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:FanBox', |
| 29 | + 'description' => 'A new way of creating and using userboxes, based on special pages', |
| 30 | +); |
| 31 | + |
| 32 | +// ResourceLoader support for MediaWiki 1.17+ |
| 33 | +$wgResourceModules['ext.fanBoxes'] = array( |
| 34 | + 'styles' => 'FanBoxes.css', |
| 35 | + 'scripts' => 'FanBoxes.js', |
| 36 | + 'messages' => array( |
| 37 | + 'fanbox-mustenter-left', 'fanbox-mustenter-right', |
| 38 | + 'fanbox-mustenter-right-or', 'fanbox-mustenter-title', 'fanbox-hash', |
| 39 | + 'fanbox-choose-another', 'fanbox-upload-new-image' |
| 40 | + ), |
| 41 | + 'localBasePath' => dirname( __FILE__ ), |
| 42 | + 'remoteExtPath' => 'FanBoxes', |
| 43 | + 'position' => 'top' // available since r85616 |
| 44 | +); |
| 45 | + |
| 46 | +// Global fantag namespace reference |
| 47 | +if( !defined( 'NS_FANTAG' ) ) { |
| 48 | + define( 'NS_FANTAG', 600 ); |
| 49 | +} |
| 50 | + |
| 51 | +if( !defined( 'NS_FANTAG_TALK' ) ) { |
| 52 | + define( 'NS_FANTAG_TALK', 601 ); |
| 53 | +} |
| 54 | + |
| 55 | +// Set up the new special pages |
| 56 | +$dir = dirname( __FILE__ ) . '/'; |
| 57 | +$wgExtensionMessagesFiles['FanBox'] = $dir . 'FanBox.i18n.php'; |
| 58 | +$wgExtensionMessagesFiles['FanBoxNamespaces'] = $dir . 'FanBox.namespaces.php'; |
| 59 | +$wgAutoloadClasses['FanBox'] = $dir . 'FanBoxClass.php'; |
| 60 | +$wgAutoloadClasses['SpecialFanBoxAjaxUpload'] = $dir . 'MiniAjaxUpload.php'; |
| 61 | +$wgAutoloadClasses['FanBoxAjaxUploadForm'] = $dir . 'MiniAjaxUpload.php'; |
| 62 | +$wgAutoloadClasses['FanBoxUpload'] = $dir . 'MiniAjaxUpload.php'; |
| 63 | +$wgAutoloadClasses['FanBoxPage'] = $dir . 'FanBoxPage.php'; |
| 64 | +$wgAutoloadClasses['FanBoxes'] = $dir . 'SpecialFanBoxes.php'; |
| 65 | +$wgAutoloadClasses['TagCloud'] = $dir . 'TagCloudClass.php'; |
| 66 | +$wgAutoloadClasses['TopFanBoxes'] = $dir . 'SpecialTopFanBoxes.php'; |
| 67 | +$wgAutoloadClasses['UserFanBoxes'] = $dir . 'FanBoxesClass.php'; |
| 68 | +$wgAutoloadClasses['ViewFanBoxes'] = $dir . 'SpecialViewFanBoxes.php'; |
| 69 | +$wgSpecialPages['FanBoxAjaxUpload'] = 'SpecialFanBoxAjaxUpload'; |
| 70 | +$wgSpecialPages['UserBoxes'] = 'FanBoxes'; |
| 71 | +$wgSpecialPages['TopUserboxes'] = 'TopFanBoxes'; |
| 72 | +$wgSpecialPages['ViewUserBoxes'] = 'ViewFanBoxes'; |
| 73 | +// Special page groups for MW 1.13+ |
| 74 | +$wgSpecialPageGroups['UserBoxes'] = 'users'; |
| 75 | +$wgSpecialPageGroups['TopUserboxes'] = 'users'; |
| 76 | +$wgSpecialPageGroups['ViewUserBoxes'] = 'users'; |
| 77 | + |
| 78 | +// AJAX functions used by this extension |
| 79 | +require_once( 'FanBox_AjaxFunctions.php' ); |
| 80 | + |
| 81 | +// <userboxes> parser hook |
| 82 | +require_once( 'UserBoxesHook.php' ); |
| 83 | + |
| 84 | +# Configuration settings |
| 85 | +// Web-readable path to FanBox files (used to fetch CSS & JS) |
| 86 | +$wgFanBoxScripts = $wgScriptPath . '/extensions/FanBoxes'; |
| 87 | +// Should we display comments on FanBox pages? Requires the Comments extension. |
| 88 | +$wgFanBoxPageDisplay['comments'] = true; |
| 89 | + |
| 90 | +// Hooked functions |
| 91 | +$wgAutoloadClasses['FanBoxHooks'] = $dir . 'FanBoxHooks.php'; |
| 92 | + |
| 93 | +$wgHooks['TitleMoveComplete'][] = 'FanBoxHooks::updateFanBoxTitle'; |
| 94 | +$wgHooks['ArticleDelete'][] = 'FanBoxHooks::deleteFanBox'; |
| 95 | +$wgHooks['ArticleFromTitle'][] = 'FanBoxHooks::fantagFromTitle'; |
| 96 | +$wgHooks['ParserBeforeStrip'][] = 'FanBoxHooks::transformFanBoxTags'; |
| 97 | +$wgHooks['ParserFirstCallInit'][] = 'FanBoxHooks::registerFanTag'; |
| 98 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'FanBoxHooks::addTables'; |
| 99 | +$wgHooks['RenameUserSQL'][] = 'FanBoxHooks::onUserRename'; // For the Renameuser extension |
| 100 | +$wgHooks['CanonicalNamespaces'][] = 'FanBoxHooks::onCanonicalNamespaces'; |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBox.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 101 | + native |
Index: trunk/extensions/FanBoxes/FanBoxHooks.php |
— | — | @@ -0,0 +1,275 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * FanBox extension's hooked function. All class methods are obviously public |
| 5 | + * and static. |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
| 10 | +class FanBoxHooks { |
| 11 | + |
| 12 | + /** |
| 13 | + * When a fanbox is moved to a new title, update the records in the fantag |
| 14 | + * table. |
| 15 | + * |
| 16 | + * @param $title Object: Title object representing the old title |
| 17 | + * @param $newtitle Object: Title object representing the new title |
| 18 | + * @param $oldid Integer: |
| 19 | + * @param $newid Integer: |
| 20 | + * @return Boolean: true |
| 21 | + */ |
| 22 | + public static function updateFanBoxTitle( &$title, &$newtitle, &$user, $oldid, $newid ) { |
| 23 | + if( $title->getNamespace() == NS_FANTAG ) { |
| 24 | + $dbw = wfGetDB( DB_MASTER ); |
| 25 | + $dbw->update( |
| 26 | + 'fantag', |
| 27 | + array( 'fantag_title' => $newtitle->getText() ), |
| 28 | + array( 'fantag_pg_id' => intval( $oldid ) ), |
| 29 | + __METHOD__ |
| 30 | + ); |
| 31 | + $dbw->commit(); |
| 32 | + } |
| 33 | + return true; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * When a page in the NS_FANTAG namespace is deleted, delete all fantag |
| 38 | + * records associated with that page. |
| 39 | + * |
| 40 | + * @param $article Object: instance of Article or its descendant class |
| 41 | + * @param $user Object: the User performing the page deletion [unused] |
| 42 | + * @param $reason String: user-supplied reason for the deletion [unused] |
| 43 | + * @return Boolean: true |
| 44 | + */ |
| 45 | + public static function deleteFanBox( &$article, &$user, $reason ) { |
| 46 | + global $wgTitle, $wgSupressPageTitle; |
| 47 | + if( $wgTitle->getNamespace() == NS_FANTAG ) { |
| 48 | + $wgSupressPageTitle = true; |
| 49 | + |
| 50 | + $dbw = wfGetDB( DB_MASTER ); |
| 51 | + |
| 52 | + $s = $dbw->selectRow( |
| 53 | + 'fantag', |
| 54 | + array( 'fantag_pg_id', 'fantag_id' ), |
| 55 | + array( 'fantag_pg_id' => intval( $article->getID() ) ), |
| 56 | + __METHOD__ |
| 57 | + ); |
| 58 | + if ( $s !== false ) { |
| 59 | + // delete fanbox records |
| 60 | + $dbw->delete( |
| 61 | + 'user_fantag', |
| 62 | + array( 'userft_fantag_id' => intval( $s->fantag_id ) ), |
| 63 | + __METHOD__ |
| 64 | + ); |
| 65 | + |
| 66 | + $dbw->delete( |
| 67 | + 'fantag', |
| 68 | + array( 'fantag_pg_id' => intval( $article->getID() ) ), |
| 69 | + __METHOD__ |
| 70 | + ); |
| 71 | + $dbw->commit(); |
| 72 | + } |
| 73 | + } |
| 74 | + return true; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Convert [[Fan:Fan Name]] tags to <fan></fan> hook |
| 79 | + * |
| 80 | + * @param $parser Unused |
| 81 | + * @param $text String: text to search for [[Fan:]] links |
| 82 | + * @param $strip_state Unused |
| 83 | + * @return Boolean: true |
| 84 | + */ |
| 85 | + public static function transformFanBoxTags( &$parser, &$text, &$strip_state ) { |
| 86 | + global $wgContLang; |
| 87 | + |
| 88 | + $fantitle = $wgContLang->getNsText( NS_FANTAG ); |
| 89 | + $pattern = "@(\[\[$fantitle)([^\]]*?)].*?\]@si"; |
| 90 | + $text = preg_replace_callback( $pattern, 'FanBoxHooks::renderFanBoxTag', $text ); |
| 91 | + |
| 92 | + return true; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * On preg_replace_callback |
| 97 | + * Found a match of [[Fan:]], so get parameters and construct <fan> hook |
| 98 | + * |
| 99 | + * @param $matches Array |
| 100 | + * @return String: HTML |
| 101 | + */ |
| 102 | + public static function renderFanBoxTag( $matches ) { |
| 103 | + $name = $matches[2]; |
| 104 | + $params = explode( '|', $name ); |
| 105 | + $fan_name = $params[0]; |
| 106 | + $fan_name = Title::newFromDBKey( $fan_name ); |
| 107 | + |
| 108 | + if( !is_object( $fan_name ) ) { |
| 109 | + return ''; |
| 110 | + } |
| 111 | + |
| 112 | + $fan = FanBox::newFromName( $fan_name->getText() ); |
| 113 | + |
| 114 | + if( $fan->exists() ) { |
| 115 | + $output = "<fan name=\"{$fan->getName()}\"></fan>"; |
| 116 | + return $output; |
| 117 | + } |
| 118 | + |
| 119 | + return $matches[0]; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Calls FanBoxPage instead of standard Article for pages in the NS_FANTAG |
| 124 | + * namespace. |
| 125 | + * |
| 126 | + * @param $title Object: instance of Title |
| 127 | + * @param $article Object: instance of Article that we transform into an |
| 128 | + * instance of FanBoxPage |
| 129 | + * @return Boolean: true |
| 130 | + */ |
| 131 | + public static function fantagFromTitle( &$title, &$article ) { |
| 132 | + global $wgRequest, $wgOut, $wgTitle, $wgSupressPageTitle, $wgSupressPageCategories, $wgFanBoxScripts; |
| 133 | + |
| 134 | + if ( $title->getNamespace() == NS_FANTAG ) { |
| 135 | + $wgSupressPageTitle = true; |
| 136 | + |
| 137 | + $wgOut->addExtensionStyle( $wgFanBoxScripts . '/FanBoxes.css' ); |
| 138 | + |
| 139 | + if( $wgRequest->getVal( 'action' ) == 'edit' ) { |
| 140 | + $addTitle = SpecialPage::getTitleFor( 'UserBoxes' ); |
| 141 | + $fan = FanBox::newFromName( $title->getText() ); |
| 142 | + if( !$fan->exists() ) { |
| 143 | + $wgOut->redirect( $addTitle->getFullURL( 'destName=' . $fan->getName() ) ); |
| 144 | + } else { |
| 145 | + $update = SpecialPage::getTitleFor( 'UserBoxes' ); |
| 146 | + $wgOut->redirect( $update->getFullURL( 'id=' . $wgTitle->getArticleID() ) ); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + $article = new FanBoxPage( $wgTitle ); |
| 151 | + } |
| 152 | + |
| 153 | + return true; |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Register the new <fan> hook with the parser. |
| 158 | + * |
| 159 | + * @param $parser Object: instance of Parser (not necessarily $wgParser) |
| 160 | + * @return Boolean: true |
| 161 | + */ |
| 162 | + public static function registerFanTag( &$parser ) { |
| 163 | + $parser->setHook( 'fan', array( 'FanBoxHooks', 'embedFanBox' ) ); |
| 164 | + return true; |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Callback function for the registerFanTag() function that expands <fan> |
| 169 | + * into valid HTML. |
| 170 | + * |
| 171 | + * @param $input |
| 172 | + * @param $argv Array: array of user-supplied arguments |
| 173 | + * @param $parser Object: instance of Parser |
| 174 | + * @return String: HTML |
| 175 | + */ |
| 176 | + public static function embedFanBox( $input, $argv, $parser ) { |
| 177 | + global $wgUser, $wgHooks; |
| 178 | + |
| 179 | + $parser->disableCache(); |
| 180 | + |
| 181 | + $wgHooks['BeforePageDisplay'][] = 'FanBoxHooks::addFanBoxScripts'; |
| 182 | + |
| 183 | + $fan_name = $argv['name']; |
| 184 | + if( !$fan_name ) { |
| 185 | + return ''; |
| 186 | + } |
| 187 | + |
| 188 | + $fan = FanBox::newFromName( $fan_name ); |
| 189 | + |
| 190 | + $output = ''; |
| 191 | + if( $fan->exists() ) { |
| 192 | + $output .= $fan->outputFanBox(); |
| 193 | + $fantagId = $fan->getFanBoxId(); |
| 194 | + |
| 195 | + $output .= '<div id="show-message-container' . intval( $fantagId ) . '">'; |
| 196 | + if( $wgUser->isLoggedIn() ) { |
| 197 | + $check = $fan->checkIfUserHasFanBox(); |
| 198 | + if( $check == 0 ) { |
| 199 | + $output .= $fan->outputIfUserDoesntHaveFanBox(); |
| 200 | + } else { |
| 201 | + $output .= $fan->outputIfUserHasFanBox(); |
| 202 | + } |
| 203 | + } else { |
| 204 | + $output .= $fan->outputIfUserNotLoggedIn(); |
| 205 | + } |
| 206 | + |
| 207 | + $output .= '</div>'; |
| 208 | + } |
| 209 | + |
| 210 | + return $output; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Add FanBox's CSS and JS into the page output. |
| 215 | + * |
| 216 | + * @param $out Object: instance of OutputPage |
| 217 | + * @param $skin Object: instance of Skin or a descendant class |
| 218 | + * @return Boolean: true |
| 219 | + */ |
| 220 | + public static function addFanBoxScripts( &$out, &$skin ) { |
| 221 | + global $wgFanBoxScripts; |
| 222 | + $out->addScriptFile( $wgFanBoxScripts . '/FanBoxes.js' ); |
| 223 | + $out->addExtensionStyle( $wgFanBoxScripts . '/FanBoxes.css' ); |
| 224 | + return true; |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * Creates the necessary database tables when the user runs |
| 229 | + * maintenance/update.php. |
| 230 | + * |
| 231 | + * @param $updater Object: instance of DatabaseUpdater |
| 232 | + * @return Boolean: true |
| 233 | + */ |
| 234 | + public static function addTables( $updater = null ) { |
| 235 | + $dir = dirname( __FILE__ ); |
| 236 | + $file = "$dir/fantag.sql"; |
| 237 | + if ( $updater === null ) { |
| 238 | + global $wgExtNewTables; |
| 239 | + $wgExtNewTables[] = array( 'fantag', $file ); |
| 240 | + $wgExtNewTables[] = array( 'user_fantag', $file ); |
| 241 | + } else { |
| 242 | + $updater->addExtensionUpdate( array( 'addTable', 'fantag', $file, true ) ); |
| 243 | + $updater->addExtensionUpdate( array( 'addTable', 'user_fantag', $file, true ) ); |
| 244 | + } |
| 245 | + return true; |
| 246 | + } |
| 247 | + |
| 248 | + /** |
| 249 | + * For the Renameuser extension. |
| 250 | + * |
| 251 | + * @param $renameUserSQL |
| 252 | + * @return Boolean: true |
| 253 | + */ |
| 254 | + public static function onUserRename( $renameUserSQL ) { |
| 255 | + $renameUserSQL->tables['fantag'] = array( |
| 256 | + 'fantag_user_name', 'fantag_user_id' |
| 257 | + ); |
| 258 | + $renameUserSQL->tables['user_fantag'] = array( |
| 259 | + 'userft_user_name', 'userft_user_id' |
| 260 | + ); |
| 261 | + return true; |
| 262 | + } |
| 263 | + |
| 264 | + /** |
| 265 | + * Register the canonical names for our namespace and its talkspace. |
| 266 | + * |
| 267 | + * @param $list Array: array of namespace numbers with corresponding |
| 268 | + * canonical names |
| 269 | + * @return Boolean: true |
| 270 | + */ |
| 271 | + public static function onCanonicalNamespaces( &$list ) { |
| 272 | + $list[NS_FANTAG] = 'UserBox'; |
| 273 | + $list[NS_FANTAG_TALK] = 'UserBox_talk'; |
| 274 | + return true; |
| 275 | + } |
| 276 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/FanBoxHooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 277 | + native |
Index: trunk/extensions/FanBoxes/ajax-loader-white.gif |
Cannot display: file marked as a binary type. |
svn:mime-type = image/gif |
Property changes on: trunk/extensions/FanBoxes/ajax-loader-white.gif |
___________________________________________________________________ |
Added: svn:mime-type |
2 | 278 | + image/gif |
Index: trunk/extensions/FanBoxes/TagCloudClass.php |
— | — | @@ -0,0 +1,58 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @copyright Copyright © 2007, Wikia Inc. |
| 5 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 6 | + */ |
| 7 | +class TagCloud { |
| 8 | + var $tags_min_pts = 8; |
| 9 | + var $tags_max_pts = 32; |
| 10 | + var $tags_highest_count = 0; |
| 11 | + var $tags_size_type = 'pt'; |
| 12 | + |
| 13 | + public function __construct( $limit = 10 ) { |
| 14 | + $this->limit = $limit; |
| 15 | + $this->initialize(); |
| 16 | + } |
| 17 | + |
| 18 | + public function initialize() { |
| 19 | + $dbr = wfGetDB( DB_MASTER ); |
| 20 | + $res = $dbr->select( |
| 21 | + 'categorylinks', |
| 22 | + array( 'cl_to', 'COUNT(*) AS count' ), |
| 23 | + array(), |
| 24 | + __METHOD__, |
| 25 | + array( |
| 26 | + 'GROUP BY' => 'cl_to', |
| 27 | + 'ORDER BY' => 'count DESC', |
| 28 | + 'LIMIT' => $this->limit |
| 29 | + ) |
| 30 | + ); |
| 31 | + wfSuppressWarnings(); // prevent PHP from bitching about strtotime() |
| 32 | + foreach( $res as $row ) { |
| 33 | + $tag_name = Title::makeTitle( NS_CATEGORY, $row->cl_to ); |
| 34 | + $tag_text = $tag_name->getText(); |
| 35 | + if( strtotime( $tag_text ) == '' ) { // don't want dates to show up |
| 36 | + if( $row->count > $this->tags_highest_count ) { |
| 37 | + $this->tags_highest_count = $row->count; |
| 38 | + } |
| 39 | + $this->tags[$tag_text] = array( 'count' => $row->count ); |
| 40 | + } |
| 41 | + } |
| 42 | + wfRestoreWarnings(); |
| 43 | + |
| 44 | + // sort tag array by key (tag name) |
| 45 | + if( $this->tags_highest_count == 0 ) { |
| 46 | + return; |
| 47 | + } |
| 48 | + ksort( $this->tags ); |
| 49 | + /* and what if we have _1_ category? like on a new wiki with nteen articles, mhm? */ |
| 50 | + if( $this->tags_highest_count == 1 ) { |
| 51 | + $coef = $this->tags_max_pts - $this->tags_min_pts; |
| 52 | + } else { |
| 53 | + $coef = ( $this->tags_max_pts - $this->tags_min_pts ) / ( ( $this->tags_highest_count - 1 ) * 2 ); |
| 54 | + } |
| 55 | + foreach( $this->tags as $tag => $att ) { |
| 56 | + $this->tags[$tag]['size'] = $this->tags_min_pts + ( $this->tags[$tag]['count'] - 1 ) * $coef; |
| 57 | + } |
| 58 | + } |
| 59 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/FanBoxes/TagCloudClass.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 60 | + native |