Merge "Remove obvious function-level profiling"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 81c93a1..a822945 100644 (file)
@@ -50,7 +50,7 @@ class WikiPage implements Page, IDBAccessObject {
        public $mLatest = false;             // !< Integer (false means "not loaded")
        /**@}}*/
 
-       /** @var stdclass Map of cache fields (text, parser output, ect) for a proposed/new edit */
+       /** @var stdClass Map of cache fields (text, parser output, ect) for a proposed/new edit */
        public $mPreparedEdit = false;
 
        /**
@@ -278,7 +278,6 @@ class WikiPage implements Page, IDBAccessObject {
                        'page_namespace',
                        'page_title',
                        'page_restrictions',
-                       'page_counter',
                        'page_is_redirect',
                        'page_is_new',
                        'page_random',
@@ -309,11 +308,11 @@ class WikiPage implements Page, IDBAccessObject {
        protected function pageData( $dbr, $conditions, $options = array() ) {
                $fields = self::selectFields();
 
-               wfRunHooks( 'ArticlePageDataBefore', array( &$this, &$fields ) );
+               Hooks::run( 'ArticlePageDataBefore', array( &$this, &$fields ) );
 
                $row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__, $options );
 
-               wfRunHooks( 'ArticlePageDataAfter', array( &$this, &$row ) );
+               Hooks::run( 'ArticlePageDataAfter', array( &$this, &$row ) );
 
                return $row;
        }
@@ -346,8 +345,7 @@ class WikiPage implements Page, IDBAccessObject {
        }
 
        /**
-        * Set the general counter, title etc data loaded from
-        * some source.
+        * Load the object from a given source by title
         *
         * @param object|string|int $from One of the following:
         *   - A DB query result object.
@@ -397,7 +395,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param string|int $from One of the following:
         *        - "fromdb" or WikiPage::READ_NORMAL if the data comes from a slave DB
         *        - "fromdbmaster" or WikiPage::READ_LATEST if the data comes from the master DB
-        *        - "forupdate"  or WikiPage::READ_LOCKING if the data comes from from
+        *        - "forupdate"  or WikiPage::READ_LOCKING if the data comes from
         *          the master DB using SELECT FOR UPDATE
         */
        public function loadFromRow( $data, $from ) {
@@ -559,7 +557,6 @@ class WikiPage implements Page, IDBAccessObject {
         * @return Revision|null
         */
        public function getOldestRevision() {
-               wfProfileIn( __METHOD__ );
 
                // Try using the slave database first, then try the master
                $continue = 2;
@@ -590,7 +587,6 @@ class WikiPage implements Page, IDBAccessObject {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $row ? Revision::newFromRow( $row ) : null;
        }
 
@@ -977,7 +973,7 @@ class WikiPage implements Page, IDBAccessObject {
                                $source = $this->mTitle->getFullURL( 'redirect=no' );
                                return $rt->getFullURL( array( 'rdfrom' => $source ) );
                        } else {
-                               // External pages pages without "local" bit set are not valid
+                               // External pages without "local" bit set are not valid
                                // redirect targets
                                return false;
                        }
@@ -1057,7 +1053,6 @@ class WikiPage implements Page, IDBAccessObject {
         * @return array Array of authors, duplicates not removed
         */
        public function getLastNAuthors( $num, $revLatest = 0 ) {
-               wfProfileIn( __METHOD__ );
                // First try the slave
                // If that doesn't have the latest revision, try the master
                $continue = 2;
@@ -1078,7 +1073,6 @@ class WikiPage implements Page, IDBAccessObject {
                        );
 
                        if ( !$res ) {
-                               wfProfileOut( __METHOD__ );
                                return array();
                        }
 
@@ -1098,7 +1092,6 @@ class WikiPage implements Page, IDBAccessObject {
                        $authors[] = $row->rev_user_text;
                }
 
-               wfProfileOut( __METHOD__ );
                return $authors;
        }
 
@@ -1131,7 +1124,6 @@ class WikiPage implements Page, IDBAccessObject {
         * @return ParserOutput|bool ParserOutput or false if the revision was not found
         */
        public function getParserOutput( ParserOptions $parserOptions, $oldid = null ) {
-               wfProfileIn( __METHOD__ );
 
                $useParserCache = $this->isParserCacheUsed( $parserOptions, $oldid );
                wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
@@ -1142,7 +1134,6 @@ class WikiPage implements Page, IDBAccessObject {
                if ( $useParserCache ) {
                        $parserOutput = ParserCache::singleton()->get( $this, $parserOptions );
                        if ( $parserOutput !== false ) {
-                               wfProfileOut( __METHOD__ );
                                return $parserOutput;
                        }
                }
@@ -1154,7 +1145,6 @@ class WikiPage implements Page, IDBAccessObject {
                $pool = new PoolWorkArticleView( $this, $parserOptions, $oldid, $useParserCache );
                $pool->execute();
 
-               wfProfileOut( __METHOD__ );
 
                return $pool->getParserOutput();
        }
@@ -1180,7 +1170,7 @@ class WikiPage implements Page, IDBAccessObject {
        public function doPurge() {
                global $wgUseSquid;
 
-               if ( !wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
+               if ( !Hooks::run( 'ArticlePurge', array( &$this ) ) ) {
                        return false;
                }
 
@@ -1230,7 +1220,6 @@ class WikiPage implements Page, IDBAccessObject {
         * @return int The newly created page_id key, or false if the title already existed
         */
        public function insertOn( $dbw ) {
-               wfProfileIn( __METHOD__ );
 
                $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
                $dbw->insert( 'page', array(
@@ -1253,7 +1242,6 @@ class WikiPage implements Page, IDBAccessObject {
                        $this->mId = $newid;
                        $this->mTitle->resetArticleID( $newid );
                }
-               wfProfileOut( __METHOD__ );
 
                return $affected ? $newid : false;
        }
@@ -1276,7 +1264,6 @@ class WikiPage implements Page, IDBAccessObject {
        ) {
                global $wgContentHandlerUseDB;
 
-               wfProfileIn( __METHOD__ );
 
                $content = $revision->getContent();
                $len = $content ? $content->getSize() : 0;
@@ -1319,7 +1306,6 @@ class WikiPage implements Page, IDBAccessObject {
                                                                                                        $this->mLatest, $revision->getContentModel() );
                }
 
-               wfProfileOut( __METHOD__ );
                return $result;
        }
 
@@ -1344,7 +1330,6 @@ class WikiPage implements Page, IDBAccessObject {
                        return true;
                }
 
-               wfProfileIn( __METHOD__ );
                if ( $isRedirect ) {
                        $this->insertRedirectEntry( $redirectTitle );
                } else {
@@ -1356,7 +1341,6 @@ class WikiPage implements Page, IDBAccessObject {
                if ( $this->getTitle()->getNamespace() == NS_FILE ) {
                        RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
                }
-               wfProfileOut( __METHOD__ );
 
                return ( $dbw->affectedRows() != 0 );
        }
@@ -1372,7 +1356,6 @@ class WikiPage implements Page, IDBAccessObject {
         * @return bool
         */
        public function updateIfNewerOn( $dbw, $revision ) {
-               wfProfileIn( __METHOD__ );
 
                $row = $dbw->selectRow(
                        array( 'revision', 'page' ),
@@ -1384,7 +1367,6 @@ class WikiPage implements Page, IDBAccessObject {
 
                if ( $row ) {
                        if ( wfTimestamp( TS_MW, $row->rev_timestamp ) >= $revision->getTimestamp() ) {
-                               wfProfileOut( __METHOD__ );
                                return false;
                        }
                        $prev = $row->rev_id;
@@ -1397,7 +1379,6 @@ class WikiPage implements Page, IDBAccessObject {
 
                $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -1516,7 +1497,6 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public function replaceSectionContent( $sectionId, Content $sectionContent, $sectionTitle = '',
                $edittime = null ) {
-               wfProfileIn( __METHOD__ );
 
                $baseRevId = null;
                if ( $edittime && $sectionId !== 'new' ) {
@@ -1527,7 +1507,6 @@ class WikiPage implements Page, IDBAccessObject {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $this->replaceSectionAtRev( $sectionId, $sectionContent, $sectionTitle, $baseRevId );
        }
 
@@ -1547,14 +1526,12 @@ class WikiPage implements Page, IDBAccessObject {
        public function replaceSectionAtRev( $sectionId, Content $sectionContent,
                $sectionTitle = '', $baseRevId = null
        ) {
-               wfProfileIn( __METHOD__ );
 
                if ( strval( $sectionId ) === '' ) {
                        // Whole-page edit; let the whole text through
                        $newContent = $sectionContent;
                } else {
                        if ( !$this->supportsSections() ) {
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( "sections not supported for content model " .
                                        $this->getContentHandler()->getModelID() );
                        }
@@ -1570,7 +1547,6 @@ class WikiPage implements Page, IDBAccessObject {
                                if ( !$rev ) {
                                        wfDebug( __METHOD__ . " asked for bogus section (page: " .
                                                $this->getId() . "; section: $sectionId)\n" );
-                                       wfProfileOut( __METHOD__ );
                                        return null;
                                }
 
@@ -1579,14 +1555,12 @@ class WikiPage implements Page, IDBAccessObject {
 
                        if ( !$oldContent ) {
                                wfDebug( __METHOD__ . ": no page text\n" );
-                               wfProfileOut( __METHOD__ );
                                return null;
                        }
 
                        $newContent = $oldContent->replaceSection( $sectionId, $sectionContent, $sectionTitle );
                }
 
-               wfProfileOut( __METHOD__ );
                return $newContent;
        }
 
@@ -1698,7 +1672,7 @@ class WikiPage implements Page, IDBAccessObject {
         *
         * @param bool|int $baseRevId The revision ID this edit was based off, if any
         * @param User $user The user doing the edit
-        * @param string $serialisation_format Format for storing the content in the
+        * @param string $serialFormat Format for storing the content in the
         *   database.
         *
         * @throws MWException
@@ -1719,7 +1693,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @since 1.21
         */
        public function doEditContent( Content $content, $summary, $flags = 0, $baseRevId = false,
-               User $user = null, $serialisation_format = null
+               User $user = null, $serialFormat = null
        ) {
                global $wgUser, $wgUseAutomaticEditSummaries, $wgUseRCPatrol, $wgUseNPPatrol;
 
@@ -1728,10 +1702,8 @@ class WikiPage implements Page, IDBAccessObject {
                        throw new MWException( 'Something is trying to edit an article with an empty title' );
                }
 
-               wfProfileIn( __METHOD__ );
 
                if ( !$content->getContentHandler()->canBeUsedOn( $this->getTitle() ) ) {
-                       wfProfileOut( __METHOD__ );
                        return Status::newFatal( 'content-not-allowed-here',
                                ContentHandler::getLocalizedName( $content->getModel() ),
                                $this->getTitle()->getPrefixedText() );
@@ -1751,7 +1723,7 @@ class WikiPage implements Page, IDBAccessObject {
                $hook_args = array( &$this, &$user, &$content, &$summary,
                                                        $flags & EDIT_MINOR, null, null, &$flags, &$status );
 
-               if ( !wfRunHooks( 'PageContentSave', $hook_args )
+               if ( !Hooks::run( 'PageContentSave', $hook_args )
                        || !ContentHandler::runLegacyHooks( 'ArticleSave', $hook_args ) ) {
 
                        wfDebug( __METHOD__ . ": ArticleSave or ArticleSaveContent hook aborted save!\n" );
@@ -1760,7 +1732,6 @@ class WikiPage implements Page, IDBAccessObject {
                                $status->fatal( 'edit-hook-aborted' );
                        }
 
-                       wfProfileOut( __METHOD__ );
                        return $status;
                }
 
@@ -1785,7 +1756,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $summary = $handler->getAutosummary( $old_content, $content, $flags );
                }
 
-               $editInfo = $this->prepareContentForEdit( $content, null, $user, $serialisation_format );
+               $editInfo = $this->prepareContentForEdit( $content, null, $user, $serialFormat );
                $serialized = $editInfo->pst;
 
                /**
@@ -1807,11 +1778,9 @@ class WikiPage implements Page, IDBAccessObject {
                                wfDebug( __METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n" );
                                $status->fatal( 'edit-gone-missing' );
 
-                               wfProfileOut( __METHOD__ );
                                return $status;
                        } elseif ( !$old_content ) {
                                // Sanity check for bug 37225
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( "Could not find text for current revision {$oldid}." );
                        }
 
@@ -1827,17 +1796,12 @@ class WikiPage implements Page, IDBAccessObject {
                                'user_text'  => $user->getName(),
                                'timestamp'  => $now,
                                'content_model' => $content->getModel(),
-                               'content_format' => $serialisation_format,
+                               'content_format' => $serialFormat,
                        ) ); // XXX: pass content object?!
 
                        $changed = !$content->equals( $old_content );
 
                        if ( $changed ) {
-                               if ( !$content->isValid() ) {
-                                       wfProfileOut( __METHOD__ );
-                                       throw new MWException( "New content failed validity check!" );
-                               }
-
                                $dbw->begin( __METHOD__ );
                                try {
 
@@ -1847,7 +1811,6 @@ class WikiPage implements Page, IDBAccessObject {
                                        if ( !$status->isOK() ) {
                                                $dbw->rollback( __METHOD__ );
 
-                                               wfProfileOut( __METHOD__ );
                                                return $status;
                                        }
                                        $revisionId = $revision->insertOn( $dbw );
@@ -1863,11 +1826,10 @@ class WikiPage implements Page, IDBAccessObject {
 
                                                $dbw->rollback( __METHOD__ );
 
-                                               wfProfileOut( __METHOD__ );
                                                return $status;
                                        }
 
-                                       wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
+                                       Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
                                        // Update recentchanges
                                        if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                                // Mark as patrolled if the user can do so
@@ -1928,7 +1890,6 @@ class WikiPage implements Page, IDBAccessObject {
                                if ( !$status->isOK() ) {
                                        $dbw->rollback( __METHOD__ );
 
-                                       wfProfileOut( __METHOD__ );
                                        return $status;
                                }
 
@@ -1942,7 +1903,6 @@ class WikiPage implements Page, IDBAccessObject {
                                        $dbw->rollback( __METHOD__ );
                                        $status->fatal( 'edit-already-exists' );
 
-                                       wfProfileOut( __METHOD__ );
                                        return $status;
                                }
 
@@ -1958,7 +1918,7 @@ class WikiPage implements Page, IDBAccessObject {
                                        'user_text'  => $user->getName(),
                                        'timestamp'  => $now,
                                        'content_model' => $content->getModel(),
-                                       'content_format' => $serialisation_format,
+                                       'content_format' => $serialFormat,
                                ) );
                                $revisionId = $revision->insertOn( $dbw );
 
@@ -1972,7 +1932,7 @@ class WikiPage implements Page, IDBAccessObject {
                                // Update the page record with revision data
                                $this->updateRevisionOn( $dbw, $revision, 0 );
 
-                               wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+                               Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
 
                                // Update recentchanges
                                if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
@@ -2003,7 +1963,7 @@ class WikiPage implements Page, IDBAccessObject {
                                                                $flags & EDIT_MINOR, null, null, &$flags, $revision );
 
                        ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $hook_args );
-                       wfRunHooks( 'PageContentInsertComplete', $hook_args );
+                       Hooks::run( 'PageContentInsertComplete', $hook_args );
                }
 
                // Do updates right now unless deferral was requested
@@ -2018,14 +1978,13 @@ class WikiPage implements Page, IDBAccessObject {
                                                        $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId );
 
                ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
-               wfRunHooks( 'PageContentSaveComplete', $hook_args );
+               Hooks::run( 'PageContentSaveComplete', $hook_args );
 
                // Promote user to any groups they meet the criteria for
                $dbw->onTransactionIdle( function () use ( $user ) {
                        $user->addAutopromoteOnceGroups( 'onEdit' );
                } );
 
-               wfProfileOut( __METHOD__ );
                return $status;
        }
 
@@ -2057,7 +2016,7 @@ class WikiPage implements Page, IDBAccessObject {
 
        /**
         * Prepare text which is about to be saved.
-        * Returns a stdclass with source, pst and output members
+        * Returns a stdClass with source, pst and output members
         *
         * @deprecated since 1.21: use prepareContentForEdit instead.
         * @return object
@@ -2070,54 +2029,76 @@ class WikiPage implements Page, IDBAccessObject {
 
        /**
         * Prepare content which is about to be saved.
-        * Returns a stdclass with source, pst and output members
+        * Returns a stdClass with source, pst and output members
         *
         * @param Content $content
         * @param int|null $revid
         * @param User|null $user
-        * @param string|null $serialization_format
+        * @param string|null $serialFormat
+        * @param bool $useCache Check shared prepared edit cache
         *
-        * @return bool|object
+        * @return object
         *
         * @since 1.21
         */
-       public function prepareContentForEdit( Content $content, $revid = null, User $user = null,
-               $serialization_format = null
+       public function prepareContentForEdit(
+               Content $content, $revid = null, User $user = null, $serialFormat = null, $useCache = true
        ) {
                global $wgContLang, $wgUser;
+
                $user = is_null( $user ) ? $wgUser : $user;
                //XXX: check $user->getId() here???
 
-               // Use a sane default for $serialization_format, see bug 57026
-               if ( $serialization_format === null ) {
-                       $serialization_format = $content->getContentHandler()->getDefaultFormat();
+               // Use a sane default for $serialFormat, see bug 57026
+               if ( $serialFormat === null ) {
+                       $serialFormat = $content->getContentHandler()->getDefaultFormat();
                }
 
                if ( $this->mPreparedEdit
                        && $this->mPreparedEdit->newContent
                        && $this->mPreparedEdit->newContent->equals( $content )
                        && $this->mPreparedEdit->revid == $revid
-                       && $this->mPreparedEdit->format == $serialization_format
+                       && $this->mPreparedEdit->format == $serialFormat
                        // XXX: also check $user here?
                ) {
                        // Already prepared
                        return $this->mPreparedEdit;
                }
 
+               // The edit may have already been prepared via api.php?action=stashedit
+               $cachedEdit = $useCache
+                       ? ApiStashEdit::checkCache( $this->getTitle(), $content, $user )
+                       : false;
+
                $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
-               wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
+               Hooks::run( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
 
                $edit = (object)array();
+               if ( $cachedEdit ) {
+                       $edit->timestamp = $cachedEdit->timestamp;
+               } else {
+                       $edit->timestamp = wfTimestampNow();
+               }
+               // @note: $cachedEdit is not used if the rev ID was referenced in the text
                $edit->revid = $revid;
-               $edit->timestamp = wfTimestampNow();
 
-               $edit->pstContent = $content ? $content->preSaveTransform( $this->mTitle, $user, $popts ) : null;
+               if ( $cachedEdit ) {
+                       $edit->pstContent = $cachedEdit->pstContent;
+               } else {
+                       $edit->pstContent = $content
+                               ? $content->preSaveTransform( $this->mTitle, $user, $popts )
+                               : null;
+               }
 
-               $edit->format = $serialization_format;
+               $edit->format = $serialFormat;
                $edit->popts = $this->makeParserOptions( 'canonical' );
-               $edit->output = $edit->pstContent
-                       ? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts )
-                       : null;
+               if ( $cachedEdit ) {
+                       $edit->output = $cachedEdit->output;
+               } else {
+                       $edit->output = $edit->pstContent
+                               ? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts )
+                               : null;
+               }
 
                $edit->newContent = $content;
                $edit->oldContent = $this->getContent( Revision::RAW );
@@ -2125,7 +2106,7 @@ class WikiPage implements Page, IDBAccessObject {
                // NOTE: B/C for hooks! don't use these fields!
                $edit->newText = $edit->newContent ? ContentHandler::getContentText( $edit->newContent ) : '';
                $edit->oldText = $edit->oldContent ? ContentHandler::getContentText( $edit->oldContent ) : '';
-               $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialization_format ) : '';
+               $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialFormat ) : '';
 
                $this->mPreparedEdit = $edit;
                return $edit;
@@ -2142,6 +2123,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param array $options Array of options, following indexes are used:
         * - changed: boolean, whether the revision changed the content (default true)
         * - created: boolean, whether the revision created the page (default false)
+        * - moved: boolean, whether the page was moved (default false)
         * - oldcountable: boolean or null (default null):
         *   - boolean: whether the page was counted as an article before that
         *     revision, only used in changed is true and created is false
@@ -2150,9 +2132,13 @@ class WikiPage implements Page, IDBAccessObject {
        public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
                global $wgEnableParserCache;
 
-               wfProfileIn( __METHOD__ );
 
-               $options += array( 'changed' => true, 'created' => false, 'oldcountable' => null );
+               $options += array(
+                       'changed' => true,
+                       'created' => false,
+                       'moved' => false,
+                       'oldcountable' => null
+               );
                $content = $revision->getContent();
 
                // Parse the text
@@ -2182,9 +2168,9 @@ class WikiPage implements Page, IDBAccessObject {
                        DataUpdate::runUpdates( $updates );
                }
 
-               wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
+               Hooks::run( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
 
-               if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
+               if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
                        if ( 0 == mt_rand( 0, 99 ) ) {
                                // Flush old entries from the `recentchanges` table; we do this on
                                // random requests so as to avoid an increase in writes for no good reason
@@ -2193,7 +2179,6 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                if ( !$this->exists() ) {
-                       wfProfileOut( __METHOD__ );
                        return;
                }
 
@@ -2201,7 +2186,7 @@ class WikiPage implements Page, IDBAccessObject {
                $title = $this->mTitle->getPrefixedDBkey();
                $shortTitle = $this->mTitle->getDBkey();
 
-               if ( !$options['changed'] ) {
+               if ( !$options['changed'] && !$options['moved'] ) {
                        $good = 0;
                } elseif ( $options['created'] ) {
                        $good = (int)$this->isCountable( $editInfo );
@@ -2229,7 +2214,7 @@ class WikiPage implements Page, IDBAccessObject {
                                wfDebug( __METHOD__ . ": invalid username\n" );
                        } else {
                                // Allow extensions to prevent user notification when a new message is added to their talk page
-                               if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
+                               if ( Hooks::run( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
                                        if ( User::isIP( $shortTitle ) ) {
                                                // An anonymous user
                                                $recipient->setNewtalk( true, $revision );
@@ -2258,7 +2243,6 @@ class WikiPage implements Page, IDBAccessObject {
                        self::onArticleEdit( $this->mTitle );
                }
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -2289,14 +2273,13 @@ class WikiPage implements Page, IDBAccessObject {
         * @param User $user The relevant user
         * @param string $comment Comment submitted
         * @param bool $minor Whereas it's a minor modification
-        * @param string $serialisation_format Format for storing the content in the database
+        * @param string $serialFormat Format for storing the content in the database
         */
        public function doQuickEditContent( Content $content, User $user, $comment = '', $minor = false,
-               $serialisation_format = null
+               $serialFormat = null
        ) {
-               wfProfileIn( __METHOD__ );
 
-               $serialized = $content->serialize( $serialisation_format );
+               $serialized = $content->serialize( $serialFormat );
 
                $dbw = wfGetDB( DB_MASTER );
                $revision = new Revision( array(
@@ -2312,9 +2295,8 @@ class WikiPage implements Page, IDBAccessObject {
                $revision->insertOn( $dbw );
                $this->updateRevisionOn( $dbw, $revision );
 
-               wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+               Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -2411,7 +2393,7 @@ class WikiPage implements Page, IDBAccessObject {
                $logRelationsField = null;
 
                if ( $id ) { // Protection of existing page
-                       if ( !wfRunHooks( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
+                       if ( !Hooks::run( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
                                return Status::newGood();
                        }
 
@@ -2491,8 +2473,8 @@ class WikiPage implements Page, IDBAccessObject {
                                __METHOD__
                        );
 
-                       wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $nullRevision, $latest, $user ) );
-                       wfRunHooks( 'ArticleProtectComplete', array( &$this, &$user, $limit, $reason ) );
+                       Hooks::run( 'NewRevisionFromEditComplete', array( $this, $nullRevision, $latest, $user ) );
+                       Hooks::run( 'ArticleProtectComplete', array( &$this, &$user, $limit, $reason ) );
                } else { // Protection of non-existing page (also known as "title protection")
                        // Cascade protection is meaningless in this case
                        $cascade = false;
@@ -2754,7 +2736,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                $user = is_null( $user ) ? $wgUser : $user;
-               if ( !wfRunHooks( 'ArticleDelete', array( &$this, &$user, &$reason, &$error, &$status ) ) ) {
+               if ( !Hooks::run( 'ArticleDelete', array( &$this, &$user, &$reason, &$error, &$status ) ) ) {
                        if ( $status->isOK() ) {
                                // Hook aborted but didn't set a fatal status
                                $status->fatal( 'delete-hook-aborted' );
@@ -2870,7 +2852,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                $this->doDeleteUpdates( $id, $content );
 
-               wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id, $content, $logEntry ) );
+               Hooks::run( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id, $content, $logEntry ) );
                $status->value = $logid;
                return $status;
        }
@@ -3112,7 +3094,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                $revId = $status->value['revision']->getId();
 
-               wfRunHooks( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
+               Hooks::run( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
 
                $resultDetails = array(
                        'summary' => $summary,
@@ -3135,13 +3117,9 @@ class WikiPage implements Page, IDBAccessObject {
         *
         * @param Title $title
         */
-       public static function onArticleCreate( $title ) {
+       public static function onArticleCreate( Title $title ) {
                // Update existence markers on article/talk tabs...
-               if ( $title->isTalkPage() ) {
-                       $other = $title->getSubjectPage();
-               } else {
-                       $other = $title->getTalkPage();
-               }
+               $other = $title->getOtherPage();
 
                $other->invalidateCache();
                $other->purgeSquid();
@@ -3156,13 +3134,9 @@ class WikiPage implements Page, IDBAccessObject {
         *
         * @param Title $title
         */
-       public static function onArticleDelete( $title ) {
+       public static function onArticleDelete( Title $title ) {
                // Update existence markers on article/talk tabs...
-               if ( $title->isTalkPage() ) {
-                       $other = $title->getSubjectPage();
-               } else {
-                       $other = $title->getTalkPage();
-               }
+               $other = $title->getOtherPage();
 
                $other->invalidateCache();
                $other->purgeSquid();
@@ -3201,10 +3175,8 @@ class WikiPage implements Page, IDBAccessObject {
         * Purge caches on page update etc
         *
         * @param Title $title
-        * @todo Verify that $title is always a Title object (and never false or
-        *   null), add Title hint to parameter $title.
         */
-       public static function onArticleEdit( $title ) {
+       public static function onArticleEdit( Title $title ) {
                // Invalidate caches of articles which include this page
                DeferredUpdates::addHTMLCacheUpdate( $title, 'templatelinks' );
 
@@ -3364,12 +3336,12 @@ class WikiPage implements Page, IDBAccessObject {
 
                                foreach ( $added as $catName ) {
                                        $cat = Category::newFromName( $catName );
-                                       wfRunHooks( 'CategoryAfterPageAdded', array( $cat, $that ) );
+                                       Hooks::run( 'CategoryAfterPageAdded', array( $cat, $that ) );
                                }
 
                                foreach ( $deleted as $catName ) {
                                        $cat = Category::newFromName( $catName );
-                                       wfRunHooks( 'CategoryAfterPageRemoved', array( $cat, $that ) );
+                                       Hooks::run( 'CategoryAfterPageRemoved', array( $cat, $that ) );
                                }
                        }
                );
@@ -3522,7 +3494,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $updates = $content->getDeletionUpdates( $this );
                }
 
-               wfRunHooks( 'WikiPageDeletionUpdates', array( $this, $content, &$updates ) );
+               Hooks::run( 'WikiPageDeletionUpdates', array( $this, $content, &$updates ) );
                return $updates;
        }
 }