23 if ( !defined(
'MEDIAWIKI' ) ) {
24 die(
'Not an entry point.' );
39 parent::__construct(
'LinkTitles',
'linktitles-batch');
47 if ( !$this->userCanExecute( $this->getUser() ) ) {
48 $this->displayRestrictionError();
52 $request = $this->getRequest();
53 $output = $this->getOutput();
59 if ( $request->wasPosted() ) {
60 if ( array_key_exists(
's', $request->getValues()) ) {
61 $this->process($request, $output);
65 $this->buildInfoPage($request, $output);
70 $this->buildInfoPage($request, $output);
80 private function process( WebRequest &$request, OutputPage &$output) {
84 $startTime = microtime(
true);
87 $dbr = wfGetDB( DB_SLAVE );
91 $postValues = $request->getValues();
95 $start = intval($postValues[
's']);
98 if ( array_key_exists(
'e', $postValues) ) {
99 $end = intval($postValues[
'e']);
104 $end = $this->countPages($dbr);
107 array_key_exists(
'r', $postValues) ?
108 $reloads = $postValues[
'r'] :
116 'page_namespace = 0',
120 'LIMIT' => 999999999,
126 foreach ( $res as $row ) {
127 $curTitle = $row->page_title;
132 if ( microtime(
true)-$startTime > $wgLinkTitlesTimeLimit )
138 $this->addProgressInfo($output, $curTitle, $start, $end);
147 $output->addHTML($this->getReloaderForm($request->getRequestURL(),
148 $start, $end, $reloads));
152 $this->addCompletedInfo($output, $start, $end, $reloads);
158 private function buildInfoPage(&$request, &$output) {
159 $url = $request->getRequestURL();
162 $output->addWikiText(
169 You can start a batch linking process by clicking on the button below.
170 This will go through every page in the normal
namespace of your Wiki and
171 insert links automatically. This page will repeatedly reload itself, in
172 order to prevent blocking the server. To interrupt the process, simply
178 <form method=
"post" action=
"${url}">
179 <input type=
"submit" value=
"Start linking" />
180 <input type=
"hidden" name=
"s" value=
"0" />
192 private function addProgressInfo(&$output, $curTitle, $index, $end) {
193 $progress = $index / $end * 100;
194 $percent = sprintf(
"%01.1f", $progress);
196 $output->addWikiText(
198 == Processing pages... ==
200 extension is currently going through every page of your wiki, adding links to
201 existing pages as appropriate.
203 === Current page: $curTitle ===
208 <p>Page ${index} of ${end}.</p>
209 <div style=
"width:100%; padding:2px; border:1px solid #000; position: relative;
210 margin-bottom:16px;">
211 <span style=
"position: absolute; left: 50%; font-weight:bold; color:#555;">
214 <div style=
"width:${progress}%; background-color:#bbb; height:20px; margin:0;"></div>
218 $output->addWikiText(
220 === To abort, close
this page, or hit the
'Stop' button in your browser ===
234 private function getReloaderForm($url, $start, $end, $reloads) {
237 <form method=
"post" name=
"linktitles" action=
"${url}">
238 <input type=
"hidden" name=
"s" value=
"${start}" />
239 <input type=
"hidden" name=
"e" value=
"${end}" />
240 <input type=
"hidden" name=
"r" value=
"${reloads}" />
242 <script type=
"text/javascript">
243 document.linktitles.submit();
255 private function addCompletedInfo(&$output, $start, $end, $reloads) {
257 $pagesPerReload = sprintf(
'%0.1f', $end / $reloads);
258 $output->addWikiText(
260 == Batch processing completed! ==
263 | total number of pages: || ${end}
265 | timeout setting [s]: || ${wgLinkTitlesTimeLimit}
267 | webpage reloads: || ${reloads}
269 | pages scanned per reload interval: || ${pagesPerReload}
278 private function countPages(&$dbr) {
283 'page_namespace = 0',
287 return $res->numRows();
Central class of the extension.
execute($par)
Entry function of the special page class.
Provides a special page that can be used to batch-process all pages in the wiki.
$wgLinkTitlesTimeLimit
Time limit for online batch processing.
__construct()
Constructor.
static processPage($title, RequestContext $context)
Automatically processes a single page, given a $title Title object.