X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FParserOptions.php;h=100656d1e29c6731bb4b0f5bfa6d59e1cd48c84f;hb=d879a50eaddd64fb47fda334d1263d347ac28363;hp=7ad85a9371957418c53f8ab93599c0249e188b2b;hpb=5d318d830323cc69b046b75fafaaa19b78034e9d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 7ad85a9371..100656d1e2 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -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 ); + } ); + } }