Tpt has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/335439 )
Change subject: Uses the Index: page based on file name when there are multiple
possible Index: pages
......................................................................
Uses the Index: page based on file name when there are multiple possible Index:
pages
When more than one Index: page links to a Page: page we should use as Index:
for this page the Index: pages that shares the same file name, if it exists.
E.g. if Index:Foo and Index:Bar.djvu both link to Page:Bar.djvu/3, we should
use as index Index:Bar.djvu.
Change-Id: I738fe279933b4110cb31d0a3616aa4c52341c48a
---
M includes/page/ProofreadPagePage.php
1 file changed, 33 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage
refs/changes/39/335439/1
diff --git a/includes/page/ProofreadPagePage.php
b/includes/page/ProofreadPagePage.php
index 1d4ad82..9fa3a49 100644
--- a/includes/page/ProofreadPagePage.php
+++ b/includes/page/ProofreadPagePage.php
@@ -99,16 +99,44 @@
return $this->index;
}
- $result = ProofreadIndexDbConnector::getRowsFromTitle(
$this->title );
+ $indexTitle = $this->findIndexTitle();
+ if ( $indexTitle === null ) {
+ $this->index = false;
+ return false;
+ } else {
+ $this->index = ProofreadIndexPage::newFromTitle(
$indexTitle );
+ return $this->index;
+ }
+ }
+ private function findIndexTitle() {
+ $possibleIndexTitle =
$this->findPossibleIndexTitleBasedOnName();
+
+ // Try to find links from Index: pages
+ $result = ProofreadIndexDbConnector::getRowsFromTitle(
$this->title );
+ $indexesThatLinksHere = [];
foreach ( $result as $x ) {
$refTitle = Title::makeTitle( $x->page_namespace,
$x->page_title );
if ( $refTitle !== null && $refTitle->inNamespace(
ProofreadPage::getIndexNamespaceId() ) ) {
- $this->index =
ProofreadIndexPage::newFromTitle( $refTitle );
- return $this->index;
+ if ( $refTitle->equals( $possibleIndexTitle ) )
{ // It is the same as the linked file, we know it's this Index:
+ return $refTitle;
+ }
+ $indexesThatLinksHere[] = $refTitle;
}
}
+ if ( !empty( $indexesThatLinksHere ) ) {
+ // TODO: what should we do if there are more than 1
possible index?
+ $this->index = ProofreadIndexPage::newFromTitle(
$indexesThatLinksHere[0] );
+ return $this->index;
+ }
+ return $possibleIndexTitle;
+ }
+
+ /**
+ * @return Title|null the index page based on the name of the Page:
page and the existence of a file with the same name
+ */
+ private function findPossibleIndexTitleBasedOnName() {
$m = explode( '/', $this->title->getText(), 2 );
if ( isset( $m[1] ) ) {
$imageTitle = Title::makeTitleSafe( NS_FILE, $m[0] );
@@ -116,16 +144,11 @@
$image = wfFindFile( $imageTitle );
// if it is multipage, we use the page order of
the file
if ( $image && $image->exists() &&
$image->isMultipage() ) {
- $indexTitle = Title::makeTitle(
ProofreadPage::getIndexNamespaceId(), $image->getTitle()->getText() );
- if ( $indexTitle !== null ) {
- $this->index =
ProofreadIndexPage::newFromTitle( $indexTitle );
- return $this->index;
- }
+ return Title::makeTitle(
ProofreadPage::getIndexNamespaceId(), $image->getTitle()->getText() );
}
}
}
- $this->index = false;
- return false;
+ return null;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/335439
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I738fe279933b4110cb31d0a3616aa4c52341c48a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Tpt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits