* Added a script to prune old file cache entries.
[lhc/web/wiklou.git] / includes / EditPage.php
index 86193d7..d1c8ec5 100644 (file)
@@ -15,6 +15,9 @@
  * redirects go to, etc. $this->mTitle (as well as $mArticle) is the
  * page in the database that is actually being edited. These are
  * usually the same, but they are now allowed to be different.
+ *
+ * Surgeon General's Warning: prolonged exposure to this class is known to cause
+ * headaches, which may be fatal.
  */
 class EditPage {
        const AS_SUCCESS_UPDATE            = 200;
@@ -225,11 +228,13 @@ class EditPage {
                                        $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
                                        if ( $undotext === false ) {
                                                # Warn the user that something went wrong
-                                               $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
+                                               $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' .
+                                                       wfMsgNoTrans( 'undo-failure' ) . '</div>', true, /* interface */true );
                                        } else {
                                                $text = $undotext;
                                                # Inform the user of our success and set an automatic edit summary
-                                               $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
+                                               $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' .
+                                                       wfMsgNoTrans( 'undo-success' ) . '</div>', true, /* interface */true );
                                                $firstrev = $oldrev->getNext();
                                                # If we just undid one rev, use an autosummary
                                                if ( $firstrev->mId == $undo ) {
@@ -242,7 +247,8 @@ class EditPage {
                                        // Failed basic sanity checks.
                                        // Older revisions may have been removed since the link
                                        // was created, or we may simply have got bogus input.
-                                       $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
+                                       $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' .
+                                               wfMsgNoTrans( 'undo-norev' ) . '</div>', true, /* interface */true );
                                }
                        } elseif ( $section != '' ) {
                                if ( $section == 'new' ) {
@@ -461,6 +467,13 @@ class EditPage {
                                        $wgOut->addWikiText( $editnotice_base_msg->plain()  );
                                }
                        }
+               } else {
+                       # Even if there are no subpages in namespace, we still don't want / in MW ns.
+                       $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->mTitle->getDBkey() );
+                       $editnoticeMsg = wfMessage( $editnoticeText )->inContentLanguage();
+                       if ( $editnoticeMsg->exists() ) {
+                               $wgOut->addWikiText( $editnoticeMsg->plain() );
+                       }
                }
 
                # Attempt submission here.  This will check for edit conflicts,
