From 40ac54e1721ee8687901984cb60bed997f39ce78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Fri, 16 Sep 2005 15:09:14 +0000 Subject: [PATCH] * A new special page to search for pages in NS_IMAGE that link to a certain page in NS_TEMPLATE --- includes/SpecialLicensesearch.php | 140 ++++++++++++++++++++++++++++++ includes/SpecialPage.php | 1 + languages/Language.php | 5 ++ 3 files changed, 146 insertions(+) create mode 100644 includes/SpecialLicensesearch.php diff --git a/includes/SpecialLicensesearch.php b/includes/SpecialLicensesearch.php new file mode 100644 index 0000000000..cf2361a669 --- /dev/null +++ b/includes/SpecialLicensesearch.php @@ -0,0 +1,140 @@ + + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + */ + +/* */ +require_once 'QueryPage.php'; + +/** + * @package MediaWiki + * @subpackage SpecialPage + */ +class LicensesearchPage extends QueryPage { + var $license; + + function LicensesearchPage( $license ) { + $this->license = $license; + } + + function getName() { return 'Licensesearch'; } + + /** + * Due to this page relying upon extra fields being passed in the SELECT it + * will fail if it's set as expensive and misermode is on + */ + function isExpensive() { return false; } + function isSyndicated() { return false; } + + function linkParameters() { + return array( 'license' => $this->license ); + } + + function getSQL() { + $dbr =& wfGetDB( DB_SLAVE ); + extract( $dbr->tableNames( 'page', 'pagelinks' ) ); + $license = $dbr->addQuotes( $this->license ); + + return + "SELECT 'Licensesearch' as type, + " . NS_IMAGE . " as namespace, + page_title as title, + page_title as value + FROM $pagelinks + LEFT JOIN $page ON page_id = pl_from + WHERE page_namespace = " . NS_IMAGE . " AND pl_namespace = " . NS_TEMPLATE . " AND pl_title = $license + "; + } + + function formatResult( $skin, $result ) { + global $wgContLang; + + $nt = Title::makeTitle( $result->namespace, $result->title ); + $text = $wgContLang->convert( $nt->getText() ); + $plink = $skin->makeLink( $nt->getPrefixedText(), $text ); + + return $plink; + } +} + +/** + * constructor + */ +function wfSpecialLicensesearch( $par = null ) { + global $wgRequest, $wgTitle, $wgOut; + + $license = isset( $par ) ? $par : $wgRequest->getText( 'license' ); + + $wgOut->addHTML( + wfElement( 'form', + array( + 'id' => 'speciallicensesearch', + 'method' => 'get', + 'action' => $wgTitle->escapeLocalUrl() + ), + null + ) . + wfOpenElement( 'label' ) . + wfMsgHtml( 'licensesearch_license' ) . + wfElement( 'input', array( + 'type' => 'text', + 'size' => 20, + 'name' => 'license', + 'value' => $license + ), + '' + ) . + ' ' . + wfElement( 'input', array( + 'type' => 'submit', + 'value' => wfMsg( 'ilsubmit' ) + ), + '' + ) . + wfCloseElement( 'label' ) . + wfCloseElement( 'form' ) + ); + + $license = trim( $license, ' ' ); + if ($license == '') + return; + + $license = wfSpecialLicensesearchLicense( $license ); + $wpp = new LicensesearchPage( $license ); + + list( $limit, $offset ) = wfCheckLimits(); + $wpp->doQuery( $offset, $limit ); +} + +function wfSpecialLicensesearchLicense( $license ) { + $aliases = wfSpecialLicensesearchLicenseParser(); + + if ( @$aliases[$license] !== null ) + return $aliases[$license]; + else + return $license; +} + +function wfSpecialLicensesearchLicenseParser() { + $aliases = array(); + + $licenses = explode( "\n", wfMsgForContent( 'licensesearch_licenses' ) ); + foreach ($licenses as $line) { + if ( strpos( $line, '*' ) !== 0 || strpos( $line, '|' ) === false) + continue; + else { + $line = ltrim( $line, '* ' ); + list( $template, $alias ) = explode( '|', $line, 2 ); + $aliases[$alias] = $template; + } + } + + return $aliases; +} +?> diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 9133f8e5b7..6b60b9e528 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -71,6 +71,7 @@ $wgSpecialPages = array( 'Unlockdb' => new SpecialPage( 'Unlockdb', 'siteadmin' ), 'Userrights' => new SpecialPage( 'Userrights', 'userrights' ), 'MIMEsearch' => new SpecialPage( 'MIMEsearch' ), + 'Licensesearch' => new SpecialPage( 'Licensesearch' ), ); if ( $wgUseValidation ) diff --git a/languages/Language.php b/languages/Language.php index 916dacc967..89a0b33de1 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1076,6 +1076,11 @@ this old version, (rev) = revert to this old version. 'mimetype' => 'MIME type: ', 'download' => 'download', +# License search +# +'licensesearch' => 'License search', +'licensesearch_license' => 'License: ', + # Statistics # 'statistics' => 'Statistics', -- 2.20.1