/**
  * Blocks view source page & make it so that users cannot create/edit
  * pages that are on the takedown list.
  *
  * @param EditPage $editPage edit page instance
  * @return bool show edit page form?
  */
 public static function onAlternateEdit(EditPage $editPage)
 {
     $wg = F::app()->wg;
     $wf = F::app()->wf;
     $title = $editPage->getTitle();
     // Block view-source on the certain pages.
     if ($title->exists()) {
         // Look at the page-props to see if this page is blocked.
         if (!$wg->user->isAllowed('editlyricfind')) {
             // some users (staff/admin) will be allowed to edit these to prevent vandalism/spam issues.
             $removedProp = $wf->GetWikiaPageProp(WPP_LYRICFIND_MARKED_FOR_REMOVAL, $title->getArticleID());
             if (!empty($removedProp)) {
                 $wg->Out->addHTML(Wikia::errorbox(wfMessage('lyricfind-editpage-blocked')));
                 $blockEdit = true;
             }
         }
     } else {
         // Page is being created. Prevent this if page is prohibited by LyricFind.
         $blockEdit = LyricFindTrackingService::isPageBlockedViaApi($amgId = "", $gracenoteId = "", $title->getText());
         if ($blockEdit) {
             $wg->Out->addHTML(Wikia::errorbox(wfMessage('lyricfind-creation-blocked')));
         }
     }
     return !$blockEdit;
 }
 /**
  * Validates that the revised contents are valid JSON.
  * If not valid, rejects edit with error message.
  * @param EditPage $editor
  * @param string $text: Content of the revised article.
  * @param string &$error: Error message to return.
  * @param string $summary: Edit summary provided for edit.
  * @return True
  */
 static function onEditFilterMerged($editor, $text, &$error, $summary)
 {
     if ($editor->getTitle()->getNamespace() !== NS_SCHEMA) {
         return true;
     }
     $content = new JsonSchemaContent($text);
     try {
         $content->validate();
     } catch (JsonSchemaException $e) {
         $error = $e->getMessage();
     }
     return true;
 }
 /**
  * handler for editFilter hook
  *
  * @param EditPage $editPage -- edit page instance
  * @static
  */
 public static function editFilter($editPage, $text, $section, &$hookError, $summary)
 {
     wfProfileIn(__METHOD__);
     $title = $editPage->getTitle();
     /* 
      * Hook is called for both page creations and edits. We should only check
      * if the page is created = page does not exist (RT#61104)
      */
     if ($title->exists()) {
         wfProfileOut(__METHOD__);
         return true;
     }
     /**
      * pass to check title method
      */
     $ret = PhalanxTitleBlock::checkTitle($title);
     wfProfileOut(__METHOD__);
     return $ret;
 }
 /**
  * Load the JsonData object if we're in one of the configured namespaces
  * @param EditPage $editPage
  */
 public static function onEditPageShowEditFormInitial(&$editPage)
 {
     global $wgJsonData;
     $title = $editPage->getTitle();
     $ns = $title->getNamespace();
     if (JsonData::isJsonDataNeeded($ns)) {
         $wgJsonData = new JsonData($title);
         try {
             $jsonref = $wgJsonData->getJsonRef();
             $jsonref->validate();
         } catch (JsonSchemaException $e) {
             // if the JSON is null, don't sweat an error, since that will
             // frequently be the case for new pages
             if ($e->subtype != 'validate-fail-null' || !$editPage->firsttime) {
                 //TODO: clean up server error mechanism
                 $wgJsonData->servererror .= "<b>" . wfMessage('jsondata-server-error') . "</b>: " . htmlspecialchars($e->getMessage()) . "<br/>";
             }
         } catch (Exception $e) {
             $wgJsonData->servererror .= "<b>" . wfMessage('jsondata-server-error') . "</b>: " . htmlspecialchars($e->getMessage()) . "<br/>";
         }
         $wgJsonData->outputEditor(&$editPage);
     }
     return true;
 }
 /**
  * @param EditPage $editpage
  * @return string
  */
 private static function editBoxes(EditPage $editpage)
 {
     $context = $editpage->getArticle()->getContext();
     $request = $context->getRequest();
     $groupId = $request->getText('loadgroup', '');
     $th = new TranslationHelpers($editpage->getTitle(), $groupId);
     if ($editpage->firsttime && !$request->getCheck('oldid') && !$request->getCheck('undo')) {
         $editpage->textbox1 = (string) $th->getTranslation();
     } else {
         $th->setTranslation($editpage->textbox1);
     }
     TranslationHelpers::addModules($context->getOutput());
     return $th->getBoxes();
 }
 /**
  * Validates that the revised contents are valid JSON.
  * If not valid, rejects edit with error message.
  * @param EditPage $editor
  * @param string $text Content of the revised article.
  * @param string &$error Error message to return.
  * @param string $summary Edit summary provided for edit.
  * @return True
  */
 static function onEditFilterMerged($editor, $text, &$error, $summary)
 {
     if (!$editor->getTitle()->inNamespace(NS_CAMPAIGN)) {
         return true;
     }
     $content = new CampaignContent($text);
     try {
         $content->validate();
     } catch (JsonSchemaException $e) {
         $error = $e->getMessage();
     }
     return true;
 }
