r95082 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95081‎ | r95082 | r95083 >
Date:13:32, 20 August 2011
Author:ialex
Status:ok
Tags:
Comment:
Per Tbleher, fix for r94640: use EditPage instead of directly WikiPage::doEdit() so that checks on block and spam stuff can be done.
Modified paths:
  • /trunk/extensions/Commentbox/SpecialAddComment_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Commentbox/SpecialAddComment_body.php
@@ -20,12 +20,7 @@
2121 return;
2222 }
2323 $this->setHeaders();
24 -
2524
26 - if ( !$this->userCanExecute( $wgUser ) ) {
27 - $this->displayRestrictionError();
28 - return;
29 - }
3025 $Pagename = $wgRequest->getText( 'wpPageName' );
3126 $Author = $wgRequest->getText( 'wpAuthor', '' );
3227 $Comment = $wgRequest->getText( 'wpComment', '' );
@@ -75,14 +70,38 @@
7671 // Append <br /> after each newline, except if the user started a new paragraph
7772 $Comment = preg_replace( '/(?<!\n)\n(?!\n)/', "<br />\n", $Comment );
7873 $text .= "\n\n" . $subject . $Comment . "\n<br />" . $sig;
79 - $status = $article->doEdit( $text, wfMsgForContent( 'commentbox-log' ) );
8074
81 - if ( $status->isOK() ) {
 75+ $reqArr = array(
 76+ 'wpTextbox1' => $text,
 77+ 'wpSummary' => wfMsgForContent( 'commentbox-log' ),
 78+ 'wpEditToken' => $wgUser->editToken(),
 79+ 'wpIgnoreBlankSummary' => '',
 80+ 'wpStarttime' => wfTimestampNow(),
 81+ 'wpEdittime' => $article->getTimestamp(),
 82+ );
 83+ $request = new FauxRequest( $reqArr, true );
 84+ $ep = new EditPage( $article );
 85+ $ep->setContextTitle( $title );
 86+ $ep->importFormData( $request );
 87+ $details = array(); // Passed by ref
 88+ $retval = $ep->internalAttemptSave( $details );
 89+
 90+ switch ( $retval ) {
 91+ case EditPage::AS_SUCCESS_UPDATE:
8292 $wgOut->redirect( $title->getFullURL() );
83 - } else {
84 - $wgOut->setPageTitle( wfMsg( 'commentbox-errorpage-title' ) );
85 - $wgOut->addWikiText( $status->getWikiText() );
86 - $wgOut->returnToMain( false, $title );
 93+ break;
 94+ case EditPage::AS_SPAM_ERROR:
 95+ $ep->spamPageWithContent( $details['spam'] );
 96+ break;
 97+ case EditPage::AS_BLOCKED_PAGE_FOR_USER:
 98+ $wgOut->blockedPage();
 99+ break;
 100+ case EditPage::AS_READ_ONLY_PAGE_ANON:
 101+ case EditPage::AS_READ_ONLY_PAGE_LOGGED:
 102+ $wgOut->permissionRequired( 'edit' );
 103+ break;
 104+ case EditPage::AS_READ_ONLY_PAGE:
 105+ $wgOut->readOnlyPage();
87106 }
88107 }
89108

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94640Removed usage of internal API call in Special:AddComment that was broken by r...ialex14:45, 16 August 2011

Status & tagging log