Chapter 9 Browsing and searching
Viewing the set of all pages
MediaWiki provides a standard way of seeing the entire set of pages in the wiki: the special page Special:AllPages. It lets you view an alphabetical list of pages in the wiki for each namespace, other than “Special:” – that includes all the namespaces, so you can also view categories, templates, files, etc. Figure 9 shows the top of the page Special:AllPages for mediawiki.org.
The listing of page ranges in Figure 9 keeps going like that for another 10 lines. Clicking on any of those names will display a list of all the pages within that row's alphabetical range; that list is separated into three columns.
You can also use the form at the top to display a manual list of pages within a certain alphabetical range.
For pages in the "File:" namespace, i.e. pages for uploaded files, there's an alternate way to see them listed: the page
Special:ListFiles. This special page has an advantage over Special:AllPages in that it also shows a thumbnail image for each file.
Figure 9 shows how the page Special:ListFiles looks on mediawiki.org.
For each file, the following information is shown: the date it was uploaded, or last uploaded if more than one version has been uploaded; a thumbnail of the file if it's an image; its size; the user who last uploaded it; and a description of the file, if one was submitted during the upload. The name of each file is a link to that file's page in the “File:” namespace, while the subsequent “(file)” link is a link directly to that file.
Searching
MediaWiki search functionality is available via its search bar, which in the Vector skin shows up on the top of the page (Figure 9 shows it in the context of the whole set of interface tabs, on Wikipedia).
When a user does a search, they are sent to the page Special:Search, which handles all the actual search functionality. This page lets the user modify their search term, as well as change the set of namespaces that are being searched.
Within Special:Search, assuming you're using the Vector skin, if the user runs their search and then clicks on the “Advanced” link, they will see an interface like the one shown in Figure 9.
Searches always start out being done only for namespaces defined as being "content namespaces", which by default is just the main (blank) namespace. As an administrator, you can change that by adding to $wgContentNamespaces. For instance, to also get pages in the "Help:" namespace to be searched, you would add the following to LocalSettings.php:
$wgContentNamespaces = [NS_MAIN, NS_HELP];
Each link changes the set of namespaces being searched. MediaWiki's search interface is case-insensitive. If a user enters text in the search box that exactly matches the name of a page, they will be sent directly to that page. Which is usually the right behavior; but what if the user wants to instead search on that text? This could be more obvious in the interface, but the way for the user to do it is to type in the search string, then wait for the autocompletion dropdown to show up, and select the last item, “containing... search-string”.
Installing another search engine
MediaWiki's default search simply uses SQL querying. It's not bad, although it is sometimes criticized as primitive. Notably, it lacks the ability to find alternate spellings of words. It also ignores any advanced search-engine syntax, though it does support the most common syntax, of putting phrases in quotations to indicate that they should show up exactly as written.
There were formerly various different solutions to search engine applications that can be be substituted in to MediaWiki in place of the default one, but at this point there is really only one: Elasticsearch
. It is the search engine used on all Wikimedia sites, and it works quite well: it checks for misspellings, it searches on the text of pages when the templates are fully expanded, not on the raw wikitext (which, in most cases, is the right behavior), and it can search on the text of uploaded files, such as Word documents and PDFs. Perhaps needless to say, it is also open source.
To use it, you also will need to install the extension Elastica
, which is what directly interfaces with Elasticsearch:
Conversely, there may be cases where you want to do precise searches on wikitext – to find all pages where a specific parser function is called with a specific parameter, for instance. For such cases, one unexpected trick adopted by some wiki administrators is to use the Replace Text extension
(here); although it was not intended for this purpose, you can use its search-and-replace functionality to make precise searches on wikitext, including the use of regular expressions. Just make sure not to hit the “Replace” button at the end!
Using an outside search engine
The other possibility for search is to use an outside search engine, and the overwhelming favorite for this option is Google.
Google provides an easy-to-install "custom search" functionality, formerly known as Google Custom Search and now known as Google Programmable Search Engine, which is documented at:
The
GoogleCustomWikiSearch extension lets you place the input for this custom search anywhere on the page, including in place of the existing search input:
There are a few advantages to using Google's search in place of an internal one: Google's search interface is top-notch, and it's also very well-known to people. And instead of searching through the wikitext, as most internal MediaWiki search options will do, a Google search will look at what's actually displayed on the page – which in some cases could be quite different, especially if extensions like Widgets or External Data are used.
There are also some downsides, though: this setup only works for public wikis, unless you're willing to pay to install a local Google search engine on your site. And it will take some time for Google (or any other outside engine) to see changes to your wiki, so recent edits will most likely not show up in search results.