public function testDuplicateAllAssociatedEntries()
 {
     $user = $this->getUser();
     $titleOld = Title::newFromText('WatchedItemIntegrationTestPageOld');
     $titleNew = Title::newFromText('WatchedItemIntegrationTestPageNew');
     WatchedItem::fromUserTitle($user, $titleOld->getSubjectPage())->addWatch();
     WatchedItem::fromUserTitle($user, $titleOld->getTalkPage())->addWatch();
     // Cleanup after previous tests
     WatchedItem::fromUserTitle($user, $titleNew->getSubjectPage())->removeWatch();
     WatchedItem::fromUserTitle($user, $titleNew->getTalkPage())->removeWatch();
     WatchedItem::duplicateEntries($titleOld, $titleNew);
     $this->assertTrue(WatchedItem::fromUserTitle($user, $titleOld->getSubjectPage())->isWatched());
     $this->assertTrue(WatchedItem::fromUserTitle($user, $titleOld->getTalkPage())->isWatched());
     $this->assertTrue(WatchedItem::fromUserTitle($user, $titleNew->getSubjectPage())->isWatched());
     $this->assertTrue(WatchedItem::fromUserTitle($user, $titleNew->getTalkPage())->isWatched());
 }
예제 #2
0
파일: Title.php 프로젝트: arlendotcn/ilias
 /**
  * Move a title to a new location
  * @param Title &$nt the new title
  * @param bool $auth indicates whether $wgUser's permissions
  * 	should be checked
  * @return mixed true on success, message name on failure
  */
 public function moveTo(&$nt, $auth = true, $reason = '')
 {
     $err = $this->isValidMoveOperation($nt, $auth);
     if (is_string($err)) {
         return $err;
     }
     $pageid = $this->getArticleID();
     if ($nt->exists()) {
         $this->moveOverExistingRedirect($nt, $reason);
         $pageCountChange = 0;
     } else {
         # Target didn't exist, do normal move.
         $this->moveToNewTitle($nt, $reason);
         $pageCountChange = 1;
     }
     $redirid = $this->getArticleID();
     # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
     $dbw = wfGetDB(DB_MASTER);
     $categorylinks = $dbw->tableName('categorylinks');
     $sql = "UPDATE {$categorylinks} SET cl_sortkey=" . $dbw->addQuotes($nt->getPrefixedText()) . " WHERE cl_from=" . $dbw->addQuotes($pageid) . " AND cl_sortkey=" . $dbw->addQuotes($this->getPrefixedText());
     $dbw->query($sql, 'SpecialMovepage::doSubmit');
     # Update watchlists
     $oldnamespace = $this->getNamespace() & ~1;
     $newnamespace = $nt->getNamespace() & ~1;
     $oldtitle = $this->getDBkey();
     $newtitle = $nt->getDBkey();
     if ($oldnamespace != $newnamespace || $oldtitle != $newtitle) {
         WatchedItem::duplicateEntries($this, $nt);
     }
     # Update search engine
     $u = new SearchUpdate($pageid, $nt->getPrefixedDBkey());
     $u->doUpdate();
     $u = new SearchUpdate($redirid, $this->getPrefixedDBkey(), '');
     $u->doUpdate();
     # Update site_stats
     if ($this->isContentPage() && !$nt->isContentPage()) {
         # No longer a content page
         # Not viewed, edited, removing
         $u = new SiteStatsUpdate(0, 1, -1, $pageCountChange);
     } elseif (!$this->isContentPage() && $nt->isContentPage()) {
         # Now a content page
         # Not viewed, edited, adding
         $u = new SiteStatsUpdate(0, 1, +1, $pageCountChange);
     } elseif ($pageCountChange) {
         # Redirect added
         $u = new SiteStatsUpdate(0, 0, 0, 1);
     } else {
         # Nothing special
         $u = false;
     }
     if ($u) {
         $u->doUpdate();
     }
     global $wgUser;
     wfRunHooks('TitleMoveComplete', array(&$this, &$nt, &$wgUser, $pageid, $redirid));
     return true;
 }
