function wfFanBoxShowaddRemoveMessage($addremove, $title, $individual_fantag_id)
{
    global $wgUser;
    $out = '';
    $fanbox = FanBox::newFromName($title);
    if ($addremove == 1) {
        $fanbox->changeCount($individual_fantag_id, +1);
        $fanbox->addUserFan($individual_fantag_id);
        if ($wgUser->isLoggedIn()) {
            $check = $fanbox->checkIfUserHasFanBox();
            if ($check == 0) {
                $out .= $fanbox->outputIfUserDoesntHaveFanBox();
            } else {
                $out .= $fanbox->outputIfUserHasFanBox();
            }
        } else {
            $out .= $fanbox->outputIfUserNotLoggedIn();
        }
        $out .= '<div class="show-individual-addremove-message">' . wfMsg('fanbox-successful-add') . '</div>';
    }
    if ($addremove == 2) {
        $fanbox->changeCount($individual_fantag_id, -1);
        $fanbox->removeUserFanBox($individual_fantag_id);
        if ($wgUser->isLoggedIn()) {
            $check = $fanbox->checkIfUserHasFanBox();
            if ($check == 0) {
                $out .= $fanbox->outputIfUserDoesntHaveFanBox();
            } else {
                $out .= $fanbox->outputIfUserHasFanBox();
            }
        } else {
            $out .= $fanbox->outputIfUserNotLoggedIn();
        }
        $out .= '<div class="show-individual-addremove-message">' . wfMsg('fanbox-successful-remove') . '</div>';
    }
    return $out;
}
Exemplo n.º 2
0
    /**
     * Show the special page
     *
     * @param $par Mixed: parameter passed to the page or null
     */
    public function execute($par)
    {
        global $wgOut, $wgUser, $wgRequest, $wgHooks, $wgFanBoxScripts;
        // Set it up so that you must be logged in to create a userbox
        if ($wgUser->getID() == 0) {
            $wgOut->setPageTitle(wfMsgHtml('fanbox-woops-title'));
            $login = SpecialPage::getTitleFor('Userlogin');
            $wgOut->redirect($login->getFullURL('returnto=Special:UserBoxes'));
            return false;
        }
        // Don't allow blocked users (RT #12589)
        if ($wgUser->isBlocked()) {
            $wgOut->blockedPage();
            return true;
        }
        // If the database is in read-only mode, bail out
        if (wfReadOnly()) {
            $wgOut->readOnlyPage();
            return true;
        }
        // Extension's CSS & JS
        $wgOut->addScriptFile($wgFanBoxScripts . '/FanBoxes.js');
        $wgOut->addExtensionStyle($wgFanBoxScripts . '/FanBoxes.css');
        // colorpicker
        $wgOut->addScript("<script type=\"text/javascript\" src=\"http://yui.yahooapis.com/2.5.2/build/utilities/utilities.js\"></script>\n");
        $wgOut->addScript("<script type=\"text/javascript\" src=\"http://yui.yahooapis.com/2.5.2/build/slider/slider-min.js\"></script>\n");
        $wgOut->addScript("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://yui.yahooapis.com/2.5.2/build/colorpicker/assets/skins/sam/colorpicker.css\"/>\n");
        $wgOut->addScript("<script type=\"text/javascript\" src=\"http://yui.yahooapis.com/2.5.2/build/colorpicker/colorpicker-min.js\"></script>\n");
        // Add i18n messages as JS globals (this can be removed once we require
        // ResourceLoader/MW 1.17+)
        $wgHooks['MakeGlobalVariablesScript'][] = 'FanBoxes::addJSGlobals';
        $output = '';
        $title = str_replace('#', '', $wgRequest->getVal('wpTitle'));
        $fanboxId = $wgRequest->getInt('id');
        $categories = '';
        // Set up the edit fanbox part
        if ($fanboxId) {
            $title = Title::newFromID($fanboxId);
            $update_fan = new FanBox($title);
            // Get categories
            $dbr = wfGetDB(DB_SLAVE);
            $res = $dbr->select('categorylinks', 'cl_to', array('cl_from' => intval($fanboxId)), __METHOD__);
            $fanboxCategory = wfMsgForContent('fanbox-userbox-category');
            foreach ($res as $row) {
                if ($row->cl_to != $fanboxCategory && strpos($row->cl_to, 'Userboxes_by_User_') === false) {
                    $categories .= ($categories ? ', ' : '') . $row->cl_to;
                }
            }
            $output .= "\n\t\t\t<form action=\"\" method=\"post\" name=\"form1\">\n\t\t\t<input type=\"hidden\" name=\"fantag_image_name\" id=\"fantag_image_name\" value=\"{$update_fan->getFanBoxImage()}\">\n\t\t\t<input type=\"hidden\" name=\"textSizeRightSide\" id=\"textSizeRightSide\" value=\"{$update_fan->getFanBoxRightTextSize()}\" >\n\t\t\t<input type=\"hidden\" name=\"textSizeLeftSide\" id=\"textSizeLeftSide\" value=\"{$update_fan->getFanBoxLeftTextSize()}\">\n\t\t\t<input type=\"hidden\" name=\"bgColorLeftSideColor\" id=\"bgColorLeftSideColor\" value=\"{$update_fan->getFanBoxLeftBgColor()}\">\n\t\t\t<input type=\"hidden\" name=\"textColorLeftSideColor\" id=\"textColorLeftSideColor\" value=\"{$update_fan->getFanBoxLeftTextColor()}\">\n\t\t\t<input type=\"hidden\" name=\"bgColorRightSideColor\" id=\"bgColorRightSideColor\" value=\"{$update_fan->getFanBoxRightBgColor()}\">\n\t\t\t<input type=\"hidden\" name=\"textColorRightSideColor\" id=\"textColorRightSideColor\" value=\"{$update_fan->getFanBoxRightTextColor()}\">";
            if ($update_fan->getFanBoxImage()) {
                $fantag_image_width = 45;
                $fantag_image_height = 53;
                $fantag_image = wfFindFile($update_fan->getFanBoxImage());
                $fantag_image_url = '';
                if (is_object($fantag_image)) {
                    $fantag_image_url = $fantag_image->createThumb($fantag_image_width, $fantag_image_height);
                }
                $fantag_image_tag = '<img alt="" src="' . $fantag_image_url . '" />';
            }
            if ($update_fan->getFanBoxLeftText() == '') {
                $fantag_leftside = $fantag_image_tag;
                $fantag_imageholder = $fantag_image_tag;
            } else {
                $fantag_leftside = $update_fan->getFanBoxLeftText();
                $fantag_imageholder = '';
            }
            $leftfontsize = $rightfontsize = '';
            if ($update_fan->getFanBoxLeftTextSize() == 'mediumfont') {
                $leftfontsize = '14px';
            }
            if ($update_fan->getFanBoxLeftTextSize() == 'bigfont') {
                $leftfontsize = '20px';
            }
            if ($update_fan->getFanBoxRightTextSize() == 'smallfont') {
                $rightfontsize = '12px';
            }
            if ($update_fan->getFanBoxRightTextSize() == 'mediumfont') {
                $rightfontsize = '14px';
            }
            $output .= "\n" . '<table class="fanBoxTable" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td id="fanBoxLeftSideContainer" bgcolor="' . $update_fan->getFanBoxLeftBgColor() . '">
						<table cellspacing="0" width="55px" height="63px">
							<tr>
							<td id="fanBoxLeftSideOutput2" style="color:' . $update_fan->getFanBoxLeftTextColor() . '; font-size:' . $leftfontsize . '">' . $fantag_leftside . '</td>
						</table>
						</td>
					<td id="fanBoxRightSideContainer" bgcolor="' . $update_fan->getFanBoxRightBgColor() . '">
						<table cellspacing="0">
							<tr>
							<td id="fanBoxRightSideOutput2" style="color:' . $update_fan->getFanBoxRightTextColor() . '; font-size:' . $rightfontsize . '">' . $update_fan->getFanBoxRightText() . '</td>
						</table>
					</td>
				</table>';
            $output .= '<h1>' . wfMsg('fanbox-addtext') . '</h1>
				<div class="create-fanbox-text">
					<div id="fanbox-left-text">
						<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>\n\t\t\t\t\t\t<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 />\n\t\t\t\t\t\t<font size=\"1\">" . wfMsg('fanbox-leftsideinstructions') . '</font>
					</div>
					<div id="fanbox-right-text">
						<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>\n\t\t\t\t\t\t<input type=\"text\" name=\"inputRightSide\" id=\"inputRightSide\" style=\"width:350px\" value=\"{$update_fan->getFanBoxRightText()}\" oninput=\"FanBoxes.displayRightSide();\n\t\t\t\t\t\trightSideFanBoxFormat()\"\n\t\t\t\t\t\tonkeydown=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\"\n\t\t\t\t\t\tonkeyup=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\"\n\t\t\t\t\t\tonpaste=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\"\n\t\t\t\t\t\tonkeypress=\"FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()\"\n\t\t\t\t\t\tmaxlength=\"70\" /><br />\n\t\t\t\t\t\t<font size=\"1\">" . wfMsg('fanbox-rightsideinstructions') . '</font>
					</div>
					</form>
				</div>';
            $output .= '
					<div id="create-fanbox-image" class="create-fanbox-image">
						<h1>' . wfMsg('fanbox-leftsideimage') . ' <font size="1">' . wfMsg('fanbox-leftsideimageinstructions') . " </font></h1>\n\t\t\t\t\t\t<div id=\"fanbox_image\" onclick=\"FanBoxes.insertImageToLeft()\">{$fantag_imageholder}</div>\n\t\t\t\t\t\t<div id=\"fanbox_image2\"> </div>\n\t\t\t\t\t\t<div id=\"real-form\" style=\"display:block;height:70px;\">\n\t\t\t\t\t\t<iframe id=\"imageUpload-frame\" class=\"imageUpload-frame\" width=\"700\"\n\t\t\t\t\t\t\tscrolling=\"no\" frameborder=\"0\" src=\"" . SpecialPage::getTitleFor('FanBoxAjaxUpload')->escapeFullURL() . '">
						</iframe>
						</div>
					</div>';
            $output .= $this->colorPickerAndCategoryCloud($categories);
            $output .= '<div class="create-fanbox-buttons">
				<input type="button" class="site-button" value="' . wfMsg('fanbox-update-button') . '" size="20" onclick="FanBoxes.createFantagSimple()" />
			</div>';
        }
        // Set it up so that the page title includes the title of the red link that the user clicks on
        $destination = $wgRequest->getVal('destName');
        $page_title = wfMsg('fan-addfan-title');
        if ($destination) {
            $page_title = wfMsg('fan-createfor', str_replace('_', ' ', $destination));
        }
        if ($fanboxId) {
            $page_title = wfMsg('fan-updatefan', str_replace('_', ' ', $update_fan->getName()));
        }
        $wgOut->setPageTitle($page_title);
        // Set it up so that the title of the page the user creates using the create form ends
        // up being the title of the red link he clicked on to get to the create form
        if ($destination) {
            $title = $destination;
        }
        if (!$fanboxId) {
            $output .= '<div class="lr-right">' . wfMsgExt('userboxes-instructions', 'parse') . '</div>

			<form action="" method="post" name="form1">
			<input type="hidden" name="fantag_image_name" id="fantag_image_name" />
			<input type="hidden" name="fantag_imgname" id="fantag_imgname" />
			<input type="hidden" name="fantag_imgtag" id="fantag_imgtag" />
			<input type="hidden" name="textSizeRightSide" id="textSizeRightSide" />
			<input type="hidden" name="textSizeLeftSide" id="textSizeLeftSide" />
			<input type="hidden" name="bgColorLeftSideColor" id="bgColorLeftSideColor" value="" />
			<input type="hidden" name="textColorLeftSideColor" id="textColorLeftSideColor" value="" />
			<input type="hidden" name="bgColorRightSideColor" id="bgColorRightSideColor" value="" />
			<input type="hidden" name="textColorRightSideColor" id="textColorRightSideColor" value="" />';
            if (!$destination) {
                $output .= '<h1>' . wfMsg('fanbox-title') . '</h1>
					<div class="create-fanbox-title">
						<input type="text" name="wpTitle" id="wpTitle" value="' . $wgRequest->getVal('wpTitle') . '" style="width:350px" maxlength="60" /><br />
						<font size="1">(' . wfMsg('fanboxes-maxchars-sixty') . ')</font><br />
					</div>';
            } else {
                $output .= Html::hidden('wpTitle', $destination, array('id' => 'wpTitle'));
            }
            $output .= '<table class="fanBoxTable" border="0" cellpadding="0" cellspacing="0">
				<tr>
				<td id="fanBoxLeftSideContainer">
					<table cellspacing="0" width="55px" height="63px">
						<tr>
							<td id="fanBoxLeftSideOutput2"></td>
						</tr>
					</table>
				</td>
				<td id="fanBoxRightSideContainer">
					<table cellspacing="0" width="212px" height="63px">
						<tr>
							<td id="fanBoxRightSideOutput2"></td>
						</tr>
					</table>
				</td>
				</tr>
			</table>' . "\n";
            $output .= '<h1>' . wfMsg('fanbox-addtext') . '</h1>
				<div class="create-fanbox-text">
					<div id="fanbox-left-text">
						<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>
						<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()"
						maxlength="11" /><br />
						<font size="1">' . wfMsgForContent('fanbox-leftsideinstructions') . '</font>
					</div>
					<div id="fanbox-right-text">
					<h3>' . wfMsgForContent('fanbox-rightsidetext') . '<span id="countdownbox"> <span class="fanbox-right-text-message">' . wfMsg('fanbox-charsleft', '<input readonly="readonly" type="text" name="countdown" style="width:20px; height:15px;" value="70" />') . '</span></span></h3>
						<input type="text" name="inputRightSide" id="inputRightSide" style="width:350px" oninput="FanBoxes.displayRightSide();
						FanBoxes.rightSideFanBoxFormat()"
						onkeydown="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()"
						onkeyup="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()"
						onpaste="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()"
						onkeypress="FanBoxes.limitText(this.form.inputRightSide,this.form.countdown,70); FanBoxes.displayRightSide(); FanBoxes.rightSideFanBoxFormat()"
						maxlength="70" /><br />
						<font size="1">' . wfMsg('fanbox-rightsideinstructions') . '</font>
					</div>
					<div class="cleared"></div>
					</form>
				</div>';
            $output .= '<div id="create-fanbox-image" class="create-fanbox-image">
						<h1>' . wfMsg('fanbox-leftsideimage') . ' <font size="1">' . wfMsgForContent('fanbox-leftsideimageinstructions') . ' </font></h1>
						<div id="fanbox_image" onclick="FanBoxes.insertImageToLeft()"></div>
						<div id="fanbox_image2"></div>

						<div id="real-form" style="display: block; height: 70px;">
						<iframe id="imageUpload-frame" class="imageUpload-frame" width="700"
							scrolling="no" frameborder="0" src="' . SpecialPage::getTitleFor('FanBoxAjaxUpload')->escapeFullURL() . '">
						</iframe>
						</div>
					</div>';
            $output .= $this->colorPickerAndCategoryCloud($categories);
            $output .= '<div class="create-fanbox-buttons">
				<input type="button" class="site-button" value="' . wfMsg('fanbox-create-button') . '" size="20" onclick="FanBoxes.createFantag()" />
			</div>';
        }
        $wgOut->addHTML($output);
        // Send values to database and create fantag page when form is submitted
        if ($wgRequest->wasPosted()) {
            if (!$fanboxId) {
                $fan = FanBox::newFromName($title);
                $fantagId = $fan->addFan($wgRequest->getVal('inputLeftSide'), $wgRequest->getVal('textColorLeftSideColor'), $wgRequest->getVal('bgColorLeftSideColor'), $wgRequest->getVal('inputRightSide'), $wgRequest->getVal('textColorRightSideColor'), $wgRequest->getVal('bgColorRightSideColor'), $wgRequest->getVal('fantag_image_name'), $wgRequest->getVal('textSizeLeftSide'), $wgRequest->getVal('textSizeRightSide'), $wgRequest->getVal('pageCtg'));
                $fan->addUserFan($fantagId);
                $wgOut->redirect($fan->title->getFullURL());
            }
            if ($fanboxId) {
                $title = Title::newFromID($fanboxId);
                $update_fan = new FanBox($title);
                $update_fan->updateFan($wgRequest->getVal('inputLeftSide'), $wgRequest->getVal('textColorLeftSideColor'), $wgRequest->getVal('bgColorLeftSideColor'), $wgRequest->getVal('inputRightSide'), $wgRequest->getVal('textColorRightSideColor'), $wgRequest->getVal('bgColorRightSideColor'), $wgRequest->getVal('fantag_image_name'), $wgRequest->getVal('textSizeLeftSide'), $wgRequest->getVal('textSizeRightSide'), $fanboxId, $wgRequest->getVal('pageCtg'));
                $wgOut->redirect($update_fan->title->getFullURL());
            }
        }
    }
