Ejemplo n.º 1
0
 public function output()
 {
     switch ($this->format) {
         case 'json':
             header('Content-Type: application/json; charset=utf-8');
             echo json_encode($this->response);
             break;
             // http://stackoverflow.com/a/8811412/319266
         // http://stackoverflow.com/a/8811412/319266
         case 'jsonp':
             header('Content-Type: text/javascript; charset=utf-8');
             $callback = $this->context->getRequest()->getVal('callback', '');
             echo preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback) . '(' . json_encode($this->response) . ')';
             break;
             // https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/api/ApiFormatPhp.php?revision=103273&view=markup
         // https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/api/ApiFormatPhp.php?revision=103273&view=markup
         case 'php':
             header('Content-Type: application/vnd.php.serialized; charset=utf-8');
             echo serialize($this->response);
             break;
             // http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/api/ApiFormatDump.php?revision=70727&view=markup
         // http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/api/ApiFormatDump.php?revision=70727&view=markup
         case 'debug':
             $debugPage = ApiDebugPage::newFromContext($this->context);
             $debugPage->setApiResponse($this->response);
             $debugPage->output();
             break;
     }
 }
Ejemplo n.º 2
0
 public function output()
 {
     switch ($this->format) {
         case 'json':
             header('Content-Type: application/json; charset=utf-8');
             echo json_encode2($this->response);
             break;
             // http://stackoverflow.com/a/8811412/319266
         // http://stackoverflow.com/a/8811412/319266
         case 'jsonp':
             header('Content-Type: text/javascript; charset=utf-8');
             $callback = $this->context->getRequest()->getVal('callback', '');
             echo preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback) . '(' . json_encode2($this->response) . ')';
             break;
         case 'debug':
             $debugPage = ApiDebugPage::newFromContext($this->context);
             $debugPage->setApiResponse($this->response);
             $debugPage->output();
             break;
     }
 }