X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fpage%2FWikiPage.php;h=ab95eea4e3f101ee75acf17c4050e7326e76cb98;hb=9ad27459646786b011a98ed30966be621edab55f;hp=924a395d7b1a21598517d8b4115d07d5db9e6770;hpb=b26ad1ac3f9477dcf7a04705b641d5e42fbec3a4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 924a395d7b..ab95eea4e3 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -316,7 +316,10 @@ class WikiPage implements Page, IDBAccessObject { protected function pageData( $dbr, $conditions, $options = [] ) { $fields = self::selectFields(); - Hooks::run( 'ArticlePageDataBefore', [ &$this, &$fields ] ); + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + + Hooks::run( 'ArticlePageDataBefore', [ &$wikiPage, &$fields ] ); $row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__, $options ); @@ -685,28 +688,6 @@ class WikiPage implements Page, IDBAccessObject { return null; } - /** - * Get the text of the current revision. No side-effects... - * - * @param int $audience One of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions - * @param User $user User object to check for, only if FOR_THIS_USER is passed - * to the $audience parameter - * @return string|bool The text of the current revision - * @deprecated since 1.21, getContent() should be used instead. - */ - public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { - wfDeprecated( __METHOD__, '1.21' ); - - $this->loadLastEdit(); - if ( $this->mLastRevision ) { - return $this->mLastRevision->getText( $audience, $user ); - } - return false; - } - /** * @return string MW timestamp of last article revision */ @@ -1143,7 +1124,10 @@ class WikiPage implements Page, IDBAccessObject { * @return bool */ public function doPurge( $flags = self::PURGE_ALL ) { - if ( !Hooks::run( 'ArticlePurge', [ &$this ] ) ) { + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + + if ( !Hooks::run( 'ArticlePurge', [ &$wikiPage ] ) ) { return false; } @@ -1173,22 +1157,8 @@ class WikiPage implements Page, IDBAccessObject { } if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - // @todo move this logic to MessageCache - if ( $this->exists() ) { - // NOTE: use transclusion text for messages. - // This is consistent with MessageCache::getMsgFromNamespace() - - $content = $this->getContent(); - $text = $content === null ? null : $content->getWikitextForTransclusion(); - - if ( $text === null ) { - $text = false; - } - } else { - $text = false; - } - - MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text ); + $messageCache = MessageCache::singleton(); + $messageCache->updateMessageOverride( $this->mTitle, $this->getContent() ); } return true; @@ -1427,7 +1397,7 @@ class WikiPage implements Page, IDBAccessObject { } /** - * @param string|number|null|bool $sectionId Section identifier as a number or string + * @param string|int|null|bool $sectionId Section identifier as a number or string * (e.g. 0, 1 or 'T-1'), null/false or an empty string for the whole page * or 'new' for a new section. * @param Content $sectionContent New content of the section. @@ -1467,7 +1437,7 @@ class WikiPage implements Page, IDBAccessObject { } /** - * @param string|number|null|bool $sectionId Section identifier as a number or string + * @param string|int|null|bool $sectionId Section identifier as a number or string * (e.g. 0, 1 or 'T-1'), null/false or an empty string for the whole page * or 'new' for a new section. * @param Content $sectionContent New content of the section. @@ -1534,68 +1504,6 @@ class WikiPage implements Page, IDBAccessObject { return $flags; } - /** - * Change an existing article or create a new article. Updates RC and all necessary caches, - * optionally via the deferred update array. - * - * @param string $text New text - * @param string $summary Edit summary - * @param int $flags Bitfield: - * EDIT_NEW - * Article is known or assumed to be non-existent, create a new one - * EDIT_UPDATE - * Article is known or assumed to be pre-existing, update it - * EDIT_MINOR - * Mark this edit minor, if the user is allowed to do so - * EDIT_SUPPRESS_RC - * Do not log the change in recentchanges - * EDIT_FORCE_BOT - * Mark the edit a "bot" edit regardless of user rights - * EDIT_AUTOSUMMARY - * Fill in blank summaries with generated text where possible - * EDIT_INTERNAL - * Signal that the page retrieve/save cycle happened entirely in this request. - * - * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the - * article will be detected. If EDIT_UPDATE is specified and the article - * doesn't exist, the function will return an edit-gone-missing error. If - * EDIT_NEW is specified and the article does exist, an edit-already-exists - * error will be returned. These two conditions are also possible with - * auto-detection due to MediaWiki's performance-optimised locking strategy. - * - * @param bool|int $baseRevId The revision ID this edit was based off, if any. - * This is not the parent revision ID, rather the revision ID for older - * content used as the source for a rollback, for example. - * @param User $user The user doing the edit - * - * @throws MWException - * @return Status Possible errors: - * edit-hook-aborted: The ArticleSave hook aborted the edit but didn't - * set the fatal flag of $status - * edit-gone-missing: In update mode, but the article didn't exist. - * edit-conflict: In update mode, the article changed unexpectedly. - * edit-no-change: Warning that the text was the same as before. - * edit-already-exists: In creation mode, but the article already exists. - * - * Extensions may define additional errors. - * - * $return->value will contain an associative array with members as follows: - * new: Boolean indicating if the function attempted to create a new article. - * revision: The revision object for the inserted revision, or null. - * - * Compatibility note: this function previously returned a boolean value - * indicating success/failure - * - * @deprecated since 1.21: use doEditContent() instead. - */ - public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) { - wfDeprecated( __METHOD__, '1.21' ); - - $content = ContentHandler::makeContent( $text, $this->getTitle() ); - - return $this->doEditContent( $content, $summary, $flags, $baseRevId, $user ); - } - /** * Change an existing article or create a new article. Updates RC and all necessary caches, * optionally via the deferred update array. @@ -1634,6 +1542,7 @@ class WikiPage implements Page, IDBAccessObject { * @param array|null $tags Change tags to apply to this edit * Callers are responsible for permission checks * (with ChangeTags::canAddTagsAccompanyingChange) + * @param Int $undidRevId Id of revision that was undone or 0 * * @throws MWException * @return Status Possible errors: @@ -1655,7 +1564,7 @@ class WikiPage implements Page, IDBAccessObject { */ public function doEditContent( Content $content, $summary, $flags = 0, $baseRevId = false, - User $user = null, $serialFormat = null, $tags = [] + User $user = null, $serialFormat = null, $tags = [], $undidRevId = 0 ) { global $wgUser, $wgUseAutomaticEditSummaries; @@ -1684,14 +1593,15 @@ class WikiPage implements Page, IDBAccessObject { $user = $user ?: $wgUser; $flags = $this->checkFlags( $flags ); + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + // Trigger pre-save hook (using provided edit summary) $hookStatus = Status::newGood( [] ); - $hook_args = [ &$this, &$user, &$content, &$summary, + $hook_args = [ &$wikiPage, &$user, &$content, &$summary, $flags & EDIT_MINOR, null, null, &$flags, &$hookStatus ]; // Check if the hook rejected the attempted save - if ( !Hooks::run( 'PageContentSave', $hook_args ) - || !ContentHandler::runLegacyHooks( 'ArticleSave', $hook_args, '1.21' ) - ) { + if ( !Hooks::run( 'PageContentSave', $hook_args ) ) { if ( $hookStatus->isOK() ) { // Hook returned false but didn't call fatal(); use generic message $hookStatus->fatal( 'edit-hook-aborted' ); @@ -1734,7 +1644,8 @@ class WikiPage implements Page, IDBAccessObject { 'oldId' => $this->getLatest(), 'oldIsRedirect' => $this->isRedirect(), 'oldCountable' => $this->isCountable(), - 'tags' => ( $tags !== null ) ? (array)$tags : [] + 'tags' => ( $tags !== null ) ? (array)$tags : [], + 'undidRevId' => $undidRevId ]; // Actually create the revision and create/update the page @@ -1912,10 +1823,12 @@ class WikiPage implements Page, IDBAccessObject { 'oldrevision' => $meta['oldRevision'] ] ); + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; // Trigger post-save hook - $params = [ &$this, &$user, $content, $summary, $flags & EDIT_MINOR, - null, null, &$flags, $revision, &$status, $meta['baseRevId'] ]; - ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params ); + $params = [ &$wikiPage, &$user, $content, $summary, $flags & EDIT_MINOR, + null, null, &$flags, $revision, &$status, $meta['baseRevId'], + $meta['undidRevId'] ]; Hooks::run( 'PageContentSaveComplete', $params ); } ), @@ -2032,16 +1945,15 @@ class WikiPage implements Page, IDBAccessObject { ) { // Update links, etc. $this->doEditUpdates( $revision, $user, [ 'created' => true ] ); + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; // Trigger post-create hook - $params = [ &$this, &$user, $content, $summary, + $params = [ &$wikiPage, &$user, $content, $summary, $flags & EDIT_MINOR, null, null, &$flags, $revision ]; - ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $params, '1.21' ); Hooks::run( 'PageContentInsertComplete', $params ); // Trigger post-save hook $params = array_merge( $params, [ &$status, $meta['baseRevId'] ] ); - ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params, '1.21' ); Hooks::run( 'PageContentSaveComplete', $params ); - } ), DeferredUpdates::PRESEND @@ -2076,22 +1988,6 @@ class WikiPage implements Page, IDBAccessObject { return $options; } - /** - * Prepare text which is about to be saved. - * Returns a stdClass with source, pst and output members - * - * @param string $text - * @param int|null $revid - * @param User|null $user - * @deprecated since 1.21: use prepareContentForEdit instead. - * @return object - */ - public function prepareTextForEdit( $text, $revid = null, User $user = null ) { - wfDeprecated( __METHOD__, '1.21' ); - $content = ContentHandler::makeContent( $text, $this->getTitle() ); - return $this->prepareContentForEdit( $content, $revid, $user ); - } - /** * Prepare content which is about to be saved. * Returns a stdClass with source, pst and output members @@ -2192,8 +2088,12 @@ class WikiPage implements Page, IDBAccessObject { ); } else { // Try to avoid a second parse if {{REVISIONID}} is used - $edit->popts->setSpeculativeRevIdCallback( function () { - return 1 + (int)wfGetDB( DB_MASTER )->selectField( + $dbIndex = ( $this->mDataLoadedFrom & self::READ_LATEST ) === self::READ_LATEST + ? DB_MASTER // use the best possible guess + : DB_REPLICA; // T154554 + + $edit->popts->setSpeculativeRevIdCallback( function () use ( $dbIndex ) { + return 1 + (int)wfGetDB( $dbIndex )->selectField( 'revision', 'MAX(rev_id)', [], @@ -2250,7 +2150,7 @@ class WikiPage implements Page, IDBAccessObject { * - 'no-change': don't update the article count, ever */ public function doEditUpdates( Revision $revision, User $user, array $options = [] ) { - global $wgRCWatchCategoryMembership, $wgContLang; + global $wgRCWatchCategoryMembership; $options += [ 'changed' => true, @@ -2326,9 +2226,12 @@ class WikiPage implements Page, IDBAccessObject { } } - Hooks::run( 'ArticleEditUpdates', [ &$this, &$editInfo, $options['changed'] ] ); + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + + Hooks::run( 'ArticleEditUpdates', [ &$wikiPage, &$editInfo, $options['changed'] ] ); - if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', [ &$this ] ) ) { + if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', [ &$wikiPage ] ) ) { // Flush old entries from the `recentchanges` table if ( mt_rand( 0, 9 ) == 0 ) { JobQueueGroup::singleton()->lazyPush( RecentChangesUpdateJob::newPurgeJob() ); @@ -2372,9 +2275,12 @@ class WikiPage implements Page, IDBAccessObject { if ( !$recipient ) { wfDebug( __METHOD__ . ": invalid username\n" ); } else { + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + // Allow extensions to prevent user notification // when a new message is added to their talk page - if ( Hooks::run( 'ArticleEditUpdateNewTalk', [ &$this, $recipient ] ) ) { + if ( Hooks::run( 'ArticleEditUpdateNewTalk', [ &$wikiPage, $recipient ] ) ) { if ( User::isIP( $shortTitle ) ) { // An anonymous user $recipient->setNewtalk( true, $revision ); @@ -2388,17 +2294,7 @@ class WikiPage implements Page, IDBAccessObject { } if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - // XXX: could skip pseudo-messages like js/css here, based on content model. - $msgtext = $content ? $content->getWikitextForTransclusion() : null; - if ( $msgtext === false || $msgtext === null ) { - $msgtext = ''; - } - - MessageCache::singleton()->replace( $shortTitle, $msgtext ); - - if ( $wgContLang->hasVariants() ) { - $wgContLang->updateConversionTable( $this->mTitle ); - } + MessageCache::singleton()->updateMessageOverride( $this->mTitle, $content ); } if ( $options['created'] ) { @@ -2513,7 +2409,10 @@ class WikiPage implements Page, IDBAccessObject { $nullRevision = null; if ( $id ) { // Protection of existing page - if ( !Hooks::run( 'ArticleProtect', [ &$this, &$user, $limit, $reason ] ) ) { + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + + if ( !Hooks::run( 'ArticleProtect', [ &$wikiPage, &$user, $limit, $reason ] ) ) { return Status::newGood(); } @@ -2600,9 +2499,12 @@ class WikiPage implements Page, IDBAccessObject { __METHOD__ ); + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + Hooks::run( 'NewRevisionFromEditComplete', [ $this, $nullRevision, $latest, $user ] ); - Hooks::run( 'ArticleProtectComplete', [ &$this, &$user, $limit, $reason ] ); + Hooks::run( 'ArticleProtectComplete', [ &$wikiPage, &$user, $limit, $reason ] ); } else { // Protection of non-existing page (also known as "title protection") // Cascade protection is meaningless in this case $cascade = false; @@ -2882,9 +2784,12 @@ class WikiPage implements Page, IDBAccessObject { return $status; } + // Avoid PHP 7.1 warning of passing $this by reference + $wikiPage = $this; + $user = is_null( $user ) ? $wgUser : $user; if ( !Hooks::run( 'ArticleDelete', - [ &$this, &$user, &$reason, &$error, &$status, $suppress ] + [ &$wikiPage, &$user, &$reason, &$error, &$status, $suppress ] ) ) { if ( $status->isOK() ) { // Hook aborted but didn't set a fatal status @@ -3396,8 +3301,6 @@ class WikiPage implements Page, IDBAccessObject { * @param Title $title */ public static function onArticleDelete( Title $title ) { - global $wgContLang; - // Update existence markers on article/talk tabs... $other = $title->getOtherPage(); @@ -3414,11 +3317,7 @@ class WikiPage implements Page, IDBAccessObject { // Messages if ( $title->getNamespace() == NS_MEDIAWIKI ) { - MessageCache::singleton()->replace( $title->getDBkey(), false ); - - if ( $wgContLang->hasVariants() ) { - $wgContLang->updateConversionTable( $title ); - } + MessageCache::singleton()->updateMessageOverride( $title, null ); } // Images