Index: trunk/phase3/includes/Article.php |
— | — | @@ -95,13 +95,16 @@ |
96 | 96 | # Query the redirect table |
97 | 97 | $dbr = wfGetDB( DB_SLAVE ); |
98 | 98 | $row = $dbr->selectRow( 'redirect', |
99 | | - array( 'rd_namespace', 'rd_title' ), |
| 99 | + array( 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ), |
100 | 100 | array( 'rd_from' => $this->getID() ), |
101 | 101 | __METHOD__ |
102 | 102 | ); |
103 | 103 | |
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 ); |
106 | 109 | } |
107 | 110 | |
108 | 111 | # This page doesn't have an entry in the redirect table |
— | — | @@ -112,36 +115,44 @@ |
113 | 116 | * Insert an entry for this page into the redirect table. |
114 | 117 | * |
115 | 118 | * 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 |
117 | 120 | */ |
118 | 121 | 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() ); |
121 | 124 | if ( !$retval ) { |
122 | 125 | return null; |
123 | 126 | } |
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 ) { |
125 | 137 | $dbw = wfGetDB( DB_MASTER ); |
126 | 138 | $dbw->replace( 'redirect', array( 'rd_from' ), |
127 | 139 | array( |
128 | 140 | '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(), |
131 | 145 | ), |
132 | 146 | __METHOD__ |
133 | 147 | ); |
134 | | - |
135 | | - return $retval; |
136 | 148 | } |
137 | 149 | |
138 | 150 | /** |
139 | | - * Get the Title object this page redirects to |
| 151 | + * Get the Title object or URL this page redirects to |
140 | 152 | * |
141 | 153 | * @return mixed false, Title of in-wiki target, or string with URL |
142 | 154 | */ |
143 | 155 | public function followRedirect() { |
144 | | - $text = $this->getContent(); |
145 | | - return $this->followRedirectText( $text ); |
| 156 | + return $this->getRedirectURL( $this->getRedirectTarget() ); |
146 | 157 | } |
147 | 158 | |
148 | 159 | /** |
— | — | @@ -149,11 +160,21 @@ |
150 | 161 | * |
151 | 162 | * @param $text string article content containing redirect info |
152 | 163 | * @return mixed false, Title of in-wiki target, or string with URL |
| 164 | + * @deprecated |
153 | 165 | */ |
154 | 166 | public function followRedirectText( $text ) { |
155 | 167 | // 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 ) { |
158 | 179 | if ( $rt ) { |
159 | 180 | if ( $rt->getInterwiki() != '' ) { |
160 | 181 | if ( $rt->isLocal() ) { |
— | — | @@ -1768,7 +1789,7 @@ |
1769 | 1790 | wfProfileIn( __METHOD__ ); |
1770 | 1791 | |
1771 | 1792 | $text = $revision->getText(); |
1772 | | - $rt = Title::newFromRedirect( $text ); |
| 1793 | + $rt = Title::newFromRedirectRecurse( $text ); |
1773 | 1794 | |
1774 | 1795 | $conditions = array( 'page_id' => $this->getId() ); |
1775 | 1796 | |
— | — | @@ -1821,13 +1842,7 @@ |
1822 | 1843 | if ( $isRedirect || is_null( $lastRevIsRedirect ) || $lastRevIsRedirect !== $isRedirect ) { |
1823 | 1844 | wfProfileIn( __METHOD__ ); |
1824 | 1845 | 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 ); |
1832 | 1847 | } else { |
1833 | 1848 | // This is not a redirect, remove row from redirect table |
1834 | 1849 | $where = array( 'rd_from' => $this->getId() ); |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -255,11 +255,12 @@ |
256 | 256 | * @param $ns \type{\int} the namespace of the article |
257 | 257 | * @param $title \type{\string} the unprefixed database key form |
258 | 258 | * @param $fragment \type{\string} The link fragment (after the "#") |
| 259 | + * @param $interwiki \type{\string} The interwiki prefix |
259 | 260 | * @return \type{Title} the new object |
260 | 261 | */ |
261 | | - public static function &makeTitle( $ns, $title, $fragment = '' ) { |
| 262 | + public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) { |
262 | 263 | $t = new Title(); |
263 | | - $t->mInterwiki = ''; |
| 264 | + $t->mInterwiki = $interwiki; |
264 | 265 | $t->mFragment = $fragment; |
265 | 266 | $t->mNamespace = $ns = intval( $ns ); |
266 | 267 | $t->mDbkeyform = str_replace( ' ', '_', $title ); |
— | — | @@ -277,11 +278,12 @@ |
278 | 279 | * @param $ns \type{\int} the namespace of the article |
279 | 280 | * @param $title \type{\string} the database key form |
280 | 281 | * @param $fragment \type{\string} The link fragment (after the "#") |
| 282 | + * @param $interwiki \type{\string} The interwiki prefix |
281 | 283 | * @return \type{Title} the new object, or NULL on an error |
282 | 284 | */ |
283 | | - public static function makeTitleSafe( $ns, $title, $fragment = '' ) { |
| 285 | + public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) { |
284 | 286 | $t = new Title(); |
285 | | - $t->mDbkeyform = Title::makeName( $ns, $title, $fragment ); |
| 287 | + $t->mDbkeyform = Title::makeName( $ns, $title, $fragment, $interwiki ); |
286 | 288 | if ( $t->secureAndSplit() ) { |
287 | 289 | return $t; |
288 | 290 | } else { |
— | — | @@ -473,13 +475,17 @@ |
474 | 476 | * @param $ns \type{\int} numerical representation of the namespace |
475 | 477 | * @param $title \type{\string} the DB key form the title |
476 | 478 | * @param $fragment \type{\string} The link fragment (after the "#") |
| 479 | + * @param $interwiki \type{\string} The interwiki prefix |
477 | 480 | * @return \type{\string} the prefixed form of the title |
478 | 481 | */ |
479 | | - public static function makeName( $ns, $title, $fragment = '' ) { |
| 482 | + public static function makeName( $ns, $title, $fragment = '', $interwiki = '' ) { |
480 | 483 | global $wgContLang; |
481 | 484 | |
482 | 485 | $namespace = $wgContLang->getNsText( $ns ); |
483 | 486 | $name = $namespace == '' ? $title : "$namespace:$title"; |
| 487 | + if ( strval( $interwiki ) != '' ) { |
| 488 | + $name = "$interwiki:$name"; |
| 489 | + } |
484 | 490 | if ( strval( $fragment ) != '' ) { |
485 | 491 | $name .= '#' . $fragment; |
486 | 492 | } |