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.1 shows the top of the page Special:AllPages for mediawiki.org.
Figure 9.1 Special:AllPages on mediawiki.org
The listing of page ranges in Figure 9.1 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.2 shows how the page Special:ListFiles looks on mediawiki.org.
Figure 9.2 Special:ListFiles 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.
MediaWiki search functionality is available via its search bar, which in the Vector skin shows up on the top of the page (Figure 9.3).
Figure 9.3 Search bar in the Vector skin
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.4.
Figure 9.4 Special:Search page
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 = array( 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 are two search engine applications that can be be substituted in to MediaWiki in place of the default one: Elasticsearch
. Both have features that the regular MediaWiki search doesn't, like checking for misspellings, and both are open source.
The Elasticsearch engine is available via the MediaWiki extension called CirrusSearch
To use it, you also will need to install the extension Elastica, which is what directly interfaces with Elasticsearch:
Elasticsearch/CirrusSearch works very well, and is the default search engine used on Wikipedia. It is superior to Sphinx in a few key ways. Perhaps its biggest advantage is that it searches on the text of pages when the templates are fully expanded, not on the raw wikitext. Another big advantage it that it searches on the text of uploaded files, such as Word documents and PDFs. It also seems to excel in terms of both speed and support for non-Latin characters.
To use Sphinx instead, you need to install Sphinx, as well as the SphinxSearch MediaWiki extension. You can view that one here:
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.