* Populate rev_parent_id
[lhc/web/wiklou.git] / includes / EditPage.php
index 36424ba..3ec0ec0 100644 (file)
@@ -105,7 +105,7 @@ class EditPage {
         * @private
         */
        function getContent( $def_text = '' ) {
-               global $wgOut, $wgRequest, $wgParser;
+               global $wgOut, $wgRequest, $wgParser, $wgMessageCache;
 
                # Get variables from query string :P
                $section = $wgRequest->getVal( 'section' );
@@ -118,6 +118,7 @@ class EditPage {
                $text = '';
                if( !$this->mTitle->exists() ) {
                        if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+                               $wgMessageCache->loadAllMessages();
                                # If this is a system message, get the default text. 
                                $text = wfMsgWeirdKey ( $this->mTitle->getText() ) ;
                        } else {
@@ -538,9 +539,12 @@ class EditPage {
                        # whitespace from the text boxes. This may be significant formatting.
                        $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
                        $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
-                       $this->mMetaData = rtrim( $request->getText( 'metadata'   ) );
+                       $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
                        # Truncate for whole multibyte characters. +5 bytes for ellipsis
-                       $this->summary   = $wgLang->truncate( $request->getText( 'wpSummary'  ), 250 );
+                       $this->summary = $wgLang->truncate( $request->getText( 'wpSummary'  ), 250 );
+                       
+                       # Remove extra headings from summaries and new sections.
+                       $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1$2$3', $this->summary);
 
                        $this->edittime = $request->getVal( 'wpEdittime' );
                        $this->starttime = $request->getVal( 'wpStarttime' );
@@ -577,7 +581,7 @@ class EditPage {
                                        $this->preview = true;
                                }
                        }
-                       $this->save    = ! ( $this->preview OR $this->diff );
+                       $this->save = !$this->preview && !$this->diff;
                        if( !preg_match( '/^\d{14}$/', $this->edittime )) {
                                $this->edittime = null;
                        }
@@ -686,7 +690,7 @@ class EditPage {
                        if( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
                                global $wgOut;
                                $revision = Revision::newFromTitle( $title );
-                               $wgOut->addSecondaryWikiText( $revision->getText() );
+                               $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle );
                                return true;
                        } else {
                                return false;
@@ -920,7 +924,7 @@ class EditPage {
                        }
                }
 
-               #And a similar thing for new sections
+               # And a similar thing for new sections
                if( $this->section == 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary' ) ) {
                        if (trim($this->summary) == '') {
                                $this->missingSummary = true;
@@ -1493,7 +1497,7 @@ END
         * @todo document
         */
        function getPreviewText() {
-               global $wgOut, $wgUser, $wgTitle, $wgParser;
+               global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
 
                $fname = 'EditPage::getPreviewText';
                wfProfileIn( $fname );
@@ -1541,7 +1545,26 @@ END
                                $toparse="== {$this->summary} ==\n\n".$toparse;
                        }
 
-                       if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ;
+                       if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
+
+                       // Parse mediawiki messages with correct target language
+                       if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+                               $pos = strrpos( $this->mTitle->getText(), '/' );
+                               if ( $pos !== false ) {
+                                       $code = substr( $this->mTitle->getText(), $pos+1 );
+                                       switch ($code) {
+                                               case $wgLang->getCode():
+                                                       $obj = $wgLang; break;
+                                               case $wgContLang->getCode():
+                                                       $obj = $wgContLang; break;
+                                               default:
+                                                       $obj = Language::factory( $code );
+                                       }
+                                       $parserOptions->setTargetLanguage( $obj );
+                               }
+                       }
+
+
                        $parserOptions->setTidy(true);
                        $parserOptions->enableLimitReport();
                        $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n",
@@ -2182,20 +2205,17 @@ END
         * @param OutputPage $out
         */
        private function showDeletionLog( $out ) {
-               $title = $this->mTitle;
-               $reader = new LogReader(
-                       new FauxRequest(
-                               array(
-                                       'page' => $title->getPrefixedText(),
-                                       'type' => 'delete',
-                                       )
-                       )
-               );
-               if( $reader->hasRows() ) {
+               global $wgUser;
+               $loglist = new LogEventsList( $wgUser->getSkin() );
+               $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
+               if( $pager->getNumRows() > 0 ) {
                        $out->addHtml( '<div id="mw-recreate-deleted-warn">' );
                        $out->addWikiMsg( 'recreate-deleted-warn' );
-                       $viewer = new LogViewer( $reader );
-                       $viewer->showList( $out );
+                       $out->addHTML(
+                               $loglist->beginLogEventsList() .
+                               $pager->getBody() .
+                               $loglist->endLogEventsList()
+                       );
                        $out->addHtml( '</div>' );
                }
        }