Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -2507,7 +2507,7 @@ |
2508 | 2508 | } |
2509 | 2509 | return $templates; |
2510 | 2510 | } else { |
2511 | | - return $this->mArticle->getUsedTemplates(); |
| 2511 | + return $this->mTitle->getTemplateLinksFrom(); |
2512 | 2512 | } |
2513 | 2513 | } |
2514 | 2514 | |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -2256,8 +2256,7 @@ |
2257 | 2257 | $this->addHTML( Html::element( 'textarea', $params, $source ) ); |
2258 | 2258 | |
2259 | 2259 | // Show templates used by this article |
2260 | | - $page = WikiPage::factory( $this->getTitle() ); |
2261 | | - $templates = Linker::formatTemplates( $page->getUsedTemplates() ); |
| 2260 | + $templates = Linker::formatTemplates( $this->getTitle()->getTemplateLinksFrom() ); |
2262 | 2261 | $this->addHTML( "<div class='templatesUsed'> |
2263 | 2262 | $templates |
2264 | 2263 | </div> |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -3126,8 +3126,6 @@ |
3127 | 3127 | * @return Array of Title objects linking here |
3128 | 3128 | */ |
3129 | 3129 | public function getLinksTo( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) { |
3130 | | - $linkCache = LinkCache::singleton(); |
3131 | | - |
3132 | 3130 | if ( count( $options ) > 0 ) { |
3133 | 3131 | $db = wfGetDB( DB_MASTER ); |
3134 | 3132 | } else { |
— | — | @@ -3146,7 +3144,8 @@ |
3147 | 3145 | ); |
3148 | 3146 | |
3149 | 3147 | $retVal = array(); |
3150 | | - if ( $db->numRows( $res ) ) { |
| 3148 | + if ( $res->numRows() ) { |
| 3149 | + $linkCache = LinkCache::singleton(); |
3151 | 3150 | foreach ( $res as $row ) { |
3152 | 3151 | $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ); |
3153 | 3152 | if ( $titleObj ) { |
— | — | @@ -3173,6 +3172,76 @@ |
3174 | 3173 | } |
3175 | 3174 | |
3176 | 3175 | /** |
| 3176 | + * Get an array of Title objects linked from this Title |
| 3177 | + * Also stores the IDs in the link cache. |
| 3178 | + * |
| 3179 | + * WARNING: do not use this function on arbitrary user-supplied titles! |
| 3180 | + * On heavily-used templates it will max out the memory. |
| 3181 | + * |
| 3182 | + * @param $options Array: may be FOR UPDATE |
| 3183 | + * @param $table String: table name |
| 3184 | + * @param $prefix String: fields prefix |
| 3185 | + * @return Array of Title objects linking here |
| 3186 | + */ |
| 3187 | + public function getLinksFrom( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) { |
| 3188 | + $id = $this->getArticleId(); |
| 3189 | + |
| 3190 | + # If the page doesn't exist; there can't be any link from this page |
| 3191 | + if ( !$id ) { |
| 3192 | + return array(); |
| 3193 | + } |
| 3194 | + |
| 3195 | + if ( count( $options ) > 0 ) { |
| 3196 | + $db = wfGetDB( DB_MASTER ); |
| 3197 | + } else { |
| 3198 | + $db = wfGetDB( DB_SLAVE ); |
| 3199 | + } |
| 3200 | + |
| 3201 | + $namespaceFiled = "{$prefix}_namespace"; |
| 3202 | + $titleField = "{$prefix}_title"; |
| 3203 | + |
| 3204 | + $res = $db->select( |
| 3205 | + array( $table, 'page' ), |
| 3206 | + array( $namespaceFiled, $titleField, 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ), |
| 3207 | + array( "{$prefix}_from" => $id ), |
| 3208 | + __METHOD__, |
| 3209 | + $options, |
| 3210 | + array( 'page' => array( 'LEFT JOIN', array( "page_namespace=$namespaceFiled", "page_title=$titleField" ) ) ) |
| 3211 | + ); |
| 3212 | + |
| 3213 | + $retVal = array(); |
| 3214 | + if ( $res->numRows() ) { |
| 3215 | + $linkCache = LinkCache::singleton(); |
| 3216 | + foreach ( $res as $row ) { |
| 3217 | + $titleObj = Title::makeTitle( $row->$namespaceFiled, $row->$titleField ); |
| 3218 | + if ( $titleObj ) { |
| 3219 | + if ( $row->page_id ) { |
| 3220 | + $linkCache->addGoodLinkObjFromRow( $titleObj, $row ); |
| 3221 | + } else { |
| 3222 | + $linkCache->addBadLinkObj( $titleObj ); |
| 3223 | + } |
| 3224 | + $retVal[] = $titleObj; |
| 3225 | + } |
| 3226 | + } |
| 3227 | + } |
| 3228 | + return $retVal; |
| 3229 | + } |
| 3230 | + |
| 3231 | + /** |
| 3232 | + * Get an array of Title objects used on this Title as a template |
| 3233 | + * Also stores the IDs in the link cache. |
| 3234 | + * |
| 3235 | + * WARNING: do not use this function on arbitrary user-supplied titles! |
| 3236 | + * On heavily-used templates it will max out the memory. |
| 3237 | + * |
| 3238 | + * @param $options Array: may be FOR UPDATE |
| 3239 | + * @return Array of Title the Title objects used here |
| 3240 | + */ |
| 3241 | + public function getTemplateLinksFrom( $options = array() ) { |
| 3242 | + return $this->getLinksFrom( $options, 'templatelinks', 'tl' ); |
| 3243 | + } |
| 3244 | + |
| 3245 | + /** |
3177 | 3246 | * Get an array of Title objects referring to non-existent articles linked from this page |
3178 | 3247 | * |
3179 | 3248 | * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case) |
Index: trunk/phase3/includes/WikiPage.php |
— | — | @@ -2306,35 +2306,6 @@ |
2307 | 2307 | /**#@-*/ |
2308 | 2308 | |
2309 | 2309 | /** |
2310 | | - * Return a list of templates used by this article. |
2311 | | - * Uses the templatelinks table |
2312 | | - * |
2313 | | - * @return Array of Title objects |
2314 | | - */ |
2315 | | - public function getUsedTemplates() { |
2316 | | - $result = array(); |
2317 | | - $id = $this->mTitle->getArticleID(); |
2318 | | - |
2319 | | - if ( $id == 0 ) { |
2320 | | - return array(); |
2321 | | - } |
2322 | | - |
2323 | | - $dbr = wfGetDB( DB_SLAVE ); |
2324 | | - $res = $dbr->select( array( 'templatelinks' ), |
2325 | | - array( 'tl_namespace', 'tl_title' ), |
2326 | | - array( 'tl_from' => $id ), |
2327 | | - __METHOD__ ); |
2328 | | - |
2329 | | - if ( $res !== false ) { |
2330 | | - foreach ( $res as $row ) { |
2331 | | - $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title ); |
2332 | | - } |
2333 | | - } |
2334 | | - |
2335 | | - return $result; |
2336 | | - } |
2337 | | - |
2338 | | - /** |
2339 | 2310 | * Returns a list of hidden categories this page is a member of. |
2340 | 2311 | * Uses the page_props and categorylinks tables. |
2341 | 2312 | * |
— | — | @@ -2628,6 +2599,17 @@ |
2629 | 2600 | } |
2630 | 2601 | |
2631 | 2602 | /** |
| 2603 | + * Return a list of templates used by this article. |
| 2604 | + * Uses the templatelinks table |
| 2605 | + * |
| 2606 | + * @deprecated in 1.19; use Title::getTemplateLinksFrom() |
| 2607 | + * @return Array of Title objects |
| 2608 | + */ |
| 2609 | + public function getUsedTemplates() { |
| 2610 | + return $this->mTitle->getTemplateLinksFrom(); |
| 2611 | + } |
| 2612 | + |
| 2613 | + /** |
2632 | 2614 | * Perform article updates on a special page creation. |
2633 | 2615 | * |
2634 | 2616 | * @param $rev Revision object |