[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [websites/wiki-kde-org/develop] extensions/TitleKey: add titlekey extension
From:       Ingo Malchow <imalchow () kde ! org>
Date:       2012-07-24 20:50:25
Message-ID: 20120724205025.C4D16A60DA () git ! kde ! org
[Download RAW message or body]

Git commit 5724fc44dde944fb79f60cf11661ae0f1ee622c5 by Ingo Malchow.
Committed on 24/07/2012 at 22:46.
Pushed by imalchow into branch 'develop'.

add titlekey extension

A  +41   -0    extensions/TitleKey/README
A  +585  -0    extensions/TitleKey/TitleKey.i18n.php
A  +60   -0    extensions/TitleKey/TitleKey.php
A  +222  -0    extensions/TitleKey/TitleKey_body.php
A  +63   -0    extensions/TitleKey/rebuildTitleKeys.php
A  +10   -0    extensions/TitleKey/titlekey.pg.sql
A  +15   -0    extensions/TitleKey/titlekey.sql

http://commits.kde.org/websites/wiki-kde-org/5724fc44dde944fb79f60cf11661ae0f1ee622c5


diff --git a/extensions/TitleKey/README b/extensions/TitleKey/README
new file mode 100644
index 0000000..093cce6
--- /dev/null
+++ b/extensions/TitleKey/README
@@ -0,0 +1,41 @@
+This extension provides case-insensitive matches for a few points in
+MediaWiki's functionality:
+
+* "go" exact title matches
+* Prefix-based searches in OpenSearch (Firefox plugin) and internal AJAX \
searches +
+It does not provide complete case-insensitivity for title linking within \
the wiki. +
+
+== Database schema ==
+
+A 'titlekey' table is added to the wiki's database, which maintains a \
case-folded +copy of each page's title. This is then binary-indexed for \
matching and sorting. +
+The table must be present for the wiki to function once the extension is \
enabled, +and it must be populated for the title match functions to pick up \
matches. +
+
+== Installation ==
+
+To enable the extension, add the following line to your LocalSettings.php \
file: +
+  include "$IP/extensions/TitleKey/TitleKey.php";
+
+
+You must then create and populate the new database table.
+
+The easiest way to do this is to run MediaWIki's standard updaters:
+
+  php maintenance/update.php
+
+
+If you do not have command-line access to your server, you can manually
+apply the titlekey.sql file's commands to your database (check for proper
+table prefix, etc).
+
+
+== Repopulating the titlekey table ==
+
+The titlekey table can be repopulated by hand by running the \
rebuildTitleKeys.php +command-line script.
diff --git a/extensions/TitleKey/TitleKey.i18n.php \
b/extensions/TitleKey/TitleKey.i18n.php new file mode 100644
index 0000000..cf4018e
--- /dev/null
+++ b/extensions/TitleKey/TitleKey.i18n.php
@@ -0,0 +1,585 @@
+<?php
+/**
+ * Internationalisation file for extension TitleKey.
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$messages = array();
+
+/** English
+ * @author Brion Vibber
+ */
+$messages['en'] = array(
+	'titlekey-desc' => 'Title prefix search suggestion backend',
+);
+
+/** Message documentation (Message documentation)
+ * @author Mormegil
+ */
+$messages['qqq'] = array(
+	'titlekey-desc' => 'Description of the [[mw:Extension:TitleKey|TitleKey \
extension]], providing a case-insensitive title prefix search plugin', +);
+
+/** Afrikaans (Afrikaans)
+ * @author පසිඳු කාවින්ද
+ */
+$messages['af'] = array(
+	'titlekey-desc' => 'Titel voorvoegsel soek voorstel backend',
+);
+
+/** Aragonese (Aragonés)
+ * @author Juanpabl
+ */
+$messages['an'] = array(
+	'titlekey-desc' => 'Socherencias con prefixos en a busca por títols',
+);
+
+/** Arabic (العربية)
+ * @author Meno25
+ */
+$messages['ar'] = array(
+	'titlekey-desc' => 'نهاية اقتراح بحث عنوان \
البادئة', +);
+
+/** Egyptian Spoken Arabic (مصرى)
+ * @author Ramsis II
+ */
+$messages['arz'] = array(
+	'titlekey-desc' => 'نهاية اقتراح التدوير على \
بريفيكس للعنوان', +);
+
+/** Asturian (Asturianu)
+ * @author Esbardu
+ */
+$messages['ast'] = array(
+	'titlekey-desc' => 'Suxerencies de busca de prefixos de títulu',
+);
+
+/** Azerbaijani (Azərbaycanca)
+ * @author Sortilegus
+ */
+$messages['az'] = array(
+	'titlekey-desc' => 'Adın ilk hərflərinə görə ipucu axtarış \
sürgüsü', +);
+
+/** Bashkir (Башҡортса)
+ * @author Assele
+ */
+$messages['ba'] = array(
+	'titlekey-desc' => 'Исемдең тәүге хәрефтәре \
буйынса эҙләү тәҡдимдәре ҡоралы', +);
+
+/** Southern Balochi (بلوچی مکرانی)
+ * @author Mostafadaneshvar
+ */
+$messages['bcc'] = array(
+	'titlekey-desc' => 'عنوان پیشوند گردگ پیشنهاد \
ترینگ', +);
+
+/** Belarusian (Taraškievica orthography) (‪Беларуская \
(тарашкевіца)‬) + * @author EugeneZelenko
+ * @author Red Winged Duck
+ * @author Wizardist
+ */
+$messages['be-tarask'] = array(
+	'titlekey-desc' => 'Праграмная забесьпячэньне \
для пошукавых падказак па першых літарах \
назвы', +);
+
+/** Breton (Brezhoneg)
+ * @author Fulup
+ */
+$messages['br'] = array(
+	'titlekey-desc' => 'Stignad da ginnig enklaskoù dre rakgerioù titloù',
+);
+
+/** Bosnian (Bosanski)
+ * @author CERminator
+ */
+$messages['bs'] = array(
+	'titlekey-desc' => 'Pozadinski proces pri traženju po naslovima',
+);
+
+/** Chechen (Нохчийн)
+ * @author Sasan700
+ */
+$messages['ce'] = array(
+	'titlekey-desc' => 'Лохуш цlера дуьххьара элпца \
дош хьагойтуш болу гlирс', +);
+
+/** Czech (Česky)
+ * @author Mormegil
+ */
+$messages['cs'] = array(
+	'titlekey-desc' => 'Implementace našeptávače hledajícího podle \
počátku názvu', +);
+
+/** Danish (Dansk)
+ * @author Froztbyte
+ */
+$messages['da'] = array(
+	'titlekey-desc' => 'Bagstykke til søgning efter titelpræfiks',
+);
+
+/** German (Deutsch)
+ * @author Kghbln
+ * @author Raimond Spekking
+ */
+$messages['de'] = array(
+	'titlekey-desc' => 'Ermöglicht einen Hintergrundprozess für die \
Titelsuche', +);
+
+/** Zazaki (Zazaki)
+ * @author Aspar
+ */
+$messages['diq'] = array(
+	'titlekey-desc' => 'pêşniyazê pêşkeşwani, cıgêrayişê prefixê \
sernameyi', +);
+
+/** Lower Sorbian (Dolnoserbski)
+ * @author Michawiki
+ */
+$messages['dsb'] = array(
+	'titlekey-desc' => 'Proces w slězynje za naraźenje pytanja za titlami',
+);
+
+/** Greek (Ελληνικά)
+ * @author Dead3y3
+ */
+$messages['el'] = array(
+	'titlekey-desc' => 'Backend για την πρόταση \
αναζήτησης προθέματος τίτλου', +);
+
+/** Esperanto (Esperanto)
+ * @author Yekrats
+ */
+$messages['eo'] = array(
+	'titlekey-desc' => 'Etendilo por serĉosugestoj laŭ titola prefikso',
+);
+
+/** Spanish (Español)
+ * @author Sanbec
+ */
+$messages['es'] = array(
+	'titlekey-desc' => 'Mecanismo para sugerir búsquedas por prefijo de \
título', +);
+
+/** Estonian (Eesti)
+ * @author Pikne
+ */
+$messages['et'] = array(
+	'titlekey-desc' => 'Pealkirja eesliiteotsinguvihjete taustprotsess',
+);
+
+/** Basque (Euskara)
+ * @author Kobazulo
+ */
+$messages['eu'] = array(
+	'titlekey-desc' => 'Izenburuaren aurrizkiarekin bilaketak iradokitzeko \
mekanismoa', +);
+
+/** Persian (فارسی)
+ * @author Huji
+ */
+$messages['fa'] = array(
+	'titlekey-desc' => 'پشتوانه پیشنهاد جستجو بر \
اساس پیشوند عنوان', +);
+
+/** Finnish (Suomi)
+ * @author Crt
+ */
+$messages['fi'] = array(
+	'titlekey-desc' => 'Taustajärjestelmä otsikon alkuosaan perustuvan haun \
ennakoivalle tekstinsyötölle.', +);
+
+/** French (Français)
+ * @author Grondin
+ * @author McDutchie
+ * @author Verdy p
+ */
+$messages['fr'] = array(
+	'titlekey-desc' => 'Mécanisme de suggestion de recherche par préfixe de \
titre', +);
+
+/** Franco-Provençal (Arpetan)
+ * @author ChrisPtDe
+ */
+$messages['frp'] = array(
+	'titlekey-desc' => 'Mècanismo de consèly de rechèrche per prèfixo de \
titro.', +);
+
+/** Galician (Galego)
+ * @author Toliño
+ */
+$messages['gl'] = array(
+	'titlekey-desc' => 'Procura de suxestión por prefixos de títulos',
+);
+
+/** Swiss German (Alemannisch)
+ * @author Als-Holder
+ */
+$messages['gsw'] = array(
+	'titlekey-desc' => 'Hintergrundprozäss fir d Titelsuechi',
+);
+
+/** Hebrew (עברית)
+ * @author Rotem Liss
+ */
+$messages['he'] = array(
+	'titlekey-desc' => 'מערכת לעיבוד הצעות החיפוש \
לפי התחלה של כותרת', +);
+
+/** Hindi (हिन्दी)
+ * @author Kaustubh
+ */
+$messages['hi'] = array(
+	'titlekey-desc' => 'शीर्षक उपपद खोज \
सजेशन बॅकएन्ड', +);
+
+/** Hiligaynon (Ilonggo)
+ * @author Tagimata
+ */
+$messages['hil'] = array(
+	'titlekey-desc' => 'Titulo prefiks pangitaon sugestiyon bakend',
+);
+
+/** Croatian (Hrvatski)
+ * @author Dalibor Bosits
+ */
+$messages['hr'] = array(
+	'titlekey-desc' => 'Daje prijedlog traženja po prefiksu',
+);
+
+/** Upper Sorbian (Hornjoserbsce)
+ * @author Michawiki
+ */
+$messages['hsb'] = array(
+	'titlekey-desc' => 'Pozadkowy proces za namjety tituloweho pytanja',
+);
+
+/** Hungarian (Magyar)
+ * @author Dani
+ */
+$messages['hu'] = array(
+	'titlekey-desc' => 'Címek keresésekor címeket ajánl az előtagjuk \
alapján', +);
+
+/** Interlingua (Interlingua)
+ * @author McDutchie
+ */
+$messages['ia'] = array(
+	'titlekey-desc' => 'Mechanismo pro facer suggestiones de recerca per \
prefixo de titulo', +);
+
+/** Indonesian (Bahasa Indonesia)
+ * @author IvanLanin
+ * @author Rex
+ */
+$messages['id'] = array(
+	'titlekey-desc' => 'Alat pemrosesan di belakang layar untuk pencarian \
awalan judul', +);
+
+/** Italian (Italiano)
+ * @author Pietrodn
+ */
+$messages['it'] = array(
+	'titlekey-desc' => 'Backend dei suggerimenti per la ricerca dei prefissi \
dei titoli', +);
+
+/** Japanese (日本語)
+ * @author Fryed-peach
+ * @author JtFuruhata
+ */
+$messages['ja'] = array(
+	'titlekey-desc' => \
'ページ名の前方一致インクリメンタル検索を実現する内部機構',
 +);
