summaryrefslogtreecommitdiff
path: root/includes/filerepo/LocalRepo.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/filerepo/LocalRepo.php')
-rw-r--r--includes/filerepo/LocalRepo.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php
index 72f9e9a6..a259bd48 100644
--- a/includes/filerepo/LocalRepo.php
+++ b/includes/filerepo/LocalRepo.php
@@ -62,4 +62,52 @@ class LocalRepo extends FSRepo {
}
return $status;
}
+
+ /**
+ * Function link Title::getArticleID().
+ * We can't say Title object, what database it should use, so we duplicate that function here.
+ */
+ private function getArticleID( $title ) {
+ if( !$title instanceof Title ) {
+ return 0;
+ }
+ $dbr = $this->getSlaveDB();
+ $id = $dbr->selectField(
+ 'page', // Table
+ 'page_id', //Field
+ array( //Conditions
+ 'page_namespace' => $title->getNamespace(),
+ 'page_title' => $title->getDbKey(),
+ ),
+ __METHOD__ //Function name
+ );
+ return $id;
+ }
+
+ function checkRedirect( $title ) {
+ global $wgFileRedirects;
+ if( !$wgFileRedirects ) {
+ return false;
+ }
+
+ if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) {
+ $title = Title::makeTitle( NS_IMAGE, $title->getText() );
+ }
+
+ $id = $this->getArticleID( $title );
+ if( !$id ) {
+ return false;
+ }
+ $dbr = $this->getSlaveDB();
+ $row = $dbr->selectRow(
+ 'redirect',
+ array( 'rd_title', 'rd_namespace' ),
+ array( 'rd_from' => $id ),
+ __METHOD__
+ );
+ if( !$row ) {
+ return false;
+ }
+ return Title::makeTitle( $row->rd_namespace, $row->rd_title );
+ }
}