Number of pages in a Mediawiki site

I wanted to know how many A4 pages I would have to print on a printer, if I wanted to print all the articles in a Mediawiki installation.

We have a Mediawiki installation with a total number of 1,418 content pages.

I already managed to export all the articles to their respective PDF files.

This I did with another bash-script I wrote (I will add this in another post later on).

First I had to find the file-names of all the PDF files located in my export directory:
find . -type f -name '*.pdf' | sed 's/\.\///g' > /tmp/pdffiles.txt;

Then I could use this PHP code for counting the number of a4 pages to print if the selected PDF file should be printed. The number of pages to print is a number located in the PDF file.


if (!$fp = fopen($FILEN,"r")) {
echo ‘failed opening file ‘.$FILEN;
else {
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match(‘/\/Count [0-9]+/’, $line, $matches)){
preg_match(‘/[0-9]+/’,$matches[0], $matches2);
if ($max<$matches2[0]) $max=$matches2[0];
echo "There ".($max<2?"is ":"are ").$max." page".($max<2?"":"s")." in ". $FILEN.".\r\n";

The PHP code would have the file as an argument, and would be run on the command line with:
php test.php "filename.pdf"
The output would be something like:
There are 2 pages in KlientRegnemaskiner.pdf.

I would gather all the 1418 lines with this command in a bash file name:

php test.php "Uibrepo.pdf"
php test.php "Maskinen sender mailer til ukjente adresser.pdf"
php test.php "IP-telefon feilfinning.pdf"
php test.php "Puppetklient.pdf"
php test.php "WordPress.pdf"
php test.php "Basware - Overføre OM-lisens i Basware IP.pdf"

and run the command with:
./ | awk {'print $3'} >> numberofpages.txt
The file numberofpages.txt will contain a list of numbers, each representing the number of pages per PDF file:


In order to sum up everything, i would then run this command:
paste -sd+ numberofpages.txt | bc

The result in my case was: 4109 pages.
Which means that from the 1418 wiki articles, I would have to print 4109 A4 pages. Let’s say a a normal book contains of 300 pages, then I would have 14 books.


Leave a Reply

Your email address will not be published. Required fields are marked *