Beispiel #7
0
 /**
  * Wikia change - Add modules and console in the editor in Oasis
  *
  * @param  EditPage $editPage
  * @param  Array   $hidden
  * @return bool
  */
 public static function onAfterDisplayingTextbox(EditPage $editPage, &$hidden)
 {
     $app = F::app();
     if (!$app->checkSkin('oasis') || !$editPage instanceof EditPageLayout || $editPage->getTitle()->getNamespace() !== NS_MODULE) {
         return true;
     }
     $editPage->addCustomCheckbox('scribunto_ignore_errors', wfMessage('scribunto-ignore-errors')->escaped(), false);
     $app->wg->Out->addModules('ext.scribunto.edit');
     $app->wg->Out->addHtml('<div class="wikia-scribunto-console"><div id="mw-scribunto-console"></div></div>');
     return true;
 }
 protected function doStore(EditPage $editor)
 {
     $title = $editor->getTitle();
     // If they used redlink=1 and the page exists, redirect to the main article and send notice
     if ($this->getRequest()->getBool('redlink') && $title->exists()) {
         $this->logMessage(wfMessage('sf_autoedit_redlinkexists')->parse(), self::WARNING);
     }
     $permErrors = $title->getUserPermissionsErrors('edit', $this->getUser());
     // if this title needs to be created, user needs create rights
     if (!$title->exists()) {
         $permErrors = array_merge($permErrors, wfArrayDiff2($title->getUserPermissionsErrors('create', $this->getUser()), $permErrors));
     }
     if ($permErrors) {
         // Auto-block user's IP if the account was "hard" blocked
         $this->getUser()->spreadAnyEditBlock();
         foreach ($permErrors as $error) {
             $this->logMessage(call_user_func_array('wfMessage', $error)->parse());
         }
         return;
     }
     $resultDetails = false;
     # Allow bots to exempt some edits from bot flagging
     $bot = $this->getUser()->isAllowed('bot') && $editor->bot;
     $request = $editor->sfFauxRequest;
     if ($editor->tokenOk($request)) {
         $ctx = RequestContext::getMain();
         $tempTitle = $ctx->getTitle();
         $ctx->setTitle($title);
         $status = $editor->internalAttemptSave($resultDetails, $bot);
         $ctx->setTitle($tempTitle);
     } else {
         throw new MWException(wfMessage('session_fail_preview')->parse());
     }
     switch ($status->value) {
         case EditPage::AS_HOOK_ERROR_EXPECTED:
             // A hook function returned an error
             // show normal Edit page
             // remove Preview and Diff standard buttons from editor page
             Hooks::register('EditPageBeforeEditButtons', function (&$editor, &$buttons, &$tabindex) {
                 foreach (array_keys($buttons) as $key) {
                     if ($key !== 'save') {
                         unset($buttons[$key]);
                     }
                 }
             });
             // Context title needed for correct Cancel link
             $editor->setContextTitle($title);
             $editor->showEditForm();
             return false;
             // success
         // success
         case EditPage::AS_CONTENT_TOO_BIG:
             // Content too big (> $wgMaxArticleSize)
         // Content too big (> $wgMaxArticleSize)
         case EditPage::AS_ARTICLE_WAS_DELETED:
             // article was deleted while editting and param wpRecreate == false or form was not posted
         // article was deleted while editting and param wpRecreate == false or form was not posted
         case EditPage::AS_CONFLICT_DETECTED:
             // (non-resolvable) edit conflict
         // (non-resolvable) edit conflict
         case EditPage::AS_SUMMARY_NEEDED:
             // no edit summary given and the user has forceeditsummary set and the user is not editting in his own userspace or talkspace and wpIgnoreBlankSummary == false
         // no edit summary given and the user has forceeditsummary set and the user is not editting in his own userspace or talkspace and wpIgnoreBlankSummary == false
         case EditPage::AS_TEXTBOX_EMPTY:
             // user tried to create a new section without content
         // user tried to create a new section without content
         case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
             // article is too big (> $wgMaxArticleSize), after merging in the new section
         // article is too big (> $wgMaxArticleSize), after merging in the new section
         case EditPage::AS_END:
             // WikiPage::doEdit() was unsuccessfull
             throw new MWException(wfMessage('sf_autoedit_fail', $this->mOptions['target'])->parse());
         case EditPage::AS_HOOK_ERROR:
             // Article update aborted by a hook function
             $this->logMessage('Article update aborted by a hook function', self::DEBUG);
             return false;
             // success
             // TODO: This error code only exists from 1.21 onwards. It is
             // suitably handled by the default branch, but really should get its
             // own branch. Uncomment once compatibility to pre1.21 is dropped.
             //			case EditPage::AS_PARSE_ERROR: // can't parse content
             //
             //				throw new MWException( $status->getHTML() );
             //				return true; // fail
         // success
         // TODO: This error code only exists from 1.21 onwards. It is
         // suitably handled by the default branch, but really should get its
         // own branch. Uncomment once compatibility to pre1.21 is dropped.
         //			case EditPage::AS_PARSE_ERROR: // can't parse content
         //
         //				throw new MWException( $status->getHTML() );
         //				return true; // fail
         case EditPage::AS_SUCCESS_NEW_ARTICLE:
             // Article successfully created
             $query = $resultDetails['redirect'] ? 'redirect=no' : '';
             $anchor = isset($resultDetails['sectionanchor']) ? $resultDetails['sectionanchor'] : '';
             $this->getOutput()->redirect($title->getFullURL($query) . $anchor);
             $this->getResult()->addValue(NULL, 'redirect', $title->getFullURL($query) . $anchor);
             return false;
             // success
         // success
         case EditPage::AS_SUCCESS_UPDATE:
             // Article successfully updated
             $extraQuery = '';
             $sectionanchor = $resultDetails['sectionanchor'];
             // Give extensions a chance to modify URL query on update
             Hooks::run('ArticleUpdateBeforeRedirect', array($editor->getArticle(), &$sectionanchor, &$extraQuery));
             if ($resultDetails['redirect']) {
                 if ($extraQuery == '') {
                     $extraQuery = 'redirect=no';
                 } else {
                     $extraQuery = 'redirect=no&' . $extraQuery;
                 }
             }
             $this->getOutput()->redirect($title->getFullURL($extraQuery) . $sectionanchor);
             $this->getResult()->addValue(NULL, 'redirect', $title->getFullURL($extraQuery) . $sectionanchor);
             return false;
             // success
         // success
         case EditPage::AS_BLANK_ARTICLE:
             // user tried to create a blank page
             $this->logMessage('User tried to create a blank page', self::DEBUG);
             $this->getOutput()->redirect($editor->getContextTitle()->getFullURL());
             $this->getResult()->addValue(NULL, 'redirect', $editor->getContextTitle()->getFullURL());
             return false;
             // success
         // success
         case EditPage::AS_SPAM_ERROR:
             // summary contained spam according to one of the regexes in $wgSummarySpamRegex
             $match = $resultDetails['spam'];
             if (is_array($match)) {
                 $match = $this->getLanguage()->listToText($match);
             }
             throw new MWException(wfMessage('spamprotectionmatch', wfEscapeWikiText($match))->parse());
             // FIXME: Include better error message
         // FIXME: Include better error message
         case EditPage::AS_BLOCKED_PAGE_FOR_USER:
             // User is blocked from editting editor page
             throw new UserBlockedError($this->getUser()->getBlock());
         case EditPage::AS_IMAGE_REDIRECT_ANON:
             // anonymous user is not allowed to upload (User::isAllowed('upload') == false)
         // anonymous user is not allowed to upload (User::isAllowed('upload') == false)
         case EditPage::AS_IMAGE_REDIRECT_LOGGED:
             // logged in user is not allowed to upload (User::isAllowed('upload') == false)
             throw new PermissionsError('upload');
         case EditPage::AS_READ_ONLY_PAGE_ANON:
             // editor anonymous user is not allowed to edit editor page
         // editor anonymous user is not allowed to edit editor page
         case EditPage::AS_READ_ONLY_PAGE_LOGGED:
             // editor logged in user is not allowed to edit editor page
             throw new PermissionsError('edit');
         case EditPage::AS_READ_ONLY_PAGE:
             // wiki is in readonly mode (wfReadOnly() == true)
             throw new ReadOnlyError();
         case EditPage::AS_RATE_LIMITED:
             // rate limiter for action 'edit' was tripped
             throw new ThrottledError();
         case EditPage::AS_NO_CREATE_PERMISSION:
             // user tried to create editor page, but is not allowed to do that ( Title->usercan('create') == false )
             $permission = $title->isTalkPage() ? 'createtalk' : 'createpage';
             throw new PermissionsError($permission);
         default:
             // We don't recognize $status->value. The only way that can happen
             // is if an extension hook aborted from inside ArticleSave.
             // Render the status object into $editor->hookError
             $editor->hookError = '<div class="error">' . $status->getWikitext() . '</div>';
             throw new MWException($status->getHTML());
     }
 }
Beispiel #9
0
    /**
     * @param EditPage $editor
     * @param string $text
     * @param string $error
     * @param string $summary
     * @return bool
     */
    public static function validateScript(EditPage $editor, $text, &$error, $summary)
    {
        global $wgOut;
        $title = $editor->getTitle();
        if (!$title->hasContentModel(CONTENT_MODEL_SCRIBUNTO)) {
            return true;
        }
        $engine = Scribunto::newDefaultEngine();
        $engine->setTitle($title);
        $status = $engine->validate($text, $title->getPrefixedDBkey());
        if ($status->isOK()) {
            return true;
        }
        $errmsg = $status->getWikiText('scribunto-error-short', 'scribunto-error-long');
        $error = <<<WIKI
<div class="errorbox">
{$errmsg}
</div>
<br clear="all" />
WIKI;
        if (isset($status->scribunto_error->params['module'])) {
            $module = $status->scribunto_error->params['module'];
            $line = $status->scribunto_error->params['line'];
            if ($module === $title->getPrefixedDBkey() && preg_match('/^\\d+$/', $line)) {
                $wgOut->addInlineScript('window.location.hash = ' . Xml::encodeJsVar("#mw-ce-l{$line}"));
            }
        }
        return true;
    }