Exemplo n.º 3
0
 /**
  * Callback function for the registerFanTag() function that expands <fan>
  * into valid HTML.
  *
  * @param $input
  * @param $argv Array: array of user-supplied arguments
  * @param $parser Object: instance of Parser
  * @return String: HTML
  */
 public static function embedFanBox($input, $argv, $parser)
 {
     global $wgUser, $wgHooks;
     $parser->disableCache();
     $wgHooks['BeforePageDisplay'][] = 'FanBoxHooks::addFanBoxScripts';
     $fan_name = $argv['name'];
     if (!$fan_name) {
         return '';
     }
     $fan = FanBox::newFromName($fan_name);
     $output = '';
     if ($fan->exists()) {
         $output .= $fan->outputFanBox();
         $fantagId = $fan->getFanBoxId();
         $output .= '<div id="show-message-container' . intval($fantagId) . '">';
         if ($wgUser->isLoggedIn()) {
             $check = $fan->checkIfUserHasFanBox();
             if ($check == 0) {
                 $output .= $fan->outputIfUserDoesntHaveFanBox();
             } else {
                 $output .= $fan->outputIfUserHasFanBox();
             }
         } else {
             $output .= $fan->outputIfUserNotLoggedIn();
         }
         $output .= '</div>';
     }
     return $output;
 }