Index: trunk/extensions/Interlanguage/InterlanguageExtension.php |
— | — | @@ -25,7 +25,6 @@ |
26 | 26 | */ |
27 | 27 | |
28 | 28 | class InterlanguageExtension { |
29 | | - var $pageLinks = array(); |
30 | 29 | var $foreignDbr = false; |
31 | 30 | |
32 | 31 | function onLanguageGetMagic( &$magicWords, $langCode ) { |
— | — | @@ -42,8 +41,7 @@ |
43 | 42 | function interlanguage( &$parser, $param ) { |
44 | 43 | global $wgMemc; |
45 | 44 | |
46 | | - //This will later be used by pageLinks() and onArticleSave() |
47 | | - $this->pageLinks[$parser->mTitle->mArticleID][$param] = true; |
| 45 | + $this->addPageLink( $parser->getOutput(), $param ); |
48 | 46 | |
49 | 47 | $key = wfMemcKey( 'Interlanguage', md5( $param ) ); |
50 | 48 | $res = $wgMemc->get( $key ); |
— | — | @@ -180,12 +178,45 @@ |
181 | 179 | } |
182 | 180 | |
183 | 181 | /** |
| 182 | + * Add a page to the list of page links. It will later be used by pageLinks(). |
| 183 | + */ |
| 184 | + function addPageLink( &$parserOutput, $param ) { |
| 185 | + $ilp = $parserOutput->getProperty( 'interlanguage_pages' ); |
| 186 | + if(!$ilp) $ilp = array(); else $ilp = @unserialize( $ilp ); |
| 187 | + if(!isset($ilp[$param])) { |
| 188 | + $ilp[$param] = true; |
| 189 | + $parserOutput->setProperty( 'interlanguage_pages', @serialize( $ilp ) ); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * Get the list of page links. |
| 195 | + * |
| 196 | + * @param $parserOutput |
| 197 | + * @return Array of page links. Empty array if there are no links, literal false if links have not |
| 198 | + * been yet set. |
| 199 | + */ |
| 200 | + function getPageLinks( $parserOutput ) { |
| 201 | + $ilp = $parserOutput->getProperty( 'interlanguage_pages' ); |
| 202 | + if($ilp !== false) $ilp = @unserialize( $ilp ); |
| 203 | + return $ilp; |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * Copies interlanguage pages from ParserOutput to OutputPage. |
| 208 | + */ |
| 209 | + function onOutputPageParserOutput( &$out, $parserOutput ) { |
| 210 | + $out->interlanguage_pages = $this->getPageLinks( $parserOutput ); |
| 211 | + return true; |
| 212 | + } |
| 213 | + |
| 214 | + /** |
184 | 215 | * Displays a list of links to pages on the central wiki below the edit box. |
185 | 216 | * |
186 | 217 | * @param $editPage - standard EditPage object. |
187 | 218 | */ |
188 | 219 | function pageLinks( $editPage ) { |
189 | | - $pagelinktitles = $this->getPageLinkTitles( $editPage->mArticle->mTitle->mArticleID ); |
| 220 | + $pagelinktitles = $this->getPageLinkTitles( $editPage->mArticle->mTitle->mArticleID, $editPage->mParserOutput ); |
190 | 221 | |
191 | 222 | if( count( $pagelinktitles ) ) { |
192 | 223 | $linker = new Linker(); |
— | — | @@ -245,40 +276,17 @@ |
246 | 277 | } |
247 | 278 | |
248 | 279 | /** |
249 | | - * Saves names of pages on the central wiki which are linked to from the saved page |
250 | | - * by {{interlanguage:}} magic. |
251 | | - * |
252 | | - * @param $article - standard Article object. |
253 | | - */ |
254 | | - function onArticleSaveComplete( &$article ) { |
255 | | - $articleid = $article->mTitle->mArticleID; |
256 | | - $pagelinks = $this->loadPageLinks( $articleid ); |
257 | | - $dbr = wfGetDB( DB_MASTER ); |
258 | | - |
259 | | - if( count( array_diff_key( $pagelinks, $this->pageLinks[$articleid] ) ) || count( array_diff_key( $this->pageLinks[$articleid], $pagelinks ) ) ) { |
260 | | - if( count( $pagelinks ) ) { |
261 | | - $dbr->delete( 'page_props', array( 'pp_page' => $articleid, 'pp_propname' => 'interlanguage_pages' ), __FUNCTION__); |
262 | | - } |
263 | | - if( count( $this->pageLinks[$articleid] ) ) { |
264 | | - $dbr->insert( 'page_props', array( 'pp_page' => $articleid, 'pp_propname' => 'interlanguage_pages', 'pp_value' => @serialize( $this->pageLinks[$articleid] ) ), __FUNCTION__); |
265 | | - } |
266 | | - } |
267 | | - |
268 | | - return true; |
269 | | - } |
270 | | - |
271 | | - /** |
272 | 280 | * Displays a list of links to pages on the central wiki at the end of the language box. |
273 | 281 | * |
274 | 282 | * @param $editPage - standard EditPage object. |
275 | 283 | */ |
276 | 284 | function onSkinTemplateOutputPageBeforeExec( &$skin, &$template ) { |
277 | | - $pagelinktitles = $this->getPageLinkTitles( $skin->mTitle->mArticleID, wfMsg( 'editsection' ) ); |
| 285 | + $pagelinktitles = $this->getPageLinkTitles( $skin->mTitle->mArticleID ); |
278 | 286 | |
279 | 287 | foreach( $pagelinktitles as $title ) { |
280 | 288 | $template->data['language_urls'][] = array( |
281 | 289 | 'href' => $title->getFullURL( array( 'action' => 'edit' ) ), |
282 | | - 'text' => "edit", |
| 290 | + 'text' => wfMsg( 'editsection' ), |
283 | 291 | 'title' => $title->getText(), |
284 | 292 | 'class' => "interwiki-interlanguage", |
285 | 293 | 'before' => "[", |
— | — | @@ -293,15 +301,25 @@ |
294 | 302 | * Returns an array of Titles of pages on the central wiki which are linked to from a page |
295 | 303 | * on this wiki by {{interlanguage:}} magic. |
296 | 304 | * |
297 | | - * @param $articleid - ID of the article whose links should be returned. |
| 305 | + * @param $articleid ID of the article whose links should be returned. |
| 306 | + * @param $parserOutput A ParserOutput object. |
298 | 307 | * @returns The array. If there are no pages linked, an empty array is returned. |
299 | 308 | */ |
300 | | - function getPageLinkTitles( $articleid ) { |
| 309 | + function getPageLinkTitles( $articleid = null, $parserOutput = null ) { |
301 | 310 | global $wgInterlanguageExtensionInterwiki; |
302 | 311 | |
303 | | - if( isset( $this->pageLinks[$articleid] ) && count( $this->pageLinks[$articleid] ) ) { |
304 | | - $pagelinks = $this->pageLinks[$articleid]; |
| 312 | + if( $parserOutput === null) { |
| 313 | + global $wgOut; |
| 314 | + if( isset( $wgOut->interlanguage_pages ) ) { |
| 315 | + $pagelinks = $wgOut->interlanguage_pages; |
| 316 | + } else { |
| 317 | + $pagelinks = false; |
| 318 | + } |
305 | 319 | } else { |
| 320 | + $pagelinks = $this->getPageLinks( $parserOutput ); |
| 321 | + } |
| 322 | + |
| 323 | + if( ( $pagelinks === false || $pagelinks === null ) && $articleid ) { |
306 | 324 | $pagelinks = $this->loadPageLinks( $articleid ); |
307 | 325 | } |
308 | 326 | |
Index: trunk/extensions/Interlanguage/Interlanguage.php |
— | — | @@ -47,8 +47,8 @@ |
48 | 48 | |
49 | 49 | if( !isset($wgInterlanguageExtension) ) { |
50 | 50 | $wgInterlanguageExtension = new InterlanguageExtension(); |
| 51 | + $wgHooks['OutputPageParserOutput'][] = $wgInterlanguageExtension; |
51 | 52 | $wgHooks['EditPage::showEditForm:fields'][] = array( $wgInterlanguageExtension, 'pageLinks' ); |
52 | | - $wgHooks['ArticleSaveComplete'][] = $wgInterlanguageExtension; |
53 | 53 | $wgHooks['SkinTemplateOutputPageBeforeExec'][] = $wgInterlanguageExtension; |
54 | 54 | $parser->setFunctionHook( 'interlanguage', array( $wgInterlanguageExtension, 'interlanguage' ), SFH_NO_HASH ); |
55 | 55 | } |