/**
  * Executes special page rendering and data processing
  *
  * @param $sub Mixed: MediaWiki supplied sub-page path
  * @throws PermissionsError
  */
 public function execute($sub)
 {
     $out = $this->getOutput();
     $user = $this->getUser();
     $request = $this->getRequest();
     // Begin output
     $this->setHeaders();
     // Make sure the user is logged in
     if (!$user->isLoggedIn()) {
         throw new PermissionsError('read');
     }
     // Handle discarding
     $draft = Draft::newFromID($request->getIntOrNull('discard'));
     if ($draft->exists()) {
         // Discard draft
         $draft->discard();
         // Redirect to the article editor or view if returnto was set
         $section = $request->getIntOrNull('section');
         $urlSection = $section !== null ? "&section={$section}" : '';
         switch ($request->getText('returnto')) {
             case 'edit':
                 $title = Title::newFromDBKey($draft->getTitle());
                 $out->redirect(wfExpandURL($title->getEditURL() . $urlSection));
                 break;
             case 'view':
                 $title = Title::newFromDBKey($draft->getTitle());
                 $out->redirect(wfExpandURL($title->getFullURL() . $urlSection));
                 break;
         }
     }
     // Show list of drafts, or a message that there are none
     if (Drafts::display() == 0) {
         $out->addWikiMsg('drafts-view-nonesaved');
     }
 }
Beispiel #2
0
 /**
  * Executes special page rendering and data processing
  *
  * @param $sub Mixed: MediaWiki supplied sub-page path
  */
 public function execute($sub)
 {
     global $wgRequest, $wgOut, $wgUser;
     // Begin output
     $this->setHeaders();
     // Make sure the user is logged in
     if (!$wgUser->isLoggedIn()) {
         // If not, let them know they need to
         $wgOut->loginToUse();
         // Continue
         return true;
     }
     // Handle discarding
     $draft = Draft::newFromID($wgRequest->getIntOrNull('discard'));
     if ($draft->exists()) {
         // Discard draft
         $draft->discard();
         // Redirect to the article editor or view if returnto was set
         $section = $wgRequest->getIntOrNull('section');
         $urlSection = $section !== null ? "&section={$section}" : '';
         switch ($wgRequest->getText('returnto')) {
             case 'edit':
                 $title = Title::newFromDBKey($draft->getTitle());
                 $wgOut->redirect(wfExpandURL($title->getEditURL() . $urlSection));
                 break;
             case 'view':
                 $title = Title::newFromDBKey($draft->getTitle());
                 $wgOut->redirect(wfExpandURL($title->getFullURL() . $urlSection));
                 break;
         }
     }
     // Show list of drafts, or a message that there are none
     if (Drafts::display() == 0) {
         $wgOut->addHTML(wfMsgHTML('drafts-view-nonesaved'));
     }
 }