Yaron Koren has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/338151 )

Change subject: Added use of LinkRenderer for MW 1.28+
......................................................................

Added use of LinkRenderer for MW 1.28+

Change-Id: I838a5b7e9ce5b9d90bb54332b873040ee9607356
---
M includes/PF_FormEditAction.php
M includes/PF_FormUtils.php
M includes/PF_ParserFunctions.php
M includes/PF_Utils.php
M specials/PF_CreateClass.php
M specials/PF_Forms.php
M specials/PF_Templates.php
M specials/PF_UploadWindow.php
8 files changed, 76 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms 
refs/changes/51/338151/2

diff --git a/includes/PF_FormEditAction.php b/includes/PF_FormEditAction.php
index 06773a3..82670c6 100644
--- a/includes/PF_FormEditAction.php
+++ b/includes/PF_FormEditAction.php
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\MediaWikiServices;
+
 /**
  * Handles the formedit action.
  *
@@ -202,7 +205,12 @@
 
                // We need to call linkKnown(), not link(), so that PF's
                // edit=>formedit hook won't be called on this link.
-               $noFormLink = Linker::linkKnown( $title, wfMessage( 
'pf-formedit-donotuseform' )->escaped(), array(), array( 'action' => 'edit', 
'redlink' => true ) );
+               if ( function_exists( 
'MediaWiki\MediaWikiServices::getLinkRenderer' ) ) {
+                       $linkRenderer = 
MediaWikiServices::getInstance()->getLinkRenderer();
+               } else {
+                       $linkRenderer = null;
+               }
+               $noFormLink = PFUtils::makeLink( $linkRenderer, $title, 
wfMessage( 'pf-formedit-donotuseform' )->escaped(), array(), array( 'action' => 
'edit', 'redlink' => true ) );
                $output->addHTML( Html::rawElement( 'p', null, $noFormLink ) );
        }
 
diff --git a/includes/PF_FormUtils.php b/includes/PF_FormUtils.php
index c00ab17..892581a 100644
--- a/includes/PF_FormUtils.php
+++ b/includes/PF_FormUtils.php
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\MediaWikiServices;
+
 /**
  * Utilities for the display and retrieval of forms.
  *
@@ -228,8 +231,8 @@
                if ( $wgTitle == null ) {
                        $cancel = '';
                }
-               // if we're on the special 'FormEdit' page, just send the user
-               // back to the previous page they were on
+               // If we're on the special 'FormEdit' page, just send the user
+               // back to the previous page they were on.
                elseif ( $wgTitle->isSpecial( 'FormEdit' ) ) {
                        $stepsBack = 1;
                        // For IE, we need to go back twice, past the redirect.
@@ -239,7 +242,12 @@
                        }
                        $cancel = "<a 
href=\"javascript:history.go(-$stepsBack);\">$label</a>";
                } else {
-                       $cancel = Linker::link( $wgTitle, $label, array(), 
array(), 'known' );
+                       if ( function_exists( 
'MediaWiki\MediaWikiServices::getLinkRenderer' ) ) {
+                               $linkRenderer = 
MediaWikiServices::getInstance()->getLinkRenderer();
+                       } else {
+                               $linkRenderer = null;
+                       }
+                       $cancel = PFUtils::makeLink( $linkRenderer, $wgTitle, 
$label );
                }
                return "\t\t" . Html::rawElement( 'span', array( 'class' => 
'editHelp' ), $cancel ) . "\n";
        }
diff --git a/includes/PF_ParserFunctions.php b/includes/PF_ParserFunctions.php
index 6b0d5a4..8a40eda 100644
--- a/includes/PF_ParserFunctions.php
+++ b/includes/PF_ParserFunctions.php
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\MediaWikiServices;
+
 /**
  * Parser functions for Page Forms.
  *
@@ -682,10 +685,15 @@
                }
 
                if ( $parserFunctionName == 'formredlink' && $targetPageExists 
) {
-                       if ( $inExistingPageLinkStr == '' ) {
-                               return Linker::link( $targetTitle );
+                       if ( function_exists( 
'MediaWiki\MediaWikiServices::getLinkRenderer' ) ) {
+                               $linkRenderer = 
MediaWikiServices::getInstance()->getLinkRenderer();
                        } else {
-                               return Linker::link( $targetTitle, 
$inExistingPageLinkStr );
+                               $linkRenderer = null;
+                       }
+                       if ( $inExistingPageLinkStr == '' ) {
+                               return PFUtils::makeLink( $linkRenderer, 
$targetTitle );
+                       } else {
+                               return PFUtils::makeLink( $linkRenderer, 
$targetTitle, $inExistingPageLinkStr );
                        }
                }
 
diff --git a/includes/PF_Utils.php b/includes/PF_Utils.php
index 7f0af5e..81b6c5f 100644
--- a/includes/PF_Utils.php
+++ b/includes/PF_Utils.php
@@ -10,11 +10,25 @@
 class PFUtils {
 
        /**
+        * Helper function for backward compatibility.
+        */
+       public static function makeLink( $linkRenderer, $title, $msg = null, 
$attrs = array(), $params = array() ) {
+               if ( !is_null( $linkRenderer ) ) {
+                       // MW 1.28+
+                       // Is there a makeLinkKnown() method? We'll just do it
+                       // manually.
+                       return $linkRenderer->makeLink( $title, $msg, $attrs, 
$params, array( 'known' ) );
+               } else {
+                       return Linker::linkKnown( $title, $msg, $attrs, $params 
);
+               }
+       }
+
+       /**
         * Creates a link to a special page, using that page's top-level 
description as the link text.
         */
