Пример #1
0
 /**
  * Callback function for registerParserHook.
  *
  * @param $input String: user-supplied input, unused
  * @param $args Array: user-supplied arguments, unused
  * @param $parser Parser: instance of Parser, unused
  * @return String: HTML
  */
 public static function renderVote($input, $args, $parser)
 {
     global $wgOut;
     wfProfileIn(__METHOD__);
     // Disable parser cache (sadly we have to do this, because the caching is
     // messing stuff up; we want to show an up-to-date rating instead of old
     // or totally wrong rating, i.e. another page's rating...)
     $parser->disableCache();
     // Add CSS & JS
     // In order for us to do this *here* instead of having to do this in
     // registerParserHook(), we must've disabled parser cache
     $wgOut->addModules('ext.voteNY');
     // Define variable - 0 means that we'll get that green voting box by default
     $type = 0;
     // Determine what kind of a voting gadget the user wants: a box or pretty stars?
     if (preg_match("/^\\s*type\\s*=\\s*(.*)/mi", $input, $matches)) {
         $type = htmlspecialchars($matches[1]);
     } elseif (!empty($args['type'])) {
         $type = intval($args['type']);
     }
     $articleID = $wgOut->getTitle()->getArticleID();
     switch ($type) {
         case 0:
             $vote = new Vote($articleID);
             break;
         case 1:
             $vote = new VoteStars($articleID);
             break;
         default:
             $vote = new Vote($articleID);
     }
     $output = $vote->display();
     wfProfileOut(__METHOD__);
     return $output;
 }
Пример #2
0
function RenderVote($input)
{
    global $wgUser, $wgTitle, $wgOut;
    $wgOut->addScript("<script type=\"text/javascript\" src=\"extensions/Vote-Mag/Vote.js\"></script>\n");
    require_once 'VoteClass.php';
    getValue($type, $input, "type");
    switch ($type) {
        case 0:
            $Vote = new Vote($wgTitle->mArticleID);
            break;
        case 1:
            $Vote = new VoteStars($wgTitle->mArticleID);
            break;
        default:
            $Vote = new Vote($wgTitle->mArticleID);
    }
    $Vote->setUser($wgUser->mName, $wgUser->mId);
    $output = $Vote->display();
    return $output;
}