http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97755
Revision: 97755
Author: siebrand
Date: 2011-09-21 19:22:00 +0000 (Wed, 21 Sep 2011)
Log Message:
-----------
stylize.php and other whitespace updates.
Modified Paths:
--------------
trunk/extensions/IndexFunction/IndexAbstracts.php
trunk/extensions/IndexFunction/IndexFunction.i18n.php
trunk/extensions/IndexFunction/IndexFunction.php
trunk/extensions/IndexFunction/IndexFunction_body.php
trunk/extensions/IndexFunction/SpecialIndex.php
trunk/extensions/IndexFunction/indexes.sql
trunk/extensions/IndexFunction/specialindex.js
Modified: trunk/extensions/IndexFunction/IndexAbstracts.php
===================================================================
--- trunk/extensions/IndexFunction/IndexAbstracts.php 2011-09-21 19:00:41 UTC
(rev 97754)
+++ trunk/extensions/IndexFunction/IndexAbstracts.php 2011-09-21 19:22:00 UTC
(rev 97755)
@@ -3,8 +3,7 @@
/*
* Class to extract the first bit of text from an article
* Adapted from the OpenSearchXML extension, by Brion Vibber
-*/
-
+ */
class IndexAbstracts {
/**
* Strip markup to show plaintext
@@ -14,14 +13,14 @@
*/
function _stripMarkup( $text ) {
global $wgContLang;
-
+
$text = substr( $text, 0, 4096 ); // don't bother with long
text...
-
+
$text = str_replace( "'''", "", $text );
$text = str_replace( "''", "", $text );
-
+
$text = preg_replace( '#__[a-z0-9_]+__#i', '', $text ); //
magic words
-
+
$cleanChar = "[^|\[\]]";
$subLink = "\[\[$cleanChar*(?:\|$cleanChar*)*\]\]";
$pipeContents = "(?:$cleanChar|$subLink)*";
@@ -32,7 +31,7 @@
(?:\|$pipeContents)*
\]\]
#six", array( $this, '_stripLink' ), $text );
-
+
$protocols = wfUrlProtocols();
$text = preg_replace( '#\\[(?:$protocols).*? (.*?)\\]#s', '$1',
$text ); // URL links
$text = preg_replace( '#</?[a-z0-9]+.*?>#s', '', $text ); //
HTML-style tags
@@ -40,21 +39,24 @@
$text = preg_replace( '#^:.*$#m', '', $text ); // indented
lines near start are usually disambigs or notices
$text = Sanitizer::decodeCharReferences( $text );
+
return trim( $text );
}
-
+
function _stripLink( $matches ) {
$target = trim( $matches[1] );
- if( isset( $matches[2] ) ) {
+
+ if ( isset( $matches[2] ) ) {
$text = trim( $matches[2] );
} else {
$text = $target;
}
-
+
$title = Title::newFromText( $target );
- if( $title ) {
+
+ if ( $title ) {
$ns = $title->getNamespace();
- if( $title->getInterwiki() || $ns == NS_IMAGE || $ns ==
NS_CATEGORY ) {
+ if ( $title->getInterwiki() || $ns == NS_IMAGE || $ns
== NS_CATEGORY ) {
return "";
} else {
return $text;
@@ -63,7 +65,7 @@
return $matches[0];
}
}
-
+
/**
* Extract the first two sentences, if detectable, from the text.
* @param string $text
@@ -77,63 +79,69 @@
'.', '!', '?', // double-width roman forms
'。', // half-width ideographic full stop
);
-
+
$endgroup = implode( '|', $endchars );
$end = "(?:$endgroup)";
$sentence = ".*?$end+";
$firstone = "/^($sentence)/u";
- if( preg_match( $firstone, $text, $matches ) ) {
+
+ if ( preg_match( $firstone, $text, $matches ) ) {
return $matches[1];
} else {
// Just return the first line
$lines = explode( "\n", $text );
+
return trim( $lines[0] );
}
}
-
- public function getExtract( $title, $chars=50 ) {
+
+ public function getExtract( $title, $chars = 50 ) {
$rev = Revision::newFromTitle( $title );
- if( $rev ) {
+
+ if ( $rev ) {
$text = substr( $rev->getText(), 0, 16384 );
-
+
// Ok, first note this is a TERRIBLE HACK. :D
//
// First, we use the system preprocessor to break down
the text
// into text, templates, extensions, and comments:
global $wgParser;
+
$wgParser->mOptions = new ParserOptions();
$wgParser->clearState();
+
$frame = $wgParser->getPreprocessor()->newFrame();
$dom = $wgParser->preprocessToDom( $text );
-
+
$imageArgs = array(
'image',
'image_skyline',
'img',
'Img',
);
-
+
// Now, we strip out everything that's not text.
// This works with both DOM and Hash parsers, but feels
fragile.
$node = $dom->getFirstChild();
$out = '';
- while( $node ) {
- if( $node->getName() == '#text' ) {
+
+ while ( $node ) {
+ if ( $node->getName() == '#text' ) {
$out .= $frame->expand( $node,
PPFrame::RECOVER_ORIG );
}
$node = $node->getNextSibling();
}
-
+
// The remaining text may still contain wiki and HTML
markup.
// We'll use our shitty hand parser to strip most of
those from
// the beginning of the text.
$stripped = $this->_stripMarkup( $out );
-
+
// And now, we'll grab just the first sentence as text,
and
// also try to rip out a badge image.
return $this->_extractStart( $stripped );
}
+
return '';
}
-
}
Modified: trunk/extensions/IndexFunction/IndexFunction.i18n.php
===================================================================
--- trunk/extensions/IndexFunction/IndexFunction.i18n.php 2011-09-21
19:00:41 UTC (rev 97754)
+++ trunk/extensions/IndexFunction/IndexFunction.i18n.php 2011-09-21
19:22:00 UTC (rev 97755)
@@ -32,9 +32,9 @@
'index-emptylist' => 'There are no pages associated with "$1"',
'index-expand-detail' => 'Show pages indexed under this title',
'index-hide-detail' => 'Hide the list of pages',
- 'index-no-results' => 'The search returned no results',
- 'index-search-explain' => 'This page uses a prefix search.
-
+ 'index-no-results' => 'The search returned no results',
+ 'index-search-explain' => 'This page uses a prefix search.
+
Type the first few characters and press the submit button to search for page
titles and index entries that start with the search string',
'index-details-explain' => 'Entries with arrows are index entries.
Click the arrow to show all pages indexed under that title.',
@@ -213,7 +213,7 @@
'index-search-explain' => 'Ober a ra ar bajenn-mañ gant ur rakger klask.
Merkit an nebeud arouezennoù kentañ ha pouezit war ar bouton klask evit kavout
titloù ar pajennoù a grog gant an neudennad klask-se',
- 'index-details-explain' => 'Monedoù meneger eo ar monedoù gant biroù.
+ 'index-details-explain' => 'Monedoù meneger eo ar monedoù gant biroù.
Klikit war ar bir evit gwelet an holl bajennoù menegeret dindan an titl-se.',
);
@@ -439,13 +439,13 @@
$messages['fi'] = array(
'indexfunc-desc' => 'Jäsenninfunktio automaattisten ohjauksien ja
täsmennyssivujen luomiseen.',
'indexfunc-badtitle' => 'Epäkelpo otsikko: ”$1”',
- 'indexfunc-editwarning' => 'Varoitus:
+ 'indexfunc-editwarning' => 'Varoitus:
Tämä otsikko on indeksiotsikko {{PLURAL:$2|seuraavalle sivulle|seuraaville
sivuille}}:
$1
Tarkista ettei sivua, jota olet luomassa ole jo olemassa toisella otsikolla.
Jos luot tämän sivun, poista otsikko <nowiki>{{#index:}}</nowiki>-tagista
{{PLURAL:$2|yllä olevalla sivulla|yllä olevilla sivuilla}}.',
'indexfunc-index-exists' => 'Sivu ”$1” on jo olemassa',
- 'indexfunc-movewarn' => 'Virhe:
+ 'indexfunc-movewarn' => 'Virhe:
”$1” on indeksiotsikko {{PLURAL:$3|seuraavalle sivulle|seuraaville sivuille}}:
$2
Poista ”$1” <nowiki>{{#index:}}</nowiki>-tagista {{PLURAL:$3|yllä olevilla
sivuilla|yllä olevalla sivulla}}.',
@@ -461,7 +461,7 @@
'index-search-explain' => 'Tämä sivu käyttää etuliitehakua.
Kirjoita pari ensimmäistä kirjainta ja napsauta lähetä-nappia hakeaksesi
sivujen otsikoista ja indeksimerkinnöistä, jotka alkavat hakusanalla.',
- 'index-details-explain' => 'Nuolin varustetut merkinnät ovat
indeksimerkintöjä.
+ 'index-details-explain' => 'Nuolin varustetut merkinnät ovat
indeksimerkintöjä.
Napsauta nuolta näyttääksesi kaikki sivut, jotka on indeksoitu otsikon alle.',
);
@@ -538,7 +538,7 @@
'index-expand-detail' => 'Mostrar as páxinas indexadas baixo este
título',
'index-hide-detail' => 'Agochar a lista de páxinas',
'index-no-results' => 'A procura non devolveu resultados',
- 'index-search-explain' => 'Esta páxina usa unha procura por prefixos.
+ 'index-search-explain' => 'Esta páxina usa unha procura por prefixos.
Insira os primeiros caracteres e prema o botón "Enviar" para buscar títulos de
páxinas e entradas de índice que comezan coa secuencia de procura',
'index-details-explain' => 'As entradas con frechas son entradas de
índice.
@@ -576,7 +576,7 @@
'index-expand-detail' => 'Syte aazeige, wu unter däm Titel ufglischtet
sin',
'index-hide-detail' => 'D Sytelischt verstecke',
'index-no-results' => 'D Suechi het kei Ergebnis brocht',
- 'index-search-explain' => 'Die Syte verwändet e Präfixsuechi.
+ 'index-search-explain' => 'Die Syte verwändet e Präfixsuechi.
Tipp di erschte paar Buehcstabe yy un druck dr „Abschicke“-Chnopf go Sytetitel
un Verzeichnisyytreg suech, wu mit däre Zeichechette aafange',
'index-details-explain' => 'Yytreg mit Bege sin Verzeichnisyytreg.
@@ -720,12 +720,12 @@
'indexfunc-badtitle' => 'Judul tidak sah: "$1"',
'indexfunc-editwarning' => 'Peringatan:
Judul ini adalah judul indeks {{PLURAL:$2|halaman|halaman}} berikut :
-$1
-Pastikan halaman yang akan Anda buat tidak ada pada judul yang berbeda.
+$1
+Pastikan halaman yang akan Anda buat tidak ada pada judul yang berbeda.
Jika Anda membuat halaman ini, hapus halaman ini dari
<nowiki>{{#index:}}</nowiki> di atas {{PLURAL:$2|halaman|halaman}}.',
'indexfunc-index-exists' => 'Halaman "$1" sudah ada',
'indexfunc-movewarn' => 'Peringatan:
-"$1" adalah judul indeks {{PLURAL:$3|halaman|halaman}} berikut :
+"$1" adalah judul indeks {{PLURAL:$3|halaman|halaman}} berikut :
$2
Hapus "$1" dari <nowiki>{{#index:}}</nowiki> di atas
{{PLURAL:$3|halaman|halaman}}.',
'index' => 'Indeks',
@@ -1056,7 +1056,7 @@
'indexfunc-editwarning' => 'Uwaga.
Ten tytuł jest tytułem indeksu {{PLURAL:$2|strony|następujących stron:}}
$1
-Upewnij się, że strona, którą chcesz utworzyć nie istnieje pod inną nazwą.
+Upewnij się, że strona, którą chcesz utworzyć nie istnieje pod inną nazwą.
Jeśli utworzysz tę stronę, usuń tytułu z <nowiki>{{#index:}}</nowiki> dla
{{PLURAL:$2|powyższej strony|powyższych stron}}.',
'indexfunc-index-exists' => 'Strona „$1” już istnieje',
'indexfunc-movewarn' => 'Uwaga.
Modified: trunk/extensions/IndexFunction/IndexFunction.php
===================================================================
--- trunk/extensions/IndexFunction/IndexFunction.php 2011-09-21 19:00:41 UTC
(rev 97754)
+++ trunk/extensions/IndexFunction/IndexFunction.php 2011-09-21 19:22:00 UTC
(rev 97755)
@@ -3,20 +3,20 @@
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'IndexFunction',
- 'author' =>'Alex Zaddach',
- 'url' => 'http://www.mediawiki.org/wiki/Extension:IndexFunction',
+ 'author' => 'Alex Zaddach',
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:IndexFunction',
'descriptionmsg' => 'indexfunc-desc',
);
-$dir = dirname(__FILE__) . '/';
+$dir = dirname( __FILE__ ) . '/';
-# Register function
+# Register function
$wgHooks['ParserFirstCallInit'][] = 'efIndexSetup';
$wgHooks['LanguageGetMagic'][] = 'IndexFunctionHooks::addIndexFunction';
# Add to database
-$wgHooks['OutputPageParserOutput'][] = 'IndexFunctionHooks::doIndexes';
+$wgHooks['OutputPageParserOutput'][] = 'IndexFunctionHooks::doIndexes';
# Make links to indexes blue
-$wgHooks['LinkEnd'][] = 'IndexFunctionHooks::blueLinkIndexes';
+$wgHooks['LinkEnd'][] = 'IndexFunctionHooks::blueLinkIndexes';
# Make links to indexes redirect
$wgHooks['InitializeArticleMaybeRedirect'][] =
'IndexFunctionHooks::doRedirect';
# Make "go" searches for indexes redirect
@@ -53,9 +53,10 @@
* Can be 1 of 2 options:
* 'extract' (default) - Show an extract from the start of the article
* 'categories' - Show a comma-separated list of categories the article is in
-*/
+ */
$wgSpecialIndexContext = 'extract';
+// @todo FIXME: put these methods in a separate class and file.
function efIndexSetup( &$parser ) {
$parser->setFunctionHook( 'index-func', array( 'IndexFunctionHooks',
'indexRender' ) );
return true;
@@ -69,9 +70,12 @@
$updater->addExtensionUpdate( array( 'addTable', 'indexes',
dirname( __FILE__ ) . '/indexes.sql', true ) );
}
+
return true;
}
+
function efParserTestTables( &$tables ) {
$tables[] = 'indexes';
+
return true;
}
Modified: trunk/extensions/IndexFunction/IndexFunction_body.php
===================================================================
--- trunk/extensions/IndexFunction/IndexFunction_body.php 2011-09-21
19:00:41 UTC (rev 97754)
+++ trunk/extensions/IndexFunction/IndexFunction_body.php 2011-09-21
19:22:00 UTC (rev 97755)
@@ -1,5 +1,4 @@
<?php
-
/* TODO:
* Memcached
* Warnings for API edit
@@ -7,7 +6,6 @@
*/
class IndexFunction {
-
var $mTo = array(); // An array of titles for pages being indexed
var $mFrom = null; // A title object representing the index-title
@@ -18,20 +16,26 @@
$ns = $indextitle->getNamespace();
$t = $indextitle->getDBkey();
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'indexes', 'in_from',
+
+ $res = $dbr->select( 'indexes', 'in_from',
array( 'in_namespace' => $ns, 'in_title' => $t ),
__METHOD__
);
+
if ( !$res->numRows() ) {
return null;
}
+
$ind = new IndexFunction();
$ids = array();
+
foreach ( $res as $row ) {
$ids[] = $row->in_from;
}
+
$ind->mTo = Title::newFromIDs( $ids );
$ind->mFrom = $indextitle;
+
return $ind;
}
@@ -39,16 +43,20 @@
public static function newFromTarget( Title $target ) {
$pageid = $target->getArticleID();
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'indexes', array('in_namespace',
'in_title'),
+
+ $res = $dbr->select( 'indexes', array( 'in_namespace',
'in_title' ),
array( 'in_from' => $pageid ),
__METHOD__
);
+
if ( !$res->numRows() ) {
return null;
}
+
$ind = new IndexFunction();
$row = $res->fetchRow();
$ind->mFrom = Title::makeTitle( $row->in_namespace,
$row->in_title );
+
return $ind;
}
@@ -60,32 +68,42 @@
if ( $this->mTo ) {
return $this->mTo;
}
+
$dbr = wfGetDB( DB_SLAVE );
$ns = $this->mFrom->getNamespace();
$t = $this->mFrom->getDBkey();
- $res = $dbr->select( 'indexes', 'in_from',
+
+ $res = $dbr->select( 'indexes', 'in_from',
array( 'in_namespace' => $ns, 'in_title' => $t ),
__METHOD__
);
+
$ids = array();
+
foreach ( $res as $row ) {
$ids[] = $row->in_from;
}
+
$this->mTo = Title::newFromIDs( $ids );
+
return $this->mTo;
}
-
+
// Makes an HTML <ul> list of targets
public function makeTargetList() {
global $wgUser;
+
$sk = $wgUser->getSkin();
$targets = $this->getTargets();
$list = Xml::openElement( 'ul' );
- foreach( $targets as $t ) {
- $link = $sk->link( $t, $t->getPrefixedText(), array(),
array(), array('known', 'noclasses') );
- $list.= Xml::tags( 'li', null, $link );
+
+ foreach ( $targets as $t ) {
+ $link = $sk->link( $t, $t->getPrefixedText(), array(),
array(), array( 'known', 'noclasses' ) );
+ $list .= Xml::tags( 'li', null, $link );
}
+
$list .= Xml::CloseElement( 'ul' );
+
return $list;
}
@@ -95,105 +113,131 @@
if ( !$this->mTo ) {
$this->getTargets();
}
- return count( $this->mTo) > 1;
+
+ return count( $this->mTo ) > 1;
}
}
class IndexFunctionHooks {
-
// Makes "Go" searches for an index title go directly to their target
static function redirectSearch( $term, &$title ) {
$title = Title::newFromText( $term );
- if ( is_null($title) ) {
+
+ if ( is_null( $title ) ) {
return true;
}
+
$index = IndexFunction::newFromTitle( $title );
+
if ( !$index ) {
return true;
} elseif ( $index->useSpecialPage() ) {
global $wgOut;
+
$title = SpecialPage::getTitleFor( 'Index',
$title->getPrefixedText() );
$wgOut->redirect( $title->getLocalURL() );
+
return true;
}
+
$targets = $index->getTargets();
$title = $targets[0];
+
return false;
}
// Make indexes work like redirects
- static function doRedirect( &$title, &$request,& $ignoreRedirect,
&$target, &$article ) {
+ static function doRedirect( &$title, &$request, & $ignoreRedirect,
&$target, &$article ) {
if ( $article->exists() ) {
return true;
}
+
$index = IndexFunction::newFromTitle( $title );
+
if ( !$index ) {
return true;
- } elseif ($index->useSpecialPage() ) {
+ } elseif ( $index->useSpecialPage() ) {
global $wgOut;
+
$t = SpecialPage::getTitleFor( 'Index',
$title->getPrefixedText() );
$wgOut->redirect( $t->getLocalURL() );
+
return true;
- }
+ }
+
$targets = $index->getTargets();
$target = $targets[0];
$article->mIsRedirect = true;
$ignoreRedirect = false;
+
return true;
}
-
+
// Turn links to indexes into blue links
static function blueLinkIndexes( $skin, $target, $options, &$text,
&$attribs, &$ret ) {
if ( in_array( 'known', $options ) ) {
return true;
}
+
$index = IndexFunction::newFromTitle( $target );
+
if ( !$index ) {
return true;
}
+
$attribs['class'] = str_replace( 'new', 'mw-index',
$attribs['class'] );
$attribs['href'] = $target->getLinkUrl();
$attribs['title'] = $target->getEscapedText();
+
return true;
}
// Register the function name
static function addIndexFunction( &$magicWords, $langCode ) {
$magicWords['index-func'] = array( 0, 'index' );
+
return true;
}
-
+
// Function called to render the parser function
// Output is an empty string unless there are errors
static function indexRender( &$parser ) {
- if ( !isset($parser->mOutput->mIndexes) ) {
+ if ( !isset( $parser->mOutput->mIndexes ) ) {
$parser->mOutput->mIndexes = array();
- }
-
+ }
+
static $indexCount = 0;
static $indexes = array();
+
$args = func_get_args();
unset( $args[0] );
+
if ( $parser->mOptions->getIsPreview() ) {
# This is kind of hacky, but it seems that we only
# know if its a preview during parse, not when its
# done, which is when it matters for this
$parser->mOutput->setProperty( 'preview', 1 );
}
+
$errors = array();
$pageid = $parser->mTitle->getArticleID();
+
foreach ( $args as $name ) {
$t = Title::newFromText( $name );
- if( is_null( $t ) ) {
+
+ if ( is_null( $t ) ) {
$errors[] = wfMsg( 'indexfunc-badtitle', $name
);
continue;
}
+
$ns = $t->getNamespace();
$dbkey = $t->getDBkey();
$entry = array( $ns, $dbkey );
+
if ( in_array( $entry, $indexes ) ) {
continue;
- }
+ }
+
if ( $t->exists() ) {
$errors[] = wfMsg( 'indexfunc-index-exists',
$name );
continue;
@@ -201,58 +245,77 @@
$indexCount++;
$parser->mOutput->mIndexes[$indexCount] = $entry;
}
+
if ( !$errors ) {
return '';
}
- $out = Xml::openElement( 'ul', array( 'class'=>'error' ) );
- foreach( $errors as $e ) {
+
+ $out = Xml::openElement( 'ul', array( 'class' => 'error' ) );
+
+ foreach ( $errors as $e ) {
$out .= Xml::element( 'li', null, $e );
}
+
$out .= Xml::closeElement( 'ul' );
+
return $out;
}
// Called after parse, updates the index table
static function doIndexes( $out, $parseroutput ) {
- if ( !isset($parseroutput->mIndexes) ) {
+ if ( !isset( $parseroutput->mIndexes ) ) {
$parseroutput->mIndexes = array();
}
+
if ( $parseroutput->getProperty( 'preview' ) ) {
return true;
}
+
$pageid = $out->getTitle()->getArticleID();
$dbw = wfGetDB( DB_MASTER );
- $res = $dbw->select( 'indexes',
+
+ $res = $dbw->select( 'indexes',
array( 'in_namespace', 'in_title' ),
array( 'in_from' => $pageid ),
__METHOD__
);
+
$current = array();
- foreach( $res as $row ) {
+
+ foreach ( $res as $row ) {
$current[] = array( $row->in_namespace, $row->in_title
);
}
+
$toAdd = wfArrayDiff2( $parseroutput->mIndexes, $current );
$toRem = wfArrayDiff2( $current, $parseroutput->mIndexes );
+
if ( $toAdd || $toRem ) {
$dbw->begin( __METHOD__ );
+
if ( $toRem ) {
$delCond = "in_from = $pageid AND (";
- $parts = array();
+ $parts = array();
+
# Looking at Database::delete, it seems to turn
arrays into AND statements
# but we need to chain together groups of ANDs
with ORs
foreach ( $toRem as $entry ) {
- $parts[] = "(in_namespace = " .
$entry[0] . " AND in_title = " . $dbw->addQuotes($entry[1]) . ")";
+ $parts[] = "(in_namespace = " .
$entry[0] . " AND in_title = " . $dbw->addQuotes( $entry[1] ) . ")";
}
+
$delCond .= implode( ' OR ', $parts ) . ")";
- $dbw->delete( 'indexes', array($delCond),
__METHOD__ );
+ $dbw->delete( 'indexes', array( $delCond ),
__METHOD__ );
}
+
if ( $toAdd ) {
$ins = array();
+
foreach ( $toAdd as $entry ) {
$ins[] = array( 'in_from' => $pageid,
'in_namespace' => $entry[0], 'in_title' => $entry[1] );
}
+
$dbw->insert( 'indexes', $ins, __METHOD__ );
}
+
$dbw->commit( __METHOD__ );
}
return true;
@@ -261,7 +324,8 @@
// When deleting a page, delete all rows from the index table that
point to it
static function onDelete( &$article, &$user, $reason, $id ) {
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'indexes', array( 'in_from'=>$id ), __METHOD__ );
+ $dbw->delete( 'indexes', array( 'in_from' => $id ), __METHOD__
);
+
return true;
}
@@ -271,10 +335,12 @@
$ns = $t->getNamespace();
$dbkey = $t->getDBkey();
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'indexes',
- array( 'in_namespace'=>$ns, 'in_title'=>$dbkey ),
- __METHOD__
+
+ $dbw->delete( 'indexes',
+ array( 'in_namespace' => $ns, 'in_title' => $dbkey ),
+ __METHOD__
);
+
return true;
}
@@ -282,37 +348,44 @@
static function editWarning( $editpage ) {
$t = $editpage->mTitle;
$index = IndexFunction::newFromTitle( $t );
- if (!$index) {
+
+ if ( !$index ) {
return true;
}
-
+
$list = $index->makeTargetList();
$c = count( $index->getTargets() );
$warn = wfMsgExt( 'indexfunc-editwarning', array( 'parsemag' ),
$list, $c );
$editpage->editFormTextTop .= "<span
class='error'>$warn</span>";
+
return true;
}
static function afterMove( &$form, &$orig, &$new ) {
global $wgOut;
+
$index = IndexFunction::newFromTitle( $new );
+
if ( !$index ) {
return true;
}
+
$c = count( $index->getTargets() );
$list = $index->makeTargetList();
$newns = $new->getNamespace();
$newdbk = $new->getDBkey();
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'indexes',
- array( 'in_namespace'=>$newns, 'in_title'=>$newdbk ),
- __METHOD__
+
+ $dbw->delete( 'indexes',
+ array( 'in_namespace' => $newns, 'in_title' => $newdbk
),
+ __METHOD__
);
+
$msg = wfMsgExt( 'indexfunc-movewarn', array( 'parsemag' ),
$new->getPrefixedText(), $list, $c );
$msg = "<span class='error'>$msg</span>";
+
$wgOut->addHTML( $msg );
+
return true;
}
-
}
-
Modified: trunk/extensions/IndexFunction/SpecialIndex.php
===================================================================
--- trunk/extensions/IndexFunction/SpecialIndex.php 2011-09-21 19:00:41 UTC
(rev 97754)
+++ trunk/extensions/IndexFunction/SpecialIndex.php 2011-09-21 19:22:00 UTC
(rev 97755)
@@ -1,19 +1,19 @@
<?php
class SpecialIndexPager extends AlphabeticPager {
-
public $mSearchTitle;
private $mJSid = 0;
function __construct( $search ) {
$this->mSearchTitle = $search;
- parent::__construct();
+ parent::__construct();
// This can potentially be a lot of data, set a lower max limit
$this->mLimit = $this->mLimit > 1000 ? 1000 : $this->mLimit;
}
function formatRow( $row ) {
$sk = $this->getSkin();
+
if ( $row->type == 'page' ) {
$title = Title::makeTitle( $row->ns, $row->title );
$ret = Xml::openElement( 'tr' );
@@ -23,52 +23,62 @@
$ret .= Xml::tags( 'td', null, $link );
$ret .= Xml::tags( 'td', null, ' ' );
$ret .= Xml::closeElement( 'tr' );
+
return $ret;
} else {
$ret = Xml::openElement( 'tr' );
$targettitle = Title::makeTitle( $row->ns, $row->title
);
$title = SpecialPage::getTitleFor( 'Index', $row->title
);
- $link = $sk->link( $title,
$targettitle->getPrefixedText(), array( 'class'=>'mw-index' ), array(), array(
'known', 'noclasses' ) );
-
+ $link = $sk->link( $title,
$targettitle->getPrefixedText(), array( 'class' => 'mw-index' ), array(),
array( 'known', 'noclasses' ) );
+
$jsid = $this->mJSid;
$expandTitle = wfMsgHtml( 'index-expand-detail' );
$closeTitle = wfMsgHtml( 'index-hide-detail' );
$toggleLink = "onclick='toggleVisibility($jsid); return
false'";
$tl = "<span id='mw-index-open-$jsid'
class='mw-index-expanded' style='visibility:hidden' ><a href='#' $toggleLink
title='$expandTitle'>" . $this->sideArrow() . "</a></span>";
$tl .= "<span id='mw-index-close-$jsid'
class='mw-index-hidden' style='display:none'><a href='#' $toggleLink
title='$closeTitle'>" . $this->downArrow() . "</a></span>";
-
+
$ret .= Xml::tags( 'td', array( 'style' =>
'vertical-align:top' ), $tl . ' ' );
$ret .= Xml::tags( 'td', array( 'style' =>
'vertical-align:top' ), $link );
$ret .= Xml::openElement( 'td' );
- $ret .= Xml::openElement( 'ul',
- array( 'style' => 'margin-top:1em',
'class'=>'mw-index-hidden', 'id'=>"mw-index-inner-$jsid" )
- );
+ $ret .= Xml::openElement( 'ul',
+ array( 'style' => 'margin-top:1em', 'class' =>
'mw-index-hidden', 'id' => "mw-index-inner-$jsid" )
+ );
+
$pages = explode( '|', $row->extra );
- foreach( $pages as $page ) {
+
+ foreach ( $pages as $page ) {
$bits = explode( ':', $page, 2 );
$t = Title::makeTitle( $bits[0], $bits[1] );
$ln = $sk->link( $t, null, array(), array(),
array( 'known', 'noclasses' ) );
- $ret .= Xml::tags( 'li', null, $ln );
+ $ret .= Xml::tags( 'li', null, $ln );
}
+
$ret .= Xml::closeElement( 'ul' );
$ret .= Xml::closeElement( 'td' );
$ret .= Xml::closeElement( 'tr' );
+
$this->mJSid++;
- return $ret;
+
+ return $ret;
}
}
-
- protected function arrow( $dir, $alt='', $title='' ) {
+
+ protected function arrow( $dir, $alt = '', $title = '' ) {
global $wgStylePath;
+
$encUrl = htmlspecialchars( $wgStylePath .
'/common/images/Arr_' . $dir . '.png' );
$encAlt = htmlspecialchars( $alt );
$encTitle = htmlspecialchars( $title );
+
return "<img src=\"$encUrl\" width=\"12\" height=\"12\"
alt=\"$encAlt\" title=\"$encTitle\" />";
}
protected function sideArrow() {
global $wgContLang;
+
$dir = $wgContLang->isRTL() ? 'l' : 'r';
+
return $this->arrow( $dir, '+', wfMsg( 'index-expand-detail' )
);
}
@@ -80,250 +90,277 @@
return $this->arrow( '', codepointToUtf8( 0xa0 ) ); //
non-breaking space
}
-
-
// Since we're overriding reallyDoQuery, we don't really need this
// its easier to just do it all in one function
function getQueryInfo() { }
-
+
function getIndexField() {
- return 'title';
+ return 'title';
}
-
+
function getEmptyBody() {
- return "<tr><td class='errorbox'>" . wfMsgHtml(
'index-no-results' ) ."</td></tr>";
+ return "<tr><td class='errorbox'>" . wfMsgHtml(
'index-no-results' ) . "</td></tr>";
}
-
+
// Need to override reallyDoQuery() to do the UNION
- function reallyDoQuery( $offset, $limit, $descending ) {
+ function reallyDoQuery( $offset, $limit, $descending ) {
$limit = ' LIMIT ' . intval( $limit );
- $order = " ORDER BY {$this->mIndexField}";
+ $order = " ORDER BY {$this->mIndexField}";
+
if ( $descending ) {
$operator = '>';
} else {
$order .= ' DESC';
$operator = '<';
- }
-
+ }
+
$pageconds = array();
$indexconds = array();
+
if ( $offset != '' ) {
$pageconds[] = 'page_title' . $operator .
$this->mDb->addQuotes( $offset );
$indexconds[] = 'in_title' . $operator .
$this->mDb->addQuotes( $offset );
- }
+ }
+
$ns = $this->mSearchTitle->getNamespace();
$like = $this->mDb->buildLike( $this->mSearchTitle->getDBkey(),
$this->mDb->anyString() );
-
+
$pageconds[] = "page_namespace = $ns";
$pageconds[] = "page_title " . $like;
$indexconds[] = "in_namespace = $ns";
$indexconds[] = "in_title " . $like;
-
-
- $pagequery = $this->mDb->selectSQLText( 'page',
+
+ $pagequery = $this->mDb->selectSQLText( 'page',
"page_title AS title, page_namespace AS ns, 'page' AS
type, NULL AS extra",
$pageconds,
''
);
- $indexquery = $this->mDb->selectSQLText( array('indexes',
'page'),
- "in_title AS title, in_namespace AS ns, 'index' AS
type,
+
+ $indexquery = $this->mDb->selectSQLText( array( 'indexes',
'page' ),
+ "in_title AS title, in_namespace AS ns, 'index' AS type,
GROUP_CONCAT(page_namespace,':',page_title SEPARATOR
'|') AS extra",
$indexconds,
'',
array( 'GROUP BY' => 'in_namespace, in_title' ),
- array( 'page' => array('JOIN','page_id=in_from') )
+ array( 'page' => array( 'JOIN', 'page_id=in_from' ) )
);
-
+
$union = $this->mDb->unionQueries( array( $pagequery,
$indexquery ), false );
- $union .= $order . $limit;
+ $union .= $order . $limit;
$res = $this->mDb->query( $union, __METHOD__ );
return new ResultWrapper( $this->mDb, $res );
}
-
}
class SpecialIndex extends SpecialPage {
function __construct() {
-
parent::__construct( 'Index' );
}
-
- function execute( $par ) {
-
+
+ function execute( $par ) {
+
$this->setHeaders();
- if ($par) {
+ if ( $par ) {
$t1 = Title::newFromText( $par );
$this->showDabPage( $t1 );
- } else {
- $this->showSearchForm();
+ } else {
+ $this->showSearchForm();
}
+ }
- }
-
function showSearchForm() {
global $wgOut, $wgRequest, $wgScript, $wgExtensionAssetsPath;
$search = $wgRequest->getText( 'searchtext' );
$wgOut->addScriptFile(
"$wgExtensionAssetsPath/IndexFunction/specialindex.js" );
$wgOut->addWikiMsg( 'index-search-explain' );
- $form = Xml::openElement( 'fieldset', array(
'style'=>'line-height:200%' ) ) .
- Xml::element( 'legend', array(), wfMsgHtml( 'index-legend' ) )
.
- Xml::openElement( 'form', array( 'method'=>'GET',
'action'=>$wgScript ) ) .
+ $form = Xml::openElement( 'fieldset', array( 'style' =>
'line-height:200%' ) ) .
+ Xml::element( 'legend', array(), wfMsgHtml( 'index-legend' ) ) .
+ Xml::openElement( 'form', array( 'method' => 'GET', 'action' =>
$wgScript ) ) .
Html::Hidden( 'title', $this->getTitle()->getPrefixedDbKey() )
.
Xml::label( wfMsg( 'index-search' ), 'mw-index-searchtext' ) .
- Xml::input( 'searchtext', 100, $search, array( 'id' =>
'mw-index-searchtext' ) ) .
- '<br />' .
+ Xml::input( 'searchtext', 100, $search, array( 'id' =>
'mw-index-searchtext' ) ) .
+ '<br />' .
Xml::submitButton( wfMsg( 'index-submit' ) ) .
- Xml::closeElement( 'form' ) .
- Xml::closeElement( 'fieldset' );
+ Xml::closeElement( 'form' ) .
+ Xml::closeElement( 'fieldset' );
$wgOut->addHTML( $form );
-
+
$t = Title::newFromText( $search );
-
- if ( !is_null( $t) ) {
+
+ if ( !is_null( $t ) ) {
$t = Title::newFromText( $wgRequest->getVal(
'searchtext' ) );
$pager = new SpecialIndexPager( $t );
- $out = Xml::openElement( 'div', array(
'id'=>'mw-index-searchresults' ) ) .
+ $out = Xml::openElement( 'div', array( 'id' =>
'mw-index-searchresults' ) ) .
'<div id="use-js-note" style="display:none">' .
wfMsgExt( 'index-details-explain' , array( 'parse' ) ) . '</div>' .
$pager->getNavigationBar() .
- Xml::openElement( 'table' ) .
- $pager->getBody() .
+ Xml::openElement( 'table' ) .
+ $pager->getBody() .
Xml::closeElement( 'table' ) .
$pager->getNavigationBar() .
Xml::closeElement( 'div' );
$wgOut->addHtml( $out );
-
+
}
-
}
-
+
function showDabPage( Title $t1 ) {
global $wgOut, $wgUser, $wgSpecialIndexContext;
$sk = $wgUser->getSkin();
$wgOut->setPagetitle( $t1->getPrefixedText() );
$dbr = wfGetDB( DB_SLAVE );
- $pages = $dbr->select( array('page', 'indexes'),
+ $pages = $dbr->select( array( 'page', 'indexes' ),
array( 'page_id', 'page_namespace', 'page_title' ),
- array( 'in_namespace'=>$t1->getNamespace(),
'in_title'=>$t1->getDBkey() ),
- __METHOD__,
- array('ORDER BY'=> 'page_namespace, page_title'),
- array( 'indexes' => array('JOIN', 'in_from=page_id') )
+ array( 'in_namespace' => $t1->getNamespace(),
'in_title' => $t1->getDBkey() ),
+ __METHOD__,
+ array( 'ORDER BY' => 'page_namespace, page_title' ),
+ array( 'indexes' => array( 'JOIN', 'in_from=page_id' ) )
);
-
+
$list = array();
- foreach( $pages as $row ) {
+
+ foreach ( $pages as $row ) {
$t = Title::newFromRow( $row );
- $list[strval($row->page_id)] = array( 'title' => $t,
'cats' => array() );
+ $list[strval( $row->page_id )] = array( 'title' => $t,
'cats' => array() );
}
- if (count($list) == 0) {
+
+ if ( count( $list ) == 0 ) {
$wgOut->addWikiMsg( 'index-emptylist',
$t1->getPrefixedText() );
+
return;
- } elseif (count($list) == 1) {
+ } elseif ( count( $list ) == 1 ) {
$target = reset( $list );
$wgOut->redirect( $target['title']->getLocalURL() );
- }
+ }
+
$wgOut->addWikiMsg( 'index-disambig-start',
$t1->getPrefixedText() );
$keys = array_keys( $list );
- $set = '(' . implode(',', $keys) . ')';
-
- $exclude = wfMsg('index-exclude-categories');
+ $set = '(' . implode( ',', $keys ) . ')';
+
+ $exclude = wfMsg( 'index-exclude-categories' );
$excludecats = array();
- if ($exclude) {
+
+ if ( $exclude ) {
$exclude = explode( '\n', $exclude );
- foreach( $exclude as $cat ) {
- if (!$cat) {
+
+ foreach ( $exclude as $cat ) {
+ if ( !$cat ) {
continue;
}
+
$cat = Title::newFromText( $cat, NS_CATEGORY );
- if ( !is_null($cat) ) {
+
+ if ( !is_null( $cat ) ) {
$excludecats[] = $dbr->addQuotes(
$cat->getDBkey() );
}
}
- $excludecats = 'AND cl_to NOT IN (' . implode(',',
$excludecats) . ')';
+
+ $excludecats = 'AND cl_to NOT IN (' . implode( ',',
$excludecats ) . ')';
} else {
$excludecats = '';
}
-
+
$categories = $dbr->select( 'categorylinks',
- array('cl_from', 'cl_to'),
+ array( 'cl_from', 'cl_to' ),
"cl_from IN $set $excludecats",
__METHOD__,
- array('ORDER BY' => 'cl_from')
+ array( 'ORDER BY' => 'cl_from' )
);
+
$groups = array();
$catlist = array();
- foreach( $categories as $row ) {
+
+ foreach ( $categories as $row ) {
$ct = Title::newFromText( $row->cl_to, NS_CATEGORY );
$textform = $ct->getText();
- $list[strval($row->cl_from)]['cats'][] = $textform;
+ $list[strval( $row->cl_from )]['cats'][] = $textform;
+
if ( array_key_exists( $textform, $catlist ) ) {
- $catlist[$textform][] = strval($row->cl_from);
+ $catlist[$textform][] = strval( $row->cl_from );
} else {
- $catlist[$textform] = array (
strval($row->cl_from) );
+ $catlist[$textform] = array ( strval(
$row->cl_from ) );
}
}
- if (count($catlist) > 2) {
- while (true) {
- arsort($catlist);
+
+ if ( count( $catlist ) > 2 ) {
+ while ( true ) {
+ arsort( $catlist );
$group = reset( $catlist );
- if (count($group) == 0) {
+
+ if ( count( $group ) == 0 ) {
break;
}
- $keys = array_keys($catlist, $group);
+
+ $keys = array_keys( $catlist, $group );
$heading = $keys[0];
- $grouphtml = Xml::element('h2', null, $heading);
+ $grouphtml = Xml::element( 'h2', null, $heading
);
$grouphtml .= Xml::openElement( 'ul' );
- foreach( $group as $pageid ) {
+
+ foreach ( $group as $pageid ) {
$t = $list[$pageid]['title'];
- $cats = $list[$pageid]['cats'];
- $grouphtml .= $this->makeContextLine(
$t, $cats );
+ $cats = $list[$pageid]['cats'];
+ $grouphtml .= $this->makeContextLine(
$t, $cats );
+
unset( $list[$pageid] );
- ksort($list);
- foreach($catlist as $remaining) {
+ ksort( $list );
+
+ foreach ( $catlist as $remaining ) {
$key = array_search( $pageid,
$remaining );
+
if ( $key !== false ) {
- $masterkeys =
array_keys($catlist, $remaining);
+ $masterkeys =
array_keys( $catlist, $remaining );
$heading =
$masterkeys[0];
-
unset($catlist[$heading][$key]);
-
sort($catlist[$heading]);
+ unset(
$catlist[$heading][$key] );
+ sort(
$catlist[$heading] );
}
}
}
+
$grouphtml .= Xml::closeElement( 'ul' );
$groups[] = $grouphtml;
+
unset( $catlist[$heading] );
- if (count($catlist) == 0) {
+
+ if ( count( $catlist ) == 0 ) {
break;
- }
+ }
}
- if (count($list) != 0) { //Pages w/ no cats
+
+ if ( count( $list ) != 0 ) { // Pages w/ no cats
$grouphtml = Xml::openElement( 'ul' );
- foreach( $list as $pageid => $info ) {
+
+ foreach ( $list as $pageid => $info ) {
$grouphtml .= $this->makeContextLine(
$info['title'], array() );
}
- $grouphtml .= Xml::closeElement('ul');
- $groups = array_merge( array($grouphtml),
$groups);
+
+ $grouphtml .= Xml::closeElement( 'ul' );
+ $groups = array_merge( array( $grouphtml ),
$groups );
}
+
$out = implode( "\n", $groups );
} else {
$out = Xml::openElement( 'ul' );
- foreach( $list as $pageid => $info ) {
+
+ foreach ( $list as $pageid => $info ) {
$out .= $this->makeContextLine( $info['title'],
$info['cats'] );
}
- $out .= Xml::closeElement('ul');
+
+ $out .= Xml::closeElement( 'ul' );
}
-
- $wgOut->addHtml($out);
+
+ $wgOut->addHtml( $out );
}
-
+
private function makeContextLine( $title, $cats ) {
global $wgUser, $wgSpecialIndexContext;
+
$sk = $wgUser->getSkin();
$link = $sk->link( $title, null, array(), array(), array(
'known', 'noclasses' ) );
+
if ( $wgSpecialIndexContext == 'extract' ) {
$extracter = new IndexAbstracts();
$text = $extracter->getExtract( $title );
@@ -337,6 +374,7 @@
} else {
$line = $link;
}
+
$line = Xml::tags( 'li', array(), $line );
} elseif ( $wgSpecialIndexContext == 'categories' ) {
if ( $cats ) {
@@ -350,6 +388,4 @@
}
return $line;
}
-
}
-
Modified: trunk/extensions/IndexFunction/indexes.sql
===================================================================
--- trunk/extensions/IndexFunction/indexes.sql 2011-09-21 19:00:41 UTC (rev
97754)
+++ trunk/extensions/IndexFunction/indexes.sql 2011-09-21 19:22:00 UTC (rev
97755)
@@ -1,7 +1,7 @@
CREATE TABLE /*$wgDBprefix*/indexes (
-- The pageid of the page containing the parser function
in_from int unsigned NOT NULL default 0,
-
+
-- The NS/title that should redirect to the page
in_namespace int NOT NULL default 0,
in_title varchar(255) binary NOT NULL default '',
Modified: trunk/extensions/IndexFunction/specialindex.js
===================================================================
--- trunk/extensions/IndexFunction/specialindex.js 2011-09-21 19:00:41 UTC
(rev 97754)
+++ trunk/extensions/IndexFunction/specialindex.js 2011-09-21 19:22:00 UTC
(rev 97755)
@@ -13,12 +13,12 @@
'}'+
'#use-js-note {'+
' display: block !important;'+
- '}'
+ '}'
);
/*
* Switch details between hidden/shown
-*/
+ */
function toggleVisibility(idNumber) {
var openarrow = document.getElementById("mw-index-open-"+idNumber);
var closearrow = document.getElementById("mw-index-close-"+idNumber);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs