truncate summary for multibyte chars
[lhc/web/wiklou.git] / includes / EditPage.php
index df6d3a2..b6b1a77 100644 (file)
@@ -295,6 +295,7 @@ class EditPage {
         * @todo document
         */
        function importFormData( &$request ) {
+               global $wgLang ;
                $fname = 'EditPage::importFormData';
                wfProfileIn( $fname );
 
@@ -305,7 +306,8 @@ class EditPage {
                        $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
                        $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
                        $this->mMetaData = rtrim( $request->getText( 'metadata'   ) );
-                       $this->summary   =        $request->getText( 'wpSummary'  );
+                       # Truncate for whole multibyte characters. +5 bytes for ellipsis
+                       $this->summary   = $wgLang->truncate( $request->getText( 'wpSummary'  ), 250 );
 
                        $this->edittime = $request->getVal( 'wpEdittime' );
                        $this->starttime = $request->getVal( 'wpStarttime' );
@@ -385,7 +387,7 @@ class EditPage {
        }
 
        function showIntro() {
-               global $wgOut;
+               global $wgOut, $wgUser;
                $addstandardintro=true;
                if($this->editintro) {
                        $introtitle=Title::newFromText($this->editintro);
@@ -398,7 +400,10 @@ class EditPage {
                        }
                }
                if($addstandardintro) {
-                       $wgOut->addWikiText( wfMsg( 'newarticletext' ) );                               
+                       if ( $wgUser->isLoggedIn() ) 
+                               $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
+                       else
+                               $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
                }
        }
 
@@ -430,6 +435,12 @@ class EditPage {
                        wfProfileOut( "$fname-checks" );
                        return false;
                }
+               if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1, $this->section ) ) ) {
+                       # Error messages or other handling should be performed by the filter function
+                       wfProfileOut( $fname );
+                       wfProfileOut( "$fname-checks" );
+                       return false;
+               }
                if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
                        # Check block state against master, thus 'false'.
                        $this->blockedIPpage();
@@ -447,6 +458,7 @@ class EditPage {
                        }
                        else {
                                $wgOut->readOnlyPage();
+                               wfProfileOut( "$fname-checks" );
                                wfProfileOut( $fname );
                                return false;
                        }
@@ -479,23 +491,16 @@ class EditPage {
                $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
                if ( 0 == $aid ) {
                        # Don't save a new article if it's blank.
-                       if ( ( '' == $this->textbox1 ) ||
-                               ( wfMsg( 'newarticletext' ) == $this->textbox1 ) ) {
+                       if ( ( '' == $this->textbox1 ) ) {
                                        $wgOut->redirect( $this->mTitle->getFullURL() );
                                        wfProfileOut( $fname );
                                        return false;
-                               }
-                       if (wfRunHooks('ArticleSave', array(&$this->mArticle, &$wgUser, &$this->textbox1,
-                               &$this->summary, &$this->minoredit, &$this->watchthis, NULL)))
-                       {                                       
-
-                               $isComment=($this->section=='new');
-                               $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
-                                       $this->minoredit, $this->watchthis, false, $isComment);
-                               wfRunHooks('ArticleSaveComplete', array(&$this->mArticle, &$wgUser, $this->textbox1,
-                                       $this->summary, $this->minoredit,
-                                       $this->watchthis, NULL));
                        }
+
+                       $isComment=($this->section=='new');
+                       $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
+                               $this->minoredit, $this->watchthis, false, $isComment);
+                       
                        wfProfileOut( $fname );
                        return false;
                }
@@ -522,8 +527,8 @@ class EditPage {
                        $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary);
                }
 
-               # Suppress edit conflict with self
-               if ( ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
+               # Suppress edit conflict with self, except for section edits where merging is required.
+               if ( ( $this->section == '' ) && ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
                        wfDebug( "Suppressing edit conflict, same user.\n" );
                        $this->isConflict = false;
                } else {
@@ -574,23 +579,13 @@ class EditPage {
                $this->textbox1 = $text;
                $this->section = '';
 
-               if (wfRunHooks('ArticleSave', array(&$this->mArticle, &$wgUser, &$text,
-                       &$this->summary, &$this->minoredit,
-                       &$this->watchthis, &$sectionanchor)))
-               {
-                       # update the article here
-                       if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
-                               $this->watchthis, '', $sectionanchor ))
-                       {
-                               wfRunHooks('ArticleSaveComplete',
-                                       array(&$this->mArticle, &$wgUser, $text,
-                                       $this->summary, $this->minoredit,
-                                       $this->watchthis, $sectionanchor));
-                               wfProfileOut( $fname );
-                               return false;
-                       } else {
-                               $this->isConflict = true;
-                       }
+               # update the article here
+               if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
+                       $this->watchthis, '', $sectionanchor ) ) {
+                       wfProfileOut( $fname );
+                       return false;
+               } else {
+                       $this->isConflict = true;
                }
                wfProfileOut( $fname );
                return true;
