示例#1
0
 /**
  * Occurs when a page  has been moved. If there is a problem, it's too late to cancel it.
  * <ul>
  * <li>old page renamed</li>
  * <li>new page created, with old name, containing a redirect to the new one</li>
  * </ul>
  * @param Title $old_name_title old title
  * @param Title $new_name_title
  * @param User $user user who did the move
  * @param int $renamed_page_id database ID of the page that's been moved
  * @param int $redirect_page_id database ID of the created redirect
  * @return boolean true to continue hook processing or false to abort
  */
 public static function onTitleMoveComplete(&$old_name_title, &$new_name_title, &$user, $renamed_page_id, $redirect_page_id)
 {
     $old_in_wp = WpPage::isInWikiplace($old_name_title->getNamespace(), $old_name_title->getDBkey());
     $new_in_wp = WpPage::isInWikiplace($new_name_title->getNamespace(), $new_name_title->getDBkey());
     if (!$old_in_wp && !$new_in_wp) {
         return true;
     }
     $old_pdb_key = $old_name_title->getPrefixedDBkey();
     $new_pdb_key = $new_name_title->getPrefixedDBkey();
     wfDebugLog('wikiplaces-debug', "moved {$old_pdb_key}({$renamed_page_id}) to {$new_pdb_key} " . ($redirect_page_id != 0 ? "with a redirect ({$redirect_page_id})" : "without redirect"));
     if (!$old_in_wp) {
         // from  something not in wp
         if (WpPage::isHomepage($new_name_title)) {
             // from  something not in wp  to  a homepage
             $dest_wp = self::doCreateWikiplace($user->getId(), $renamed_page_id);
             if ($dest_wp == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR cannot create wikiplace '{$new_pdb_key}'");
                 // throw new MWException('Cannot create wikiplace.');
                 return true;
             }
             $new_wp_page = WpPage::create($renamed_page_id, $dest_wp->getId());
             if ($new_wp_page == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot create wikiplace homepage '{$new_pdb_key}'");
                 // throw new MWException('Cannot create wikiplace homepage.');
             }
         } else {
             // from  something not in wp  to  a subpage
             $dest_wp = WpWikiplace::getBySubpage($new_name_title->getDBkey(), $new_name_title->getNamespace());
             if ($dest_wp == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot find container wikiplace for '{$new_pdb_key}'");
                 // throw new MWException('Cannot find container wikiplace.');
                 return true;
             }
             $new_wp_page = WpPage::create($renamed_page_id, $dest_wp->getId());
             if ($new_wp_page == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot create wikiplace homepage '{$new_pdb_key}'");
                 // throw new MWException('Cannot create wikiplace homepage.');
             }
         }
     } elseif (WpPage::isHomepage($old_name_title)) {
         // from  a homepage
         // currently, this case is forbidden and cannot occur because items become orphan... but, now, it's too late :(
         wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot move homepage '{$old_pdb_key}'");
         // throw new MWException('Cannot move wikiplace homepage.');
         if (!$new_in_wp) {
             // from  a homepage  to  something not in wp
         } elseif (WpPage::isHomepage($new_name_title)) {
             // from  a homepage  to  a homepage
         } else {
             // from  a homepage  to  a subpage
         }
     } else {
         // from  a subpage
         if (!$new_in_wp) {
             // from  a subpage  to  something not in wp
             // currently, this case is forbidden and should not occur, but actually it can be moved
             wfDebugLog('wikiplaces', "onTitleMoveComplete() WARNING moving a subpage out of wikiplace space '{$new_pdb_key}'");
             if ($redirect_page_id != 0) {
                 $renamed_wp_page = WpPage::newFromArticleId($renamed_page_id);
                 if ($renamed_wp_page == null) {
                     wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot find subpage to move ({$renamed_page_id})");
                     // throw new MWException('Cannot find subpage to move.');
                     return true;
                 }
                 $renamed_wp_page->setPageId($redirect_page_id);
             } else {
                 if (!WpPage::delete($renamed_page_id)) {
                     wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: while deleting the Wikiplace page ({$renamed_page_id})");
                     // throw new MWException('Error while deleting the Wikiplace page.');
                 }
             }
         } elseif (WpPage::isHomepage($new_name_title)) {
             // from  a subpage  to  a homepage
             $dest_wp = self::doCreateWikiplace($user->getId(), $renamed_page_id);
             if ($dest_wp == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot create wikiplace '{$new_pdb_key}'");
                 // throw new MWException('Cannot create wikiplace.');
                 return true;
             }
             $renamed_wp_page = WpPage::newFromArticleId($renamed_page_id);
             if ($renamed_wp_page == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot find subpage to move ({$renamed_page_id})");
                 // throw new MWException('Cannot find subpage to move.');
                 return true;
             }
             if ($redirect_page_id != 0) {
                 $old_wp_id = $renamed_wp_page->getWikiplaceId();
                 if (WpPage::create($redirect_page_id, $old_wp_id) == null) {
                     wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot create redirect subpage ({$renamed_page_id})");
                     // throw new MWException('Cannot create redirect subpage.');
                     return true;
                 }
             }
             $dest_wp_id = $dest_wp->getId();
             $renamed_wp_page->setWikiplaceId($dest_wp_id);
         } else {
             // from  a subpage  to  a subpage
             $dest_wp = WpWikiplace::getBySubpage($new_name_title->getDBkey(), $new_name_title->getNamespace());
             if ($dest_wp == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot find destination wikiplace '{$new_pdb_key}'");
                 // throw new MWException('Cannot find destination wikiplace.');
                 return true;
             }
             $renamed_wp_page = WpPage::newFromArticleId($renamed_page_id);
             if ($renamed_wp_page == null) {
                 wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot find subpage to move '{$renamed_page_id}'");
                 // throw new MWException('Cannot find subpage to move.');
                 return true;
             }
             $old_wp_id = $renamed_wp_page->getWikiplaceId();
             if ($redirect_page_id != 0) {
                 if (WpPage::create($redirect_page_id, $old_wp_id) == null) {
                     wfDebugLog('wikiplaces', "onTitleMoveComplete() ERROR: cannot create redirect subpage ({$renamed_page_id})");
                     // throw new MWException('Cannot create redirect subpage.');
                     return true;
                 }
             }
             $dest_wp_id = $dest_wp->getId();
             if ($old_wp_id != $dest_wp_id) {
                 $renamed_wp_page->setWikiplaceId($dest_wp_id);
             }
         }
     }
     return true;
 }