X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FTidy.php;h=dd7e9650f5949a2e9a1915b3bda91c2f853a9023;hb=234109c0f296929200995457beb9a07d295138b8;hp=3a6d3e9ca897731c3920bcedeaa33ee53784ccc7;hpb=2e3f7a97fdefb6c514fb1c9f170763e027f33de5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/Tidy.php b/includes/parser/Tidy.php index 3a6d3e9ca8..dd7e9650f5 100644 --- a/includes/parser/Tidy.php +++ b/includes/parser/Tidy.php @@ -2,7 +2,23 @@ /** * HTML validation and correction * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file + * @ingroup Parser */ /** @@ -11,9 +27,11 @@ * we may create a real postprocessor or something that will replace this. * It's called wrapper because for now it basically takes over MWTidy::tidy's task * of wrapping the text in a xhtml block - * + * * This re-uses some of the parser's UNIQ tricks, though some of it is private so it's * duplicated. Perhaps we should create an abstract marker hiding class. + * + * @ingroup Parser */ class MWTidyWrapper { @@ -40,10 +58,16 @@ class MWTidyWrapper { $this->mUniqPrefix = "\x7fUNIQ" . dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) ); $this->mMarkerIndex = 0; - + + // Replace elements with placeholders $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX, array( &$this, 'replaceEditSectionLinksCallback' ), $text ); + // Modify inline Microdata and elements so they say and so + // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config + $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', ''. 'test'.$wrappedtext.''; @@ -68,7 +92,13 @@ class MWTidyWrapper { * @return string */ public function postprocess( $text ) { - return $this->mTokens->replace( $text ); + // Revert back to <{link,meta}> + $text = preg_replace( '!]*?)(/{0,1}>)!', '<$1$2$3', $text ); + + // Restore the contents of placeholder tokens + $text = $this->mTokens->replace( $text ); + + return $text; } } @@ -126,7 +156,7 @@ class MWTidy { */ public static function checkErrors( $text, &$errorStr = null ) { global $wgTidyInternal; - + $retval = 0; if( $wgTidyInternal ) { $errorStr = self::execInternalTidy( $text, true, $retval ); @@ -143,7 +173,7 @@ class MWTidy { * * @param $text String: HTML to check * @param $stderr Boolean: Whether to read result from STDERR rather than STDOUT - * @param &$retval Exit code (-1 on internal error) + * @param &$retval int Exit code (-1 on internal error) * @return mixed String or null */ private static function execExternalTidy( $text, $stderr = false, &$retval = null ) { @@ -166,7 +196,7 @@ class MWTidy { 2 => array( 'file', wfGetNull(), 'a' ) ); } - + $readpipe = $stderr ? 2 : 1; $pipes = array(); @@ -207,7 +237,7 @@ class MWTidy { * * @param $text String: HTML to check * @param $stderr Boolean: Whether to read result from error status instead of output - * @param &$retval Exit code (-1 on internal error) + * @param &$retval int Exit code (-1 on internal error) * @return mixed String or null */ private static function execInternalTidy( $text, $stderr = false, &$retval = null ) { @@ -217,7 +247,7 @@ class MWTidy { if ( !MWInit::classExists( 'tidy' ) ) { wfWarn( "Unable to load internal tidy class." ); $retval = -1; - + wfProfileOut( __METHOD__ ); return null; } @@ -230,24 +260,24 @@ class MWTidy { wfProfileOut( __METHOD__ ); return $tidy->errorBuffer; + } + + $tidy->cleanRepair(); + $retval = $tidy->getStatus(); + if ( $retval == 2 ) { + // 2 is magic number for fatal error + // http://www.php.net/manual/en/function.tidy-get-status.php + $cleansource = null; } else { - $tidy->cleanRepair(); - $retval = $tidy->getStatus(); - if ( $retval == 2 ) { - // 2 is magic number for fatal error - // http://www.php.net/manual/en/function.tidy-get-status.php - $cleansource = null; - } else { - $cleansource = tidy_get_output( $tidy ); - if ( $wgDebugTidy && $retval > 0 ) { - $cleansource .= "', '-->', $tidy->errorBuffer ) . - "\n-->"; - } + $cleansource = tidy_get_output( $tidy ); + if ( $wgDebugTidy && $retval > 0 ) { + $cleansource .= "', '-->', $tidy->errorBuffer ) . + "\n-->"; } - - wfProfileOut( __METHOD__ ); - return $cleansource; } + + wfProfileOut( __METHOD__ ); + return $cleansource; } }