r69181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69180‎ | r69181 | r69182 >
Date:10:49, 8 July 2010
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Followup to r51583: actually use the rd_interwiki and rd_fragment fields, in the spirit of r33133: we now use the redirect table as a cache for redirect targets, no longer pulling the page text from ES for every logged-in redirect view. Old-style redirect table entries with NULL for fragment and interwiki are automatically updated when the redirect is visited or edited.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -95,13 +95,16 @@
9696 # Query the redirect table
9797 $dbr = wfGetDB( DB_SLAVE );
9898 $row = $dbr->selectRow( 'redirect',
99 - array( 'rd_namespace', 'rd_title' ),
 99+ array( 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ),
100100 array( 'rd_from' => $this->getID() ),
101101 __METHOD__
102102 );
103103
104 - if ( $row ) {
105 - return $this->mRedirectTarget = Title::makeTitle( $row->rd_namespace, $row->rd_title );
 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 );
106109 }
107110
108111 # This page doesn't have an entry in the redirect table
@@ -112,36 +115,44 @@
113116 * Insert an entry for this page into the redirect table.
114117 *
115118 * Don't call this function directly unless you know what you're doing.
116 - * @return Title object
 119+ * @return Title object or null if not a redirect
117120 */
118121 public function insertRedirect() {
119 - $retval = Title::newFromRedirect( $this->getContent() );
120 -
 122+ // recurse through to only get the final target
 123+ $retval = Title::newFromRedirectRecurse( $this->getContent() );
121124 if ( !$retval ) {
122125 return null;
123126 }
124 -
 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 ) {
125137 $dbw = wfGetDB( DB_MASTER );
126138 $dbw->replace( 'redirect', array( 'rd_from' ),
127139 array(
128140 'rd_from' => $this->getID(),
129 - 'rd_namespace' => $retval->getNamespace(),
130 - 'rd_title' => $retval->getDBkey()
 141+ 'rd_namespace' => $rt->getNamespace(),
 142+ 'rd_title' => $rt->getDBkey(),
 143+ 'rd_fragment' => $rt->getFragment(),
 144+ 'rd_interwiki' => $rt->getInterwiki(),
131145 ),
132146 __METHOD__
133147 );
134 -
135 - return $retval;
136148 }
137149
138150 /**
139 - * Get the Title object this page redirects to
 151+ * Get the Title object or URL this page redirects to
140152 *
141153 * @return mixed false, Title of in-wiki target, or string with URL
142154 */
143155 public function followRedirect() {
144 - $text = $this->getContent();
145 - return $this->followRedirectText( $text );
 156+ return $this->getRedirectURL( $this->getRedirectTarget() );
146157 }
147158
148159 /**
@@ -149,11 +160,21 @@
150161 *
151162 * @param $text string article content containing redirect info
152163 * @return mixed false, Title of in-wiki target, or string with URL
 164+ * @deprecated
153165 */
154166 public function followRedirectText( $text ) {
155167 // recurse through to only get the final target
156 - $rt = Title::newFromRedirectRecurse( $text );
157 -
 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 ) {
158179 if ( $rt ) {
159180 if ( $rt->getInterwiki() != '' ) {
160181 if ( $rt->isLocal() ) {
@@ -1768,7 +1789,7 @@
17691790 wfProfileIn( __METHOD__ );
17701791
17711792 $text = $revision->getText();
1772 - $rt = Title::newFromRedirect( $text );
 1793+ $rt = Title::newFromRedirectRecurse( $text );
17731794
17741795 $conditions = array( 'page_id' => $this->getId() );
17751796
@@ -1821,13 +1842,7 @@
18221843 if ( $isRedirect || is_null( $lastRevIsRedirect ) || $lastRevIsRedirect !== $isRedirect ) {
18231844 wfProfileIn( __METHOD__ );
18241845 if ( $isRedirect ) {
1825 - // This title is a redirect, Add/Update row in the redirect table
1826 - $set = array( /* SET */
1827 - 'rd_namespace' => $redirectTitle->getNamespace(),
1828 - 'rd_title' => $redirectTitle->getDBkey(),
1829 - 'rd_from' => $this->getId(),
1830 - );
1831 - $dbw->replace( 'redirect', array( 'rd_from' ), $set, __METHOD__ );
 1846+ $this->insertRedirectEntry( $redirectTitle );
18321847 } else {
18331848 // This is not a redirect, remove row from redirect table
18341849 $where = array( 'rd_from' => $this->getId() );
Index: trunk/phase3/includes/Title.php
@@ -255,11 +255,12 @@
256256 * @param $ns \type{\int} the namespace of the article
257257 * @param $title \type{\string} the unprefixed database key form
258258 * @param $fragment \type{\string} The link fragment (after the "#")
 259+ * @param $interwiki \type{\string} The interwiki prefix
259260 * @return \type{Title} the new object
260261 */
261 - public static function &makeTitle( $ns, $title, $fragment = '' ) {
 262+ public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
262263 $t = new Title();
263 - $t->mInterwiki = '';
 264+ $t->mInterwiki = $interwiki;
264265 $t->mFragment = $fragment;
265266 $t->mNamespace = $ns = intval( $ns );
266267 $t->mDbkeyform = str_replace( ' ', '_', $title );
@@ -277,11 +278,12 @@
278279 * @param $ns \type{\int} the namespace of the article
279280 * @param $title \type{\string} the database key form
280281 * @param $fragment \type{\string} The link fragment (after the "#")
 282+ * @param $interwiki \type{\string} The interwiki prefix
281283 * @return \type{Title} the new object, or NULL on an error
282284 */
283 - public static function makeTitleSafe( $ns, $title, $fragment = '' ) {
 285+ public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
284286 $t = new Title();
285 - $t->mDbkeyform = Title::makeName( $ns, $title, $fragment );
 287+ $t->mDbkeyform = Title::makeName( $ns, $title, $fragment, $interwiki );
286288 if ( $t->secureAndSplit() ) {
287289 return $t;
288290 } else {
@@ -473,13 +475,17 @@
474476 * @param $ns \type{\int} numerical representation of the namespace
475477 * @param $title \type{\string} the DB key form the title
476478 * @param $fragment \type{\string} The link fragment (after the "#")
 479+ * @param $interwiki \type{\string} The interwiki prefix
477480 * @return \type{\string} the prefixed form of the title
478481 */
479 - public static function makeName( $ns, $title, $fragment = '' ) {
 482+ public static function makeName( $ns, $title, $fragment = '', $interwiki = '' ) {
480483 global $wgContLang;
481484
482485 $namespace = $wgContLang->getNsText( $ns );
483486 $name = $namespace == '' ? $title : "$namespace:$title";
 487+ if ( strval( $interwiki ) != '' ) {
 488+ $name = "$interwiki:$name";
 489+ }
484490 if ( strval( $fragment ) != '' ) {
485491 $name .= '#' . $fragment;
486492 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r81710Revert r69181 since the rd_fragment patch isn't applied. Tested locally.tstarling10:42, 8 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r33133Committing patch for bug 10931, which also fixes bug 13651. For a detailed ex...catrope15:20, 11 April 2008
r51583SCHEMA CHANGE: adding rd_interwiki patch from bug 14418. Actual use of this s...catrope07:11, 8 June 2009

Comments

#Comment by 😂 (talk | contribs)   11:07, 8 July 2010

Oooh, an old one. Long overdue :)

#Comment by Siebrand (talk | contribs)   14:14, 23 January 2012

Suspect for bugzilla:33520: $wgMaxRedirects totally broke at some point

Status & tagging log