@@ -604,13 +599,16 @@ class EditPage {
                $this->edittime = $this->mArticle->getTimestamp();
                $this->textbox1 = $this->mArticle->getContent( true );
                $this->summary = '';
-               $this->proxyCheck();
+               wfProxyCheck();
        }
 
        /**
         * Send the edit form and related headers to $wgOut
+        * @param $formCallback Optional callable that takes an OutputPage
+        *                      parameter; will be called during form output
+        *                      near the top, for captchas and the like.
         */
-       function showEditForm() {
+       function showEditForm( $formCallback=null ) {
                global $wgOut, $wgUser, $wgAllowAnonymousMinor, $wgLang, $wgContLang;
 
                $fname = 'EditPage::showEditForm';
@@ -826,6 +824,12 @@ class EditPage {
 {$toolbar}
 <form id="editform" name="editform" method="post" action="$action"
 enctype="multipart/form-data">
+END
+);
+               if( is_callable( $formCallback ) ) {
+                       call_user_func_array( $formCallback, array( &$wgOut ) );
+               }
+               $wgOut->addHTML( <<<END
 $recreate
 {$commentsubject}
 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
@@ -1032,7 +1036,7 @@ END
         * @todo document
         */
        function blockedIPpage() {
-               global $wgOut, $wgUser, $wgContLang, $wgIP;
+               global $wgOut, $wgUser, $wgContLang;
 
                $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
@@ -1040,7 +1044,7 @@ END
 
                $id = $wgUser->blockedBy();
                $reason = $wgUser->blockedFor();
-               $ip = $wgIP;
+               $ip = wfGetIP();
 
                if ( is_numeric( $id ) ) {
                        $name = User::whoIs( $id );
@@ -1085,50 +1089,6 @@ END
                $wgOut->returnToMain( false );
        }
 
-       /**
-        * Forks processes to scan the originating IP for an open proxy server
-        * MemCached can be used to skip IPs that have already been scanned
-        */
-       function proxyCheck() {
-               global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
-               global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
-
-               if ( !$wgBlockOpenProxies ) {
-                       return;
-               }
-
-               # Get MemCached key
-               $skip = false;
-               if ( $wgUseMemCached ) {
-                       $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
-                       $mcValue = $wgMemc->get( $mcKey );
-                       if ( $mcValue ) {
-                               $skip = true;
-                       }
-               }
-
-               # Fork the processes
-               if ( !$skip ) {
-                       $title = Title::makeTitle( NS_SPECIAL, 'Blockme' );
-                       $iphash = md5( $wgIP . $wgProxyKey );
-                       $url = $title->getFullURL( 'ip='.$iphash );
-
-                       foreach ( $wgProxyPorts as $port ) {
-                               $params = implode( ' ', array(
-                                                       escapeshellarg( $wgProxyScriptPath ),
-                                                       escapeshellarg( $wgIP ),
-                                                       escapeshellarg( $port ),
-                                                       escapeshellarg( $url )
-                                                       ));
-                               exec( "php $params &>/dev/null &" );
-                       }
-                       # Set MemCached key
-                       if ( $wgUseMemCached ) {
-                               $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
-                       }
-               }
-       }
-
        /**
         * @access private
         * @todo document
@@ -1320,10 +1280,7 @@ END
                        $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
                }
 
-               $toolbar.="addInfobox('" . wfEscapeJsString( wfMsg( "infobox" ) ) .
-                       "','" . wfEscapeJsString( wfMsg( "infobox_alert" ) ) . "');\n";
                $toolbar.="document.writeln(\"</div>\");\n";
-
                $toolbar.="/*]]>*/\n</script>";
                return $toolbar;
        }
@@ -1360,13 +1317,15 @@ END
         * @return string HTML
         */
        function getDiff() {
+               global $wgUser;
+
                require_once( 'DifferenceEngine.php' );
                $oldtext = $this->mArticle->fetchContent();
                $newtext = $this->mArticle->replaceSection(
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
                $oldtitle = wfMsg( 'currentrev' );
                $newtitle = wfMsg( 'yourtext' );
-               if ( $oldtext != wfMsg( 'noarticletext' ) || $newtext != '' ) {
+               if ( $oldtext != wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) || $newtext != '' ) {
                        $difftext = DifferenceEngine::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
                }