コード例 #1
0
 public static function showUnmoderatedEdit(&$text, &$title, &$editPage)
 {
     global $wgRequest, $wgOut;
     $section = $wgRequest->getVal('section');
     if ($section && $section == 'new') {
         return;
     }
     # Nothing to preload if new section is being created
     $row = ModerationPreload::loadUnmoderatedEdit($title);
     if (!$row) {
         return;
     }
     $wgOut->addModules('ext.moderation.edit');
     $wgOut->wrapWikiMsg('<div id="mw-editing-your-version">$1</div>', array('moderation-editing-your-version'));
     $text = $row->text;
     if ($editPage) {
         $editPage->summary = $row->comment;
         if ($section != false) {
             $fullContent = ContentHandler::makeContent($text, $title);
             $sectionContent = $fullContent->getSection($section);
             if ($sectionContent) {
                 $text = $sectionContent->getNativeData();
             }
         }
     }
 }
コード例 #2
0
 public static function onPageContentSave(&$page, &$user, &$content, &$summary, $is_minor, $is_watch, $section, &$flags, &$status)
 {
     global $wgOut, $wgContLang;
     if (ModerationCanSkip::canSkip($user)) {
         return true;
     }
     $old_content = $page->getContent(Revision::RAW);
     // current revision's content
     $request = $user->getRequest();
     $title = $page->getTitle();
     $popts = ParserOptions::newFromUserAndLang($user, $wgContLang);
     $dbw = wfGetDB(DB_MASTER);
     $fields = array('mod_timestamp' => $dbw->timestamp(wfTimestampNow()), 'mod_user' => $user->getId(), 'mod_user_text' => $user->getName(), 'mod_cur_id' => $page->getId(), 'mod_namespace' => $title->getNamespace(), 'mod_title' => $title->getText(), 'mod_comment' => $summary, 'mod_minor' => $is_minor, 'mod_bot' => $flags & EDIT_FORCE_BOT, 'mod_new' => $page->exists() ? 0 : 1, 'mod_last_oldid' => $page->getLatest(), 'mod_ip' => $request->getIP(), 'mod_old_len' => $old_content ? $old_content->getSize() : 0, 'mod_new_len' => $content->getSize(), 'mod_header_xff' => $request->getHeader('X-Forwarded-For'), 'mod_header_ua' => $request->getHeader('User-Agent'), 'mod_text' => $content->preSaveTransform($title, $user, $popts)->getNativeData(), 'mod_preload_id' => ModerationPreload::generatePreloadId(), 'mod_preloadable' => 1);
     $mblockCheck = new ModerationBlockCheck();
     if ($mblockCheck->isModerationBlocked($user->getName())) {
         $fields['mod_rejected'] = 1;
         $fields['mod_rejected_by_user'] = 0;
         $fields['mod_rejected_by_user_text'] = wfMessage('Moderation block')->inContentLanguage()->text();
         $fields['mod_rejected_auto'] = 1;
         $fields['mod_preloadable'] = 1;
         # User can still edit this change, so that spammers won't notice that they are blocked
     }
     // Check if we need to update existing row (if this edit is by the same user to the same page)
     $row = ModerationPreload::loadUnmoderatedEdit($title);
     if (!$row) {
         $dbw->insert('moderation', $fields, __METHOD__);
         ModerationEditHooks::$LastInsertId = $dbw->insertId();
     } else {
         $section = $request->getVal('wpSection', $request->getVal('section'));
         if ($section) {
             #
             # We must recalculate $fields['mod_text'] here.
             # Otherwise if the user adds or modifies two (or more) different sections (in consequent edits),
             # then only modification to the last one will be saved,
             # because $content is [old content] PLUS [modified section from the edit].
             #
             # Difference between $index and $section:
             # $index: section number in $content. $index can't be "new". If $section was "new", then we need to recalculate $index.
             # $section: section number in $saved_content. $section can be "new". Used when calling replaceSection().
             #
             $index = $section;
             if ($section == 'new') {
                 #
                 # Parser doesn't allow to get the LAST section directly.
                 # We have to get the entire TOC - just for a single index.
                 #
                 $sections = $content->getParserOutput($title, null, null, false)->getSections();
                 $new_section_content = end($sections);
                 $index = $new_section_content['index'];
             }
             # $new_section_content is exactly what the user just wrote in the edit form (one section only).
             $new_section_content = $content->getSection($index);
             $saved_content = ContentHandler::makeContent($row->text, null, $content->getModel());
             $new_content = $saved_content->replaceSection($section, $new_section_content, '');
             $fields['mod_text'] = $new_content->preSaveTransform($title, $user, $popts)->getNativeData();
         }
         $dbw->update('moderation', $fields, array('mod_id' => $row->id), __METHOD__);
         ModerationEditHooks::$LastInsertId = $row->id;
     }
     // In case the caller treats "edit-hook-aborted" as an error.
     $dbw->commit();
     /*
     	We have queued this edit for moderation.
     	No need to save anything at this point.
     	Later (if approved) the edit will be saved via doEditContent().
     
     	Here we just redirect the users back to the page they edited
     	(as was the behavior for unmoderated edits).
     	Notification "Your edit was successfully sent for moderation"
     	will be shown by JavaScript.
     */
     $wgOut->redirect($title->getFullURL(array('modqueued' => 1)));
     return false;
 }