r17291 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17290‎ | r17291 | r17292 >
Date:21:25, 29 October 2006
Author:yurik
Status:old
Tags:
Comment:
Updates 'redirect' table on each save. WARNING: Breaking change. You must have the latest DB schema.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -997,25 +997,31 @@
998998 * when different from the currently set value.
999999 * Giving 0 indicates the new page flag should
10001000 * be set on.
 1001+ * @param bool $lastRevIsRedirect If given, will optimize adding and
 1002+ * removing rows in redirect table.
10011003 * @return bool true on success, false on failure
10021004 * @private
10031005 */
1004 - function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
 1006+ function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) {
10051007 wfProfileIn( __METHOD__ );
10061008
 1009+ $text = $revision->getText();
 1010+ $rt = Title::newFromRedirect( $text );
 1011+
 1012+ $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
 1013+
10071014 $conditions = array( 'page_id' => $this->getId() );
10081015 if( !is_null( $lastRevision ) ) {
10091016 # An extra check against threads stepping on each other
10101017 $conditions['page_latest'] = $lastRevision;
10111018 }
10121019
1013 - $text = $revision->getText();
10141020 $dbw->update( 'page',
10151021 array( /* SET */
10161022 'page_latest' => $revision->getId(),
10171023 'page_touched' => $dbw->timestamp(),
10181024 'page_is_new' => ($lastRevision === 0) ? 1 : 0,
1019 - 'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0,
 1025+ 'page_is_redirect' => $rt !== NULL ? 1 : 0,
10201026 'page_len' => strlen( $text ),
10211027 ),
10221028 $conditions,
@@ -1026,6 +1032,56 @@
10271033 }
10281034
10291035 /**
 1036+ * Add row to the redirect table if this is a redirect, remove otherwise.
 1037+ *
 1038+ * @param Database $dbw
 1039+ * @param $redirectTitle a title object pointing to the redirect target,
 1040+ * or NULL if this is not a redirect
 1041+ * @param bool $lastRevIsRedirect If given, will optimize adding and
 1042+ * removing rows in redirect table.
 1043+ * @return bool true on success, false on failure
 1044+ * @private
 1045+ */
 1046+ function updateRedirectOn( &$dbw, $redirectTitle, $lastRevIsRedirect = null ) {
 1047+
 1048+ // Always update redirects (target link might have changed)
 1049+ // Update/Insert if we don't know if the last revision was a redirect or not
 1050+ // Delete if changing from redirect to non-redirect
 1051+ $isRedirect = !is_null($redirectTitle);
 1052+ if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) {
 1053+
 1054+ wfProfileIn( __METHOD__ );
 1055+
 1056+ $where = array('rd_from' => $this->getId());
 1057+
 1058+ if ($isRedirect) {
 1059+
 1060+ // This title is a redirect, Add/Update row in the redirect table
 1061+ $set = array( /* SET */
 1062+ 'rd_namespace' => $redirectTitle->getNamespace(),
 1063+ 'rd_title' => $redirectTitle->getDBkey()
 1064+ );
 1065+
 1066+ $dbw->update( 'redirect', $set, $where, __METHOD__ );
 1067+
 1068+ if ( $dbw->affectedRows() == 0 ) {
 1069+ // Update failed, need to insert the row instead
 1070+ $dbw->insert( 'redirect', array_merge($set, $where), __METHOD__ );
 1071+ }
 1072+ } else {
 1073+
 1074+ // This is not a redirect, remove row from redirect table
 1075+ $dbw->delete( 'redirect', $where, __METHOD__);
 1076+ }
 1077+
 1078+ wfProfileOut( __METHOD__ );
 1079+ return ( $dbw->affectedRows() != 0 );
 1080+ }
 1081+
 1082+ return true;
 1083+ }
 1084+
 1085+ /**
10301086 * If the given revision is newer than the currently set page_latest,
10311087 * update the page record. Otherwise, do nothing.
10321088 *
@@ -1037,7 +1093,7 @@
10381094
10391095 $row = $dbw->selectRow(
10401096 array( 'revision', 'page' ),
1041 - array( 'rev_id', 'rev_timestamp' ),
 1097+ array( 'rev_id', 'rev_timestamp', 'page_is_redirect' ),
10421098 array(
10431099 'page_id' => $this->getId(),
10441100 'page_latest=rev_id' ),
@@ -1048,12 +1104,14 @@
10491105 return false;
10501106 }
10511107 $prev = $row->rev_id;
 1108+ $lastRevIsRedirect = $row->page_is_redirect === '1';
10521109 } else {
10531110 # No or missing previous revision; mark the page as new
10541111 $prev = 0;
 1112+ $lastRevIsRedirect = null;
10551113 }
10561114
1057 - $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
 1115+ $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
10581116 wfProfileOut( __METHOD__ );
10591117 return $ret;
10601118 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r17292Updated info on bug 7304 (redirect table). This relates to checkin r17291.yurik21:40, 29 October 2006