Removed deprecated ContentHandler hooks.
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index dc65549..920ba87 100644 (file)
@@ -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;
                }
 
@@ -1413,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.
@@ -1453,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.
@@ -1620,6 +1604,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:
@@ -1641,7 +1626,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;
 
@@ -1670,14 +1655,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' );
@@ -1720,7 +1706,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
@@ -1898,10 +1885,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 );
                                }
                        ),
@@ -2018,16 +2007,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
@@ -2062,22 +2050,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
@@ -2312,9 +2284,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() );
@@ -2358,9 +2333,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 );
@@ -2489,7 +2467,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();
                        }
 
@@ -2576,9 +2557,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;
@@ -2858,9 +2842,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
@@ -3489,28 +3476,6 @@ class WikiPage implements Page, IDBAccessObject {
                return $result;
        }
 
-       /**
-        * Return an applicable autosummary if one exists for the given edit.
-        * @param string|null $oldtext The previous text of the page.
-        * @param string|null $newtext The submitted text of the page.
-        * @param int $flags Bitmask: a bitmask of flags submitted for the edit.
-        * @return string An appropriate autosummary, or an empty string.
-        *
-        * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
-        */
-       public static function getAutosummary( $oldtext, $newtext, $flags ) {
-               // NOTE: stub for backwards-compatibility. assumes the given text is
-               // wikitext. will break horribly if it isn't.
-
-               wfDeprecated( __METHOD__, '1.21' );
-
-               $handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
-               $oldContent = is_null( $oldtext ) ? null : $handler->unserializeContent( $oldtext );
-               $newContent = is_null( $newtext ) ? null : $handler->unserializeContent( $newtext );
-
-               return $handler->getAutosummary( $oldContent, $newContent, $flags );
-       }
-
        /**
         * Auto-generates a deletion reason
         *
@@ -3719,4 +3684,30 @@ class WikiPage implements Page, IDBAccessObject {
        public function isLocal() {
                return true;
        }
+
+       /**
+        * The display name for the site this content
+        * come from. If a subclass overrides isLocal(),
+        * this could return something other than the
+        * current site name
+        *
+        * @since 1.28
+        * @return string
+        */
+       public function getWikiDisplayName() {
+               global $wgSitename;
+               return $wgSitename;
+       }
+
+       /**
+        * Get the source URL for the content on this page,
+        * typically the canonical URL, but may be a remote
+        * link if the content comes from another site
+        *
+        * @since 1.28
+        * @return string
+        */
+       public function getSourceURL() {
+               return $this->getTitle()->getCanonicalURL();
+       }
 }