+
+/** Javanese (Basa Jawa)
+ * @author Meursault2004
+ */
+$messages['jv'] = array(
+	'titlekey-desc' => 'Backend prosès panggolèkan irah-irahan préfiks',
+);
+
+/** Georgian (ქა თული)
+ * @author გიო გიმელა
+ */
+$messages['ka'] = array(
+	'titlekey-desc' => 'საძიება დახმა \
ებათა ძ ავა სიტყვების პი \
ველი ასოების გამოყენებით', +);
+
+/** Korean (한국어)
+ * @author Kwj2772
+ */
+$messages['ko'] = array(
+	'titlekey-desc' => '문서  목의  두어로 검색어를  안',
+);
+
+/** Colognian (Ripoarisch)
+ * @author Purodha
+ */
+$messages['ksh'] = array(
+	'titlekey-desc' => 'Deit em Hengerjrond noh de Aanfäng fun Sigge-Tittele \
söke un de jefonge Tittele vörschlare.', +);
+
+/** Luxembourgish (Lëtzebuergesch)
+ * @author Robby
+ */
+$messages['lb'] = array(
+	'titlekey-desc' => 'Hannergrondprozess fir no Titelen ze sichen',
+);
+
+/** Limburgish (Limburgs)
+ * @author Matthias
+ */
+$messages['li'] = array(
+	'titlekey-desc' => 'Backend veur zeuksuggesties veur \
paginanaamveurvoegsels', +);
+
+/** Lithuanian (Lietuvių)
+ * @author Matasg
+ */
+$messages['lt'] = array(
+	'titlekey-desc' => 'Pavadinimo prefikso paieška pasiūlymo \
sugrąžinimui', +);
+
+/** Macedonian (Македонски)
+ * @author Bjankuloski06
+ */
+$messages['mk'] = array(
+	'titlekey-desc' => 'Сугерирање при \
пребарувањето на префикс на наслови', +);
+
+/** Malayalam (മലയാളം)
+ * @author Praveenp
+ */
+$messages['ml'] = array(
+	'titlekey-desc' => 'പിന്തുണയ്ക്കായി \
തലക്കെട്ടിന്റെ പൂർവ്വപദ \
തിരച്ചിൽ നിർദ്ദേശം', +);
+
+/** Marathi (मरा ी)
+ * @author Kaustubh
+ */
+$messages['mr'] = array(
+	'titlekey-desc' => 'शीर्षक उपपद शोध \
सल्ला बॅकएन्ड', +);
+
+/** Malay (Bahasa Melayu)
+ * @author Aviator
+ */
+$messages['ms'] = array(
+	'titlekey-desc' => 'Atur cara untuk cadangan gelintar bagi awalan tajuk',
+);
+
+/** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬)
+ * @author Jon Harald Søby
+ */
+$messages['nb'] = array(
+	'titlekey-desc' => 'Bakstykke for søk etter tittelprefiks',
+);
+
+/** Low German (Plattdüütsch)
+ * @author Slomox
+ */
+$messages['nds'] = array(
+	'titlekey-desc' => 'Achtergrundprozess för de Titelsöök',
+);
+
+/** Dutch (Nederlands)
+ * @author Siebrand
+ */
+$messages['nl'] = array(
+	'titlekey-desc' => 'Backend voor zoeksuggesties voor \
paginanaamvoorvoegsels', +);
+
+/** Norwegian Nynorsk (‪Norsk (nynorsk)‬)
+ * @author Frokor
+ */
+$messages['nn'] = array(
+	'titlekey-desc' => 'Bakstykke for søk etter tittelprefiks',
+);
+
+/** Occitan (Occitan)
+ * @author Cedric31
+ */
+$messages['oc'] = array(
+	'titlekey-desc' => "Retorn cap a la fin de la suggestion de recèrca d'un \
prefix de títol", +);
+
+/** Polish (Polski)
+ * @author Sp5uhe
+ */
+$messages['pl'] = array(
+	'titlekey-desc' => 'Obsługa podpowiedzi w wyszukiwarce na podstawie \
wpisanego początku tytułu', +);
+
+/** Piedmontese (Piemontèis)
+ * @author Dragonòt
+ */
+$messages['pms'] = array(
+	'titlekey-desc' => '"Backend" dij sugeriment dl\'arserca dij prefiss dij \
tìtoj', +);
+
+/** Portuguese (Português)
+ * @author Malafaya
+ */
+$messages['pt'] = array(
+	'titlekey-desc' => 'Motor de sugestão de pesquisa por prefixo de \
título', +);
+
+/** Brazilian Portuguese (Português do Brasil)
+ * @author Eduardo.mps
+ */
+$messages['pt-br'] = array(
+	'titlekey-desc' => 'Motor de sugestão de pesquisa por prefixo de \
título', +);
+
+/** Romanian (Română)
+ * @author AdiJapan
+ */
+$messages['ro'] = array(
+	'titlekey-desc' => 'Mecanism de sugestie de căutare prin prefixul \
titlului', +);
+
+/** Tarandíne (Tarandíne)
+ * @author Joetaras
+ */
+$messages['roa-tara'] = array(
+	'titlekey-desc' => "'A ricerche d'u prefisse d'u titele se consiglie da \
rete", +);
+
+/** Russian ( усский)
+ * @author Александр Сигачёв
+ */
+$messages['ru'] = array(
+	'titlekey-desc' => 'Движок поисковых подсказок \
по первым буквам названия', +);
+
+/** Rusyn ( усиньскый)
+ * @author Gazeb
+ */
+$messages['rue'] = array(
+	'titlekey-desc' => 'Імлементація нашепкавача \
глядаючого за початком назвы', +);
+
+/** Sakha (Саха тыла)
+ * @author HalanTul
+ */
+$messages['sah'] = array(
+	'titlekey-desc' => 'Көрдүүргэ сатабыллаах \
буоллун диэн аат бастакы буукубаларыгар \
эбэн этэн биэрии движога', +);
+
+/** Slovak (Slovenčina)
+ * @author Helix84
+ */
+$messages['sk'] = array(
+	'titlekey-desc' => 'Backend pre návrh prefixového vyhľadávania názvu \
stránky', +);
+
+/** Slovenian (Slovenščina)
+ * @author Dbc334
+ */
+$messages['sl'] = array(
+	'titlekey-desc' => 'Podpora predlogom iskanja strani po korenu',
+);
+
+/** Serbian (Cyrillic script) (‪Српски (ћирилица)‬)
+ * @author Millosh
+ */
+$messages['sr-ec'] = array(
+	'titlekey-desc' => 'Позадинска машина за \
претрагу префикса наслова.', +);
+
+/** Serbian (Latin script) (‪Srpski (latinica)‬)
+ * @author Michaello
+ */
+$messages['sr-el'] = array(
+	'titlekey-desc' => 'Pozadinska mašina za pretragu prefiksa naslova.',
+);
+
+/** Seeltersk (Seeltersk)
+ * @author Pyt
+ */
+$messages['stq'] = array(
+	'titlekey-desc' => 'Bäätergruundprozess foar ju Tittelsäike',
+);
+
+/** Swedish (Svenska)
+ * @author M.M.S.
+ */
+$messages['sv'] = array(
+	'titlekey-desc' => 'Bakstycke för sökning efter titelprefix',
+);
+
+/** Telugu (తెలుగు)
+ * @author Kiranmayee
+ */
+$messages['te'] = array(
+	'titlekey-desc' => 'శీర్షిక ప్రీఫిక్స్  \
వెతుకు సలహా బ్యాక్ఎండ్', +);
+
+/** Turkmen (Türkmençe)
+ * @author Hanberke
+ */
+$messages['tk'] = array(
+	'titlekey-desc' => 'At pristawkasy gözlegi teklip beriji işi',
+);
+
+/** Tagalog (Tagalog)
+ * @author AnakngAraw
+ */
+$messages['tl'] = array(
+	'titlekey-desc' => 'Mungkahing katapusang panghulihan pagkaraan ng \
paghahanap ng unlaping pampamagat', +);
+
+/** Turkish (Türkçe)
+ * @author Joseph
+ */
+$messages['tr'] = array(
+	'titlekey-desc' => 'Başlık öneki araması öneri sunucu uygulaması',
+);
+
+/** Ukrainian (Українська)
+ * @author Ahonc
+ */
+$messages['uk'] = array(
+	'titlekey-desc' => 'Двигун пошукових підказок за \
першими літерами назви', +);
+
+/** Vèneto (Vèneto)
+ * @author Candalua
+ */
+$messages['vec'] = array(
+	'titlekey-desc' => 'Motor de sugerimento de riserca par prefissi de \
titolo', +);
+
+/** Vietnamese (Tiếng Việt)
+ * @author Vinhtantran
+ */
+$messages['vi'] = array(
+	'titlekey-desc' => 'Bộ giúp đỡ tìm kiếm theo tiền tố của \
tựa đề', +);
+
+/** Cantonese (粵語)
+ * @author Shinjiman
+ */
+$messages['yue'] = array(
+	'titlekey-desc' => '標題前綴搵嘢建議背幹',
+);
+
+/** Simplified Chinese (‪中文(简体)‬)
+ * @author PhiLiP
+ * @author Shinjiman
+ */
+$messages['zh-hans'] = array(
+	'titlekey-desc' => ' 题前缀搜寻建议后台',
+);
+
+/** Traditional Chinese (‪中文(繁體)‬)
+ * @author Shinjiman
+ */
+$messages['zh-hant'] = array(
+	'titlekey-desc' => '標題前綴搜尋建議背幹',
+);
+
diff --git a/extensions/TitleKey/TitleKey.php \
b/extensions/TitleKey/TitleKey.php new file mode 100644
index 0000000..4ece835
--- /dev/null
+++ b/extensions/TitleKey/TitleKey.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Copyright (C) 2008 Brion Vibber <brion@pobox.com>
+ * http://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+$wgExtensionCredits['other'][] = array(
+	'path' => __FILE__,
+	'name' => 'TitleKey',
+	'author' => 'Brion Vibber',
+	'descriptionmsg' => 'titlekey-desc',
+	'url' => 'https://www.mediawiki.org/wiki/Extension:TitleKey',
+);
+
+// The 'SearchUpdate' hook would be right, but it's called in the
+// wrong place and I don't want to rewrite it all just this second.
+
+// Update hooks...
+$wgHooks['ArticleDelete'        ][] = 'TitleKey::updateDeleteSetup';
+$wgHooks['ArticleDeleteComplete'][] = 'TitleKey::updateDelete';
+$wgHooks['ArticleInsertComplete'][] = 'TitleKey::updateInsert';
+$wgHooks['ArticleUndelete'      ][] = 'TitleKey::updateUndelete';
+$wgHooks['TitleMoveComplete'    ][] = 'TitleKey::updateMove';
+
+// Maintenance hooks...
+$wgHooks['ParserTestTables'          ][] = 'TitleKey::testTables';
+$wgHooks['LoadExtensionSchemaUpdates'][] = 'TitleKey::schemaUpdates';
+
+// Search hooks...
+// Delay setup to avoid compatibility problems with hook ordering
+// when coexisting with MWSearch... we want MWSearch to be able to
+// take over the PrefixSearchBackend hook without disabling the
+// SearchGetNearMatch hook point.
+$wgExtensionFunctions[] = 'efTitleKeySetup';
+
+function efTitleKeySetup() {
+	global $wgHooks;
+	$wgHooks['PrefixSearchBackend'][] = 'TitleKey::prefixSearchBackend';
+	$wgHooks['SearchGetNearMatch' ][] = 'TitleKey::searchGetNearMatch';
+}
+
+$dir = dirname(__FILE__) . '/';
+$wgExtensionMessagesFiles['TitleKey'] = $dir . 'TitleKey.i18n.php';
+$wgAutoloadClasses['TitleKey'] = $dir . 'TitleKey_body.php';
+$wgAutoloadClasses['RebuildTitleKeys'] = $dir . 'rebuildTitleKeys.php';
diff --git a/extensions/TitleKey/TitleKey_body.php \
b/extensions/TitleKey/TitleKey_body.php new file mode 100644
index 0000000..9b02a9d
--- /dev/null
+++ b/extensions/TitleKey/TitleKey_body.php
@@ -0,0 +1,222 @@
+<?php
+/**
+ * Copyright (C) 2008 Brion Vibber <brion@pobox.com>
+ * http://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+class TitleKey {
+	static $deleteIds = array();
+	
+	// Active functions...
+	static function deleteKey( $id ) {
+		$db = wfGetDB( DB_MASTER );
+		$db->delete( 'titlekey',
+			array( 'tk_page' => $id ),
+			__METHOD__ );
+	}
+
+	static function setKey( $id, $title ) {
+		self::setBatchKeys( array( $id => $title ) );
+	}
+	
+	static function setBatchKeys( $titles ) {
+		$rows = array();
+		foreach( $titles as $id => $title ) {
+			$rows[] = array(
+				'tk_page' => $id,
+				'tk_namespace' => $title->getNamespace(),
+				'tk_key' => self::normalizeTitle( $title ),
+			);
+		}
+		$db = wfGetDB( DB_MASTER );
+		$db->replace( 'titlekey', array( 'tk_page' ),
+			$rows,
+			__METHOD__ );
+	}
+	
+	
+	// Normalization...
+	static function normalizeTitle( $title ) {
+		return self::normalize( $title->getText() );
+	}
+	
+	static function normalize( $text ) {
+		global $wgContLang;
+		return $wgContLang->caseFold( $text );
+	}
+
+
+	// Hook functions....
+
+	static function updateDeleteSetup( $article, $user, $reason ) {
+		$title = $article->mTitle->getPrefixedText();
+		self::$deleteIds[$title] = $article->getID();
+		return true;
+	}
+
+	static function updateDelete( $article, $user, $reason ) {
+		$title = $article->mTitle->getPrefixedText();
+		if( isset( self::$deleteIds[$title] ) ) {
+			self::deleteKey( self::$deleteIds[$title] );
+		}
+		return true;
+	}
+
+	static function updateInsert( $article, $user, $text, $summary, $isMinor, \
$isWatch, $section, $flags, $revision ) { +		self::setKey( \
$article->getId(), $article->getTitle() ); +		return true;
+	}
+	
+	static function updateMove( $from, $to, $user, $fromid, $toid ) {
+		// FIXME
+		self::setKey( $toid, $from );
+		self::setKey( $fromid, $to );
+		return true;
+	}
+
+	static function testTables( &$tables ) {
+		$tables[] = 'titlekey';
+		return true;
+	}
+
+	static function updateUndelete( $title, $isnewid ) {
+		$article = new Article($title);
+		$id = $article->getID();
+		self::setKey( $id, $title );
+		return true;
+	}
+	
+	/**
+	 * Apply schema updates as necessary.
+	 * If creating the titlekey table for the first time,
+	 * will populate the table with all titles in the page table.
+	 *
+	 * Status info is sent to stdout.
+	 */
+	public static function schemaUpdates( $updater = null ) {
+		$updater->addExtensionUpdate( array( array( __CLASS__, 'runUpdates' ) ) \
); +		return true;
+	}
+
+	public static function runUpdates( $updater ) {
+		$db = $updater->getDB();
+		if( $db->tableExists( 'titlekey' ) ) {
+			$updater->output( "...titlekey table already exists.\n" );
+		} else {
+			$updater->output( "Creating titlekey table..." );
+			$sourcefile = $db->getType() == 'postgres' ? '/titlekey.pg.sql' : \
'/titlekey.sql'; +			$err = $db->sourceFile( dirname( __FILE__ ) . \
$sourcefile ); +			if( $err !== true ) {
+				throw new MWException( $err );
+			}
+
+			$updater->output( "ok.\n" );
+			$task = $updater->maintenance->runChild( 'RebuildTitleKeys' );
+			$task->execute();
+		}
+	}
+
+	/**
+	 * Override the default OpenSearch backend...
+	 * @param string $search term
+	 * @param int $limit max number of items to return
+	 * @param array &$results out param -- list of title strings
+	 */
+	static function prefixSearchBackend( $ns, $search, $limit, &$results ) {
+		$results = self::prefixSearch( $ns, $search, $limit );
+		return false;
+	}
+	
+	static function prefixSearch( $namespaces, $search, $limit ) {
+		$ns = array_shift( $namespaces ); // support only one namespace
+		if( in_array( NS_MAIN, $namespaces ) )
+			$ns = NS_MAIN; // if searching on many always default to main 
+		
+		$key = self::normalize( $search );
+		
+		$dbr = wfGetDB( DB_SLAVE );
+		$result = $dbr->select(
+			array( 'titlekey', 'page' ),
+			array( 'page_namespace', 'page_title' ),
+			array(
+				'tk_page=page_id',
+				'tk_namespace' => $ns,
+				'tk_key ' . $dbr->buildLike( $key, $dbr->anyString() ),
+			),
+			__METHOD__,
+			array(
+				'ORDER BY' => 'tk_key',
+				'LIMIT' => $limit ) );
+		
+		// Reformat useful data for future printing by JSON engine
+		$srchres = array();
+		foreach( $result as $row ) {
+			$title = Title::makeTitle( $row->page_namespace, $row->page_title );
+			$srchres[] = $title->getPrefixedText();
+		}
+		$result->free();
+		
+		return $srchres;
+	}
+	
+	/**
+	 * Find matching titles after the default 'go' search exact match fails.
+	 * This'll let 'mcgee' match 'McGee' etc.
+	 * @param string $term
+	 * @param Title outparam &$title
+	 */
+	static function searchGetNearMatch( $term, &$title ) {
+		$temp = Title::newFromText( $term );
+		if( $temp ) {
+			$match = self::exactMatchTitle( $temp );
+			if( $match ) {
+				// Yay!
+				$title = $match;
+				return false;
+			}
+		}
+		// No matches. :(
+		return true;
+	}
+	
+	static function exactMatchTitle( $title ) {
+		$ns = $title->getNamespace();
+		return self::exactMatch( $ns, $title->getText() );
+	}
+	
+	static function exactMatch( $ns, $text ) {
+		$key = self::normalize( $text );
+		
+		$dbr = wfGetDB( DB_SLAVE );
+		$row = $dbr->selectRow(
+			array( 'titlekey', 'page' ),
+			array( 'page_namespace', 'page_title' ),
+			array(
+				'tk_page=page_id',
+				'tk_namespace' => $ns,
+				'tk_key' => $key,
+			),
+			__METHOD__ );
+		
+		if( $row ) {
+			return Title::makeTitle( $row->page_namespace, $row->page_title );
+		} else {
+			return null;
+		}
+	}
+}
diff --git a/extensions/TitleKey/rebuildTitleKeys.php \
b/extensions/TitleKey/rebuildTitleKeys.php new file mode 100644
index 0000000..c26c2c6
--- /dev/null
+++ b/extensions/TitleKey/rebuildTitleKeys.php
@@ -0,0 +1,63 @@
+<?php
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false )
+	$IP = dirname( __FILE__ ) . '/../..';
+
+require_once( "$IP/maintenance/Maintenance.php" );
+
+// In case we want to do offline initialization...
+if( !class_exists( 'TitleKey' ) ) {
+	require dirname( __FILE__ ) . '/TitleKey_body.php';
+}
+
+class RebuildTitleKeys extends Maintenance {
+	function __construct() {
+		parent::__construct();
+		$this->mDescription = "Rebuilds titlekey table entries for all pages in \
DB."; +		$this->setBatchSize( 1000 );
+		$this->addOption( 'start', 'Page ID to start from', false, true );
+	}
+
+	function execute() {
+		$start = $this->getOption( 'start', 0 );
+		$this->output( "Rebuilding titlekey table...\n" );
+		$dbr = $this->getDB( DB_SLAVE );
+
+		$maxId = $dbr->selectField( 'page', 'MAX(page_id)', '', __METHOD__ );
+		
+		$lastId = 0;
+		for( ; $start <= $maxId; $start += $this->mBatchSize ) {
+			if( $start != 0 ) {
+				$this->output( "... $start...\n" );
+			}
+			$result = $dbr->select( 'page',
+				array( 'page_id', 'page_namespace', 'page_title' ),
+				array( 'page_id > ' . intval( $start ) ),
+				__METHOD__,
+				array(
+					'ORDER BY' => 'page_id',
+					'LIMIT' => $this->mBatchSize ) );
+			
+			$titles = array();
+			foreach( $result as $row ) {
+				$titles[$row->page_id] =
+					Title::makeTitle( $row->page_namespace, $row->page_title );
+				$lastId = $row->page_id;
+			}
+			$result->free();
+			
+			TitleKey::setBatchKeys( $titles );
+			
+			wfWaitForSlaves( 20 );
+		}
+		if( $lastId ) {
+			$this->output( "... $lastId ok.\n" );
+		} else {
+			$this->output( "... no pages.\n" );
+		}
+	}
+}
+
+$maintClass = 'RebuildTitleKeys';
+require_once( RUN_MAINTENANCE_IF_MAIN );
diff --git a/extensions/TitleKey/titlekey.pg.sql \
b/extensions/TitleKey/titlekey.pg.sql new file mode 100644
index 0000000..3adf96e
--- /dev/null
+++ b/extensions/TitleKey/titlekey.pg.sql
@@ -0,0 +1,10 @@
+
+-- Postgres version of schema for the TitleKey extension
+
+CREATE TABLE titlekey (
+  tk_page       INTEGER   NOT NULL PRIMARY KEY,
+  tk_namespace  SMALLINT  NOT NULL,
+  tk_key        TEXT      NOT NULL
+);
+
+CREATE INDEX titlekey_name_key ON titlekey(tk_namespace, tk_key);
diff --git a/extensions/TitleKey/titlekey.sql \
b/extensions/TitleKey/titlekey.sql new file mode 100644
index 0000000..7662126
--- /dev/null
+++ b/extensions/TitleKey/titlekey.sql
@@ -0,0 +1,15 @@
+CREATE TABLE /*$wgDBprefix*/titlekey (
+  -- Ref to page_id
+  tk_page int unsigned NOT NULL,
+
+  -- Keep a denormalized copy of the namespace for filtering
+  tk_namespace int NOT NULL,
+
+  -- Normalized title.
+  -- With namespace prefix, case-folded, in space form.
+  tk_key varchar(255) binary NOT NULL,
+  
+  PRIMARY KEY tk_page (tk_page),
+  INDEX name_key (tk_namespace, tk_key)
+
+) /*$wgDBTableOptions*/;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic