Merge "Fix documentation in Linker::formatTemplates."
[lhc/web/wiklou.git] / includes / parser / Parser_LinkHooks.php
index d1ca8aa..b2cdc41 100644 (file)
@@ -105,9 +105,9 @@ class Parser_LinkHooks extends Parser {
         */
        public function setLinkHook( $ns, $callback, $flags = 0 ) {
                if( $flags & SLH_PATTERN && !is_string($ns) )
-                       throw new MWException( __METHOD__.'() expecting a regex string pattern.' );
-               elseif( $flags | ~SLH_PATTERN && !is_int($ns) )
-                       throw new MWException( __METHOD__.'() expecting a namespace index.' );
+                       throw new MWException( __METHOD__ . '() expecting a regex string pattern.' );
+               elseif( $flags | ~SLH_PATTERN && !is_int( $ns ) )
+                       throw new MWException( __METHOD__ . '() expecting a namespace index.' );
                $oldVal = isset( $this->mLinkHooks[$ns] ) ? $this->mLinkHooks[$ns][0] : null;
                $this->mLinkHooks[$ns] = array( $callback, $flags );
                return $oldVal;
@@ -133,8 +133,8 @@ class Parser_LinkHooks extends Parser {
        function replaceInternalLinks2( &$s ) {
                wfProfileIn( __METHOD__ );
 
-               wfProfileIn( __METHOD__.'-setup' );
-               static $tc = FALSE, $titleRegex;//$e1, $e1_img;
+               wfProfileIn( __METHOD__ . '-setup' );
+               static $tc = false, $titleRegex; //$e1, $e1_img;
                if( !$tc ) {
                        # the % is needed to support urlencoded titles as well
                        $tc = Title::legalChars() . '#%';
@@ -149,12 +149,12 @@ class Parser_LinkHooks extends Parser {
                $holders = new LinkHolderArray( $this );
 
                if( is_null( $this->mTitle ) ) {
-                       wfProfileOut( __METHOD__.'-setup' );
+                       wfProfileOut( __METHOD__ . '-setup' );
                        wfProfileOut( __METHOD__ );
-                       throw new MWException( __METHOD__.": \$this->mTitle is null\n" );
+                       throw new MWException( __METHOD__ . ": \$this->mTitle is null\n" );
                }
 
-               wfProfileOut( __METHOD__.'-setup' );
+               wfProfileOut( __METHOD__ . '-setup' );
 
                $offset = 0;
                $offsetStack = array();
@@ -167,7 +167,7 @@ class Parser_LinkHooks extends Parser {
                        # Determine if the bracket is a starting or ending bracket
                        # When we find both, use the first one
                        elseif( $startBracketOffset !== false && $endBracketOffset !== false )
-                            $isStart = $startBracketOffset <= $endBracketOffset;
+                               $isStart = $startBracketOffset <= $endBracketOffset;
                        # When we only found one, check which it is
                        else $isStart = $startBracketOffset !== false;
                        $bracketOffset = $isStart ? $startBracketOffset : $endBracketOffset;
@@ -178,26 +178,26 @@ class Parser_LinkHooks extends Parser {
                        } else {
                                /** Closing bracket **/
                                # Pop the start pos for our current link zone off the stack
-                               $startBracketOffset = array_pop($offsetStack);
+                               $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) ) {
+                               if( isset( $startBracketOffset ) ) {
                                        # Extract text inside the link
-                                       @list( $titleText, $paramText ) = explode('|',
-                                               substr($s, $startBracketOffset+2, $endBracketOffset-$startBracketOffset-4), 2);
+                                       @list( $titleText, $paramText ) = explode( '|',
+                                               substr( $s, $startBracketOffset + 2, $endBracketOffset - $startBracketOffset - 4 ), 2 );
                                        # Create markers only for valid links
                                        if( preg_match( $titleRegex, $titleText ) ) {
                                                # Store the text for the marker
-                                               $marker = $markers->addMarker($titleText, $paramText);
+                                               $marker = $markers->addMarker( $titleText, $paramText );
                                                # Replace the current link with the marker
-                                               $s = substr($s,0,$startBracketOffset).
-                                                       $marker.
-                                                       substr($s, $endBracketOffset);
+                                               $s = substr( $s, 0, $startBracketOffset ) .
+                                                       $marker .
+                                                       substr( $s, $endBracketOffset );
                                                # We have modified $s, because of this we need to set the
                                                # offset manually since the end position is different now
-                                               $offset = $startBracketOffset+strlen($marker);
+                                               $offset = $startBracketOffset+strlen( $marker );
                                                continue;
                                        }
                                        # ToDo: Some LinkHooks may allow recursive links inside of
@@ -212,9 +212,9 @@ class Parser_LinkHooks extends Parser {
                }
 
                # Now expand our tree
-               wfProfileIn( __METHOD__.'-expand' );
+               wfProfileIn( __METHOD__ . '-expand' );
                $s = $markers->expand( $s );
-               wfProfileOut( __METHOD__.'-expand' );
+               wfProfileOut( __METHOD__ . '-expand' );
 
                wfProfileOut( __METHOD__ );
                return $holders;
@@ -222,14 +222,14 @@ class Parser_LinkHooks extends Parser {
 
        function replaceInternalLinksCallback( $parser, $holders, $markers, $titleText, $paramText ) {
                wfProfileIn( __METHOD__ );
-               $wt = isset($paramText) ? "[[$titleText|$paramText]]" : "[[$titleText]]";
-               wfProfileIn( __METHOD__."-misc" );
+               $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" );
+               if( preg_match( '/^\b(?i:' . wfUrlProtocols() . ')/', $titleText ) ) {
+                       wfProfileOut( __METHOD__ . "-misc" );
                        wfProfileOut( __METHOD__ );
                        return $wt;
                }
@@ -243,17 +243,17 @@ class Parser_LinkHooks extends Parser {
                $leadingColon = $titleText[0] == ':';
                if( $leadingColon ) $titleText = substr( $titleText, 1 );
 
-               wfProfileOut( __METHOD__."-misc" );
+               wfProfileOut( __METHOD__ . "-misc" );
                # Make title object
-               wfProfileIn( __METHOD__."-title" );
+               wfProfileIn( __METHOD__ . "-title" );
                $title = Title::newFromText( $this->mStripState->unstripNoWiki( $titleText ) );
                if( !$title ) {
-                       wfProfileOut( __METHOD__."-title" );
+                       wfProfileOut( __METHOD__ . "-title" );
                        wfProfileOut( __METHOD__ );
                        return $wt;
                }
                $ns = $title->getNamespace();
-               wfProfileOut( __METHOD__."-title" );
+               wfProfileOut( __METHOD__ . "-title" );
 
                # Default for Namespaces is a default link
                # ToDo: Default for patterns is plain wikitext
@@ -279,7 +279,7 @@ class Parser_LinkHooks extends Parser {
                if( $return === false ) {
                        # False (no link) was returned, output plain wikitext
                        # Build it again as the hook is allowed to modify $paramText
-                       $return = isset($paramText) ? "[[$titleText|$paramText]]" : "[[$titleText]]";
+                       $return = isset( $paramText ) ? "[[$titleText|$paramText]]" : "[[$titleText]]";
                }
                # Content was returned, return it
                wfProfileOut( __METHOD__ );
@@ -300,14 +300,14 @@ class LinkMarkerReplacer {
                $this->callback = $callback;
        }
 
-       function addMarker($titleText, $paramText) {
+       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 );
+               return (bool) preg_match( '/<!-- LINKMARKER [0-9]+ -->/', $string );
        }
 
        function expand( $string ) {
@@ -315,8 +315,8 @@ class LinkMarkerReplacer {
        }
 
        function callback( $m ) {
-               $id = intval($m[1]);
-               if( !array_key_exists($id, $this->markers) ) return $m[0];
+               $id = intval( $m[1] );
+               if( !array_key_exists( $id, $this->markers ) ) return $m[0];
                $args = $this->markers[$id];
                array_unshift( $args, $this );
                array_unshift( $args, $this->holders );