Revert r35848 per Brion's WONTFIX of bug 14536: "This would just mean that there...
[lhc/web/wiklou.git] / includes / Parser.php
index 9a73ee7..a763ab1 100644 (file)
@@ -1,10 +1,10 @@
 <?php
-
 /**
+ * @defgroup Parser Parser
  *
+ * @file
+ * @ingroup Parser
  * File for Parser and related classes
- *
- * @addtogroup Parser
  */
 
 
@@ -41,7 +41,7 @@
  *  * only within ParserOptions
  * </pre>
  *
- * @addtogroup Parser
+ * @ingroup Parser
  */
 class Parser
 {
@@ -394,14 +394,7 @@ class Parser
                }
                global $wgExpensiveParserFunctionLimit;
                if ( $this->mExpensiveFunctionCount > $wgExpensiveParserFunctionLimit ) {
-                       if ( is_callable( array( $this->mOutput, 'addWarning' ) ) ) {
-                               $warning = wfMsg( 'expensive-parserfunction-warning', $this->mExpensiveFunctionCount, $wgExpensiveParserFunctionLimit );
-                               $this->mOutput->addWarning( $warning );
-                               $cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( 'expensive-parserfunction-category' ) );
-                               if ( $cat ) {
-                                       $this->mOutput->addCategory( $cat->getDBkey(), $this->getDefaultSort() );
-                               }
-                       }
+                       $this->limitationWarn( 'expensive-parserfunction', $this->mExpensiveFunctionCount, $wgExpensiveParserFunctionLimit );
                }
 
                wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
@@ -475,6 +468,7 @@ class Parser
 
        function &getTitle() { return $this->mTitle; }
        function getOptions() { return $this->mOptions; }
+       function getRevisionId() { return $this->mRevisionId; }
 
        function getFunctionLang() {
                global $wgLang, $wgContLang;
@@ -1872,8 +1866,7 @@ class Parser
         */
        function areSubpagesAllowed() {
                # Some namespaces don't allow subpages
-               global $wgNamespacesWithSubpages;
-               return !empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()]);
+               return MWNamespace::hasSubpages( $this->mTitle->getNamespace() );
        }
 
        /**
@@ -2702,6 +2695,28 @@ class Parser
                return $assocArgs;
        }
 
+       /**
+        * Warn the user when a parser limitation is reached
+        * Will warn at most once the user per limitation type
+        *
+        * @param string $limitationType, should be one of:
+        *   'expensive-parserfunction' (corresponding messages: 'expensive-parserfunction-warning', 'expensive-parserfunction-category')
+        *   'post-expand-template-argument' (corresponding messages: 'post-expand-template-argument-warning', 'post-expand-template-argument-category')
+        *   'post-expand-template-inclusion' (corresponding messages: 'post-expand-template-inclusion-warning', 'post-expand-template-inclusion-category')
+        * @params int $current, $max When an explicit limit has been
+        *       exceeded, provide the values (optional)
+        */
+       function limitationWarn( $limitationType, $current=null, $max=null) {
+               $msgName = $limitationType . '-warning';
+               //does no harm if $current and $max are present but are unnecessary for the message
+               $warning = wfMsg( $msgName, $current, $max); 
+               $this->mOutput->addWarning( $warning );
+               $cat = Title::makeTitleSafe( NS_CATEGORY, wfMsgForContent( $limitationType . '-category' ) );
+               if ( $cat ) {
+                       $this->mOutput->addCategory( $cat->getDBkey(), $this->getDefaultSort() );
+               }
+       }
+
        /**
         * Return the text of a template, after recursively
         * replacing any variables or templates within the template.
@@ -2988,6 +3003,7 @@ class Parser
                        # Error, oversize inclusion
                        $text = "[[$originalTitle]]" .
                                $this->insertStripItem( '<!-- WARNING: template omitted, post-expand include size too large -->' );
+                       $this->limitationWarn( 'post-expand-template-inclusion' );
                }
 
                if ( $isLocalObj ) {
@@ -3082,6 +3098,11 @@ class Parser
                        }
                        $rev = $id ? Revision::newFromId( $id ) : Revision::newFromTitle( $title );
                        $rev_id = $rev ? $rev->getId() : 0;
+                       // If there is no current revision, there is no page
+                       if( $id === false && !$rev ) {
+                               $linkCache = LinkCache::singleton();
+                               $linkCache->addBadLinkObj( $title );
+                       }
 
                        $deps[] = array(
                                'title' => $title,
@@ -3181,6 +3202,7 @@ class Parser
                }
                if ( !$this->incrementIncludeSize( 'arg', strlen( $text ) ) ) {
                        $error = '<!-- WARNING: argument omitted, expansion size too large -->';
+                       $this->limitationWarn( 'post-expand-template-argument' );
                }
 
                if ( $text === false && $object === false ) {
@@ -4344,6 +4366,9 @@ class Parser
                        if ( count( $matches ) == 0 ) {
                                continue;
                        }
+                       
+                       if ( strpos( $matches[0], '%' ) !== false )
+                               $matches[1] = urldecode( $matches[1] );
                        $tp = Title::newFromText( $matches[1] );
                        $nt =& $tp;
                        if( is_null( $nt ) ) {
@@ -4438,8 +4463,8 @@ class Parser
                $sk = $this->mOptions->getSkin();
 
                # Give extensions a chance to select the file revision for us
-               $skip = $time = false;
-               wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$title, &$skip, &$time ) );
+               $skip = $time = $descQuery = false;
+               wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$title, &$skip, &$time, &$descQuery ) );
 
                if ( $skip ) {
                        return $sk->makeLinkObj( $title );
@@ -4535,7 +4560,7 @@ class Parser
                wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
 
                # Linker does the rest
-               $ret = $sk->makeImageLink2( $title, $file, $params['frame'], $params['handler'], $time );
+               $ret = $sk->makeImageLink2( $title, $file, $params['frame'], $params['handler'], $time, $descQuery );
 
                # Give the handler a chance to modify the parser object
                if ( $handler ) {
@@ -4893,7 +4918,7 @@ class Parser
 
 /**
  * @todo document, briefly.
- * @addtogroup Parser
+ * @ingroup Parser
  */
 class StripState {
        var $general, $nowiki;
@@ -4937,7 +4962,7 @@ class StripState {
 
 /**
  * @todo document, briefly.
- * @addtogroup Parser
+ * @ingroup Parser
  */
 class OnlyIncludeReplacer {
        var $output = '';