예제 #3
0
 /**
  * Move a title to a new location
  *
  * @param $nt Title the new title
  * @param $auth Bool indicates whether $wgUser's permissions
  *  should be checked
  * @param $reason String the reason for the move
  * @param $createRedirect Bool Whether to create a redirect from the old title to the new title.
  *  Ignored if the user doesn't have the suppressredirect right.
  * @return Mixed true on success, getUserPermissionsErrors()-like array on failure
  */
 public function moveTo(&$nt, $auth = true, $reason = '', $createRedirect = true)
 {
     global $wgUser;
     $err = $this->isValidMoveOperation($nt, $auth, $reason);
     if (is_array($err)) {
         // Auto-block user's IP if the account was "hard" blocked
         $wgUser->spreadAnyEditBlock();
         return $err;
     }
     // If it is a file, move it first. It is done before all other moving stuff is
     // done because it's hard to revert
     $dbw = wfGetDB(DB_MASTER);
     if ($this->getNamespace() == NS_FILE) {
         $file = wfLocalFile($this);
         if ($file->exists()) {
             $status = $file->move($nt);
             if (!$status->isOk()) {
                 return $status->getErrorsArray();
             }
         }
     }
     $dbw->begin();
     # If $file was a LocalFile, its transaction would have closed our own.
     $pageid = $this->getArticleID(self::GAID_FOR_UPDATE);
     $protected = $this->isProtected();
     $pageCountChange = ($createRedirect ? 1 : 0) - ($nt->exists() ? 1 : 0);
     // Do the actual move
     $err = $this->moveToInternal($nt, $reason, $createRedirect);
     if (is_array($err)) {
         # @todo FIXME: What about the File we have already moved?
         $dbw->rollback();
         return $err;
     }
     $redirid = $this->getArticleID();
     // Refresh the sortkey for this row.  Be careful to avoid resetting
     // cl_timestamp, which may disturb time-based lists on some sites.
     $prefixes = $dbw->select('categorylinks', array('cl_sortkey_prefix', 'cl_to'), array('cl_from' => $pageid), __METHOD__);
     foreach ($prefixes as $prefixRow) {
         $prefix = $prefixRow->cl_sortkey_prefix;
         $catTo = $prefixRow->cl_to;
         $dbw->update('categorylinks', array('cl_sortkey' => Collation::singleton()->getSortKey($nt->getCategorySortkey($prefix)), 'cl_timestamp=cl_timestamp'), array('cl_from' => $pageid, 'cl_to' => $catTo), __METHOD__);
     }
     if ($protected) {
         # Protect the redirect title as the title used to be...
         $dbw->insertSelect('page_restrictions', 'page_restrictions', array('pr_page' => $redirid, 'pr_type' => 'pr_type', 'pr_level' => 'pr_level', 'pr_cascade' => 'pr_cascade', 'pr_user' => 'pr_user', 'pr_expiry' => 'pr_expiry'), array('pr_page' => $pageid), __METHOD__, array('IGNORE'));
         # Update the protection log
         $log = new LogPage('protect');
         $comment = wfMsgForContent('prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText());
         if ($reason) {
             $comment .= wfMsgForContent('colon-separator') . $reason;
         }
         // @todo FIXME: $params?
         $log->addEntry('move_prot', $nt, $comment, array($this->getPrefixedText()));
     }
     # Update watchlists
     $oldnamespace = $this->getNamespace() & ~1;
     $newnamespace = $nt->getNamespace() & ~1;
     $oldtitle = $this->getDBkey();
     $newtitle = $nt->getDBkey();
     if ($oldnamespace != $newnamespace || $oldtitle != $newtitle) {
         WatchedItem::duplicateEntries($this, $nt);
     }
     # Update search engine
     $u = new SearchUpdate($pageid, $nt->getPrefixedDBkey());
     $u->doUpdate();
     $u = new SearchUpdate($redirid, $this->getPrefixedDBkey(), '');
     $u->doUpdate();
     $dbw->commit();
     # Update site_stats
     if ($this->isContentPage() && !$nt->isContentPage()) {
         # No longer a content page
         # Not viewed, edited, removing
         $u = new SiteStatsUpdate(0, 1, -1, $pageCountChange);
     } elseif (!$this->isContentPage() && $nt->isContentPage()) {
         # Now a content page
         # Not viewed, edited, adding
         $u = new SiteStatsUpdate(0, 1, +1, $pageCountChange);
     } elseif ($pageCountChange) {
         # Redirect added
         $u = new SiteStatsUpdate(0, 0, 0, 1);
     } else {
         # Nothing special
         $u = false;
     }
     if ($u) {
         $u->doUpdate();
     }
     # Update message cache for interface messages
     if ($this->getNamespace() == NS_MEDIAWIKI) {
         # @bug 17860: old article can be deleted, if this the case,
         # delete it from message cache
         if ($this->getArticleID() === 0) {
             MessageCache::singleton()->replace($this->getDBkey(), false);
         } else {
             $oldarticle = new Article($this);
             MessageCache::singleton()->replace($this->getDBkey(), $oldarticle->getContent());
         }
     }
     if ($nt->getNamespace() == NS_MEDIAWIKI) {
         $newarticle = new Article($nt);
         MessageCache::singleton()->replace($nt->getDBkey(), $newarticle->getContent());
     }
     global $wgUser;
     wfRunHooks('TitleMoveComplete', array(&$this, &$nt, &$wgUser, $pageid, $redirid));
     return true;
 }
예제 #4
0
 /**
  * Move a title to a new location
  *
  * @param Title $nt The new title
  * @param bool $auth Indicates whether $wgUser's permissions
  *  should be checked
  * @param string $reason The reason for the move
  * @param bool $createRedirect Whether to create a redirect from the old title to the new title.
  *  Ignored if the user doesn't have the suppressredirect right.
  * @return array|bool True on success, getUserPermissionsErrors()-like array on failure
  */
 public function moveTo(&$nt, $auth = true, $reason = '', $createRedirect = true)
 {
     global $wgUser;
     $err = $this->isValidMoveOperation($nt, $auth, $reason);
     if (is_array($err)) {
         // Auto-block user's IP if the account was "hard" blocked
         $wgUser->spreadAnyEditBlock();
         return $err;
     }
     // Check suppressredirect permission
     if ($auth && !$wgUser->isAllowed('suppressredirect')) {
         $createRedirect = true;
     }
     wfRunHooks('TitleMove', array($this, $nt, $wgUser));
     // If it is a file, move it first.
     // It is done before all other moving stuff is done because it's hard to revert.
     $dbw = wfGetDB(DB_MASTER);
     if ($this->getNamespace() == NS_FILE) {
         $file = wfLocalFile($this);
         if ($file->exists()) {
             $status = $file->move($nt);
             if (!$status->isOk()) {
                 return $status->getErrorsArray();
             }
         }
         // Clear RepoGroup process cache
         RepoGroup::singleton()->clearCache($this);
         RepoGroup::singleton()->clearCache($nt);
         # clear false negative cache
     }
     $dbw->begin(__METHOD__);
     # If $file was a LocalFile, its transaction would have closed our own.
     $pageid = $this->getArticleID(self::GAID_FOR_UPDATE);
     $protected = $this->isProtected();
     // Do the actual move
     $this->moveToInternal($nt, $reason, $createRedirect);
     // Refresh the sortkey for this row.  Be careful to avoid resetting
     // cl_timestamp, which may disturb time-based lists on some sites.
     $prefixes = $dbw->select('categorylinks', array('cl_sortkey_prefix', 'cl_to'), array('cl_from' => $pageid), __METHOD__);
     foreach ($prefixes as $prefixRow) {
         $prefix = $prefixRow->cl_sortkey_prefix;
         $catTo = $prefixRow->cl_to;
         $dbw->update('categorylinks', array('cl_sortkey' => Collation::singleton()->getSortKey($nt->getCategorySortkey($prefix)), 'cl_timestamp=cl_timestamp'), array('cl_from' => $pageid, 'cl_to' => $catTo), __METHOD__);
     }
     $redirid = $this->getArticleID();
     if ($protected) {
         # Protect the redirect title as the title used to be...
         $dbw->insertSelect('page_restrictions', 'page_restrictions', array('pr_page' => $redirid, 'pr_type' => 'pr_type', 'pr_level' => 'pr_level', 'pr_cascade' => 'pr_cascade', 'pr_user' => 'pr_user', 'pr_expiry' => 'pr_expiry'), array('pr_page' => $pageid), __METHOD__, array('IGNORE'));
         # Update the protection log
         $log = new LogPage('protect');
         $comment = wfMessage('prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText())->inContentLanguage()->text();
         if ($reason) {
             $comment .= wfMessage('colon-separator')->inContentLanguage()->text() . $reason;
         }
         // @todo FIXME: $params?
         $logId = $log->addEntry('move_prot', $nt, $comment, array($this->getPrefixedText()), $wgUser);
         // reread inserted pr_ids for log relation
         $insertedPrIds = $dbw->select('page_restrictions', 'pr_id', array('pr_page' => $redirid), __METHOD__);
         $logRelationsValues = array();
         foreach ($insertedPrIds as $prid) {
             $logRelationsValues[] = $prid->pr_id;
         }
         $log->addRelations('pr_id', $logRelationsValues, $logId);
     }
     // Update *_from_namespace fields as needed
     if ($this->getNamespace() != $nt->getNamespace()) {
         $dbw->update('pagelinks', array('pl_from_namespace' => $nt->getNamespace()), array('pl_from' => $pageid), __METHOD__);
         $dbw->update('templatelinks', array('tl_from_namespace' => $nt->getNamespace()), array('tl_from' => $pageid), __METHOD__);
         $dbw->update('imagelinks', array('il_from_namespace' => $nt->getNamespace()), array('il_from' => $pageid), __METHOD__);
     }
     # Update watchlists
     $oldtitle = $this->getDBkey();
     $newtitle = $nt->getDBkey();
     $oldsnamespace = MWNamespace::getSubject($this->getNamespace());
     $newsnamespace = MWNamespace::getSubject($nt->getNamespace());
     if ($oldsnamespace != $newsnamespace || $oldtitle != $newtitle) {
         WatchedItem::duplicateEntries($this, $nt);
     }
     $dbw->commit(__METHOD__);
     wfRunHooks('TitleMoveComplete', array(&$this, &$nt, &$wgUser, $pageid, $redirid, $reason));
     return true;
 }
예제 #5
0
파일: Title.php 프로젝트: ErdemA/wikihow
 /**
  * Move a title to a new location
  * @param Title &$nt the new title
  * @param bool $auth indicates whether $wgUser's permissions
  * 	should be checked
  * @param string $reason The reason for the move
  * @param bool $createRedirect Whether to create a redirect from the old title to the new title.
  *  Ignored if the user doesn't have the suppressredirect right.
  * @return mixed true on success, message name on failure
  */
 public function moveTo(&$nt, $auth = true, $reason = '', $createRedirect = true)
 {
     $err = $this->isValidMoveOperation($nt, $auth);
     if (is_string($err)) {
         return $err;
     }
     $pageid = $this->getArticleID();
     if ($nt->exists()) {
         $this->moveOverExistingRedirect($nt, $reason, $createRedirect);
         $pageCountChange = $createRedirect ? 0 : -1;
     } else {
         # Target didn't exist, do normal move.
         $this->moveToNewTitle($nt, $reason, $createRedirect);
         $pageCountChange = $createRedirect ? 1 : 0;
     }
     $redirid = $this->getArticleID();
     // Category memberships include a sort key which may be customized.
     // If it's left as the default (the page title), we need to update
     // the sort key to match the new title.
     //
     // Be careful to avoid resetting cl_timestamp, which may disturb
     // time-based lists on some sites.
     //
     // Warning -- if the sort key is *explicitly* set to the old title,
     // we can't actually distinguish it from a default here, and it'll
     // be set to the new title even though it really shouldn't.
     // It'll get corrected on the next edit, but resetting cl_timestamp.
     $dbw = wfGetDB(DB_MASTER);
     $dbw->update('categorylinks', array('cl_sortkey' => $nt->getPrefixedText(), 'cl_timestamp=cl_timestamp'), array('cl_from' => $pageid, 'cl_sortkey' => $this->getPrefixedText()), __METHOD__);
     # Update watchlists
     $oldnamespace = $this->getNamespace() & ~1;
     $newnamespace = $nt->getNamespace() & ~1;
     $oldtitle = $this->getDBkey();
     $newtitle = $nt->getDBkey();
     if ($oldnamespace != $newnamespace || $oldtitle != $newtitle) {
         WatchedItem::duplicateEntries($this, $nt);
     }
     # Update search engine
     $u = new SearchUpdate($pageid, $nt->getPrefixedDBkey());
     $u->doUpdate();
     $u = new SearchUpdate($redirid, $this->getPrefixedDBkey(), '');
     $u->doUpdate();
     # Update site_stats
     if ($this->isContentPage() && !$nt->isContentPage()) {
         # No longer a content page
         # Not viewed, edited, removing
         $u = new SiteStatsUpdate(0, 1, -1, $pageCountChange);
     } elseif (!$this->isContentPage() && $nt->isContentPage()) {
         # Now a content page
         # Not viewed, edited, adding
         $u = new SiteStatsUpdate(0, 1, +1, $pageCountChange);
     } elseif ($pageCountChange) {
         # Redirect added
         $u = new SiteStatsUpdate(0, 0, 0, 1);
     } else {
         # Nothing special
         $u = false;
     }
     if ($u) {
         $u->doUpdate();
     }
     # Update message cache for interface messages
     if ($nt->getNamespace() == NS_MEDIAWIKI) {
         global $wgMessageCache;
         $oldarticle = new Article($this);
         $wgMessageCache->replace($this->getDBkey(), $oldarticle->getContent());
         $newarticle = new Article($nt);
         $wgMessageCache->replace($nt->getDBkey(), $newarticle->getContent());
     }
     global $wgUser;
     wfRunHooks('TitleMoveComplete', array(&$this, &$nt, &$wgUser, $pageid, $redirid));
     return true;
 }
예제 #6
0
 /**
  * @param User $user
  * @param string $reason
  * @param bool $createRedirect
  * @return Status
  */
 public function move(User $user, $reason, $createRedirect)
 {
     global $wgCategoryCollation;
     Hooks::run('TitleMove', array($this->oldTitle, $this->newTitle, $user));
     // If it is a file, move it first.
     // It is done before all other moving stuff is done because it's hard to revert.
     $dbw = wfGetDB(DB_MASTER);
     if ($this->oldTitle->getNamespace() == NS_FILE) {
         $file = wfLocalFile($this->oldTitle);
         $file->load(File::READ_LATEST);
         if ($file->exists()) {
             $status = $file->move($this->newTitle);
             if (!$status->isOk()) {
                 return $status;
             }
         }
         // Clear RepoGroup process cache
         RepoGroup::singleton()->clearCache($this->oldTitle);
         RepoGroup::singleton()->clearCache($this->newTitle);
         # clear false negative cache
     }
     $dbw->begin(__METHOD__);
     # If $file was a LocalFile, its transaction would have closed our own.
     $pageid = $this->oldTitle->getArticleID(Title::GAID_FOR_UPDATE);
     $protected = $this->oldTitle->isProtected();
     // Do the actual move
     $this->moveToInternal($user, $this->newTitle, $reason, $createRedirect);
     // 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 ($this->newTitle->getNamespace() == NS_CATEGORY) {
         $type = 'subcat';
     } elseif ($this->newTitle->getNamespace() == NS_FILE) {
         $type = 'file';
     } else {
         $type = 'page';
     }
     foreach ($prefixes as $prefixRow) {
         $prefix = $prefixRow->cl_sortkey_prefix;
         $catTo = $prefixRow->cl_to;
         $dbw->update('categorylinks', array('cl_sortkey' => Collation::singleton()->getSortKey($this->newTitle->getCategorySortkey($prefix)), 'cl_collation' => $wgCategoryCollation, 'cl_type' => $type, 'cl_timestamp=cl_timestamp'), array('cl_from' => $pageid, 'cl_to' => $catTo), __METHOD__);
     }
     $redirid = $this->oldTitle->getArticleID();
     if ($protected) {
         # Protect the redirect title as the title used to be...
         $dbw->insertSelect('page_restrictions', 'page_restrictions', array('pr_page' => $redirid, 'pr_type' => 'pr_type', 'pr_level' => 'pr_level', 'pr_cascade' => 'pr_cascade', 'pr_user' => 'pr_user', 'pr_expiry' => 'pr_expiry'), array('pr_page' => $pageid), __METHOD__, array('IGNORE'));
         // Build comment for log
         $comment = wfMessage('prot_1movedto2', $this->oldTitle->getPrefixedText(), $this->newTitle->getPrefixedText())->inContentLanguage()->text();
         if ($reason) {
             $comment .= wfMessage('colon-separator')->inContentLanguage()->text() . $reason;
         }
         // reread inserted pr_ids for log relation
         $insertedPrIds = $dbw->select('page_restrictions', 'pr_id', array('pr_page' => $redirid), __METHOD__);
         $logRelationsValues = array();
         foreach ($insertedPrIds as $prid) {
             $logRelationsValues[] = $prid->pr_id;
         }
         // Update the protection log
         $logEntry = new ManualLogEntry('protect', 'move_prot');
         $logEntry->setTarget($this->newTitle);
         $logEntry->setComment($comment);
         $logEntry->setPerformer($user);
         $logEntry->setParameters(array('4::oldtitle' => $this->oldTitle->getPrefixedText()));
         $logEntry->setRelations(array('pr_id' => $logRelationsValues));
         $logId = $logEntry->insert();
         $logEntry->publish($logId);
     }
     // Update *_from_namespace fields as needed
     if ($this->oldTitle->getNamespace() != $this->newTitle->getNamespace()) {
         $dbw->update('pagelinks', array('pl_from_namespace' => $this->newTitle->getNamespace()), array('pl_from' => $pageid), __METHOD__);
         $dbw->update('templatelinks', array('tl_from_namespace' => $this->newTitle->getNamespace()), array('tl_from' => $pageid), __METHOD__);
         $dbw->update('imagelinks', array('il_from_namespace' => $this->newTitle->getNamespace()), array('il_from' => $pageid), __METHOD__);
     }
     # Update watchlists
     $oldtitle = $this->oldTitle->getDBkey();
     $newtitle = $this->newTitle->getDBkey();
     $oldsnamespace = MWNamespace::getSubject($this->oldTitle->getNamespace());
     $newsnamespace = MWNamespace::getSubject($this->newTitle->getNamespace());
     if ($oldsnamespace != $newsnamespace || $oldtitle != $newtitle) {
         WatchedItem::duplicateEntries($this->oldTitle, $this->newTitle);
     }
     $dbw->commit(__METHOD__);
     Hooks::run('TitleMoveComplete', array(&$this->oldTitle, &$this->newTitle, &$user, $pageid, $redirid, $reason));
     return Status::newGood();
 }
예제 #7
0
<?php

require_once "commandLine.inc";
require_once "{$IP}/extensions/structuredNamespaces/StructuredData.php";
require_once "{$IP}/extensions/familytree/FamilyTreePropagator.php";
require_once "{$IP}/includes/Title.php";
$db =& wfGetDB(DB_MASTER);
$rows = $db->query("select page_namespace, page_title from page where page_is_redirect > 0 and (page_namespace = 108 or page_namespace = 110)");
while ($row = $db->fetchObject($rows)) {
    $title = Title::makeTitle($row->page_namespace, $row->page_title);
    $newTitle = StructuredData::getRedirectToTitle($title);
    if ($title->getPrefixedText() != $newTitle->getPrefixedText()) {
        //		print "title=" . $title->getPrefixedText() . " newTitle=" . $newTitle->getPrefixedText() . "\n";
        // from wrArticleSave
        WatchedItem::duplicateEntries($title, $newTitle);
    }
}
$db->freeResult($rows);
예제 #8
0
 /**
  * Move a title to a new location
  * @param &$nt \type{Title} the new title
  * @param $auth \type{\bool} indicates whether $wgUser's permissions
  *  should be checked
  * @param $reason \type{\string} The reason for the move
  * @param $createRedirect \type{\bool} Whether to create a redirect from the old title to the new title.
  *  Ignored if the user doesn't have the suppressredirect right.
  * @return \type{\mixed} true on success, getUserPermissionsErrors()-like array on failure
  */
 public function moveTo(&$nt, $auth = true, $reason = '', $createRedirect = true)
 {
     $err = $this->isValidMoveOperation($nt, $auth, $reason);
     if (is_array($err)) {
         return $err;
     }
     // If it is a file, move it first. It is done before all other moving stuff is done because it's hard to revert
     $dbw = wfGetDB(DB_MASTER);
     if ($this->getNamespace() == NS_FILE) {
         $file = wfLocalFile($this);
         if ($file->exists()) {
             $status = $file->move($nt);
             if (!$status->isOk()) {
                 return $status->getErrorsArray();
             }
         }
     }
     $pageid = $this->getArticleID();
     $protected = $this->isProtected();
     if ($nt->exists()) {
         $err = $this->moveOverExistingRedirect($nt, $reason, $createRedirect);
         $pageCountChange = $createRedirect ? 0 : -1;
     } else {
         # Target didn't exist, do normal move.
         $err = $this->moveToNewTitle($nt, $reason, $createRedirect);
         $pageCountChange = $createRedirect ? 1 : 0;
     }
     if (is_array($err)) {
         return $err;
     }
     $redirid = $this->getArticleID();
     // Category memberships include a sort key which may be customized.
     // If it's left as the default (the page title), we need to update
     // the sort key to match the new title.
     //
     // Be careful to avoid resetting cl_timestamp, which may disturb
     // time-based lists on some sites.
     //
     // Warning -- if the sort key is *explicitly* set to the old title,
     // we can't actually distinguish it from a default here, and it'll
     // be set to the new title even though it really shouldn't.
     // It'll get corrected on the next edit, but resetting cl_timestamp.
     $dbw->update('categorylinks', array('cl_sortkey' => $nt->getPrefixedText(), 'cl_timestamp=cl_timestamp'), array('cl_from' => $pageid, 'cl_sortkey' => $this->getPrefixedText()), __METHOD__);
     if ($protected) {
         # Protect the redirect title as the title used to be...
         $dbw->insertSelect('page_restrictions', 'page_restrictions', array('pr_page' => $redirid, 'pr_type' => 'pr_type', 'pr_level' => 'pr_level', 'pr_cascade' => 'pr_cascade', 'pr_user' => 'pr_user', 'pr_expiry' => 'pr_expiry'), array('pr_page' => $pageid), __METHOD__, array('IGNORE'));
         # Update the protection log
         $log = new LogPage('protect');
         $comment = wfMsgForContent('prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText());
         if ($reason) {
             $comment .= wfMsgForContent('colon-separator') . $reason;
         }
         $log->addEntry('move_prot', $nt, $comment, array($this->getPrefixedText()));
         // FIXME: $params?
     }
     # Update watchlists
     $oldnamespace = $this->getNamespace() & ~1;
     $newnamespace = $nt->getNamespace() & ~1;
     $oldtitle = $this->getDBkey();
     $newtitle = $nt->getDBkey();
     if ($oldnamespace != $newnamespace || $oldtitle != $newtitle) {
         WatchedItem::duplicateEntries($this, $nt);
     }
     # Update search engine
     $u = new SearchUpdate($pageid, $nt->getPrefixedDBkey());
     $u->doUpdate();
     $u = new SearchUpdate($redirid, $this->getPrefixedDBkey(), '');
     $u->doUpdate();
     # Update site_stats
     if ($this->isContentPage() && !$nt->isContentPage()) {
         # No longer a content page
         # Not viewed, edited, removing
         $u = new SiteStatsUpdate(0, 1, -1, $pageCountChange);
     } elseif (!$this->isContentPage() && $nt->isContentPage()) {
         # Now a content page
         # Not viewed, edited, adding
         $u = new SiteStatsUpdate(0, 1, +1, $pageCountChange);
     } elseif ($pageCountChange) {
         # Redirect added
         $u = new SiteStatsUpdate(0, 0, 0, 1);
     } else {
         # Nothing special
         $u = false;
     }
     if ($u) {
         $u->doUpdate();
     }
     # Update message cache for interface messages
     if ($nt->getNamespace() == NS_MEDIAWIKI) {
         global $wgMessageCache;
         # @bug 17860: old article can be deleted, if this the case,
         # delete it from message cache
         if ($this->getArticleID() === 0) {
             $wgMessageCache->replace($this->getDBkey(), false);
         } else {
             $oldarticle = new Article($this);
             $wgMessageCache->replace($this->getDBkey(), $oldarticle->getContent());
         }
         $newarticle = new Article($nt);
         $wgMessageCache->replace($nt->getDBkey(), $newarticle->getContent());
     }
     global $wgUser;
     wfRunHooks('TitleMoveComplete', array(&$this, &$nt, &$wgUser, $pageid, $redirid));
     return true;
 }
예제 #9
0
파일: Hooks.php 프로젝트: k-hasan-19/wiki
function wrArticleSave(&$article, &$user, $text)
{
    $newTitle = Title::newFromRedirect($text);
    // can't use $article->content or SD:getRedirectToTitle because they return the wrong results
    if ($newTitle != null) {
        // if this article is a redirect
        $newTitle = StructuredData::getRedirectToTitle($newTitle, true);
        // get final redirect; unreliable on the article title for some reason
        $newRevision = StructuredData::getRevision($newTitle, false, true);
        $newText = $newRevision ? $newRevision->getText() : '';
        $summary = StructuredData::getWatchlistSummary($newTitle, $newText);
        WatchedItem::duplicateEntries($article->getTitle(), $newTitle, $summary);
        StructuredData::purgeTitle($newTitle, +1);
        StructuredData::requestIndex($newTitle);
        // remove watchers from redirected titles
        StructuredData::removeAllWatchers($article->getTitle());
    }
    return true;
}
예제 #10
0
 public function testDuplicateEntries()
 {
     $oldTitle = Title::newFromText('OldTitle');
     $newTitle = Title::newFromText('NewTitle');
     $store = $this->getMockWatchedItemStore();
     $store->expects($this->once())->method('duplicateAllAssociatedEntries')->with($oldTitle, $newTitle);
     $this->setService('WatchedItemStore', $store);
     WatchedItem::duplicateEntries($oldTitle, $newTitle);
 }