Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/165044

Change subject: Improved handling for "target=" for #formlink, incl. new "edit 
existing target"
......................................................................

Improved handling for "target=" for #formlink, incl. new "edit existing target"

Change-Id: Ib217b6c49d373abe68105c611e43117b19ad88ab
---
M includes/SF_Utils.php
1 file changed, 22 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms 
refs/changes/44/165044/1

diff --git a/includes/SF_Utils.php b/includes/SF_Utils.php
index e08b2e7..f8775a7 100644
--- a/includes/SF_Utils.php
+++ b/includes/SF_Utils.php
@@ -906,6 +906,7 @@
                // Set defaults.
                $inFormName = $inLinkStr = $inLinkType = $inTooltip =
                        $inQueryStr = $inTargetName = '';
+               $inEditExistingTarget = false;
                if ( $specialPageName == 'RunQuery' ) {
                        $inLinkStr = wfMessage( 'runquery' )->text();
                }
@@ -958,6 +959,8 @@
                                $classStr = 'popupformlink';
                        } elseif ( $param_name == null && $value == 'new 
window' ) {
                                $targetWindow = '_blank';
+                       } elseif ( $param_name == null && $value == 'edit 
existing target' ) {
+                               $inEditExistingTarget = true;
                        } elseif ( $param_name !== null && 
!$positionalParameters ) {
                                $value = urlencode( $value );
                                parse_str( "$param_name=$value", $arr );
@@ -980,12 +983,22 @@
                        }
                }
 
-               $ad = SpecialPageFactory::getPage( $specialPageName );
+               // If "red link only" was specified, and a target page was
+               // specified, and it exists, just link to the page.
+               if ( $inTargetName != '' ) {
+                       $targetTitle = Title::newFromText( $inTargetName );
+                       $targetPageExists = ( $targetTitle != '' & 
$targetTitle->exists() );
+               }
+               if ( !$inEditExistingTarget && $targetPageExists ) {
+                       return Linker::link( $targetTitle );
+               } 
+
+               $formSpecialPage = SpecialPageFactory::getPage( 
$specialPageName );
                if ( strpos( $inFormName, '/' ) == true ) {
                        $query = array( 'form' => $inFormName, 'target' => 
$inTargetName );
-                       $link_url = $ad->getTitle()->getLocalURL( $query );
+                       $link_url = $formSpecialPage->getTitle()->getLocalURL( 
$query );
                } else {
-                       $link_url = $ad->getTitle()->getLocalURL() . 
"/$inFormName";
+                       $link_url = $formSpecialPage->getTitle()->getLocalURL() 
. "/$inFormName";
                        if ( ! empty( $inTargetName ) ) {
                                $link_url .= "/$inTargetName";
                        }
@@ -1023,10 +1036,14 @@
                        // If a target page has been specified but it doesn't
                        // exist, make it a red link.
                        if ( ! empty( $inTargetName ) ) {
-                               $targetTitle = Title::newFromText( 
$inTargetName );
-                               if ( is_null( $targetTitle ) || 
!$targetTitle->exists() ) {
+                               if ( !$targetPageExists ) {
                                        $classStr .= " new";
                                }
+                               // If no link string was specified, make it
+                               // the name of the page.
+                               if ( $inLinkStr == '' ) {
+                                       $inLinkStr = $inTargetName;
+                               }
                        }
                        $str = Html::rawElement( 'a', array( 'href' => 
$link_url, 'class' => $classStr, 'title' => $inTooltip, 'target' => 
$targetWindow ), $inLinkStr );
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib217b6c49d373abe68105c611e43117b19ad88ab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
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