r107653 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107652‎ | r107653 | r107654 >
Date:20:43, 30 December 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Inverted the precedence between section edition and revision undoing, now undo and undoafter will be ignored if the section (or even wpSection) is provided to be consistent the remaining of the interface
* Modified EditPage::getContent() to load the original content only when really needed
* Don't put the 'missing-article' in the textbox when a non-existing revision is provided, instead display it above the form
* Always diff to the current version when showing a conflict or a spam filter match
* Factorised code to get the current text on edit conflict
* Compare the correct text in EditPage::internalAttemptSave()
* Some little coding style fixes
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -694,91 +694,84 @@
695695 global $wgOut, $wgRequest, $wgParser;
696696
697697 wfProfileIn( __METHOD__ );
698 - # Get variables from query string :P
699 - $section = $wgRequest->getVal( 'section' );
700698
701 - $preload = $wgRequest->getVal( 'preload',
702 - // Custom preload text for new sections
703 - $section === 'new' ? 'MediaWiki:addsection-preload' : '' );
704 - $undoafter = $wgRequest->getVal( 'undoafter' );
705 - $undo = $wgRequest->getVal( 'undo' );
 699+ $text = false;
706700
707701 // For message page not locally set, use the i18n message.
708702 // For other non-existent articles, use preload text if any.
709 - if ( !$this->mTitle->exists() ) {
710 - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
 703+ if ( !$this->mTitle->exists() || $section == 'new' ) {
 704+ if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && $section != 'new' ) {
711705 # If this is a system message, get the default text.
712706 $text = $this->mTitle->getDefaultMessageText();
713 - if( $text === false ) {
714 - $text = $this->getPreloadedText( $preload );
715 - }
716 - } else {
 707+ }
 708+ if ( $text === false ) {
717709 # If requested, preload some text.
 710+ $preload = $wgRequest->getVal( 'preload',
 711+ // Custom preload text for new sections
 712+ $this->section === 'new' ? 'MediaWiki:addsection-preload' : '' );
718713 $text = $this->getPreloadedText( $preload );
719714 }
720715 // For existing pages, get text based on "undo" or section parameters.
721716 } else {
722 - $text = $this->mArticle->getContent();
723 - if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
724 - # If they got undoafter and undo round the wrong way, switch them
725 - list( $undo, $undoafter ) = array( $undoafter, $undo );
726 - }
727 - if ( $undo > 0 && $undo > $undoafter ) {
728 - # Undoing a specific edit overrides section editing; section-editing
729 - # doesn't work with undoing.
730 - if ( $undoafter ) {
 717+ if ( $this->section != '' ) {
 718+ // Get section edit text (returns $def_text for invalid sections)
 719+ $text = $wgParser->getSection( $this->getOriginalContent(), $this->section, $def_text );
 720+ } else {
 721+ $undoafter = $wgRequest->getInt( 'undoafter' );
 722+ $undo = $wgRequest->getInt( 'undo' );
 723+
 724+ if ( $undo > 0 && $undoafter > 0 ) {
 725+ if ( $undo < $undoafter ) {
 726+ # If they got undoafter and undo round the wrong way, switch them
 727+ list( $undo, $undoafter ) = array( $undoafter, $undo );
 728+ }
 729+
731730 $undorev = Revision::newFromId( $undo );
732731 $oldrev = Revision::newFromId( $undoafter );
733 - } else {
734 - $undorev = Revision::newFromId( $undo );
735 - $oldrev = $undorev ? $undorev->getPrevious() : null;
736 - }
737732
738 - # Sanity check, make sure it's the right page,
739 - # the revisions exist and they were not deleted.
740 - # Otherwise, $text will be left as-is.
741 - if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
742 - $undorev->getPage() == $oldrev->getPage() &&
743 - $undorev->getPage() == $this->mTitle->getArticleId() &&
744 - !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
745 - !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
 733+ # Sanity check, make sure it's the right page,
 734+ # the revisions exist and they were not deleted.
 735+ # Otherwise, $text will be left as-is.
 736+ if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
 737+ $undorev->getPage() == $oldrev->getPage() &&
 738+ $undorev->getPage() == $this->mTitle->getArticleId() &&
 739+ !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
 740+ !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
746741
747 - $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
748 - if ( $undotext === false ) {
749 - # Warn the user that something went wrong
750 - $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' .
751 - wfMsgNoTrans( 'undo-failure' ) . '</div>', true, /* interface */true );
752 - } else {
753 - $text = $undotext;
754 - # Inform the user of our success and set an automatic edit summary
755 - $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' .
756 - wfMsgNoTrans( 'undo-success' ) . '</div>', true, /* interface */true );
757 - $firstrev = $oldrev->getNext();
758 - # If we just undid one rev, use an autosummary
759 - if ( $firstrev->getId() == $undo ) {
760 - $undoSummary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
761 - if ( $this->summary === '' ) {
762 - $this->summary = $undoSummary;
763 - } else {
764 - $this->summary = $undoSummary . wfMsgForContent( 'colon-separator' ) . $this->summary;
 742+ $text = $this->mArticle->getUndoText( $undorev, $oldrev );
 743+ if ( $text === false ) {
 744+ # Warn the user that something went wrong
 745+ $undoMsg = 'failure';
 746+ } else {
 747+ # Inform the user of our success and set an automatic edit summary
 748+ $undoMsg = 'success';
 749+
 750+ # If we just undid one rev, use an autosummary
 751+ $firstrev = $oldrev->getNext();
 752+ if ( $firstrev->getId() == $undo ) {
 753+ $undoSummary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
 754+ if ( $this->summary === '' ) {
 755+ $this->summary = $undoSummary;
 756+ } else {
 757+ $this->summary = $undoSummary . wfMsgForContent( 'colon-separator' ) . $this->summary;
 758+ }
 759+ $this->undidRev = $undo;
765760 }
766 - $this->undidRev = $undo;
 761+ $this->formtype = 'diff';
767762 }
768 - $this->formtype = 'diff';
 763+ } else {
 764+ // Failed basic sanity checks.
 765+ // Older revisions may have been removed since the link
 766+ // was created, or we may simply have got bogus input.
 767+ $undoMsg = 'norev';
769768 }
770 - } else {
771 - // Failed basic sanity checks.
772 - // Older revisions may have been removed since the link
773 - // was created, or we may simply have got bogus input.
774 - $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' .
775 - wfMsgNoTrans( 'undo-norev' ) . '</div>', true, /* interface */true );
 769+
 770+ $this->editFormPageTop .= $wgOut->parse( "<div class=\"error mw-undo-{$undoMsg}\">" .
 771+ wfMsgNoTrans( 'undo-' . $undoMsg ) . '</div>', true, /* interface */true );
776772 }
777 - } elseif ( $section != '' ) {
778 - if ( $section == 'new' ) {
779 - $text = $this->getPreloadedText( $preload );
780 - } else {
781 - // Get section edit text (returns $def_text for invalid sections)
782 - $text = $wgParser->getSection( $text, $section, $def_text );
 773+
 774+ if ( $text === false ) {
 775+ $text = $this->getOriginalContent();
783776 }
784777 }
785778 }
@@ -788,6 +781,48 @@
789782 }
790783
791784 /**
 785+ * Get the content of the wanted revision, without section extraction.
 786+ *
 787+ * The result of this function can be used to compare user's input with
 788+ * section replaced in its context (using WikiPage::replaceSection())
 789+ * to the original text of the edit.
 790+ *
 791+ * This difers from Article::getContent() that when a missing revision is
 792+ * encountered the result will be an empty string and not the
 793+ * 'missing-article' message.
 794+ *
 795+ * @since 1.19
 796+ * @return string
 797+ */
 798+ private function getOriginalContent() {
 799+ if ( $this->section == 'new' ) {
 800+ return $this->getCurrentText();
 801+ }
 802+ $revision = $this->mArticle->getRevisionFetched();
 803+ if ( $revision === null ) {
 804+ return '';
 805+ }
 806+ return $this->mArticle->getContent();
 807+ }
 808+
 809+ /**
 810+ * Get the actual text of the page. This is basically similar to
 811+ * WikiPage::getRawText() except that when the page doesn't exist an empty
 812+ * string is returned instead of false.
 813+ *
 814+ * @since 1.19
 815+ * @return string
 816+ */
 817+ private function getCurrentText() {
 818+ $text = $this->mArticle->getRawText();
 819+ if ( $text === false ) {
 820+ return '';
 821+ } else {
 822+ return $text;
 823+ }
 824+ }
 825+
 826+ /**
792827 * Use this method before edit() to preload some text into the edit box
793828 *
794829 * @param $text string
@@ -1245,7 +1280,7 @@
12461281
12471282 # Handle the user preference to force summaries here, but not for null edits
12481283 if ( $this->section != 'new' && !$this->allowBlankSummary
1249 - && 0 != strcmp( $this->mArticle->getContent(), $text )
 1284+ && $this->getOriginalContent() != $text
12501285 && !Title::newFromRedirect( $text ) ) # check if it's not a redirect
12511286 {
12521287 if ( md5( $this->summary ) == $this->autoSumm ) {
@@ -1721,7 +1756,10 @@
17221757 // and fallback to the raw wpTextbox1 since editconflicts can't be
17231758 // resolved between page source edits and custom ui edits using the
17241759 // custom edit ui.
1725 - $this->showTextbox1( null, $this->getContent() );
 1760+ $this->textbox2 = $this->textbox1;
 1761+ $this->textbox1 = $this->getCurrentText();
 1762+
 1763+ $this->showTextbox1();
17261764 } else {
17271765 $this->showContentForm();
17281766 }
@@ -1750,8 +1788,9 @@
17511789 HTML
17521790 );
17531791
1754 - if ( $this->isConflict )
 1792+ if ( $this->isConflict ) {
17551793 $this->showConflict();
 1794+ }
17561795
17571796 $wgOut->addHTML( $this->editFormTextBottom );
17581797 $wgOut->addHTML( "</form>\n" );
@@ -1837,6 +1876,12 @@
18381877 $this->mArticle->setOldSubtitle( $revision->getId() );
18391878 $wgOut->addWikiMsg( 'editingold' );
18401879 }
 1880+ } else {
 1881+ // Something went wrong
 1882+
 1883+ $wgOut->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>\n",
 1884+ array( 'missing-article', $this->mTitle->getPrefixedText(),
 1885+ wfMsgNoTrans( 'missingarticle-rev', $this->oldid ) ) );
18411886 }
18421887 }
18431888 }
@@ -2167,11 +2212,7 @@
21682213 function showDiff() {
21692214 global $wgUser, $wgContLang, $wgParser, $wgOut;
21702215
2171 - if ( $this->section == 'new' ) {
2172 - $oldtext = $this->mArticle->getRawText();
2173 - } else {
2174 - $oldtext = $this->mArticle->fetchContent();
2175 - }
 2216+ $oldtext = $this->getOriginalContent();
21762217 $newtext = $this->mArticle->replaceSection(
21772218 $this->section, $this->textbox1, $this->summary, $this->edittime );
21782219
@@ -2271,8 +2312,7 @@
22722313 */
22732314 protected function showConflict() {
22742315 global $wgOut;
2275 - $this->textbox2 = $this->textbox1;
2276 - $this->textbox1 = $this->getContent();
 2316+
22772317 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
22782318 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
22792319
@@ -2895,7 +2935,7 @@
28962936
28972937 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
28982938 $de = new DifferenceEngine( $this->mArticle->getContext() );
2899 - $de->setText( $this->getContent(), $this->textbox2 );
 2939+ $de->setText( $this->getCurrentText(), $this->textbox2 );
29002940 $de->showDiff( wfMsg( "storedversion" ), wfMsgExt( 'yourtext', 'parseinline' ) );
29012941
29022942 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );

Follow-up revisions

RevisionCommit summaryAuthorDate
r107658Per Raymond, fix for r107653: missed two changes from $section to $this->sectionialex21:34, 30 December 2011
r107720Per Nikerabbit, fix for r107653: don't show the "missing revision" warning on...ialex11:54, 31 December 2011
r112911Per happy-melon, fix for r107653: don't add the error class on success messageialex19:35, 2 March 2012

Comments

#Comment by Raymond (talk | contribs)   21:23, 30 December 2011
PHP Notice: Undefined variable: section in /www/w/includes/EditPage.php on line 703
#Comment by IAlex (talk | contribs)   21:34, 30 December 2011

Fixed in r107658.

#Comment by Nikerabbit (talk | contribs)   10:04, 31 December 2011

Causes LQT to display ugly errors when posting replies to threads.

#Comment by IAlex (talk | contribs)   11:54, 31 December 2011

Fixed in r107720.

#Comment by Happy-melon (talk | contribs)   15:58, 2 March 2012

This causes the "error" class to be added to the undo message wrapper even when there is no failure, so the message displays in big-red even when it's saying the edit can be undone (eg).

#Comment by IAlex (talk | contribs)   19:35, 2 March 2012

Fixed in r112911.

Status & tagging log