28 if ( !defined(
'MEDIAWIKI' ) ) {
29 die(
'Not an entry point.' );
39 class Special
extends \SpecialPage {
45 function __construct() {
49 parent::__construct(
'LinkTitles',
'linktitles-batch' );
50 $this->config =
new Config();
53 function getGroupName() {
62 function execute( $par ) {
64 if ( !$this->userCanExecute( $this->getUser() ) ) {
65 $this->displayRestrictionError();
69 $request = $this->getRequest();
70 $output = $this->getOutput();
76 if ( $request->wasPosted() ) {
77 if ( array_key_exists(
's', $request->getValues() ) ) {
78 $this->process( $request, $output );
82 $this->buildInfoPage( $request, $output );
87 $this->buildInfoPage( $request, $output );
98 private function process( \WebRequest &$request, \OutputPage &$output) {
100 $namespacesClause = str_replace(
'_',
' ',
'(' . implode(
', ',$this->config->sourceNamespaces ) .
')' );
103 $startTime = microtime(
true );
106 $dbr = wfGetDB( DB_SLAVE );
110 $postValues = $request->getValues();
114 $start = intval( $postValues[
's'] );
117 if ( array_key_exists(
'e', $postValues ) ) {
118 $end = intval( $postValues[
'e'] );
123 $end = $this->countPages( $dbr, $namespacesClause );
126 array_key_exists(
'r', $postValues ) ? $reloads = $postValues[
'r'] : $reloads = 0;
131 array(
'page_title',
'page_namespace'),
133 'page_namespace IN ' . $namespacesClause,
137 'LIMIT' => 999999999,
143 foreach ( $res as $row ) {
144 $curTitle = \Title::makeTitleSafe( $row->page_namespace, $row->page_title);
145 Extension::processPage( $curTitle, $this->getContext() );
149 if ( microtime(
true ) - $startTime > $config->specialPageReloadAfter )
155 $this->addProgressInfo( $output, $curTitle, $start, $end );
164 $output->addHTML( $this->getReloaderForm( $request->getRequestURL(),
165 $start, $end, $reloads) );
169 $this->addCompletedInfo( $output, $start, $end, $reloads );
177 private function buildInfoPage( &$request, &$output ) {
178 $output->addWikiMsg(
'linktitles-special-info', Extension::URL );
179 $url = $request->getRequestURL();
180 $submitButtonLabel = $this->msg(
'linktitles-special-submit' );
183 <form method=
"post" action=
"${url}">
184 <input type=
"submit" value=
"$submitButtonLabel" />
185 <input type=
"hidden" name=
"s" value=
"0" />
198 private function addProgressInfo( &$output, $curTitle, $index, $end ) {
199 $progress = $index / $end * 100;
200 $percent = sprintf(
"%01.1f", $progress);
202 $output->addWikiMsg(
'linktitles-special-progress', Extension::URL, $curTitle );
203 $pageInfo = $this->msg(
'linktitles-page-count', $index, $end );
204 $output->addWikiMsg(
'linktitles-special-page-count', $index, $end );
207 <div style=
"width:100%; padding:2px; border:1px solid #000; position: relative; margin-bottom:16px;">
208 <span style=
"position: absolute; left: 50%; font-weight:bold; color:#555;">${percent}%</span>
209 <div style=
"width:${progress}%; background-color:#bbb; height:20px; margin:0;"></div>
213 $output->addWikiMsg(
'linktitles-special-cancel-notice' );
225 private function getReloaderForm( $url, $start, $end, $reloads ) {
228 <form method=
"post" name=
"linktitles" action=
"${url}">
229 <input type=
"hidden" name=
"s" value=
"${start}" />
230 <input type=
"hidden" name=
"e" value=
"${end}" />
231 <input type=
"hidden" name=
"r" value=
"${reloads}" />
233 <script type=
"text/javascript">
234 document.linktitles.submit();
248 private function addCompletedInfo( &$output, $start, $end, $reloads ) {
249 $pagesPerReload = sprintf(
'%0.1f', $end / $reloads);
250 $output->addWikiMsg(
'linktitltes-special-completed-info', $end,
251 $config->specialPageReloadAfter, $reloads, $pagesPerReload
260 private function countPages( &$dbr, $namespacesClause ) {
263 array(
'pagecount' =>
"COUNT(page_id)"),
265 'page_namespace IN ' . $namespacesClause,
270 return $res->current()->pagecount;
The LinkTitles class holds configuration for the LinkTitles extension.