Add TitleExists hook
[lhc/web/wiklou.git] / includes / Title.php
index 2bb56ca..8ffea35 100644 (file)
@@ -2265,7 +2265,7 @@ class Title {
                } elseif ( $action == 'delete' ) {
                        $tempErrors = $this->checkPageRestrictions( 'edit',
                                $user, array(), $doExpensiveQueries, true );
-                       if( !$tempErrors ) {
+                       if ( !$tempErrors ) {
                                $tempErrors = $this->checkCascadingSourcesRestrictions( 'edit',
                                        $user, $tempErrors, $doExpensiveQueries, true );
                        }
@@ -3323,8 +3323,8 @@ class Title {
                        // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
                        //        the parsing code with Title, while avoiding massive refactoring.
                        // @todo: get rid of secureAndSplit, refactor parsing code.
-                       $parser = self::getTitleParser();
-                       $parts = $parser->splitTitleString( $dbkey, $this->getDefaultNamespace() );
+                       $titleParser = self::getTitleParser();
+                       $parts = $titleParser->splitTitleString( $dbkey, $this->getDefaultNamespace() );
                } catch ( MalformedTitleException $ex ) {
                        return false;
                }
@@ -3748,7 +3748,7 @@ class Title {
         * @return array|bool True on success, getUserPermissionsErrors()-like array on failure
         */
        public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
-               global $wgUser;
+               global $wgUser, $wgCategoryCollation;
                $err = $this->isValidMoveOperation( $nt, $auth, $reason );
                if ( is_array( $err ) ) {
                        // Auto-block user's IP if the account was "hard" blocked
@@ -3787,12 +3787,21 @@ class Title {
 
                // Refresh the sortkey for this row.  Be careful to avoid resetting
                // cl_timestamp, which may disturb time-based lists on some sites.
+               // @todo This block should be killed, it's duplicating code
+               // from LinksUpdate::getCategoryInsertions() and friends.
                $prefixes = $dbw->select(
                        'categorylinks',
                        array( 'cl_sortkey_prefix', 'cl_to' ),
                        array( 'cl_from' => $pageid ),
                        __METHOD__
                );
+               if ( $nt->getNamespace() == NS_CATEGORY ) {
+                       $type = 'subcat';
+               } elseif ( $nt->getNamespace() == NS_FILE ) {
+                       $type = 'file';
+               } else {
+                       $type = 'page';
+               }
                foreach ( $prefixes as $prefixRow ) {
                        $prefix = $prefixRow->cl_sortkey_prefix;
                        $catTo = $prefixRow->cl_to;
@@ -3800,6 +3809,8 @@ class Title {
                                array(
                                        'cl_sortkey' => Collation::singleton()->getSortKey(
                                                $nt->getCategorySortkey( $prefix ) ),
+                                       'cl_collation' => $wgCategoryCollation,
+                                       'cl_type' => $type,
                                        'cl_timestamp=cl_timestamp' ),
                                array(
                                        'cl_from' => $pageid,
@@ -3931,9 +3942,13 @@ class Title {
                        $redirectContent = null;
                }
 
+               // bug 57084: log_page should be the ID of the *moved* page
+               $oldid = $this->getArticleID();
+               $logTitle = clone $this;
+
                $logEntry = new ManualLogEntry( 'move', $logType );
                $logEntry->setPerformer( $wgUser );
-               $logEntry->setTarget( $this );
+               $logEntry->setTarget( $logTitle );
                $logEntry->setComment( $reason );
                $logEntry->setParameters( array(
                        '4::target' => $nt->getPrefixedText(),
@@ -3949,8 +3964,6 @@ class Title {
                # Truncate for whole multibyte characters.
                $comment = $wgContLang->truncate( $comment, 255 );
 
-               $oldid = $this->getArticleID();
-
                $dbw = wfGetDB( DB_MASTER );
 
                $newpage = WikiPage::factory( $nt );
@@ -4595,7 +4608,9 @@ class Title {
         * @return bool
         */
        public function exists() {
-               return $this->getArticleID() != 0;
+               $exists = $this->getArticleID() != 0;
+               wfRunHooks( 'TitleExists', array( $this, &$exists ) );
+               return $exists;
        }
 
        /**