Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -694,91 +694,84 @@ |
695 | 695 | global $wgOut, $wgRequest, $wgParser; |
696 | 696 | |
697 | 697 | wfProfileIn( __METHOD__ ); |
698 | | - # Get variables from query string :P |
699 | | - $section = $wgRequest->getVal( 'section' ); |
700 | 698 | |
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; |
706 | 700 | |
707 | 701 | // For message page not locally set, use the i18n message. |
708 | 702 | // 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' ) { |
711 | 705 | # If this is a system message, get the default text. |
712 | 706 | $text = $this->mTitle->getDefaultMessageText(); |
713 | | - if( $text === false ) { |
714 | | - $text = $this->getPreloadedText( $preload ); |
715 | | - } |
716 | | - } else { |
| 707 | + } |
| 708 | + if ( $text === false ) { |
717 | 709 | # If requested, preload some text. |
| 710 | + $preload = $wgRequest->getVal( 'preload', |
| 711 | + // Custom preload text for new sections |
| 712 | + $this->section === 'new' ? 'MediaWiki:addsection-preload' : '' ); |
718 | 713 | $text = $this->getPreloadedText( $preload ); |
719 | 714 | } |
720 | 715 | // For existing pages, get text based on "undo" or section parameters. |
721 | 716 | } 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 | + |
731 | 730 | $undorev = Revision::newFromId( $undo ); |
732 | 731 | $oldrev = Revision::newFromId( $undoafter ); |
733 | | - } else { |
734 | | - $undorev = Revision::newFromId( $undo ); |
735 | | - $oldrev = $undorev ? $undorev->getPrevious() : null; |
736 | | - } |
737 | 732 | |
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 ) ) { |
746 | 741 | |
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; |
765 | 760 | } |
766 | | - $this->undidRev = $undo; |
| 761 | + $this->formtype = 'diff'; |
767 | 762 | } |
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'; |
769 | 768 | } |
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 ); |
776 | 772 | } |
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(); |
783 | 776 | } |
784 | 777 | } |
785 | 778 | } |
— | — | @@ -788,6 +781,48 @@ |
789 | 782 | } |
790 | 783 | |
791 | 784 | /** |
| 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 | + /** |
792 | 827 | * Use this method before edit() to preload some text into the edit box |
793 | 828 | * |
794 | 829 | * @param $text string |
— | — | @@ -1245,7 +1280,7 @@ |
1246 | 1281 | |
1247 | 1282 | # Handle the user preference to force summaries here, but not for null edits |
1248 | 1283 | if ( $this->section != 'new' && !$this->allowBlankSummary |
1249 | | - && 0 != strcmp( $this->mArticle->getContent(), $text ) |
| 1284 | + && $this->getOriginalContent() != $text |
1250 | 1285 | && !Title::newFromRedirect( $text ) ) # check if it's not a redirect |
1251 | 1286 | { |
1252 | 1287 | if ( md5( $this->summary ) == $this->autoSumm ) { |
— | — | @@ -1721,7 +1756,10 @@ |
1722 | 1757 | // and fallback to the raw wpTextbox1 since editconflicts can't be |
1723 | 1758 | // resolved between page source edits and custom ui edits using the |
1724 | 1759 | // custom edit ui. |
1725 | | - $this->showTextbox1( null, $this->getContent() ); |
| 1760 | + $this->textbox2 = $this->textbox1; |
| 1761 | + $this->textbox1 = $this->getCurrentText(); |
| 1762 | + |
| 1763 | + $this->showTextbox1(); |
1726 | 1764 | } else { |
1727 | 1765 | $this->showContentForm(); |
1728 | 1766 | } |
— | — | @@ -1750,8 +1788,9 @@ |
1751 | 1789 | HTML |
1752 | 1790 | ); |
1753 | 1791 | |
1754 | | - if ( $this->isConflict ) |
| 1792 | + if ( $this->isConflict ) { |
1755 | 1793 | $this->showConflict(); |
| 1794 | + } |
1756 | 1795 | |
1757 | 1796 | $wgOut->addHTML( $this->editFormTextBottom ); |
1758 | 1797 | $wgOut->addHTML( "</form>\n" ); |
— | — | @@ -1837,6 +1876,12 @@ |
1838 | 1877 | $this->mArticle->setOldSubtitle( $revision->getId() ); |
1839 | 1878 | $wgOut->addWikiMsg( 'editingold' ); |
1840 | 1879 | } |
| 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 ) ) ); |
1841 | 1886 | } |
1842 | 1887 | } |
1843 | 1888 | } |
— | — | @@ -2167,11 +2212,7 @@ |
2168 | 2213 | function showDiff() { |
2169 | 2214 | global $wgUser, $wgContLang, $wgParser, $wgOut; |
2170 | 2215 | |
2171 | | - if ( $this->section == 'new' ) { |
2172 | | - $oldtext = $this->mArticle->getRawText(); |
2173 | | - } else { |
2174 | | - $oldtext = $this->mArticle->fetchContent(); |
2175 | | - } |
| 2216 | + $oldtext = $this->getOriginalContent(); |
2176 | 2217 | $newtext = $this->mArticle->replaceSection( |
2177 | 2218 | $this->section, $this->textbox1, $this->summary, $this->edittime ); |
2178 | 2219 | |
— | — | @@ -2271,8 +2312,7 @@ |
2272 | 2313 | */ |
2273 | 2314 | protected function showConflict() { |
2274 | 2315 | global $wgOut; |
2275 | | - $this->textbox2 = $this->textbox1; |
2276 | | - $this->textbox1 = $this->getContent(); |
| 2316 | + |
2277 | 2317 | if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) { |
2278 | 2318 | $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" ); |
2279 | 2319 | |
— | — | @@ -2895,7 +2935,7 @@ |
2896 | 2936 | |
2897 | 2937 | $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" ); |
2898 | 2938 | $de = new DifferenceEngine( $this->mArticle->getContext() ); |
2899 | | - $de->setText( $this->getContent(), $this->textbox2 ); |
| 2939 | + $de->setText( $this->getCurrentText(), $this->textbox2 ); |
2900 | 2940 | $de->showDiff( wfMsg( "storedversion" ), wfMsgExt( 'yourtext', 'parseinline' ) ); |
2901 | 2941 | |
2902 | 2942 | $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" ); |