/** * 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; }
public function execute() { global $wgHooks; $out = $this->mSpecial->getOutput(); if (!ModerationCanSkip::canSkip($this->moderator)) { // In order to merge, moderator must also be automoderated throw new ModerationError('moderation-merge-not-automoderated'); } $dbw = wfGetDB(DB_MASTER); $row = $dbw->selectRow('moderation', array('mod_namespace AS namespace', 'mod_title AS title', 'mod_user_text AS user_text', 'mod_text AS text', 'mod_conflict AS conflict'), array('mod_id' => $this->id), __METHOD__); if (!$row) { throw new ModerationError('moderation-edit-not-found'); } if (!$row->conflict) { throw new ModerationError('moderation-merge-not-needed'); } $title = Title::makeTitle($row->namespace, $row->title); $article = new Article($title); ModerationEditHooks::$NewMergeID = $this->id; $editPage = new EditPage($article); $editPage->isConflict = true; $editPage->setContextTitle($title); $editPage->textbox1 = $row->text; $editPage->summary = wfMessage("moderation-merge-comment", $row->user_text)->inContentLanguage()->plain(); $editPage->showEditForm(); }
/** * Concatenate categories on EditPage POST * * @param EditPage $editPage * @param WebRequest $request * * @return Boolean because it's a hook */ public static function onEditPageImportFormData($editPage, $request) { $app = F::app(); if ($request->wasPosted()) { $categories = $editPage->safeUnicodeInput($request, 'categories'); $categories = CategoryHelper::changeFormat($categories, 'json', 'array'); // Concatenate categories to article wikitext (if there are any). if (!empty($categories)) { if (!empty($app->wg->EnableAnswers)) { // don't add categories if the page is a redirect $magicWords = $app->wg->ContLang->getMagicWords(); $redirects = $magicWords['redirect']; // first element doesn't interest us array_shift($redirects); // check for localized versions of #REDIRECT foreach ($redirects as $alias) { if (stripos($editPage->textbox1, $alias) === 0) { return true; } } } // Extract categories from the article, merge them with those passed in, weed out // duplicates and finally append them back to the article (BugId:99348). $data = CategoryHelper::extractCategoriesFromWikitext($editPage->textbox1, true); $categories = CategoryHelper::getUniqueCategories($data['categories'], $categories); $categories = CategoryHelper::changeFormat($categories, 'array', 'wikitext'); // Remove trailing whitespace (BugId:11238) $editPage->textbox1 = $data['wikitext'] . rtrim($categories); } } return true; }
public function getDiff($wikitext, $section = '') { wfProfileIn(__METHOD__); $section = intval($section); // create "fake" EditPage if (function_exists('CategorySelectInitializeHooks')) { CategorySelectInitializeHooks(null, null, $this->mTitle, null, null, null, true); } $article = new Article($this->mTitle); $editPage = new EditPage($article); $editPage->textbox1 = $wikitext; $editPage->edittime = null; $editPage->section = $section > 0 ? $section : ''; // render diff HTML to $wgOut $out = $this->app->getGlobal('wgOut'); $oldHtml = $out->getHTML(); $out->clearHTML(); $editPage->showDiff(); $diff = $out->getHTML(); // restore state of output $out->clearHTML(); $out->addHTML($oldHtml); wfProfileOut(__METHOD__); return $diff; }
/** * Monitors edit page usage */ public static function onEditForm(EditPage $editPage) { global $wgUser, $wgEditPageTrackingRegistrationCutoff, $wgMemc; // Anonymous users if ($wgUser->isAnon()) { return true; } if ($wgEditPageTrackingRegistrationCutoff && $wgUser->getRegistration() < $wgEditPageTrackingRegistrationCutoff) { // User registered before the cutoff return true; } if (EditPageTracking::getFirstEditPage($wgUser)) { // Already stored. return true; } // Record it $dbw = wfGetDB(DB_MASTER); $title = $editPage->getArticle()->getTitle(); $timestamp = wfTimestampNow(); $row = array('ept_user' => $wgUser->getId(), 'ept_namespace' => $title->getNamespace(), 'ept_title' => $title->getDBkey(), 'ept_timestamp' => $dbw->timestamp($timestamp)); $dbw->insert('edit_page_tracking', $row, __METHOD__); $wgUser->mFirstEditPage = $timestamp; $cacheKey = wfMemcKey('first-edit-page', $wgUser->getId()); $wgMemc->set($cacheKey, $timestamp, 86400); return true; }
public function show() { $page = $this->page; $user = $this->getUser(); if (wfRunHooks('CustomEditor', array($page, $user))) { $editor = new EditPage($page); $editor->edit(); } }
function run() { wfProfileIn('DSMWPropertyTypeJob::run()'); $title = Title::newFromText('changeSetID', SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title); $editpage = new EditPage($article); $editpage->textbox1 = '[[has type::String]]'; $editpage->attemptSave(); } $title = Title::newFromText('hasSemanticQuery', SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title); $editpage = new EditPage($article); $editpage->textbox1 = '[[has type::String]]'; $editpage->attemptSave(); } $title = Title::newFromText('patchID', SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title); $editpage = new EditPage($article); $editpage->textbox1 = '[[has type::String]]'; $editpage->attemptSave(); } $title = Title::newFromText('siteID', SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title); $editpage = new EditPage($article); $editpage->textbox1 = '[[has type::String]]'; $editpage->attemptSave(); } $title = Title::newFromText('pushFeedServer', SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title); $editpage = new EditPage($article); $editpage->textbox1 = '[[has type::URL]]'; $editpage->attemptSave(); } $title = Title::newFromText('pushFeedName', SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title); $editpage = new EditPage($article); $editpage->textbox1 = '[[has type::String]]'; $editpage->attemptSave(); } $title = Title::newFromText('hasOperation', SMW_NS_PROPERTY); if (!$title->exists()) { $article = new Article($title); $editpage = new EditPage($article); $editpage->textbox1 = '[[has type::Record]] [[has fields::String;String;String;Text]]'; $editpage->attemptSave(); } wfProfileOut('DSMWPropertyTypeJob::run()'); return true; }
/** * @since 1.1 * * @param EditPage $editor * @param OutputPage &$out * * @return true */ public function onEditConflict(EditPage &$editor, OutputPage &$out) { $conctext = $editor->textbox1; $actualtext = $editor->textbox2; $initialtext = $editor->getBaseRevision()->mText; // TODO: WTF?! $editor->mArticle->doEdit($actualtext, $editor->summary, $editor->minoredit ? EDIT_MINOR : 0); $query = Title::newFromRedirect($actualtext) === null ? '' : 'redirect=no'; $out->redirect($editor->mTitle->getFullURL($query)); return true; }
/** * Insert the captcha prompt into an edit form. * @param EditPage $editPage */ function editShowCaptcha($editPage) { $context = $editPage->getArticle()->getContext(); $page = $editPage->getArticle()->getPage(); $out = $context->getOutput(); if (isset($page->ConfirmEdit_ActivateCaptcha) || $this->showEditCaptcha || $this->shouldCheck($page, '', '', false)) { $out->addWikiText($this->getMessage($this->action)); $out->addHTML($this->getForm()); } unset($page->ConfirmEdit_ActivateCaptcha); }
function wfAntiSpamInputCheck() { if (!empty($_POST['antispam'])) { $title = new Title(); $article = new Article($title); $edit = new EditPage($article); $edit->spamPageWithContent(); return false; } else { return true; } }
/** * @desc Redirects to Special:CSS if this is a try of edition of Wikia.css * * @param EditPage $editPage * @return bool */ public static function onAlternateEdit(EditPage $editPage) { wfProfileIn(__METHOD__); $app = F::app(); $model = new SpecialCssModel(); if (static::shouldRedirect($app, $model, $editPage->getArticle()->getTitle())) { $oldid = $app->wg->Request->getIntOrNull('oldid'); $app->wg->Out->redirect($model->getSpecialCssUrl(false, $oldid ? array('oldid' => $oldid) : null)); } wfProfileOut(__METHOD__); return true; }
/** * 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; }
/** * Display the Edit page for an article for an AJAX request. Outputs * HTML. * * @param Title $title title object describing which article to edit */ public static function showEditForm($title) { global $wgRequest, $wgTitle, $wgOut; $wgTitle = $title; $article = new Article($title); $editor = new EditPage($article); $editor->edit(); if ($wgOut->mRedirect != '' && $wgRequest->wasPosted()) { $wgOut->redirect(''); $rev = Revision::newFromTitle($title); $wgOut->addHTML($wgOut->parse($rev->getText())); } }
public function show() { if ($this->getContext()->getConfig()->get('UseMediaWikiUIEverywhere')) { $out = $this->getOutput(); $out->addModuleStyles(array('mediawiki.ui.input', 'mediawiki.ui.checkbox')); } $page = $this->page; $user = $this->getUser(); if (wfRunHooks('CustomEditor', array($page, $user))) { $editor = new EditPage($page); $editor->edit(); } }
public function show() { $this->useTransactionalTimeLimit(); $out = $this->getOutput(); $out->setRobotPolicy('noindex,nofollow'); if ($this->getContext()->getConfig()->get('UseMediaWikiUIEverywhere')) { $out->addModuleStyles(array('mediawiki.ui.input', 'mediawiki.ui.checkbox')); } $page = $this->page; $user = $this->getUser(); if (Hooks::run('CustomEditor', array($page, $user))) { $editor = new EditPage($page); $editor->edit(); } }
public function checkPermissions(User $user, $reason) { $status = new Status(); $errors = wfMergeErrorArrays($this->oldTitle->getUserPermissionsErrors('move', $user), $this->oldTitle->getUserPermissionsErrors('edit', $user), $this->newTitle->getUserPermissionsErrors('move-target', $user), $this->newTitle->getUserPermissionsErrors('edit', $user)); // Convert into a Status object if ($errors) { foreach ($errors as $error) { call_user_func_array(array($status, 'fatal'), $error); } } if (EditPage::matchSummarySpamRegex($reason) !== false) { // This is kind of lame, won't display nice $status->fatal('spamprotectiontext'); } # The move is allowed only if (1) the target doesn't exist, or # (2) the target is a redirect to the source, and has no history # (so we can undo bad moves right after they're done). if ($this->newTitle->getArticleID()) { # Target exists; check for validity if (!$this->isValidMoveTarget()) { $status->fatal('articleexists'); } } else { $tp = $this->newTitle->getTitleProtection(); if ($tp !== false) { if (!$user->isAllowed($tp['permission'])) { $status->fatal('cantmove-titleprotected'); } } } Hooks::run('MovePageCheckPermissions', array($this->oldTitle, $this->newTitle, $user, $reason, $status)); return $status; }
function __construct($article) { //$wgRequest; $this->name = $article->getTitle()->getPartialURL(); //$this->mode = parent::__construct($article); }
public function show() { $page = $this->page; $request = $this->getRequest(); $user = $this->getUser(); $context = $this->getContext(); if (wfRunHooks('CustomEditor', array($page, $user))) { if (ExternalEdit::useExternalEngine($context, 'edit') && $this->getName() == 'edit' && !$request->getVal('section') && !$request->getVal('oldid')) { $extedit = new ExternalEdit($context); $extedit->execute(); } else { $editor = new EditPage($page); $editor->edit(); } } }
function alfCustomActions($action, $article) { if ($action == "createPage") { $pageContent = ""; if (isset($_REQUEST["pageContent"]) == true) { $pageContent = $_REQUEST["pageContent"]; } // Create the new page with the given title $editor = new EditPage($article); $editor->save = true; $editor->textbox1 = urldecode($pageContent); $editor->attemptSave(); return false; } else { return true; } }
/** * Perform "reverse" parsing of HTML to wikitext when saving / doing preview from wysiwyg mode * * @param EditPage $form */ public static function reverse($form, $out = null) { global $wgRequest; wfProfileIn(__METHOD__); if ($wgRequest->wasPosted()) { if ($wgRequest->getVal('RTEMode') == 'wysiwyg') { RTE::log('performing reverse parsing back to wikitext'); if ($out == null) { $wikitext = RTE::HtmlToWikitext($wgRequest->getText('wpTextbox1')); $wgRequest->setVal('wpTextbox1', $wikitext); } else { $form->textbox1 = $form->getContent(); } } } wfProfileOut(__METHOD__); return true; }
function createComment($title = null, $commenter = null, $text = null) { global $wgTitle; $text = $text ? $text : 'The quick brown fox jumps over the lazy dog'; $commentTitle = Title::newFromText(sprintf("%s/%s-%s", $title->getText(), $commenter, wfTimestampNow()), NS_BLOG_ARTICLE_TALK); $wgTitle = $commentTitle; /** * add article using EditPage class (for hooks) */ $result = null; $article = new Article($commentTitle, 0); $editPage = new EditPage($article); $editPage->edittime = $article->getTimestamp(); $editPage->textbox1 = $text; $retval = $editPage->internalAttemptSave($result); $value = $retval->value; Wikia::log(__METHOD__, "editpage", "Returned value {$value}"); return array($value, $article); }
/** * 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; }
public function show() { $page = $this->page; $request = $this->getRequest(); $user = $this->getUser(); $context = $this->getContext(); if (wfRunHooks('CustomEditor', array($page, $user))) { if (ExternalEdit::useExternalEngine($context, 'edit') && $this->getName() == 'edit' && !$request->getVal('section') && !$request->getVal('oldid')) { $extedit = new ExternalEdit($context); $extedit->execute(); } else { $editor = new EditPage($page); /* Wikia change begin - @author: macbre */ /* Allow extensions to change EditPage class used for rendering edit pages */ wfRunHooks('AlternateEditPageClass', array(&$editor)); /* Wikia change - end */ $editor->edit(); } } }
/** * This is a hack to fix * http://dev.fckeditor.net/ticket/1174 * If RTE is enabled, diff must be performed on WikiText, not on HTML */ function showDiff() { global $wgFCKWikiTextBeforeParse; if (isset($wgFCKWikiTextBeforeParse)) { $_textbox1 = $this->textbox1; $this->textbox1 = $wgFCKWikiTextBeforeParse; } $result = parent::showDiff(); if (isset($wgFCKWikiTextBeforeParse)) { $this->textbox1 = $_textbox1; } }
public function submitFlags(&$params) { global $wgUser, $webplatformSectionCommentsSMW; $aTemp = json_decode($params['flags'], true); $aProperties = array(); foreach ($aTemp as $key => $value) { $aTempKey = array(); if (preg_match('#.*?\\[(.*?)\\]\\[.*?\\]#', $key, $aTempKey) && $value != '1') { $aProperties[$aTempKey[1]][] = $value; } } $sbuiltString = ''; foreach ($aProperties as $key => $value) { $sbuiltString .= "\n|" . $key . '='; $aTemp = array(); foreach ($value as $key => $val) { $aTemp[] = $val; } $sbuiltString .= implode(',', $aTemp); } $oArticle = Article::newFromID($params['pageId']); $sContent = $oArticle->fetchContent(); $sNewContent = preg_replace('#(\\{\\{' . $webplatformSectionCommentsSMW['template'] . ').*?(\\}\\})#s', "\$1{$sbuiltString}\n\$2", $sContent); $aData = array('wpTextbox1' => $sNewContent, 'wpSummary' => 'no summary', 'wpStarttime' => 'nostarttime', 'wpEdittime' => 'noedittime', 'wpEditToken' => $wgUser->isLoggedIn() ? $wgUser->editToken() : EDIT_TOKEN_SUFFIX, 'wpSave' => '', 'action' => 'submit'); $oRequest = new FauxRequest($aData, true); $oEditor = new EditPage($oArticle); $oEditor->importFormData($oRequest); // Try to save the page! $aResultDetails = array(); $oSaveResult = $oEditor->internalAttemptSave($aResultDetails); // Return value was made an object in MW 1.19 if (is_object($oSaveResult)) { $sSaveResultCode = $oSaveResult->value; } else { $sSaveResultCode = $oSaveResult; } $params['html_response'] = $sSaveResultCode; }
/** * 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; }
function hAlternateEdit(&$eobj) { if ($this->inproc) { return true; } # allow other extensions a chance to execute. # first off, disable AlternateEdit hook # or else some serious reentrance issue! $this->inproc = true; # Substitute the standard EditPage Object # normally created by MW by a slightly modified # processing flow. $ne = new EditPage($eobj->mArticle); # let the new object follow the normal processing course $ne->submit(); # run our hook wfRunHooks('AfterEdit', array(&$ne)); # Stop MW from performing normal processing on our # way to the standard work flow. # If this extension was loaded first against the # 'AlternateEdit' hook, then other extensions on this hook # won't be called twice. return false; }
function edit() { global $wgOut, $wgUser, $wgHooks, $wgTitle; //add some user variables $seqPlayer = new MV_SequencePlayer($wgTitle); mvAddGlobalJSVariables(array('mvSeqExportUrl' => $seqPlayer->getExportUrl())); //add the "switch" link to the top of the page $wgOut->addHTML('<span id="swich_seq_links"> <a id="swich_seq_text" style="display:none" href="javascript:mv_do_sequence_edit_swap(\'text\')">' . wfMsg('mv_sequence_edit_text') . '</a>' . '<a id="switch_seq_wysiwyg" href="javascript:mv_do_sequence_edit_swap(\'seq_update\')">' . wfMsg('mv_sequence_edit_visual_editor') . '</a>' . '</span>' . '<div id="seq_edit_container" style="display:none;position:relative;width:100%;height:580px;background:#AAA"></div>'); $wgOut->addHTML('<div id="mv_text_edit_container"> '); parent::edit(); $wgOut->addHTML('</div>'); }
protected function importContentFormData(&$request) { $format = $request->getVal('format', CollaborationListContentHandler::FORMAT_WIKI); if ($format !== CollaborationListContentHandler::FORMAT_WIKI) { return parent::importContentFormData($request); } $desc = trim($request->getText('wpCollabDescTextbox')); if ($desc === null) { // Only 1 textbox? return parent::importContentFormData($request); } $main = trim($request->getText('wpTextbox1', '')); $options = $request->getText('wpCollaborationKitOptions', ''); return $desc . CollaborationListContent::HUMAN_DESC_SPLIT . $options . CollaborationListContent::HUMAN_DESC_SPLIT . $main; }
protected function getFormFields() { $that = $this; $fields = array('pagetitle' => array('type' => 'text', 'name' => 'pagetitle', 'default' => $this->par, 'label-message' => 'changecontentmodel-title-label', 'validation-callback' => array($this, 'validateTitle'))); if ($this->title) { $fields['pagetitle']['readonly'] = true; $fields += array('model' => array('type' => 'select', 'name' => 'model', 'options' => $this->getOptionsForTitle($this->title), 'label-message' => 'changecontentmodel-model-label'), 'reason' => array('type' => 'text', 'name' => 'reason', 'validation-callback' => function ($reason) use($that) { $match = EditPage::matchSummarySpamRegex($reason); if ($match) { return $that->msg('spamprotectionmatch', $match)->parse(); } return true; }, 'label-message' => 'changecontentmodel-reason-label')); } return $fields; }