Merge "Fix description for MessagesBgn.php"
[lhc/web/wiklou.git] / includes / parser / ParserOptions.php
index 7ad85a9..100656d 100644 (file)
@@ -25,7 +25,7 @@
  * @brief Set options of the Parser
  *
  * All member variables are supposed to be private in theory, although in
- * practise this is not the case.
+ * practice this is not the case.
  *
  * @ingroup Parser
  */
@@ -145,9 +145,7 @@ class ParserOptions {
 
        /**
         * Clean up signature texts?
-        *
-        * 1) Strip ~~~, ~~~~ and ~~~~~ out of signatures
-        * 2) Substitute all transclusions
+        * @see Parser::cleanSig
         */
        public $mCleanSignatures;
 
@@ -639,8 +637,6 @@ class ParserOptions {
                        $wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit,
                        $wgMaxGeneratedPPNodeCount, $wgDisableLangConversion, $wgDisableTitleConversion;
 
-               wfProfileIn( __METHOD__ );
-
                // *UPDATE* ParserOptions::matches() if any of this changes as needed
                $this->mInterwikiMagic = $wgInterwikiMagic;
                $this->mAllowExternalImages = $wgAllowExternalImages;
@@ -664,7 +660,6 @@ class ParserOptions {
                $this->mStubThreshold = $user->getStubThreshold();
                $this->mUserLang = $lang;
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -672,6 +667,7 @@ class ParserOptions {
         *
         * This ignores report limit settings that only affect HTML comments
         *
+        * @param ParserOptions $other
         * @return bool
         * @since 1.25
         */
@@ -818,4 +814,46 @@ class ParserOptions {
 
                return $confstr;
        }
+
+       /**
+        * Sets a hook to force that a page exists, and sets a current revision callback to return a
+        * revision with custom content when the current revision of the page is requested.
+        *
+        * @since 1.25
+        * @param Title $title
+        * @param Content $content
+        * @param User $user The user that the fake revision is attributed to
+        * @return ScopedCallback to unset the hook
+        */
+       public function setupFakeRevision( $title, $content, $user ) {
+               $oldCallback = $this->setCurrentRevisionCallback( function ( $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback ) {
+                       if ( $titleToCheck->equals( $title ) ) {
+                               return new Revision( array(
+                                       'page' => $title->getArticleID(),
+                                       'user_text' => $user->getName(),
+                                       'user' => $user->getId(),
+                                       'parent_id' => $title->getLatestRevId(),
+                                       'title' => $title,
+                                       'content' => $content
+                               ) );
+                       } else {
+                               return call_user_func( $oldCallback, $titleToCheck, $parser );
+                       }
+               } );
+               global $wgHooks;
+               $wgHooks['TitleExists'][] =
+                       function ( $titleToCheck, &$exists ) use ( $title ) {
+                               if ( $titleToCheck->equals( $title ) ) {
+                                       $exists = true;
+                               }
+                       };
+               end( $wgHooks['TitleExists'] );
+               $key = key( $wgHooks['TitleExists'] );
+               LinkCache::singleton()->clearBadLink( $title->getPrefixedDBkey() );
+               return new ScopedCallback( function () use ( $title, $key ) {
+                       global $wgHooks;
+                       unset( $wgHooks['TitleExists'][$key] );
+                       LinkCache::singleton()->clearLink( $title );
+               } );
+       }
 }