r85559 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85558‎ | r85559 | r85560 >
Date:18:45, 6 April 2011
Author:nikola
Status:deferred
Tags:
Comment:
Various changes
Modified paths:
  • /trunk/extensions/Interlanguage/Interlanguage.php (modified) (history)
  • /trunk/extensions/Interlanguage/InterlanguageExtension.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Interlanguage/InterlanguageExtension.php
@@ -25,7 +25,6 @@
2626 */
2727
2828 class InterlanguageExtension {
29 - var $pageLinks = array();
3029 var $foreignDbr = false;
3130
3231 function onLanguageGetMagic( &$magicWords, $langCode ) {
@@ -42,8 +41,7 @@
4342 function interlanguage( &$parser, $param ) {
4443 global $wgMemc;
4544
46 - //This will later be used by pageLinks() and onArticleSave()
47 - $this->pageLinks[$parser->mTitle->mArticleID][$param] = true;
 45+ $this->addPageLink( $parser->getOutput(), $param );
4846
4947 $key = wfMemcKey( 'Interlanguage', md5( $param ) );
5048 $res = $wgMemc->get( $key );
@@ -180,12 +178,45 @@
181179 }
182180
183181 /**
 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+ /**
184215 * Displays a list of links to pages on the central wiki below the edit box.
185216 *
186217 * @param $editPage - standard EditPage object.
187218 */
188219 function pageLinks( $editPage ) {
189 - $pagelinktitles = $this->getPageLinkTitles( $editPage->mArticle->mTitle->mArticleID );
 220+ $pagelinktitles = $this->getPageLinkTitles( $editPage->mArticle->mTitle->mArticleID, $editPage->mParserOutput );
190221
191222 if( count( $pagelinktitles ) ) {
192223 $linker = new Linker();
@@ -245,40 +276,17 @@
246277 }
247278
248279 /**
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 - /**
272280 * Displays a list of links to pages on the central wiki at the end of the language box.
273281 *
274282 * @param $editPage - standard EditPage object.
275283 */
276284 function onSkinTemplateOutputPageBeforeExec( &$skin, &$template ) {
277 - $pagelinktitles = $this->getPageLinkTitles( $skin->mTitle->mArticleID, wfMsg( 'editsection' ) );
 285+ $pagelinktitles = $this->getPageLinkTitles( $skin->mTitle->mArticleID );
278286
279287 foreach( $pagelinktitles as $title ) {
280288 $template->data['language_urls'][] = array(
281289 'href' => $title->getFullURL( array( 'action' => 'edit' ) ),
282 - 'text' => "edit",
 290+ 'text' => wfMsg( 'editsection' ),
283291 'title' => $title->getText(),
284292 'class' => "interwiki-interlanguage",
285293 'before' => "[",
@@ -293,15 +301,25 @@
294302 * Returns an array of Titles of pages on the central wiki which are linked to from a page
295303 * on this wiki by {{interlanguage:}} magic.
296304 *
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.
298307 * @returns The array. If there are no pages linked, an empty array is returned.
299308 */
300 - function getPageLinkTitles( $articleid ) {
 309+ function getPageLinkTitles( $articleid = null, $parserOutput = null ) {
301310 global $wgInterlanguageExtensionInterwiki;
302311
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+ }
305319 } else {
 320+ $pagelinks = $this->getPageLinks( $parserOutput );
 321+ }
 322+
 323+ if( ( $pagelinks === false || $pagelinks === null ) && $articleid ) {
306324 $pagelinks = $this->loadPageLinks( $articleid );
307325 }
308326
Index: trunk/extensions/Interlanguage/Interlanguage.php
@@ -47,8 +47,8 @@
4848
4949 if( !isset($wgInterlanguageExtension) ) {
5050 $wgInterlanguageExtension = new InterlanguageExtension();
 51+ $wgHooks['OutputPageParserOutput'][] = $wgInterlanguageExtension;
5152 $wgHooks['EditPage::showEditForm:fields'][] = array( $wgInterlanguageExtension, 'pageLinks' );
52 - $wgHooks['ArticleSaveComplete'][] = $wgInterlanguageExtension;
5353 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = $wgInterlanguageExtension;
5454 $parser->setFunctionHook( 'interlanguage', array( $wgInterlanguageExtension, 'interlanguage' ), SFH_NO_HASH );
5555 }

Status & tagging log