@@ -794,7 +807,7 @@ class EditPage {
                                LogEventsList::showLogExtract(
                                        $wgOut,
                                        'block',
-                                       $user->getUserPage()->getPrefixedText(),
+                                       $user->getUserPage(),
                                        '',
                                        array(
                                                'lim' => 1,
@@ -817,7 +830,7 @@ class EditPage {
                }
                # Give a notice if the user is editing a deleted/moved page...
                if ( !$this->mTitle->exists() ) {
-                       LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle->getPrefixedText(),
+                       LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle,
                                '', array( 'lim' => 10,
                                           'conds' => array( "log_action != 'revision'" ),
                                           'showIfEmpty' => false,
@@ -862,7 +875,7 @@ class EditPage {
        function internalAttemptSave( &$result, $bot = false ) {
                global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
                global $wgMaxArticleSize;
-               
+
                $status = Status::newGood();
 
                wfProfileIn( __METHOD__  );
@@ -885,7 +898,6 @@ class EditPage {
                                $status->setResult( false, $code );
 
                                wfProfileOut( __METHOD__ . '-checks' );
-                               
                                wfProfileOut( __METHOD__  );
 
                                return $status;
@@ -930,6 +942,7 @@ class EditPage {
                        wfProfileOut( __METHOD__ );
                        return $status;
                }
+
                if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
                        # Check block state against master, thus 'false'.
                        $status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
@@ -937,6 +950,7 @@ class EditPage {
                        wfProfileOut( __METHOD__ );
                        return $status;
                }
+
                $this->kblength = (int)( strlen( $this->textbox1 ) / 1024 );
                if ( $this->kblength > $wgMaxArticleSize ) {
                        // Error will be displayed by showEditForm()
@@ -1124,8 +1138,10 @@ class EditPage {
                        {
                                if ( md5( $this->summary ) == $this->autoSumm ) {
                                        $this->missingSummary = true;
+                                       $status->fatal( 'missingsummary' );
+                                       $status->value = self::AS_SUMMARY_NEEDED;
                                        wfProfileOut( __METHOD__ );
-                                       return self::AS_SUMMARY_NEEDED;
+                                       return $status;
                                }
                        }
 
@@ -1360,7 +1376,7 @@ class EditPage {
         *     during form output near the top, for captchas and the like.
         */
        function showEditForm( $formCallback = null ) {
-               global $wgOut, $wgUser, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
+               global $wgOut, $wgUser;
 
                wfProfileIn( __METHOD__ );
 
@@ -1394,6 +1410,7 @@ class EditPage {
                        $toolbar = '';
                }
 
+
                $wgOut->addHTML( $this->editFormPageTop );
 
                if ( $wgUser->getOption( 'previewontop' ) ) {
@@ -1405,9 +1422,6 @@ class EditPage {
                $templates = $this->getTemplates();
                $formattedtemplates = Linker::formatTemplates( $templates, $this->preview, $this->section != '');
 
-               $distantTemplates = $this->getDistantTemplates();
-               $formattedDistantTemplates = Linker::formatDistantTemplates( $distantTemplates, $this->preview, $this->section != '' );
-
                $hiddencats = $this->mArticle->getHiddenCategories();
                $formattedhiddencats = Linker::formatHiddenCategories( $hiddencats );
 
@@ -1506,21 +1520,6 @@ HTML
 <div class='templatesUsed'>
 {$formattedtemplates}
 </div>
-HTML
-);
-
-               if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
-                                       $wgOut->addHTML( <<<HTML
-{$this->editFormTextAfterTools}
-<div class='distantTemplatesUsed'>
-{$formattedDistantTemplates}
-</div>
-HTML
-);
-               }
-
-               $wgOut->addHTML( <<<HTML
-{$this->editFormTextAfterTools}
 <div class='hiddencats'>
 {$formattedhiddencats}
 </div>
@@ -1633,7 +1632,7 @@ HTML
                                # Then it must be protected based on static groups (regular)
                                $noticeMsg = 'protectedpagewarning';
                        }
-                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '',
+                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
                                array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
                }
                if ( $this->mTitle->isCascadeProtected() ) {
@@ -1651,7 +1650,7 @@ HTML
                        $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
                }
                if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
-                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '',
+                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
                                array(  'lim' => 1,
                                        'showIfEmpty' => false,
                                        'msgKey' => array( 'titleprotectedwarning' ),
@@ -2077,7 +2076,7 @@ HTML
                                // string, which happens when you initially edit
                                // a category page, due to automatic preview-on-open.
                                $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
-                                       wfMsg( 'session_fail_preview_html' ) . "</div>" );
+                                       wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
                        }
                        wfProfileOut( __METHOD__ );
                        return $parsedNote;
@@ -2151,7 +2150,7 @@ HTML
 
                $previewhead = "<div class='previewnote'>\n" .
                        '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
-                       $wgOut->parse( $note ) . $conflict . "</div>\n";
+                       $wgOut->parse( $note, true, /* interface */true ) . $conflict . "</div>\n";
 
                $pageLang = $this->mTitle->getPageLanguage();
                $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
@@ -2182,28 +2181,6 @@ HTML
                }
        }
 
-       function getDistantTemplates() {
-               global $wgEnableInterwikiTemplatesTracking;
-               if ( !$wgEnableInterwikiTemplatesTracking ) {
-                       return array( );
-               }
-               if ( $this->preview || $this->section != '' ) {
-                       $templates = array();
-                       if ( !isset( $this->mParserOutput ) ) return $templates;
-                       $templatesList = $this->mParserOutput->getDistantTemplates();
-                       foreach( $templatesList as $prefix => $templatesbyns ) {
-                               foreach( $templatesbyns as $ns => $template ) {
-                                       foreach( array_keys( $template ) as $dbk ) {
-                                               $templates[] = Title::makeTitle( $ns, $dbk, null, $prefix );
-                                       }
-                               }
-                       }
-                       return $templates;
-               } else {
-                       return $this->mArticle->getUsedDistantTemplates();
-               }
-       }
-
        /**
         * Call the stock "user is blocked" page
         */
@@ -2523,7 +2500,6 @@ HTML
                                'key'    => 'R'
                        )
                );
-               $toolbar = "<div id='toolbar'>\n";
 
                $script = '';
                foreach ( $toolarray as $tool ) {
@@ -2544,15 +2520,11 @@ HTML
                                $cssId = $tool['id'],
                        );
 
-                       $paramList = implode( ',',
-                               array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
-                       $script .= "mw.toolbar.addButton($paramList);\n";
+                       $script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params );
                }
-               $wgOut->addScript( Html::inlineScript(
-                       "if ( window.mediaWiki ) {{$script}}"
-               ) );
+               $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
 
-               $toolbar .= "\n</div>";
+               $toolbar = '<div id="toolbar"></div>';
 
                wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );