don't use OR on empty variables
[lhc/web/wiklou.git] / includes / EditPage.php
index 3c4176e..b168b6c 100644 (file)
@@ -62,6 +62,7 @@ class EditPage {
        }
 
        function importFormData( &$request ) {
+               global $wgIsMySQL, $wgIsPg;
                # These fields need to be checked for encoding.
                # Also remove trailing whitespace, but don't remove _initial_
                # whitespace from the text boxes. This may be significant formatting.
@@ -70,7 +71,12 @@ class EditPage {
                $this->summary = trim( $request->getText( "wpSummary" ) );
 
                $this->edittime = $request->getVal( 'wpEdittime' );
-               if( !preg_match( '/^\d{14}$/', $this->edittime ) ) $this->edittime = "";
+               if ($wgIsMySQL) 
+                       if( !preg_match( '/^\d{14}$/', $this->edittime )) $this->edittime = "";
+               if ($wgIsPg)
+                       if ( !preg_match( '/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/', 
+                               $this->edittime ))
+                               $this->edittime = "";
 
                $this->preview = $request->getCheck( 'wpPreview' );
                $this->save = $request->wasPosted() && !$this->preview;
@@ -131,8 +137,12 @@ class EditPage {
                if ( "save" == $formtype ) {
                        # Check for spam
                        if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1 ) ) {
-                                       sleep(10);
-                                       $wgOut->redirect( $this->mTitle->getFullURL() );
+                                       if ( $wgUser->isSysop() ) {
+                                               $this->spamPage();
+                                       } else {
+                                               sleep(10);
+                                               $wgOut->redirect( $this->mTitle->getFullURL() );
+                                       }
                                        return;
                        }
                        if ( $wgUser->isBlocked() ) {
@@ -200,13 +210,19 @@ class EditPage {
                                        $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
                                        # we can't deal with anchors, includes, html etc in the header for now, 
                                        # headline would need to be parsed to improve this
-                                       if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
+                                       #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
+                                       if($hasmatch and strlen($matches[2]) > 0) {
                                                global $wgInputEncoding;
                                                $headline = do_html_entity_decode( $matches[2], ENT_COMPAT, $wgInputEncoding );
-                                               # strip out HTML, will be useful when 
-                                               $headline = preg_replace( "/<.*?" . ">/","",$headline );
+                                               # strip out HTML 
+                                               $headline = preg_replace( "/<.*?" . ">/","",$headline );
                                                $headline = trim( $headline );
-                                               $sectionanchor = '#'.preg_replace("/[ \\?&\\/<>\\(\\)\\[\\]=,+']+/", '_', urlencode( $headline ) );
+                                               $sectionanchor = '#'.urlencode( str_replace(' ', '_', $headline ) );
+                                               $replacearray = array(
+                                                       '%3A' => ':',
+                                                       '%' => '.'
+                                               );
+                                               $sectionanchor = str_replace(array_keys($replacearray),array_values($replacearray),$sectionanchor);
                                        }
                                }
        
@@ -301,12 +317,12 @@ class EditPage {
                $save = wfMsg( "savearticle" );
                $prev = wfMsg( "showpreview" );
 
-               $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedURL(),
+               $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedText(),
                  wfMsg( "cancel" ) );
-               $edithelpurl = $sk->makeUrl( wfMsg( "edithelppage" ));
-               $edithelp = '<a onclick="window.open('.
-               "'$edithelpurl', 'helpwindow', 'width=610,height=400,left=10,top=10'".'); return false;" href="'.$edithelpurl.'">'.
-               wfMsg( "edithelp" ).'</a>';
+               $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
+               $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
+                       htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
+                       htmlspecialchars( wfMsg( 'newwindow' ) );
                $copywarn = wfMsg( "copyrightwarning", $sk->makeKnownLink(
                  wfMsg( "copyrightpage" ) ) );
 
@@ -367,10 +383,10 @@ class EditPage {
                                } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
                                        $previewtext = wfMsg('userjspreview');
                                }
-                               $parserOutput = $wgParser->parse( $this->textbox1 , $wgTitle, $parserOptions );
+                               $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
                                $wgOut->addHTML( $parserOutput->mText );
                        } else {
-                               $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $previewtext ) ."\n\n",
+                               $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $this->textbox1 ) ."\n\n",
                                $wgTitle, $parserOptions );
                                $previewHTML = $parserOutput->mText;
 
@@ -378,6 +394,7 @@ class EditPage {
                                        $wgOut->addHTML($previewhead);
                                        $wgOut->addHTML($previewHTML);
                                }
+                               $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
                                $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
                        }
                }
@@ -409,9 +426,9 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
 </textarea>
 <br />{$editsummary}
 {$checkboxhtml}
-<input tabindex='5' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
+<input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
 " title=\"".wfMsg('tooltip-save')."\"/>
-<input tabindex='6' type='submit' value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
+<input tabindex='6' id='wpSave' type='submit' value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
 " title=\"".wfMsg('tooltip-preview')."\"/>
 <em>{$cancel}</em> | <em>{$edithelp}</em>
 <br /><br />{$copywarn}
@@ -424,7 +441,7 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
                          wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
 
                        $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
-<textarea tabindex=6 name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
+<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
 . htmlspecialchars( $wgLang->recodeForEdit( $this->textbox2 ) ) .
 "
 </textarea>" );
@@ -471,6 +488,18 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
                $wgOut->returnToMain( false );
        }
 
+       function spamPage()
+       {
+               global $wgOut, $wgSpamRegex;
+               $wgOut->setPageTitle( wfMsg( "spamprotectiontitle" ) );
+               $wgOut->setRobotpolicy( "noindex,nofollow" );
+               $wgOut->setArticleRelated( false );
+
+               $wgOut->addWikiText( wfMsg( "spamprotectiontext" ) );
+               $wgOut->addWikiText( "<pre>".$wgSpamRegex."</pre>" );
+               $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()
@@ -515,6 +544,7 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
        }
 
        /* private */ function mergeChangesInto( &$text ){
+               global $wgIsPg;
                $oldDate = $this->edittime;
                $res = wfQuery("SELECT cur_text FROM cur WHERE cur_id=" .
                        $this->mTitle->getArticleID() . " FOR UPDATE", DB_WRITE);
@@ -523,10 +553,13 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
                $yourtext = $obj->cur_text;
                $ns = $this->mTitle->getNamespace();
                $title = wfStrencode( $this->mTitle->getDBkey() );
-               $res = wfQuery("SELECT old_text FROM old WHERE old_namespace = $ns AND ".
+               $oldtable=$wgIsPg?'"old"':'old';
+               $res = wfQuery("SELECT old_text,old_flags FROM $oldtable WHERE old_namespace = $ns AND ".
                  "old_title = '{$title}' AND old_timestamp = '{$oldDate}'", DB_WRITE);
                $obj = wfFetchObject($res);
-               if(wfMerge($obj->old_text, $text, $yourtext, $result)){
+               $oldText = Article::getRevisionText( $obj );
+               
+               if(wfMerge($oldText, $text, $yourtext, $result)){
                        $text = $result;
                        return true;
                } else {