コード例 #1
0
 public function execute($sub)
 {
     global $wgOut, $wgRequest, $wgUser;
     /* Control */
     // Gets edit token
     $token = $wgRequest->getText('token');
     // Checks if a token was given
     if ($token) {
         // Validates edit token
         if ($wgUser->editToken() == $token) {
             // Gets module
             $module = $wgRequest->getText('module');
             // Gets action
             $action = $wgRequest->getText('action');
             // Checks that module and action were given
             if ($module and $action) {
                 // Calls action on module
                 CommunityVoice::callModuleAction($module, 'handle', $action);
                 // Finishes page
                 return true;
             } else {
                 throw new MWException($module . ' module or ' . $action . ' action ' . ' not found or are not callable!');
             }
         } else {
             throw new MWException('Invalid edit token!');
         }
     }
     /* View */
     // Begins output
     $this->setHeaders();
     // Breaks sub into path steps
     $path = explode('/', $sub);
     // Checks if a specific module was given
     if (count($path) >= 1 && $path[0] != '') {
         // Calls specific action on module
         CommunityVoice::callModuleAction($path[0], 'show', count($path) >= 2 ? $path[1] : 'Main', $path);
         // Finishes page
         return true;
     }
     // Modules summary view
     foreach (CommunityVoice::getModules() as $module) {
         // Adds heading
         $wgOut->addWikiText('== ' . wfMsg('communityvoice-' . strtolower($module)) . ' ==');
         // Calls summary action on module
         CommunityVoice::callModuleAction($module, 'show', 'Summary', $path);
     }
     // Finishes page
     return true;
 }
コード例 #2
0
 /**
  * Hanlder for ratings scale vote via ajax call
  */
 public static function handleScaleVoteCall($category, $title, $rating, $article)
 {
     // Adds vote and checks for success
     if (self::addVote($category, $title, $rating)) {
         // Gets new rating data
         $rating = self::getAverageRating($category, $title);
         // Builds result
         $result = array('rating' => $rating, 'stats' => CommunityVoice::getMessage('ratings', 'scale-stats', array(round($rating, 1), self::getTotalVotes($category, $title))));
         // Ensure database commits take place (since this is an ajax call)
         $dbw = wfGetDB(DB_MASTER);
         $dbw->commit();
         // Returns result
         return CsJs::toObject($result);
     }
     // Returns error information
     return CsJs::toObject(array('rating' => -1, 'stats' => 'ready'));
 }