Ejemplo n.º 1
0
 function execute($par)
 {
     global $wgOut, $wgRequest, $wgUser, $wgContLang, $wgCollectionMaxArticles;
     // support previous URLs (e.g. used in templates) which used the "$par" part
     // (i.e. subpages of the Special page)
     if ($par) {
         if ($wgRequest->wasPosted()) {
             // don't redirect POST reqs
             // TODO
         }
         $wgOut->redirect(wfAppendQuery(SkinTemplate::makeSpecialUrl('Book'), $wgRequest->appendQueryArray(array('bookcmd' => rtrim($par, '/')), true)));
         return;
     }
     switch ($wgRequest->getVal('bookcmd', '')) {
         case 'book_creator':
             $this->renderBookCreatorPage($wgRequest->getVal('referer', ''), $par);
             return;
         case 'start_book_creator':
             $title = Title::newFromText($wgRequest->getVal('referer', ''));
             if (is_null($title)) {
                 $title = Title::newMainPage();
             }
             CollectionSession::enable();
             $wgOut->redirect($title->getFullURL());
             return;
         case 'stop_book_creator':
             $title = Title::newFromText($wgRequest->getVal('referer', ''));
             if (is_null($title) || $title->equals($this->getTitle($par))) {
                 $title = Title::newMainPage();
             }
             if ($wgRequest->getVal('disable')) {
                 CollectionSession::disable();
             } elseif (!$wgRequest->getVal('continue')) {
                 $this->renderStopBookCreatorPage($title);
                 return;
             }
             $wgOut->redirect($title->getFullURL());
             return;
         case 'add_article':
             if (CollectionSession::countArticles() >= $wgCollectionMaxArticles) {
                 self::limitExceeded();
                 return;
             }
             $oldid = $wgRequest->getInt('oldid', 0);
             $title = Title::newFromText($wgRequest->getVal('arttitle', ''));
             if (!$title) {
                 return;
             }
             if (self::addArticle($title, $oldid)) {
                 if ($oldid == 0) {
                     $redirectURL = $title->getFullURL();
                 } else {
                     $redirectURL = $title->getFullURL('oldid=' . $oldid);
                 }
                 $wgOut->redirect($redirectURL);
             } else {
                 $wgOut->showErrorPage('coll-couldnotaddarticle_title', 'coll-couldnotaddarticle_msg');
             }
             return;
         case 'remove_article':
             $oldid = $wgRequest->getInt('oldid', 0);
             $title = Title::newFromText($wgRequest->getVal('arttitle', ''));
             if (!$title) {
                 return;
             }
             if (self::removeArticle($title, $oldid)) {
                 if ($oldid == 0) {
                     $redirectURL = $title->getFullURL();
                 } else {
                     $redirectURL = $title->getFullURL('oldid=' . $oldid);
                 }
                 $wgOut->redirect($redirectURL);
             } else {
                 $wgOut->showErrorPage('coll-couldnotremovearticle_title', 'coll-couldnotremovearticle_msg');
             }
             return;
         case 'clear_collection':
             CollectionSession::clearCollection();
             $redirect = $wgRequest->getVal('return_to');
             $redirectURL = SkinTemplate::makeSpecialUrl('Book');
             if (!empty($redirect)) {
                 $title = Title::newFromText($redirect);
                 if ($title) {
                     $redirectURL = $title->getFullURL();
                 }
             }
             $wgOut->redirect($redirectURL);
             return;
         case 'set_titles':
             self::setTitles($wgRequest->getText('collectionTitle', ''), $wgRequest->getText('collectionSubtitle', ''));
             $wgOut->redirect(SkinTemplate::makeSpecialUrl('Book'));
             return;
         case 'sort_items':
             self::sortItems();
             $wgOut->redirect(SkinTemplate::makeSpecialUrl('Book'));
             return;
         case 'add_category':
             $title = Title::makeTitleSafe(NS_CATEGORY, $wgRequest->getVal('cattitle', ''));
             if (self::addCategory($title)) {
                 self::limitExceeded();
                 return;
             } else {
                 $wgOut->redirect($wgRequest->getVal('return_to', $title->getFullURL()));
             }
             return;
         case 'remove_item':
             self::removeItem($wgRequest->getInt('index', 0));
             $wgOut->redirect(SkinTemplate::makeSpecialUrl('Book'));
             return;
         case 'move_item':
             self::moveItem($wgRequest->getInt('index', 0), $wgRequest->getInt('delta', 0));
             $wgOut->redirect(SkinTemplate::makeSpecialUrl('Book'));
             return;
         case 'load_collection':
             $title = Title::newFromText($wgRequest->getVal('colltitle', ''));
             if (!$title) {
                 return;
             }
             if ($wgRequest->getVal('cancel')) {
                 $wgOut->redirect($title->getFullURL());
                 return;
             }
             if (!CollectionSession::countArticles() || $wgRequest->getVal('overwrite') || $wgRequest->getVal('append')) {
                 $collection = $this->loadCollection($title, $wgRequest->getVal('append'));
                 if ($collection) {
                     CollectionSession::startSession();
                     CollectionSession::setCollection($collection);
                     CollectionSession::enable();
                     $wgOut->redirect(SkinTemplate::makeSpecialUrl('Book'));
                 }
                 return;
             }
             $this->renderLoadOverwritePage($title);
             return;
         case 'order_collection':
             $title = Title::newFromText($wgRequest->getVal('colltitle', ''));
             if (!$title) {
                 return;
             }
             $collection = $this->loadCollection($title);
             $partner = $wgRequest->getVal('partner', key($this->mPODPartners));
             return $this->postZIP($collection, $partner);
         case 'save_collection':
             if ($wgRequest->getVal('abort')) {
                 $wgOut->redirect(SkinTemplate::makeSpecialUrl('Book'));
                 return;
             }
             if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
                 return;
             }
             $colltype = $wgRequest->getVal('colltype');
             $prefixes = self::getBookPagePrefixes();
             if ($colltype == 'personal') {
                 $collname = $wgRequest->getVal('pcollname');
                 if (!$wgUser->isAllowed('collectionsaveasuserpage') || empty($collname)) {
                     return;
                 }
                 $title = Title::newFromText($prefixes['user-prefix'] . $collname);
             } elseif ($colltype == 'community') {
                 $collname = $wgRequest->getVal('ccollname');
                 if (!$wgUser->isAllowed('collectionsaveascommunitypage') || empty($collname)) {
                     return;
                 }
                 $title = Title::newFromText($prefixes['community-prefix'] . $collname);
             }
             if (!$title) {
                 return;
             }
             if ($this->saveCollection($title, $wgRequest->getBool('overwrite'))) {
                 $wgOut->redirect($title->getFullURL());
             } else {
                 $this->renderSaveOverwritePage($colltype, $title, $wgRequest->getVal('pcollname'), $wgRequest->getVal('ccollname'));
             }
             return;
         case 'render':
             return $this->renderCollection(CollectionSession::getCollection(), SpecialPage::getTitleFor('Book'), $wgRequest->getVal('writer', ''));
         case 'forcerender':
             $this->forceRenderCollection();
             return;
         case 'rendering':
             $this->renderRenderingPage();
             return;
         case 'download':
             $this->download();
             return;
         case 'render_article':
             $title = Title::newFromText($wgRequest->getVal('arttitle', ''));
             if (!$title) {
                 return;
             }
             $oldid = $wgRequest->getInt('oldid', 0);
             $this->renderArticle($title, $oldid, $wgRequest->getVal('writer', 'rl'));
             return;
         case 'render_collection':
             $title = Title::newFromText($wgRequest->getVal('colltitle', ''));
             if (!$title) {
                 return;
             }
             $collection = $this->loadCollection($title);
             if ($collection) {
                 $this->renderCollection($collection, $title, $wgRequest->getVal('writer', 'rl'));
             }
             return;
         case 'post_zip':
             $partner = $wgRequest->getVal('partner', 'pediapress');
             $this->postZIP(CollectionSession::getCollection(), $partner);
             return;
         case 'suggest':
             $add = $wgRequest->getVal('add');
             $ban = $wgRequest->getVal('ban');
             $remove = $wgRequest->getVal('remove');
             $addselected = $wgRequest->getVal('addselected');
             if ($wgRequest->getVal('resetbans')) {
                 CollectionSuggest::run('resetbans');
             } elseif (isset($add)) {
                 CollectionSuggest::run('add', $add);
             } elseif (isset($ban)) {
                 CollectionSuggest::run('ban', $ban);
             } elseif (isset($remove)) {
                 CollectionSuggest::run('remove', $remove);
             } elseif (isset($addselected)) {
                 $articleList = $wgRequest->getArray('articleList');
                 if (!is_null($articleList)) {
                     CollectionSuggest::run('addAll', $articleList);
                 } else {
                     CollectionSuggest::run();
                 }
             } else {
                 CollectionSuggest::run();
             }
             return;
         case '':
             $this->renderSpecialPage();
             return;
         default:
             $wgOut->showErrorPage('coll-unknown_subpage_title', 'coll-unknown_subpage_text');
     }
     return;
 }
 static function clearCollection()
 {
     $_SESSION['wsCollection'] = array('enabled' => true, 'title' => '', 'subtitle' => '', 'items' => array());
     CollectionSuggest::clear();
     self::touchSession();
 }
Ejemplo n.º 3
0
function wfAjaxCollectionSuggestUndoArticle($lastAction, $article)
{
    $json = new Services_JSON();
    $result = CollectionSuggest::undo($lastAction, $article);
    $r = new AjaxResponse($json->encode($result));
    $r->setContentType('application/json');
    return $r;
}