* (bug 20131) PHP Notice: Undfined index: page_latest in includes/ChangesList.php...
[lhc/web/wiklou.git] / includes / EditPage.php
index 1051c22..4aa603b 100644 (file)
@@ -48,6 +48,8 @@ class EditPage {
        var $mMetaData = '';
        var $isConflict = false;
        var $isCssJsSubpage = false;
+       var $isCssSubpage = false;
+       var $isJsSubpage = false;
        var $deletedSinceEdit = false;
        var $formtype;
        var $firsttime;
@@ -103,13 +105,15 @@ class EditPage {
                $this->editFormTextBeforeContent =
                $this->editFormTextAfterWarn =
                $this->editFormTextAfterTools =
-               $this->editFormTextBottom = "";
+               $this->editFormTextBottom =
+               $this->mPreloadText = "";
        }
        
        function getArticle() {
                return $this->mArticle;
        }
 
+
        /**
         * Fetch initial editing page content.
         * @private
@@ -200,6 +204,11 @@ class EditPage {
                wfProfileOut( __METHOD__ );
                return $text;
        }
+       
+       /** Use this method before edit() to preload some text into the edit box */
+       public function setPreloadedText( $text ) {
+               $this->mPreloadText = $text;
+       }
 
        /**
         * Get the contents of a page from its title and remove includeonly tags
@@ -208,7 +217,9 @@ class EditPage {
         * @return string The contents of the page.
         */
        protected function getPreloadedText( $preload ) {
-               if ( $preload === '' ) {
+               if ( !empty($this->mPreloadText) ) {
+                       return $this->mPreloadText;
+               } elseif ( $preload === '' ) {
                        return '';
                } else {
                        $preloadTitle = Title::newFromText( $preload );
@@ -352,7 +363,7 @@ class EditPage {
         * the newly-edited page.
         */
        function edit() {
-               global $wgOut, $wgRequest;
+               global $wgOut, $wgRequest, $wgEnableJS2system;
                // Allow extensions to modify/prevent this form or submission
                if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) ) {
                        return;
@@ -380,6 +391,10 @@ class EditPage {
                }
 
                $wgOut->addScriptFile( 'edit.js' );
+
+               if($wgEnableJS2system)
+                   $wgOut->addScriptClass( 'editPage' );
+
                $permErrors = $this->getEditPermissionErrors();
                if ( $permErrors ) {
                        wfDebug( __METHOD__.": User can't edit\n" );
@@ -414,6 +429,8 @@ class EditPage {
                $this->isConflict = false;
                // css / js subpages of user pages get a special treatment
                $this->isCssJsSubpage      = $this->mTitle->isCssJsSubpage();
+               $this->isCssSubpage        = $this->mTitle->isCssSubpage();
+               $this->isJsSubpage         = $this->mTitle->isJsSubpage();
                $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage();
 
                # Show applicable editing introductions
@@ -649,12 +666,16 @@ class EditPage {
                        }
                }
 
+               // FIXME: unused variable?
                $this->oldid = $request->getInt( 'oldid' );
 
                $this->live = $request->getCheck( 'live' );
                $this->editintro = $request->getText( 'editintro' );
 
                wfProfileOut( $fname );
+
+               // Allow extensions to modify form data
+               wfRunHooks( 'EditPage::importFormData', array( &$this, $request ) );
        }
 
        /**
@@ -865,7 +886,7 @@ class EditPage {
                        }
 
                        // Run post-section-merge edit filter
-                       if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
+                       if ( !wfRunHooks( 'EditFilterMerged', array( &$this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
                                # Error messages etc. could be handled within the hook...
                                wfProfileOut( $fname );
                                return self::AS_HOOK_ERROR;
@@ -953,7 +974,7 @@ class EditPage {
                $oldtext = $this->mArticle->getContent();
 
                // Run post-section-merge edit filter
-               if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
+               if ( !wfRunHooks( 'EditFilterMerged', array( &$this, $text, &$this->hookError, $this->summary ) ) ) {
                        # Error messages etc. could be handled within the hook...
                        wfProfileOut( $fname );
                        return self::AS_HOOK_ERROR;
@@ -1058,7 +1079,7 @@ class EditPage {
                }
                return true;
        }
-       
+
        /**
         * Check given input text against $wgSpamRegex, and return the text of the first match.
         * @return mixed -- matching string or false
@@ -1146,8 +1167,6 @@ class EditPage {
 
                $sk = $wgUser->getSkin();
 
-               wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
-
                #need to parse the preview early so that we know which templates are used,
                #otherwise users with "show preview after edit box" will get a blank list
                #we parse this near the beginning so that setHeaders can do the title
@@ -1156,6 +1175,8 @@ class EditPage {
                if ( $this->formtype == 'preview' ) {
                        $previewOutput = $this->getPreviewText();
                }
+               
+               wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
 
                $this->setHeaders();
 
@@ -1224,13 +1245,15 @@ class EditPage {
                } else {
                        if ( $this->isCssJsSubpage ) {
                                # Check the skin exists
-                               if ( $this->isValidCssJsSubpage ) {
-                                       if ( $this->formtype !== 'preview' ) {
-                                               $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
-                                       }
-                               } else {
+                               if ( !$this->isValidCssJsSubpage ) {
                                        $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
                                }
+                               if ( $this->formtype !== 'preview' ) {
+                                       if ( $this->isCssSubpage )
+                                               $wgOut->addWikiMsg( 'usercssyoucanpreview' );
+                                       if ( $this->isJsSubpage )
+                                               $wgOut->addWikiMsg( 'userjsyoucanpreview' );
+                               }
                        }
                }
 
@@ -1282,15 +1305,18 @@ class EditPage {
                        $wgOut->addHTML( "</div>\n" );
                }
 
-               $q = 'action='.$this->action;
-               #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
-               $action = $wgTitle->escapeLocalURL( $q );
+               $action = $wgTitle->escapeLocalURL( array( 'action' => $this->action ) );
 
                $summary = wfMsgExt( 'summary', 'parseinline' );
                $subject = wfMsgExt( 'subject', 'parseinline' );
 
-               $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
-                               wfMsgExt('cancel', array('parseinline')) );
+               $cancel = $sk->link(
+                       $wgTitle,
+                       wfMsgExt( 'cancel', array( 'parseinline' ) ),
+                       array(),
+                       array(),
+                       array( 'known', 'noclasses' )
+               );
                $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
                $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
                $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
@@ -1306,6 +1332,8 @@ class EditPage {
                        $copywarnMsg = array( 'copyrightwarning2',
                                '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
                }
+               // Allow for site and per-namespace customization of contribution/copyright notice.
+               wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle, &$copywarnMsg ) );
 
                if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
                        # prepare toolbar for edit buttons
@@ -1314,6 +1342,7 @@ class EditPage {
                        $toolbar = '';
                }
 
+
                // activate checkboxes if user wants them to be always active
                if ( !$this->preview && !$this->diff ) {
                        # Sort out the "watch" checkbox
@@ -1327,7 +1356,7 @@ class EditPage {
                                # Already watched
                                $this->watchthis = true;
                        }
-                       
+
                        # May be overriden by request parameters
                        if( $wgRequest->getBool( 'watchthis' ) ) {
                                $this->watchthis = true;
@@ -1380,6 +1409,8 @@ class EditPage {
                                                                                'maxlength' => '200',
                                                                                'tabindex' => '1'
                                                                        ) );
+                       } else {
+                               $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true ); # bug 18699
                        }
                        $editsummary = "<div class='editOptions'>\n";
                        global $wgParser;
@@ -1536,6 +1567,7 @@ END
                $token = htmlspecialchars( $wgUser->editToken() );
                $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
 
+               $this->showTosSummary();
                $this->showEditTools();
 
                $wgOut->addHTML( <<<END
@@ -1674,12 +1706,34 @@ END
        function doLivePreviewScript() {
                global $wgOut, $wgTitle;
                $wgOut->addScriptFile( 'preview.js' );
-               $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
+               $liveAction = $wgTitle->getLocalUrl( array(
+                       'action' => $this->action,
+                       'wpPreview' => 'true',
+                       'live' => 'true'
+               ) );
                return "return !lpDoPreview(" .
                        "editform.wpTextbox1.value," .
                        '"' . $liveAction . '"' . ")";
        }
 
+       protected function showTosSummary() {
+               $msg = 'editpage-tos-summary';
+               // Give a chance for site and per-namespace customizations of
+               // terms of service summary link that might exist separately
+               // from the copyright notice.
+               //
+               // This will display between the save button and the edit tools,
+               // so should remain short!
+               wfRunHooks( 'EditPageTosSummary', array( $this->mTitle, &$msg ) );
+               $text = wfMsg( $msg );
+               if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) {
+                       global $wgOut;
+                       $wgOut->addHTML( '<div class="mw-tos-summary">' );
+                       $wgOut->addWikiMsgArray( $msg, array() );
+                       $wgOut->addHTML( '</div>' );
+               }
+       }
+
        protected function showEditTools() {
                global $wgOut;
                $wgOut->addHTML( '<div class="mw-editTools">' );
@@ -1864,7 +1918,13 @@ END
                $skin = $wgUser->getSkin();
 
                $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
-               $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
+               $loginLink = $skin->link(
+                       $loginTitle,
+                       wfMsgHtml( 'loginreqlink' ),
+                       array(),
+                       array( 'returnto' => $wgTitle->getPrefixedText() ),
+                       array( 'known', 'noclasses' )
+               );
 
                $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
@@ -2134,9 +2194,9 @@ END
 
                $toolbar.="/*]]>*/\n</script>";
                $toolbar.="\n</div>";
-               
+
                wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
-               
+
                return $toolbar;
        }
 
@@ -2452,7 +2512,8 @@ END
                global $wgUser;
                $loglist = new LogEventsList( $wgUser->getSkin(), $out );
                $pager = new LogPager( $loglist, array('move', 'delete'), false,
-                       $this->mTitle->getPrefixedText(), '', array('log_action'=>'delete') );
+                       $this->mTitle->getPrefixedText(), '', array( "log_action != 'revision'" ) );
+
                $count = $pager->getNumRows();
                if ( $count > 0 ) {
                        $pager->mLimit = 10;