From 096c1d0e7d2018ecbbc7d8767710de5c2076ed15 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 13 Apr 2007 00:23:49 +0000 Subject: [PATCH] In regex, do not capture stuff when you dont need it, use (?:) --- includes/Article.php | 2 +- includes/Exif.php | 2 +- includes/Parser.php | 8 ++++---- includes/Sanitizer.php | 2 +- includes/SpecialContributions.php | 4 ++-- includes/SpecialUpload.php | 6 +++--- includes/Title.php | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 9e12611c13..1fb42b30b0 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -772,7 +772,7 @@ class Article { # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found if ( $ns == NS_USER && - preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey()) + preg_match('/\\/[\\w]+\\.(?:css|js)$/', $this->mTitle->getDBkey()) ) { $wgOut->addWikiText( wfMsg('clearyourcache')); $wgOut->addHTML( '
'.htmlspecialchars($this->mContent)."\n
" ); diff --git a/includes/Exif.php b/includes/Exif.php index 84d8e8d2cb..ab2e209beb 100644 --- a/includes/Exif.php +++ b/includes/Exif.php @@ -731,7 +731,7 @@ class FormatExif { case 'DateTimeDigitized': if( $val == '0000:00:00 00:00:00' ) { $tags[$tag] = wfMsg('exif-unknowndate'); - } elseif( preg_match( '/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/', $val ) ) { + } elseif( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/', $val ) ) { $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW, $val) ); } break; diff --git a/includes/Parser.php b/includes/Parser.php index 4b85c1a3e9..504780ff0f 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1641,7 +1641,7 @@ class Parser # Don't allow internal links to pages containing # PROTO: where PROTO is a valid URL protocol; these # should be external links. - if (preg_match('/^(\b(?:' . wfUrlProtocols() . '))/', $m[1])) { + if (preg_match('/^\b(?:' . wfUrlProtocols() . ')/', $m[1])) { $s .= $prefix . '[[' . $line ; continue; } @@ -2136,9 +2136,9 @@ class Parser wfProfileIn( "$fname-paragraph" ); # No prefix (not in list)--go to paragraph mode // XXX: use a stack for nestable elements like span, table and div - $openmatch = preg_match('/(mUniqPrefix.'-pre|<\\/li|<\\/ul|<\\/ol|<\\/?center)/iS', $t ); if ( $openmatch or $closematch ) { $paragraphStack = false; @@ -3173,7 +3173,7 @@ class Parser # If the template begins with a table or block-level # element, it should be treated as beginning a new line. - if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) /*}*/{ + if (!$piece['lineStart'] && preg_match('/^(?:{\\||:|;|#|\*)/', $text)) /*}*/{ $text = "\n" . $text; } } elseif ( !$noargs ) { diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index b7021888aa..6e1f37b688 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -615,7 +615,7 @@ class Sanitizer { $stripped = preg_replace( '!\\\\([0-9A-Fa-f]{1,6})[ \\n\\r\\t\\f]?!e', 'codepointToUtf8(hexdec("$1"))', $stripped ); $stripped = str_replace( '\\', '', $stripped ); - if( preg_match( '/(expression|tps*:\/\/|url\\s*\().*/is', + if( preg_match( '/(?:expression|tps*:\/\/|url\\s*\().*/is', $stripped ) ) { # haxx0r return false; diff --git a/includes/SpecialContributions.php b/includes/SpecialContributions.php index 3dbb1936a3..2776acf1ec 100644 --- a/includes/SpecialContributions.php +++ b/includes/SpecialContributions.php @@ -76,7 +76,7 @@ class ContribsFinder { if( $matches[1] == 24 ) $ipmask = $abcd[0] . '.' . $abcd[1] . '.' . $abcd[2] . '.%'; else $ipmask=$abcd[0] . '.' . $abcd[1] . '.%'; $condition = 'rev_user_text LIKE ' . $this->dbr->addQuotes($ipmask); - } else if ( IP::isIPv6( $this->username ) && preg_match("/^(64|80|96|112)$/", $this->username) ) { + } else if ( IP::isIPv6( $this->username ) && preg_match("/^(?64|80|96|112)$/", $this->username) ) { $abcdefgh = explode( ":", IP::sanitizeIP($this->username) ); $abcd = implode( ":", array_slice($abcdefgh, 0, 4) ); switch( $matches[1] ) { @@ -287,7 +287,7 @@ function wfSpecialContributions( $par = null ) { if ( $target == 'newbies' ) { $wgOut->setSubtitle( wfMsgHtml( 'sp-contributions-newbies-sub') ); - } else if ( preg_match( "/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/(24|16)/", $target ) ) { + } else if ( preg_match( "/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/(?:24|16)/", $target ) ) { $wgOut->setSubtitle( wfMsgHtml( 'contribsub', $target ) ); } else { $wgOut->setSubtitle( wfMsgHtml( 'contribsub', contributionsSub( $nt ) ) ); diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index 46565c5ee7..af4070a686 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -1125,13 +1125,13 @@ class UploadForm { $chunk = Sanitizer::decodeCharReferences( $chunk ); #look for script-types - if (preg_match('!type\s*=\s*[\'"]?\s*(\w*/)?(ecma|java)!sim',$chunk)) return true; + if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim',$chunk)) return true; #look for html-style script-urls - if (preg_match('!(href|src|data)\s*=\s*[\'"]?\s*(ecma|java)script:!sim',$chunk)) return true; + if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true; #look for css-style script-urls - if (preg_match('!url\s*\(\s*[\'"]?\s*(ecma|java)script:!sim',$chunk)) return true; + if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true; wfDebug("SpecialUpload::detectScript: no scripts found\n"); return false; diff --git a/includes/Title.php b/includes/Title.php index 8a85532457..50faf93991 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1301,7 +1301,7 @@ class Title { * @access public */ function isCssJsSubpage() { - return ( NS_USER == $this->mNamespace and preg_match("/\\/.*\\.(css|js)$/", $this->mTextform ) ); + return ( NS_USER == $this->mNamespace and preg_match("/\\/.*\\.(?:css|js)$/", $this->mTextform ) ); } /** * Is this a *valid* .css or .js subpage of a user page? -- 2.20.1