コード例 #1
0
 /**
  * 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');
     }
 }
コード例 #2
0
ファイル: Drafts.pages.php プロジェクト: Tjorriemorrie/app
 /**
  * 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'));
     }
 }
コード例 #3
0
ファイル: Drafts.classes.php プロジェクト: Tjorriemorrie/app
 /**
  * Outputs a table of existing drafts
  *
  * @param $title Object: [optional] Title of article, defaults to all articles
  * @param $userID Integer: [optional] ID of user, defaults to current user
  * @return Number of drafts in the table
  */
 public static function display($title = null, $userID = null)
 {
     global $wgOut, $wgRequest, $wgUser, $wgLang;
     // Gets draftID
     $currentDraft = Draft::newFromID($wgRequest->getIntOrNull('draft'));
     // Output HTML for list of drafts
     $drafts = Drafts::get($title, $userID);
     if (count($drafts) > 0) {
         global $egDraftsLifeSpan;
         // Internationalization
         // Add a summary, on Special:Drafts only
         if (!$title || $title->getNamespace() == NS_SPECIAL) {
             $wgOut->wrapWikiMsg('<div class="mw-drafts-summary">$1</div>', array('drafts-view-summary', $wgLang->formatNum($egDraftsLifeSpan)));
         }
         // Build XML
         $wgOut->addHTML(Xml::openElement('table', array('cellpadding' => 5, 'cellspacing' => 0, 'width' => '100%', 'border' => 0, 'id' => 'drafts-list-table')));
         $wgOut->addHTML(Xml::openElement('tr'));
         $wgOut->addHTML(Xml::element('th', array('width' => '75%', 'nowrap' => 'nowrap'), wfMsg('drafts-view-article')));
         $wgOut->addHTML(Xml::element('th', null, wfMsg('drafts-view-saved')));
         $wgOut->addHTML(Xml::element('th'));
         $wgOut->addHTML(Xml::closeElement('tr'));
         // Add existing drafts for this page and user
         foreach ($drafts as $draft) {
             // Get article title text
             $htmlTitle = $draft->getTitle()->getEscapedText();
             // Build Article Load link
             $urlLoad = $draft->getTitle()->getFullURL('action=edit&draft=' . urlencode($draft->getID()));
             // Build discard link
             $urlDiscard = SpecialPage::getTitleFor('Drafts')->getFullURL(sprintf('discard=%s&token=%s', urlencode($draft->getID()), urlencode($wgUser->editToken())));
             // If in edit mode, return to editor
             if ($wgRequest->getText('action') == 'edit' || $wgRequest->getText('action') == 'submit') {
                 $urlDiscard .= '&returnto=' . urlencode('edit');
             }
             // Append section to titles and links
             if ($draft->getSection() !== null) {
                 // Detect section name
                 $lines = explode("\n", $draft->getText());
                 // If there is any content in the section
                 if (count($lines) > 0) {
                     $htmlTitle .= '#' . htmlspecialchars(trim(trim(substr($lines[0], 0, 255), '=')));
                 }
                 // Modify article link and title
                 $urlLoad .= '&section=' . urlencode($draft->getSection());
                 $urlDiscard .= '&section=' . urlencode($draft->getSection());
             }
             // Build XML
             $wgOut->addHTML(Xml::openElement('tr'));
             $wgOut->addHTML(Xml::openElement('td'));
             $wgOut->addHTML(Xml::element('a', array('href' => $urlLoad, 'style' => 'font-weight:' . ($currentDraft->getID() == $draft->getID() ? 'bold' : 'normal')), $htmlTitle));
             $wgOut->addHTML(Xml::closeElement('td'));
             $wgOut->addHTML(Xml::element('td', null, $wgLang->timeanddate($draft->getSaveTime(), true)));
             $wgOut->addHTML(Xml::openElement('td'));
             $jsClick = "if( wgDraft.getState() !== 'unchanged' )" . "return confirm('" . Xml::escapeJsString(wfMsgHTML('drafts-view-warn')) . "')";
             $wgOut->addHTML(Xml::element('a', array('href' => $urlDiscard, 'onclick' => $jsClick), wfMsg('drafts-view-discard')));
             $wgOut->addHTML(Xml::closeElement('td'));
             $wgOut->addHTML(Xml::closeElement('tr'));
         }
         $wgOut->addHTML(Xml::closeElement('table'));
         // Return number of drafts
         return count($drafts);
     }
     return 0;
 }
