jenkins-bot has submitted this change and it was merged.

Change subject: Fix a fatal error when the Page image doesn't exit
......................................................................


Fix a fatal error when the Page image doesn't exit

Improve code of the addition of pref and next links to Page: pages
Use the same order as the old interface

Change-Id: I9df4eac6252b59736b1080e15d0cabf759547f2c
---
M ProofreadPage.body.php
1 file changed, 65 insertions(+), 39 deletions(-)

Approvals:
  Tpt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php
index 01de00d..482f5ed 100644
--- a/ProofreadPage.body.php
+++ b/ProofreadPage.body.php
@@ -865,52 +865,78 @@
        }
 
        /**
-        * Add the links to previous, next, index page and scan image.
+        * Add the links to previous, next, index page and scan image to Page: 
pages.
         * @param $skin SkinTemplate object
         * @param $links Structured navigation links
         */
        public static function onSkinTemplateNavigation( &$skin, &$links ) {
-               global $wgOut, $wgExtensionAssetsPath;
-               $titleText = $wgOut->getPageTitle();
-               $title = Title::newFromText( $titleText );
-               if( $title->inNamespace( self::getPageNamespaceId() ) ) {
-                       $page = ProofreadPagePage::newFromTitle( $title );
-                       $indexPage = $page->getIndex();
-                       if ( $indexPage !== null ) {
-                               list( $prevTitle, $nextTitle ) = 
$indexPage->getPreviousAndNextPages( $page->getTitle() );
-                               if ( $prevTitle !== null ) {
-                                       if( !$prevTitle->exists() ) {
-                                               $prevLink = 
$prevTitle->getEditURL();
-                                       } else {
-                                               $prevLink = 
$prevTitle->getLinkUrl();
-                                       }
-                                       
$links['namespaces']['proofreadPagePrevLink'] = array( 'class' => '', 'href' => 
$prevLink,
-                                               'text' => wfMessage( 
'proofreadpage_prevpage' )->plain() );
-                               }
-                               if ( $nextTitle !== null ) {
-                                       if( !$nextTitle->exists() ) {
-                                               $nextLink = 
$nextTitle->getEditURL();
-                                       } else {
-                                               $nextLink = 
$nextTitle->getLinkUrl();
-                                       }
-                                       
$links['namespaces']['proofreadPageNextLink'] = array( 'class' => '', 'href' => 
$nextLink,
-                                               'text' => wfMessage( 
'proofreadpage_nextpage' )->plain() );
-                               }
-                               $indexLink = 
$indexPage->getTitle()->getLinkUrl();
-                               $links['namespaces']['proofreadPageIndexLink'] 
= array( 'class' => '', 'href' => $indexLink,
-                                               'text' => wfMessage( 
'proofreadpage_index' )->plain() );
+               global $wgOut;
 
-                               $image = $page->getImage();
-                               $width = $image->getWidth();
-                               $filePage = $page->getPageNumber();
-                               $params = array( 'width' => $width, 'page' => 
$filePage );
-                               $image->getHandler()->normaliseParams( $image, 
$params );
-                               $thumbName = $image->thumbName( $params );
-                               $imageUrl = $image->getThumbUrl( $thumbName );
-                               $links['namespaces']['proofreadPageScanLink'] = 
array( 'class' => '', 'href' => $imageUrl,
-                                               'text' => wfMessage( 
'proofreadpage_image')->plain() );
+               $title = $wgOut->getTitle();
+               if( !$title->inNamespace( self::getPageNamespaceId() ) ) {
+                       return true;
+               }
+               
+               $page = ProofreadPagePage::newFromTitle( $title );
+               $indexPage = $page->getIndex();
+               if ( $indexPage ) {
+                       list( $prevTitle, $nextTitle ) = 
$indexPage->getPreviousAndNextPages( $page->getTitle() );
+
+                       if ( $prevTitle !== null ) {
+                               if( !$prevTitle->exists() ) {
+                                       $prevLink = $prevTitle->getEditURL();
+                               } else {
+                                       $prevLink = $prevTitle->getLinkUrl();
+                               }
+                               $links['namespaces']['proofreadPagePrevLink'] = 
array(
+                                       'class' => '',
+                                       'href' => $prevLink,
+                                       'text' => wfMessage( 
'proofreadpage_prevpage' )->plain()
+                               );
+                       }
+
+                       $indexLink = $indexPage->getTitle()->getLinkUrl();
+                       $links['namespaces']['proofreadPageIndexLink'] = array(
+                               'class' => '',
+                               'href' => $indexLink,
+                               'text' => wfMessage( 'proofreadpage_index' 
)->plain()
+                       );
+
+                       if ( $nextTitle !== null ) {
+                               if( !$nextTitle->exists() ) {
+                                       $nextLink = $nextTitle->getEditURL();
+                               } else {
+                                       $nextLink = $nextTitle->getLinkUrl();
+                               }
+                               $links['namespaces']['proofreadPageNextLink'] = 
array(
+                                       'class' => '',
+                                       'href' => $nextLink,
+                                       'text' => wfMessage( 
'proofreadpage_nextpage' )->plain()
+                               );
                        }
                }
+
+               $image = $page->getImage();
+               if ( $image ) {
+                       $transformAttributes = array(
+                               'width' => $image->getWidth()
+                       );
+                       if ( $image->isMultipage() ) {
+                               $pageNumber = $page->getPageNumber();
+                               if ( $pageNumber !== null ) {
+                                       $transformAttributes['page'] = 
$pageNumber;
+                               }
+                       }
+                       $image->getHandler()->normaliseParams( $image, $params 
);
+                       $thumbName = $image->thumbName( $params );
+                       $imageUrl = $image->getThumbUrl( $thumbName );
+                       $links['namespaces']['proofreadPageScanLink'] = array(
+                               'class' => '',
+                               'href' => $imageUrl,
+                               'text' => wfMessage( 
'proofreadpage_image')->plain()
+                       );
+               }
+
                return true;
        }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9df4eac6252b59736b1080e15d0cabf759547f2c
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: pagePagesRefactoring
Gerrit-Owner: Tpt <[email protected]>
Gerrit-Reviewer: Rtdwivedi <[email protected]>
Gerrit-Reviewer: Tpt <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to