Aude has uploaded a new change for review.

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


Change subject: Hotfix: Make Special:SetSiteLink not set already used Links
......................................................................

Hotfix: Make Special:SetSiteLink not set already used Links

Besides: fixed edit link in ItemView class to Special:SetSitelink

This leaves error message parsing slightly broken, but
that's a different matter.

Change-Id: Iaa3d0718efa34db08c770ca1eb768560ff0e37a0
---
M repo/Wikibase.i18n.php
M repo/includes/ItemView.php
M repo/includes/specials/SpecialSetSiteLink.php
3 files changed, 33 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/94/67894/1

diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index aea070b..91bef87 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -175,6 +175,8 @@
        'wikibase-setsitelink-submit' => 'Set the site link',
        'wikibase-setsitelink-warning-remove' => 'Do you really want to remove 
the site link of [[$1]]?',
        'wikibase-setsitelink-invalid-site' => 'The site id "$1" is unknown. 
Please use an existing site id, such as "enwiki".',
+       'wikibase-setsitelink-add-failed' => 'The site link could not be 
saved.',
+       'wikibase-setsitelink-remove-failed' => 'The site link could not be 
removed.',
        'wikibase-setentity-id' => 'ID:',
        'wikibase-setentity-language' => 'Language:',
        'wikibase-setentity-invalid-langcode' => 'The language identifier "$1" 
is unknown. Please use a language identifier known to the system, such as 
"en".',
@@ -752,8 +754,16 @@
        'wikibase-setsitelink-site' => 'Label for the input field to type the 
site id to set the site link to.',
        'wikibase-setsitelink-label' => 'Label for the input field to type the 
site link to set the entity to.',
        'wikibase-setsitelink-submit' => 'Label for the button that activates 
the action.',
-       'wikibase-setsitelink-warning-remove' => 'A warning message to ask the 
user if he wants to remove the site link. $1 is the id that links to the 
entity.',
-       'wikibase-setsitelink-invalid-site' => 'Response informing that the 
site id is not valid. Could give an example of a valid site id. $1 is the 
invalid id.',
+       'wikibase-setsitelink-warning-remove' => 'A warning message to ask the 
user if he wants to remove the site link.
+
+Parameters:
+* $1 - the id that links to the entity',
+       'wikibase-setsitelink-invalid-site' => 'Response informing that the 
site id is not valid. Could give an example of a valid site id.
+
+Parameters:
+* $1 - the invalid id',
+       'wikibase-setsitelink-add-failed' => 'Error message when the site link 
could not be saved.',
+       'wikibase-setsitelink-remove-failed' => 'Error message when the site 
link could not be removed.',
        'wikibase-setentity-id' => 'Label for the input field to select the ID 
of the entity.
 {{Identical|ID}}',
        'wikibase-setentity-language' => 'Label for the input field to select 
the language the label should be set in.
diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php
index 59a7e66..d9163c0 100644
--- a/repo/includes/ItemView.php
+++ b/repo/includes/ItemView.php
@@ -99,6 +99,7 @@
 
                        } else {
                                $languageCode = $site->getLanguageCode();
+                               $siteId = $site->getGlobalId();
 
                                // TODO: for non-JS, also set the dir attribute 
on the link cell;
                                // but do not build language objects for each 
site since it causes too much load
@@ -110,7 +111,7 @@
                                        htmlspecialchars( $languageCode ), // 
TODO: get an actual site id rather then just the language code
                                        htmlspecialchars( $link->getUrl() ),
                                        htmlspecialchars( $link->getPage() ),
-                                       $this->getHtmlForEditSection( $item, 
$lang, $editLink . '/' . $languageCode, 'td' )
+                                       $this->getHtmlForEditSection( $item, 
$lang, $editLink . '/' . $siteId, 'td' )
                                );
                        }
                }
diff --git a/repo/includes/specials/SpecialSetSiteLink.php 
b/repo/includes/specials/SpecialSetSiteLink.php
index f6fd866..40a7c27 100644
--- a/repo/includes/specials/SpecialSetSiteLink.php
+++ b/repo/includes/specials/SpecialSetSiteLink.php
@@ -257,18 +257,32 @@
                        return $status;
                }
 
-               if ( $siteObject->normalizePageName( $page ) === false && $page 
!== '' ) {
-                       $status->error( 'wikibase-error-ui-no-external-page' );
-                       return $status;
+               if ( $page !== '' ) {
+                       // Don't try to normalize an empty string (which means: 
remove the link)
+                       $page = $siteObject->normalizePageName( $page );
+
+                       if ( $page === false ) {
+                               $status->error( 
'wikibase-error-ui-no-external-page' );
+                               return $status;
+                       }
                }
 
                if ( $page === '' ) {
-                       $entityContent->getEntity()->removeSitelink( $site );
+                       $link = $entityContent->getItem()->getSiteLink( $site );
+                       if ( !$link ) {
+                               $status->error( 
'wikibase-setsitelink-remove-failed' );
+                               return $status;
+                       }
+                       $entityContent->getItem()->removeSitelink( $site );
                        $i18n = 'wbsetsitelink-remove';
                }
                else {
                        $siteLink = new SiteLink( $siteObject, $page );
-                       $entityContent->getEntity()->addSiteLink( $siteLink, 
'set' );
+                       $ret = $entityContent->getItem()->addSiteLink( 
$siteLink, 'set' );
+                       if ( $ret === false ) {
+                               $status->error( 
'wikibase-setsitelink-add-failed' );
+                               return $status;
+                       }
                        $i18n = 'wbsetsitelink-set';
                }
                $summary = $this->getSummary( $site, $page, $i18n ); // 
$summary is passed by reference ( &$summary )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa3d0718efa34db08c770ca1eb768560ff0e37a0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: mw1.22-wmf6
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Bene <[email protected]>

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

Reply via email to