-       public static function linkForSpecialPage( $specialPageName ) {
+       public static function linkForSpecialPage( $linkRenderer, 
$specialPageName ) {
                $specialPage = SpecialPageFactory::getPage( $specialPageName );
-               return Linker::link( $specialPage->getTitle(),
+               return self::makeLink( $linkRenderer, $specialPage->getTitle(),
                        htmlspecialchars( $specialPage->getDescription() ) );
        }
 
diff --git a/specials/PF_CreateClass.php b/specials/PF_CreateClass.php
index 9f2be5c..97a9f7e 100644
--- a/specials/PF_CreateClass.php
+++ b/specials/PF_CreateClass.php
@@ -194,12 +194,17 @@
                // Make links to all the other 'Create...' pages, in order to
                // link to them at the top of the page.
                $creation_links = array();
-               if ( defined( 'SMW_VERSION' ) ) {
-                       $creation_links[] = PFUtils::linkForSpecialPage( 
'CreateProperty' );
+               if ( method_exists( $this, 'getLinkRenderer' ) ) {
+                       $linkRenderer = $this->getLinkRenderer();
+               } else {
+                       $linkRenderer = null;
                }
-               $creation_links[] = PFUtils::linkForSpecialPage( 
'CreateTemplate' );
-               $creation_links[] = PFUtils::linkForSpecialPage( 'CreateForm' );
-               $creation_links[] = PFUtils::linkForSpecialPage( 
'CreateCategory' );
+               if ( defined( 'SMW_VERSION' ) ) {
+                       $creation_links[] = PFUtils::linkForSpecialPage( 
$linkRenderer, 'CreateProperty' );
+               }
+               $creation_links[] = PFUtils::linkForSpecialPage( $linkRenderer, 
'CreateTemplate' );
+               $creation_links[] = PFUtils::linkForSpecialPage( $linkRenderer, 
'CreateForm' );
+               $creation_links[] = PFUtils::linkForSpecialPage( $linkRenderer, 
'CreateCategory' );
 
                $text = '<form action="" method="post">' . "\n";
                $text .= "\t" . Html::rawElement( 'p', null,
diff --git a/specials/PF_Forms.php b/specials/PF_Forms.php
index 854c62a..212e47b 100644
--- a/specials/PF_Forms.php
+++ b/specials/PF_Forms.php
@@ -73,6 +73,11 @@
 
        function formatResult( $skin, $result ) {
                $title = Title::makeTitle( PF_NS_FORM, $result->value );
-               return Linker::link( $title, htmlspecialchars( 
$title->getText() ) );
+               if ( method_exists( $this, 'getLinkRenderer' ) ) {
+                       $linkRenderer = $this->getLinkRenderer();
+               } else {
+                       $linkRenderer = null;
+               }
+               return PFUtils::makeLink( $linkRenderer, $title, 
htmlspecialchars( $title->getText() ) );
        }
 }
diff --git a/specials/PF_Templates.php b/specials/PF_Templates.php
index 8f791d4..e108511 100644
--- a/specials/PF_Templates.php
+++ b/specials/PF_Templates.php
@@ -91,7 +91,12 @@
 
        function formatResult( $skin, $result ) {
                $title = Title::makeTitle( NS_TEMPLATE, $result->value );
-               $text = Linker::link( $title, htmlspecialchars( 
$title->getText() ) );
+               if ( method_exists( $this, 'getLinkRenderer' ) ) {
+                       $linkRenderer = $this->getLinkRenderer();
+               } else {
+                       $linkRenderer = null;
+               }
+               $text = PFUtils::makeLink( $linkRenderer, $title, 
htmlspecialchars( $title->getText() ) );
                $category = $this->getCategoryDefinedByTemplate( $title );
                if ( $category !== '' ) {
                        $text .= ' ' . wfMessage(
diff --git a/specials/PF_UploadWindow.php b/specials/PF_UploadWindow.php
index c5a6d90..362eb7b 100644
--- a/specials/PF_UploadWindow.php
+++ b/specials/PF_UploadWindow.php
@@ -609,7 +609,13 @@
                } elseif ( $exists['warning'] == 'was-deleted' ) {
                        # If the file existed before and was deleted, warn the 
user of this
                        $ltitle = SpecialPage::getTitleFor( 'Log' );
-                       $llink = Linker::linkKnown(
+                       if ( method_exists( $this, 'getLinkRenderer' ) ) {
+                               $linkRenderer = $this->getLinkRenderer();
+                       } else {
+                               $linkRenderer = null;
+                       }
+                       $llink = PFUtils::makeLink(
+                               $linkRenderer,
                                $ltitle,
                                wfMessage( 'deletionlog' )->escaped(),
                                array(),

-- 
To view, visit https://gerrit.wikimedia.org/r/338151
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I838a5b7e9ce5b9d90bb54332b873040ee9607356
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to