In regex, do not capture stuff when you dont need it, use (?:)
authorAntoine Musso <hashar@users.mediawiki.org>
Fri, 13 Apr 2007 00:23:49 +0000 (00:23 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Fri, 13 Apr 2007 00:23:49 +0000 (00:23 +0000)
includes/Article.php
includes/Exif.php
includes/Parser.php
includes/Sanitizer.php
includes/SpecialContributions.php
includes/SpecialUpload.php
includes/Title.php

index 9e12611..1fb42b3 100644 (file)
@@ -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( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
index 84d8e8d..ab2e209 100644 (file)
@@ -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;
index 4b85c1a..504780f 100644 (file)
@@ -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('/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<li|<\\/tr|<\\/td|<\\/th)/iS', $t );
+                               $openmatch = preg_match('/(?:<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<p|<ul|<ol|<li|<\\/tr|<\\/td|<\\/th)/iS', $t );
                                $closematch = preg_match(
-                                       '/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|'.
+                                       '/(?:<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|'.
                                        '<td|<th|<\\/?div|<hr|<\\/pre|<\\/p|'.$this->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 ) {
index b702188..6e1f37b 100644 (file)
@@ -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;
index 3dbb193..2776acf 100644 (file)
@@ -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 ) ) );
index 46565c5..af4070a 100644 (file)
@@ -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;
index 8a85532..50faf93 100644 (file)
@@ -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?