User:Pinkgothic/DPL

Scope

 * Extension DynamicPageList (third-party)

Objective
A significant performance gain.

Solution

 * 1) In   find the method.
 * 2) Wrap the method body into an if-statement that executes only if the page is a Template:

function queueRecursiveJobs { global $wgUpdateRowsPerJob; wfProfileIn( __METHOD__ ); if ($this->mTitle->getNamespace === 10 /* Templates */) { /* ... original method body ... */    }     wfProfileOut( __METHOD__ ); }

You're done. Wasn't that easy?

Background
 a/k/a "...wait a second, exactly why the hell does that work?!"


 * Templates and Transclusion
 * What links here? and Special:Wanted pages
 * Job Queue

mediawiki 101
One thing you have to know about mediawiki is that aside from saving the text of every page when you hit the magical  button, it also parses out any internal links you've put into the page and stores this information in a separate table in the database. That's to make several essential functions in mediawiki's user interface significantly faster, and to make things like 'Wanted pages' and the Toolbox's What links here? and Related changes possible.

You may also be aware that mediawiki lets you use templates - pages that you can include in the flow of another page.

Now, imagine you have a template that contains an internal link. You've included it on a dozen other pages. Sensibly, mediawiki assumes that the links on those dozen pages are important to you in their entirety, so the internal link your template provides counts as a link from the dozen pages, as well. Less cryptically stated, assuming your template is uninventively called  and you have it included on the pages ,  ,   and  , and you link to the (equally uninventively titled) page  , mediawiki will want to store the following information for you:

A --> Foo B --> Foo C --> Foo D --> Foo Template:Link --> Foo

Additionally, it will store that the pages A, B, C and D are using the template 'Link' in the templateLinks table.

So, taking a look at your page 's What links here? will list:

* A * B * C * D * Template:Link

And looking at your template's What links here? will list:

* A (transclusion) * B (transclusion) * C (transclusion) * D (transclusion)

What happens if you change the link to 'Bar'? All the 'Foo' records that are in accordance with the 'Template:Link' records have to change. In other words, if you change the link on the template, mediawiki detects a change on the page and assumes it has to rebuild the link table for the pages that include the template. Mediawiki recognises that this is potentially a costly process that shouldn't slow you down in your editing, though, and only rebuilds the links for the template, directly, and queues the link tables of the other pages for later. Since the template is used on four pages, there are four jobs - one for each page.

Assuming you haven't change the job run rate, each time someone visits a page on your wiki, one job is taken care of. That means that as far as the page  is concerned, when you hit   on the initial edit, only the template is linking to it:

Template:Link --> Bar

The next time a page loads, the first job runs, and Bar knows of one more link to it:

A --> Bar Template:Link --> Bar

The next time a page loads, the next job runs...

A --> Bar B --> Bar Template:Link --> Bar

And so on and so forth until all our four jobs have completed.

Mediawiki determines the links by building the whole page and parsing out internal links. [how?] So far, so good!

In closing, know that mediawiki also allows you to transclude pages that aren't templates. Keep that in mind. It'll be important in the next section.

DPL 101
The third-party 'dynamic page list' extension lets you create dynamic lists of an almost entirely arbitrary subset of your Wiki's pages on any other Wiki page. The invocation of a DPL query is fairly complex and quite powerful, but an example should be enough to understand the basics:

&lt;DPL&gt; category = All extensions includepage = {Extension}:version:mediawiki allowcachedresults = true table = class="wikitable sortable" style="vertical-align:top",Extension,Version,For mediawiki version... &lt;/DPL&gt;

A query like that would pull all pages in the category "All extensions", then parse them for the template "Extension" and determine what the values for the parameters 'status' and 'mediawiki' are. For example, while parsing the page Extension:DynamicPageList (third-party) (which is in the "All extensions" category), it would find these lines:



The generated table would look something like this:

What happens on page load
@todo job queue

Side effects
If your wiki encourages non-Template page transclusion, you'll want to run refreshLinks.php as a cron job (, enter  for an hourly run). This is still a better solution than using the job queue for this purpose.