* A new special page to search for pages in NS_IMAGE that link to a certain
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Fri, 16 Sep 2005 15:09:14 +0000 (15:09 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Fri, 16 Sep 2005 15:09:14 +0000 (15:09 +0000)
  page in NS_TEMPLATE

includes/SpecialLicensesearch.php [new file with mode: 0644]
includes/SpecialPage.php
languages/Language.php

diff --git a/includes/SpecialLicensesearch.php b/includes/SpecialLicensesearch.php
new file mode 100644 (file)
index 0000000..cf2361a
--- /dev/null
@@ -0,0 +1,140 @@
+<?php
+/**
+ * Search for pages in NS_IMAGE that link to a certain page in NS_TEMPLATE
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ *
+ * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
+ * @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;
+}
+?>
index 9133f8e..6b60b9e 100644 (file)
@@ -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 )
index 916dacc..89a0b33 100644 (file)
@@ -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',