r85233 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85232‎ | r85233 | r85234 >
Date:07:51, 3 April 2011
Author:nikola
Status:deferred (Comments)
Tags:
Comment:
Show edit links at the bottom of the language box
Modified paths:
  • /trunk/extensions/Interlanguage/Interlanguage.php (modified) (history)
  • /trunk/extensions/Interlanguage/InterlanguageCentral.php (modified) (history)
  • /trunk/extensions/Interlanguage/InterlanguageCentralExtension.php (modified) (history)
  • /trunk/extensions/Interlanguage/InterlanguageCentralExtensionPurgeJob.php (modified) (history)
  • /trunk/extensions/Interlanguage/InterlanguageExtension.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Interlanguage/Interlanguage.php
@@ -49,6 +49,7 @@
5050 $wgInterlanguageExtension = new InterlanguageExtension();
5151 $wgHooks['EditPage::showEditForm:fields'][] = array( $wgInterlanguageExtension, 'pageLinks' );
5252 $wgHooks['ArticleSaveComplete'][] = $wgInterlanguageExtension;
 53+ $wgHooks['SkinTemplateLanguageBoxEnd'][] = $wgInterlanguageExtension;
5354 $parser->setFunctionHook( 'interlanguage', array( $wgInterlanguageExtension, 'interlanguage' ), SFH_NO_HASH );
5455 }
5556 return true;
Index: trunk/extensions/Interlanguage/InterlanguageCentralExtensionPurgeJob.php
@@ -1,10 +1,10 @@
22 <?php
33 /**
4 - * MediaWiki InterlanguageCentral extension v1.2
 4+ * MediaWiki InterlanguageCentral extension
55 * InterlanguageCentralExtensionPurgeJob class
66 *
77 * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs>
8 - * @version 1.1
 8+ * @version 1.2
99 *
1010 * This program is free software; you can redistribute it and/or modify
1111 * it under the terms of the GNU General Public License as published by
Index: trunk/extensions/Interlanguage/InterlanguageCentralExtension.php
@@ -1,10 +1,10 @@
22 <?php
33 /**
4 - * MediaWiki InterlanguageCentral extension v1.2
 4+ * MediaWiki InterlanguageCentral extension
55 * InterlanguageCentralExtension class
66 *
77 * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs>
8 - * @version 1.1
 8+ * @version 1.2
99 *
1010 * This program is free software; you can redistribute it and/or modify
1111 * it under the terms of the GNU General Public License as published by
Index: trunk/extensions/Interlanguage/InterlanguageCentral.php
@@ -3,7 +3,7 @@
44 * MediaWiki InterlanguageCentral extension v1.2
55 *
66 * Copyright © 2010-2011 Nikola Smolenski <smolensk@eunet.rs>
7 - * @version 1.1
 7+ * @version 1.2
88 *
99 * This program is free software; you can redistribute it and/or modify
1010 * it under the terms of the GNU General Public License as published by
Index: trunk/extensions/Interlanguage/InterlanguageExtension.php
@@ -185,26 +185,9 @@
186186 * @param $editPage - standard EditPage object.
187187 */
188188 function pageLinks( $editPage ) {
189 - global $wgInterlanguageExtensionInterwiki;
 189+ $pagelinktexts = $this->getPageLinkTexts( $editPage->mArticle->mTitle->mArticleID );
190190
191 - $articleid = $editPage->mArticle->mTitle->mArticleID;
192 -
193 - if( isset( $this->pageLinks[$articleid] ) && count( $this->pageLinks[$articleid] ) ) {
194 - $pagelinks = $this->pageLinks[$articleid];
195 - } else {
196 - $pagelinks = $this->loadPageLinks( $articleid );
197 - }
198 -
199 - if( count( $pagelinks ) ) {
200 - $linker = new Linker(); $pagelinktexts = array();
201 - foreach( $pagelinks as $page => $dummy ) {
202 - $title = Title::newFromText( $wgInterlanguageExtensionInterwiki . strtr($this->translateNamespace( $page ), '_', ' ') );
203 - $link = $linker->link( $title );
204 - if( strlen( $link ) ) {
205 - $pagelinktexts[] = $link;
206 - }
207 - }
208 -
 191+ if( count( $pagelinktexts ) ) {
209192 $ple = wfMsg( 'interlanguage-pagelinksexplanation' );
210193
211194 $res = <<<THEEND
@@ -283,6 +266,60 @@
284267 }
285268
286269 /**
 270+ * Displays a list of links to pages on the central wiki at the end of the language box.
 271+ *
 272+ * @param $editPage - standard EditPage object.
 273+ */
 274+ function onSkinTemplateLanguageBoxEnd( $tpl ) {
 275+ $pagelinktexts = $this->getPageLinkTexts( $tpl->skin->mTitle->mArticleID, wfMsg( 'editsection' ) );
 276+
 277+ if( count( $pagelinktexts ) ) {
 278+ $res = "";
 279+ foreach($pagelinktexts as $link) {
 280+ $res .= "<li class=\"interwiki-interlanguage\">[$link]</li>\n";
 281+ }
 282+
 283+ echo $res;
 284+ }
 285+
 286+ return true;
 287+ }
 288+
 289+ /**
 290+ * Returns an array of link texts of pages on the central wiki which are linked to from a page
 291+ * on this wiki by {{interlanguage:}} magic.
 292+ *
 293+ * @param $articleid - ID of the article whose links should be returned.
 294+ * @param $text = false - The HTML contents of the <a> element. If set, it will be
 295+ * passed to Linker::link(), if unset the link title will be used.
 296+ * @returns The array. If there are no pages linked, an empty array is returned.
 297+ */
 298+ function getPageLinkTexts( $articleid, $text = false ) {
 299+ global $wgInterlanguageExtensionInterwiki;
 300+
 301+ if( isset( $this->pageLinks[$articleid] ) && count( $this->pageLinks[$articleid] ) ) {
 302+ $pagelinks = $this->pageLinks[$articleid];
 303+ } else {
 304+ $pagelinks = $this->loadPageLinks( $articleid );
 305+ }
 306+
 307+ $pagelinktexts = array();
 308+ if( count( $pagelinks ) ) {
 309+ $linker = new Linker();
 310+ foreach( $pagelinks as $page => $dummy ) {
 311+ $title = Title::newFromText( $wgInterlanguageExtensionInterwiki . strtr( $this->translateNamespace( $page ), '_', ' ') );
 312+ $link = $linker->link( $title, $text? $text: $page );
 313+ if( strlen( $link ) ) {
 314+ $pagelinktexts[] = $link;
 315+ }
 316+ }
 317+ }
 318+
 319+ return $pagelinktexts;
 320+
 321+ }
 322+
 323+ /**
287324 * Returns an array of names of pages on the central wiki which are linked to from a page
288325 * on this wiki by {{interlanguage:}} magic. Pagenames are array keys.
289326 *

Sign-offs

UserFlagDate
Nikerabbitinspected15:24, 3 April 2011

Comments

#Comment by Nikerabbit (talk | contribs)   15:24, 3 April 2011

Shouldn't the message be escaped?

+$pagelinktexts = $this->getPageLinkTexts( $tpl->skin->mTitle->mArticleID, wfMsg( 'editsection' ) );

I don't understand why strtr is needed here.

+$title = Title::newFromText( $wgInterlanguageExtensionInterwiki . strtr( $this->translateNamespace( $page ), '_', ' ') );
#Comment by Nikola Smolenski (talk | contribs)   03:11, 4 April 2011
Shouldn't the message be escaped?

I don't know; it is not escaped in MediaWiki itself (see Linker::doEditSectionLink() ).

I don't understand why strtr is needed here.

Yeah, me neither :) Removed it in r85309.

Status & tagging log