r81710 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81709‎ | r81710 | r81711 >
Date:10:42, 8 February 2011
Author:tstarling
Status:ok
Tags:
Comment:
Revert r69181 since the rd_fragment patch isn't applied. Tested locally.
Modified paths:
  • /branches/wmf/1.17wmf1/includes/Article.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/Title.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/Article.php
@@ -95,16 +95,13 @@
9696 # Query the redirect table
9797 $dbr = wfGetDB( DB_SLAVE );
9898 $row = $dbr->selectRow( 'redirect',
99 - array( 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ),
 99+ array( 'rd_namespace', 'rd_title' ),
100100 array( 'rd_from' => $this->getID() ),
101101 __METHOD__
102102 );
103103
104 - // rd_fragment and rd_interwiki were added later, populate them if empty
105 - if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) {
106 - return $this->mRedirectTarget = Title::makeTitle(
107 - $row->rd_namespace, $row->rd_title,
108 - $row->rd_fragment, $row->rd_interwiki );
 104+ if ( $row ) {
 105+ return $this->mRedirectTarget = Title::makeTitle( $row->rd_namespace, $row->rd_title );
109106 }
110107
111108 # This page doesn't have an entry in the redirect table
@@ -115,44 +112,36 @@
116113 * Insert an entry for this page into the redirect table.
117114 *
118115 * Don't call this function directly unless you know what you're doing.
119 - * @return Title object or null if not a redirect
 116+ * @return Title object
120117 */
121118 public function insertRedirect() {
122 - // recurse through to only get the final target
123 - $retval = Title::newFromRedirectRecurse( $this->getContent() );
 119+ $retval = Title::newFromRedirect( $this->getContent() );
 120+
124121 if ( !$retval ) {
125122 return null;
126123 }
127 - $this->insertRedirectEntry( $retval );
128 - return $retval;
129 - }
130 -
131 - /**
132 - * Insert or update the redirect table entry for this page to indicate
133 - * it redirects to $rt .
134 - * @param $rt Title redirect target
135 - */
136 - public function insertRedirectEntry( $rt ) {
 124+
137125 $dbw = wfGetDB( DB_MASTER );
138126 $dbw->replace( 'redirect', array( 'rd_from' ),
139127 array(
140128 'rd_from' => $this->getID(),
141 - 'rd_namespace' => $rt->getNamespace(),
142 - 'rd_title' => $rt->getDBkey(),
143 - 'rd_fragment' => $rt->getFragment(),
144 - 'rd_interwiki' => $rt->getInterwiki(),
 129+ 'rd_namespace' => $retval->getNamespace(),
 130+ 'rd_title' => $retval->getDBkey()
145131 ),
146132 __METHOD__
147133 );
 134+
 135+ return $retval;
148136 }
149137
150138 /**
151 - * Get the Title object or URL this page redirects to
 139+ * Get the Title object this page redirects to
152140 *
153141 * @return mixed false, Title of in-wiki target, or string with URL
154142 */
155143 public function followRedirect() {
156 - return $this->getRedirectURL( $this->getRedirectTarget() );
 144+ $text = $this->getContent();
 145+ return $this->followRedirectText( $text );
157146 }
158147
159148 /**
@@ -160,21 +149,11 @@
161150 *
162151 * @param $text string article content containing redirect info
163152 * @return mixed false, Title of in-wiki target, or string with URL
164 - * @deprecated
165153 */
166154 public function followRedirectText( $text ) {
167155 // recurse through to only get the final target
168 - return $this->getRedirectURL( Title::newFromRedirectRecurse( $text ) );
169 - }
170 -
171 - /**
172 - * Get the Title object or URL to use for a redirect. We use Title
173 - * objects for same-wiki, non-special redirects and URLs for everything
174 - * else.
175 - * @param $rt Title Redirect target
176 - * @return mixed false, Title object of local target, or string with URL
177 - */
178 - public function getRedirectURL( $rt ) {
 156+ $rt = Title::newFromRedirectRecurse( $text );
 157+
179158 if ( $rt ) {
180159 if ( $rt->getInterwiki() != '' ) {
181160 if ( $rt->isLocal() ) {
@@ -1780,7 +1759,7 @@
17811760 wfProfileIn( __METHOD__ );
17821761
17831762 $text = $revision->getText();
1784 - $rt = Title::newFromRedirectRecurse( $text );
 1763+ $rt = Title::newFromRedirect( $text );
17851764
17861765 $conditions = array( 'page_id' => $this->getId() );
17871766
@@ -1829,7 +1808,13 @@
18301809 if ( $isRedirect || is_null( $lastRevIsRedirect ) || $lastRevIsRedirect !== $isRedirect ) {
18311810 wfProfileIn( __METHOD__ );
18321811 if ( $isRedirect ) {
1833 - $this->insertRedirectEntry( $redirectTitle );
 1812+ // This title is a redirect, Add/Update row in the redirect table
 1813+ $set = array( /* SET */
 1814+ 'rd_namespace' => $redirectTitle->getNamespace(),
 1815+ 'rd_title' => $redirectTitle->getDBkey(),
 1816+ 'rd_from' => $this->getId(),
 1817+ );
 1818+ $dbw->replace( 'redirect', array( 'rd_from' ), $set, __METHOD__ );
18341819 } else {
18351820 // This is not a redirect, remove row from redirect table
18361821 $where = array( 'rd_from' => $this->getId() );
Index: branches/wmf/1.17wmf1/includes/Title.php
@@ -273,12 +273,11 @@
274274 * @param $ns \type{\int} the namespace of the article
275275 * @param $title \type{\string} the unprefixed database key form
276276 * @param $fragment \type{\string} The link fragment (after the "#")
277 - * @param $interwiki \type{\string} The interwiki prefix
278277 * @return \type{Title} the new object
279278 */
280 - public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
 279+ public static function &makeTitle( $ns, $title, $fragment = '' ) {
281280 $t = new Title();
282 - $t->mInterwiki = $interwiki;
 281+ $t->mInterwiki = '';
283282 $t->mFragment = $fragment;
284283 $t->mNamespace = $ns = intval( $ns );
285284 $t->mDbkeyform = str_replace( ' ', '_', $title );
@@ -296,12 +295,11 @@
297296 * @param $ns \type{\int} the namespace of the article
298297 * @param $title \type{\string} the database key form
299298 * @param $fragment \type{\string} The link fragment (after the "#")
300 - * @param $interwiki \type{\string} The interwiki prefix
301299 * @return \type{Title} the new object, or NULL on an error
302300 */
303 - public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
 301+ public static function makeTitleSafe( $ns, $title, $fragment = '' ) {
304302 $t = new Title();
305 - $t->mDbkeyform = Title::makeName( $ns, $title, $fragment, $interwiki );
 303+ $t->mDbkeyform = Title::makeName( $ns, $title, $fragment );
306304 if ( $t->secureAndSplit() ) {
307305 return $t;
308306 } else {
@@ -499,17 +497,13 @@
500498 * @param $ns \type{\int} numerical representation of the namespace
501499 * @param $title \type{\string} the DB key form the title
502500 * @param $fragment \type{\string} The link fragment (after the "#")
503 - * @param $interwiki \type{\string} The interwiki prefix
504501 * @return \type{\string} the prefixed form of the title
505502 */
506 - public static function makeName( $ns, $title, $fragment = '', $interwiki = '' ) {
 503+ public static function makeName( $ns, $title, $fragment = '' ) {
507504 global $wgContLang;
508505
509506 $namespace = $wgContLang->getNsText( $ns );
510507 $name = $namespace == '' ? $title : "$namespace:$title";
511 - if ( strval( $interwiki ) != '' ) {
512 - $name = "$interwiki:$name";
513 - }
514508 if ( strval( $fragment ) != '' ) {
515509 $name .= '#' . $fragment;
516510 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r69181Followup to r51583: actually use the rd_interwiki and rd_fragment fields, in ...catrope10:49, 8 July 2010

Status & tagging log