コード例 #4
0
ファイル: Drafts.hooks.php プロジェクト: yusufchang/app
 /**
  * EditPage::showEditForm:initial hook
  * Load draft...
  */
 public static function loadForm($editpage)
 {
     global $wgUser, $wgRequest, $wgOut, $wgTitle, $wgLang;
     // Check permissions
     if ($wgUser->isAllowed('edit') && $wgUser->isLoggedIn()) {
         // Get draft
         $draft = Draft::newFromID($wgRequest->getIntOrNull('draft'));
         // Load form values
         if ($draft->exists()) {
             // Override initial values in the form with draft data
             $editpage->textbox1 = $draft->getText();
             $editpage->summary = $draft->getSummary();
             $editpage->scrolltop = $draft->getScrollTop();
             $editpage->minoredit = $draft->getMinorEdit() ? true : false;
         }
         // Save draft on non-save submission
         if ($wgRequest->getVal('action') == 'submit' && $wgUser->editToken() == $wgRequest->getText('wpEditToken') && is_null($wgRequest->getText('wpDraftTitle'))) {
             // If the draft wasn't specified in the url, try using a
             // form-submitted one
             if (!$draft->exists()) {
                 $draft = Draft::newFromID($wgRequest->getIntOrNull('wpDraftID'));
             }
             // Load draft with info
             $draft->setTitle(Title::newFromText($wgRequest->getText('wpDraftTitle')));
             $draft->setSection($wgRequest->getInt('wpSection'));
             $draft->setStartTime($wgRequest->getText('wpStarttime'));
             $draft->setEditTime($wgRequest->getText('wpEdittime'));
             $draft->setSaveTime(wfTimestampNow());
             $draft->setScrollTop($wgRequest->getInt('wpScrolltop'));
             $draft->setText($wgRequest->getText('wpTextbox1'));
             $draft->setSummary($wgRequest->getText('wpSummary'));
             $draft->setMinorEdit($wgRequest->getInt('wpMinoredit', 0));
             // Save draft
             $draft->save();
             // Use the new draft id
             $wgRequest->setVal('draft', $draft->getID());
         }
     }
     // Internationalization
     $numDrafts = Drafts::num($wgTitle);
     // Show list of drafts
     if ($numDrafts > 0) {
         if ($wgRequest->getText('action') !== 'submit') {
             $wgOut->addHTML(Xml::openElement('div', array('id' => 'drafts-list-box')));
             $wgOut->addHTML(Xml::element('h3', null, wfMsg('drafts-view-existing')));
             Drafts::display($wgTitle);
             $wgOut->addHTML(Xml::closeElement('div'));
         } else {
             $jsWarn = "if( !wgAjaxSaveDraft.insync ) return confirm('" . Xml::escapeJsString(wfMsgHTML('drafts-view-warn')) . "')";
             $link = Xml::element('a', array('href' => $wgTitle->getFullURL('action=edit'), 'onclick' => $jsWarn), wfMsgExt('drafts-view-notice-link', array('parsemag'), $wgLang->formatNum($numDrafts)));
             $wgOut->addHTML(wfMsgHTML('drafts-view-notice', $link));
         }
     }
     // Continue
     return true;
 }
コード例 #5
0
 /**
  * EditPage::showEditForm:initial hook
  * Load draft...
  */
 public static function loadForm(EditPage $editpage)
 {
     global $wgRequest;
     $context = $editpage->getArticle()->getContext();
     $user = $context->getUser();
     if (!$user->getOption('extensionDrafts_enable', 'true')) {
         return true;
     }
     //XXCHANGED
     $isGuidedEditor = isset($editpage->mGuided) && $editpage->mGuided;
     $adv = $isGuidedEditor ? "" : "&advanced=true";
     $wgRequest->setVal("guidededitor", $isGuidedEditor);
     // Check permissions
     $request = $context->getRequest();
     if ($user->isAllowed('edit') && $user->isLoggedIn()) {
         // Get draft
         $draft = Draft::newFromID($request->getIntOrNull('draft'));
         // Load form values
         if ($draft->exists()) {
             // Override initial values in the form with draft data
             $editpage->textbox1 = $draft->getText();
             $editpage->summary = $draft->getSummary();
             $editpage->scrolltop = $draft->getScrollTop();
             $editpage->minoredit = $draft->getMinorEdit() ? true : false;
         }
         // Save draft on non-save submission
         if ($request->getVal('action') == 'submit' && $user->getEditToken() == $request->getText('wpEditToken') && is_null($request->getText('wpDraftTitle'))) {
             // If the draft wasn't specified in the url, try using a
             // form-submitted one
             if (!$draft->exists()) {
                 $draft = Draft::newFromID($request->getIntOrNull('wpDraftID'));
             }
             // Load draft with info
             $draft->setTitle(Title::newFromText($request->getText('wpDraftTitle')));
             $draft->setSection($request->getInt('wpSection'));
             $draft->setStartTime($request->getText('wpStarttime'));
             $draft->setEditTime($request->getText('wpEdittime'));
             $draft->setSaveTime(wfTimestampNow());
             $draft->setScrollTop($request->getInt('wpScrolltop'));
             $draft->setText($request->getText('wpTextbox1'));
             $draft->setSummary($request->getText('wpSummary'));
             $draft->setMinorEdit($request->getInt('wpMinoredit', 0));
             // Save draft
             $draft->save();
             // Use the new draft id
             $request->setVal('draft', $draft->getID());
         }
     }
     $out = $context->getOutput();
     $numDrafts = Drafts::num($context->getTitle());
     // Show list of drafts
     if ($numDrafts > 0) {
         if ($request->getText('action') !== 'submit') {
             $out->addHTML(Xml::openElement('div', array('id' => 'drafts-list-box', 'class' => 'minor_section')));
             $out->addHTML(Xml::element('h3', null, $context->msg('drafts-view-existing')->text()));
             Drafts::display($context->getTitle());
             $out->addHTML(Xml::closeElement('div'));
         } else {
             $jsWarn = "if( !wgAjaxSaveDraft.insync ) return confirm('" . Xml::escapeJsString($context->msg('drafts-view-warn')->escaped()) . "')";
             $link = Xml::element('a', array('href' => $context->getTitle()->getFullURL('action=edit'), 'onclick' => $jsWarn), $context->msg('drafts-view-notice-link')->numParams($numDrafts)->text());
             $out->addHTML($context->msg('drafts-view-notice')->rawParams($link)->escaped());
         }
     }
     // Continue
     return true;
 }