X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=3c51baebe2cc4611d1a266f662af119e9cb99905;hb=34fe90ac52644c3a543ca8adf89900c0fb2de70b;hp=6d9ddd6ddcf033b48c220306f8ec2cc95881781e;hpb=ba49dbd66ef2c61c7c42ceb172c901ea0dbf5927;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 6d9ddd6ddc..3c51baebe2 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -91,7 +91,13 @@ class Title implements LinkTarget { * @var bool|string ID of the page's content model, i.e. one of the * CONTENT_MODEL_XXX constants */ - public $mContentModel = false; + private $mContentModel = false; + + /** + * @var bool If a content model was forced via setContentModel() + * this will be true to avoid having other code paths reset it + */ + private $mForcedContentModel = false; /** @var int Estimated number of revisions; null of not loaded */ private $mEstimateRevisions; @@ -467,9 +473,9 @@ class Title implements LinkTarget { if ( isset( $row->page_latest ) ) { $this->mLatestID = (int)$row->page_latest; } - if ( isset( $row->page_content_model ) ) { + if ( !$this->mForcedContentModel && isset( $row->page_content_model ) ) { $this->mContentModel = strval( $row->page_content_model ); - } else { + } elseif ( !$this->mForcedContentModel ) { $this->mContentModel = false; # initialized lazily in getContentModel() } if ( isset( $row->page_lang ) ) { @@ -483,7 +489,9 @@ class Title implements LinkTarget { $this->mLength = 0; $this->mRedirect = false; $this->mLatestID = 0; - $this->mContentModel = false; # initialized lazily in getContentModel() + if ( !$this->mForcedContentModel ) { + $this->mContentModel = false; # initialized lazily in getContentModel() + } } } @@ -921,8 +929,9 @@ class Title implements LinkTarget { * @return string Content model id */ public function getContentModel( $flags = 0 ) { - if ( ( !$this->mContentModel || $flags === Title::GAID_FOR_UPDATE ) && - $this->getArticleID( $flags ) + if ( !$this->mForcedContentModel + && ( !$this->mContentModel || $flags === Title::GAID_FOR_UPDATE ) + && $this->getArticleID( $flags ) ) { $linkCache = LinkCache::singleton(); $linkCache->addLinkObj( $this ); # in case we already had an article ID @@ -946,6 +955,22 @@ class Title implements LinkTarget { return $this->getContentModel() == $id; } + /** + * Set a proposed content model for the page for permissions + * checking. This does not actually change the content model + * of a title! + * + * Additionally, you should make sure you've checked + * ContentHandler::canBeUsedOn() first. + * + * @since 1.28 + * @param string $model CONTENT_MODEL_XXX constant + */ + public function setContentModel( $model ) { + $this->mContentModel = $model; + $this->mForcedContentModel = true; + } + /** * Get the namespace text * @@ -1079,7 +1104,7 @@ class Title implements LinkTarget { /** * Returns true if the title is inside one of the specified namespaces. * - * @param int $namespaces,... The namespaces to check for + * @param int|int[] $namespaces,... The namespaces to check for * @return bool * @since 1.19 */ @@ -1387,7 +1412,6 @@ class Title implements LinkTarget { $fragment, $this->getInterwiki() ); - } /** @@ -2901,7 +2925,6 @@ class Title implements LinkTarget { # Cycle through all the restrictions. foreach ( $rows as $row ) { - // Don't take care of restrictions types that aren't allowed if ( !in_array( $row->pr_type, $restrictionTypes ) ) { continue; @@ -4366,16 +4389,19 @@ class Title implements LinkTarget { public function invalidateCache( $purgeTime = null ) { if ( wfReadOnly() ) { return false; - } - - if ( $this->mArticleID === 0 ) { + } elseif ( $this->mArticleID === 0 ) { return true; // avoid gap locking if we know it's not there } + $dbw = wfGetDB( DB_MASTER ); + $dbw->onTransactionPreCommitOrIdle( function () { + ResourceLoaderWikiModule::invalidateModuleCache( $this, null, null, wfWikiID() ); + } ); + $conds = $this->pageCond(); DeferredUpdates::addUpdate( new AutoCommitUpdate( - wfGetDB( DB_MASTER ), + $dbw, __METHOD__, function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) { $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() ); @@ -4572,7 +4598,6 @@ class Title implements LinkTarget { : $wgExemptFromUserRobotsControl; return !in_array( $this->mNamespace, $bannedNamespaces ); - } /**