Rtdwivedi has uploaded a new change for review. https://gerrit.wikimedia.org/r/67632
Change subject: Separated data fetching from presentation in function load_index in ProofreadPage.body.php Will do the same for other functions also. Change-Id: I9e067185529af2d259cfbeb84c3c3db66d2ddd95 ...................................................................... Separated data fetching from presentation in function load_index in ProofreadPage.body.php Will do the same for other functions also. Change-Id: I9e067185529af2d259cfbeb84c3c3db66d2ddd95 --- A .htaccess A DbConnector.php M ProofreadPage.body.php M ProofreadPage.php A includes/index/DbConnector.php 5 files changed, 124 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage refs/changes/32/67632/1 diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..fcc4e1f --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^/w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/page([0-9]+)-?([0-9]+)px-.*$ /w/thumb.php?f=$1&p=$2&w=$3 [L,QSA] diff --git a/DbConnector.php b/DbConnector.php new file mode 100644 index 0000000..6ddccbc --- /dev/null +++ b/DbConnector.php @@ -0,0 +1,77 @@ +<?php + +class DbConnector{ + +/** + * @param $updater DatabaseUpdater + * @return bool + */ + public static function onLoadExtensionSchemaUpdates( $updater = null ) { + $base = dirname( __FILE__ ); + if ( $updater === null ) { + global $wgExtNewTables; + $wgExtNewTables[] = array( 'pr_index', "$base/ProofreadPage.sql" ); + } else { + $updater->addExtensionUpdate( array( 'addTable', 'pr_index', + "$base/ProofreadPage.sql", true ) ); + } + return true; + } + + /** + * Query the database to find if the current page is referred in an Index page. + * @param $title Title + */ + private static function load_index( $title ) { +// list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); + list( $page_namespace, $index_namespace ) = ProofreadPage::getPageAndIndexNamespace(); + + $title->pr_index_title = null; + $dbr = wfGetDB( DB_SLAVE ); + $result = $dbr->select( + array( 'page', 'pagelinks' ), + array( 'page_namespace', 'page_title' ), + array( + 'pl_namespace' => $title->getNamespace(), + 'pl_title' => $title->getDBkey(), + 'pl_from=page_id' + ), + __METHOD__ + ); + + foreach ( $result as $x ) { + $ref_title = Title::makeTitle( $x->page_namespace, $x->page_title ); +// if ( $ref_title->inNamespace( self::getIndexNamespaceId() ) ) { + if ( $ref_title->inNamespace( ProofreadPage::getIndexNamespaceId() ) ) { + $title->pr_index_title = $ref_title->getPrefixedText(); + break; + } + } + + if ( $title->pr_index_title ) { + return; + } + + $imageTitle = null; + /* check if we are a page of a multipage file */ + if ( preg_match( "/^$page_namespace:(.*?)(\/(.*?)|)$/", $title->getPrefixedText(), $m ) ) { + $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] ); + } + if ( !$imageTitle ) { + return; + } + + $image = wfFindFile( $imageTitle ); + + // if it is multipage, we use the page order of the file + if ( $image && $image->exists() && $image->isMultipage() ) { + $name = $image->getTitle()->getText(); + $index_name = "$index_namespace:$name"; + + if ( !$title->pr_index_title ) { + // there is no index, or the page is not listed in the index : use canonical index + $title->pr_index_title = $index_name; + } + } + } +} \ No newline at end of file diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php index 4d37b7f..1a78d7d 100644 --- a/ProofreadPage.body.php +++ b/ProofreadPage.body.php @@ -159,17 +159,7 @@ list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); $title->pr_index_title = null; - $dbr = wfGetDB( DB_SLAVE ); - $result = $dbr->select( - array( 'page', 'pagelinks' ), - array( 'page_namespace', 'page_title' ), - array( - 'pl_namespace' => $title->getNamespace(), - 'pl_title' => $title->getDBkey(), - 'pl_from=page_id' - ), - __METHOD__ - ); + $result = DbConnector::load_index_db( $title ); foreach ( $result as $x ) { $ref_title = Title::makeTitle( $x->page_namespace, $x->page_title ); diff --git a/ProofreadPage.php b/ProofreadPage.php index e066366..2d68ae4 100644 --- a/ProofreadPage.php +++ b/ProofreadPage.php @@ -40,6 +40,7 @@ $wgExtensionMessagesFiles['ProofreadPageAlias'] = $dir . 'ProofreadPage.alias.php'; $wgAutoloadClasses['ProofreadPage'] = $dir . 'ProofreadPage.body.php'; +$wgAutoloadClasses['DbConnector'] = $dir . 'includes/index/DbConnector.php'; $wgAutoloadClasses['ProofreadPageInit'] = $dir . 'includes/ProofreadPageInit.php'; @@ -143,7 +144,7 @@ $wgHooks['EditFormPreloadText'][] = 'ProofreadPage::onEditFormPreloadText'; $wgHooks['ArticlePurge'][] = 'ProofreadPage::onArticlePurge'; $wgHooks['SpecialMovepageAfterMove'][] = 'ProofreadPage::onSpecialMovepageAfterMove'; -$wgHooks['LoadExtensionSchemaUpdates'][] = 'ProofreadPage::onLoadExtensionSchemaUpdates'; +$wgHooks['LoadExtensionSchemaUpdates'][] = 'DbConnector::onLoadExtensionSchemaUpdates'; $wgHooks['EditPage::importFormData'][] = 'ProofreadPage::onEditPageImportFormData'; $wgHooks['OutputPageParserOutput'][] = 'ProofreadPage::onOutputPageParserOutput'; $wgHooks['wgQueryPages'][] = 'ProofreadPage::onwgQueryPages'; diff --git a/includes/index/DbConnector.php b/includes/index/DbConnector.php new file mode 100644 index 0000000..131f032 --- /dev/null +++ b/includes/index/DbConnector.php @@ -0,0 +1,40 @@ +<?php + +class DbConnector{ + +/** + * @param $updater DatabaseUpdater + * @return bool + */ + public static function onLoadExtensionSchemaUpdates( $updater = null ) { + $base = dirname( __FILE__ ); + if ( $updater === null ) { + global $wgExtNewTables; + $wgExtNewTables[] = array( 'pr_index', "$base/ProofreadPage.sql" ); + } else { + $updater->addExtensionUpdate( array( 'addTable', 'pr_index', + "$base/ProofreadPage.sql", true ) ); + } + return true; + } + + /** + * Query the database to find if the current page is referred in an Index page. + * @param $title Title + */ + public static function load_index_db( $title ) { + $title->pr_index_title = null; + $dbr = wfGetDB( DB_SLAVE ); + $result = $dbr->select( + array( 'page', 'pagelinks' ), + array( 'page_namespace', 'page_title' ), + array( + 'pl_namespace' => $title->getNamespace(), + 'pl_title' => $title->getDBkey(), + 'pl_from=page_id' + ), + __METHOD__ + ); + return $result; + } +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/67632 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9e067185529af2d259cfbeb84c3c3db66d2ddd95 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ProofreadPage Gerrit-Branch: master Gerrit-Owner: Rtdwivedi <ellydwivedi2...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits