Merge "Followup I888c616e: Keep IRC line format unchanged."
[lhc/web/wiklou.git] / includes / parser / Parser_LinkHooks.php
index 9c750b8..d1ca8aa 100644 (file)
@@ -32,7 +32,7 @@ class Parser_LinkHooks extends Parser {
         * can automatically discard old data.
         */
        const VERSION = '1.6.4';
-       
+
        # Flags for Parser::setLinkHook
        # Also available as global constants from Defines.php
        const SLH_PATTERN = 1;
@@ -112,7 +112,7 @@ class Parser_LinkHooks extends Parser {
                $this->mLinkHooks[$ns] = array( $callback, $flags );
                return $oldVal;
        }
-       
+
        /**
         * Get all registered link hook identifiers
         *
@@ -147,15 +147,15 @@ class Parser_LinkHooks extends Parser {
                }
 
                $holders = new LinkHolderArray( $this );
-               
+
                if( is_null( $this->mTitle ) ) {
-                       wfProfileOut( __METHOD__ );
                        wfProfileOut( __METHOD__.'-setup' );
+                       wfProfileOut( __METHOD__ );
                        throw new MWException( __METHOD__.": \$this->mTitle is null\n" );
                }
 
                wfProfileOut( __METHOD__.'-setup' );
-               
+
                $offset = 0;
                $offsetStack = array();
                $markers = new LinkMarkerReplacer( $this, $holders, array( &$this, 'replaceInternalLinksCallback' ) );
@@ -181,7 +181,7 @@ class Parser_LinkHooks extends Parser {
                                $startBracketOffset = array_pop($offsetStack);
                                # Just to clean up the code, lets place offsets on the outer ends
                                $endBracketOffset += 2;
-                               
+
                                # Only do logic if we actually have a opening bracket for this
                                if( isset($startBracketOffset) ) {
                                        # Extract text inside the link
@@ -206,43 +206,43 @@ class Parser_LinkHooks extends Parser {
                                        # ToDO: Some LinkHooks use patterns rather than namespaces
                                        # these need to be tested at this point here
                                }
-                               
                        }
                        # Bump our offset to after our current bracket
                        $offset = $bracketOffset+2;
                }
-               
-               
+
                # Now expand our tree
                wfProfileIn( __METHOD__.'-expand' );
                $s = $markers->expand( $s );
                wfProfileOut( __METHOD__.'-expand' );
-               
+
                wfProfileOut( __METHOD__ );
                return $holders;
        }
-       
+
        function replaceInternalLinksCallback( $parser, $holders, $markers, $titleText, $paramText ) {
                wfProfileIn( __METHOD__ );
                $wt = isset($paramText) ? "[[$titleText|$paramText]]" : "[[$titleText]]";
                wfProfileIn( __METHOD__."-misc" );
+
                # 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(?i:' . wfUrlProtocols() . ')/', $titleText) ) {
+                       wfProfileOut( __METHOD__."-misc" );
                        wfProfileOut( __METHOD__ );
                        return $wt;
                }
-               
+
                # Make subpage if necessary
                if( $this->areSubpagesAllowed() ) {
                        $titleText = $this->maybeDoSubpageLink( $titleText, $paramText );
                }
-               
+
                # Check for a leading colon and strip it if it is there
                $leadingColon = $titleText[0] == ':';
                if( $leadingColon ) $titleText = substr( $titleText, 1 );
-               
+
                wfProfileOut( __METHOD__."-misc" );
                # Make title object
                wfProfileIn( __METHOD__."-title" );
@@ -254,7 +254,7 @@ class Parser_LinkHooks extends Parser {
                }
                $ns = $title->getNamespace();
                wfProfileOut( __METHOD__."-title" );
-               
+
                # Default for Namespaces is a default link
                # ToDo: Default for patterns is plain wikitext
                $return = true;
@@ -273,7 +273,7 @@ class Parser_LinkHooks extends Parser {
                }
                if( $return === true ) {
                        # True (treat as plain link) was returned, call the defaultLinkHook
-                       $return = CoreLinkFunctions::defaultLinkHook( $parser, $holders, $markers, $title, 
+                       $return = CoreLinkFunctions::defaultLinkHook( $parser, $holders, $markers, $title,
                                $titleText, $paramText, $leadingColon );
                }
                if( $return === false ) {
@@ -285,13 +285,13 @@ class Parser_LinkHooks extends Parser {
                wfProfileOut( __METHOD__ );
                return $return;
        }
-       
+
 }
 
 class LinkMarkerReplacer {
-       
+
        protected $markers, $nextId, $parser, $holders, $callback;
-       
+
        function __construct( $parser, $holders, $callback ) {
                $this->nextId   = 0;
                $this->markers  = array();
@@ -299,21 +299,21 @@ class LinkMarkerReplacer {
                $this->holders  = $holders;
                $this->callback = $callback;
        }
-       
+
        function addMarker($titleText, $paramText) {
                $id = $this->nextId++;
                $this->markers[$id] = array( $titleText, $paramText );
                return "<!-- LINKMARKER $id -->";
        }
-       
+
        function findMarker( $string ) {
                return (bool) preg_match('/<!-- LINKMARKER [0-9]+ -->/', $string );
        }
-       
+
        function expand( $string ) {
                return StringUtils::delimiterReplaceCallback( "<!-- LINKMARKER ", " -->", array( &$this, 'callback' ), $string );
        }
-       
+
        function callback( $m ) {
                $id = intval($m[1]);
                if( !array_key_exists($id, $this->markers) ) return $m[0];
@@ -323,5 +323,4 @@ class LinkMarkerReplacer {
                array_unshift( $args, $this->parser );
                return call_user_func_array( $this->callback, $args );
        }
-       
 }